forked from satanson/cpp_etudes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze4.pl
executable file
·141 lines (120 loc) · 4.22 KB
/
analyze4.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my ($fragment, $instance, $pipeline, $driver, $operator, $opid)=(undef)x6;
my %opcost=();
my @uniq_keys=();
my $plan={};
sub norm_time($) {
my $t = shift;
my %unit=(ns=>1000000, us=>1000, ms=>1);
if ($t=~/^(\d+(?:\.\d+)?)(ns|us|ms)$/){
return ($1+0.0)/$unit{$2};
}
elsif ($t=~/^(\d+)s(\d+)ms$/) {
return ($1+0)*1000+$2;
}
else {
die "undefined time format!";
return undef;
}
}
sub norm_num($) {
my $n = shift;
my %unit=(M=>1000000, K=>1000);
if ($n=~/^(\d+(?:\.\d+)?)(M|K)$/) {
return ($1+0.0)*$unit{$2};
} elsif ($n=~/^\d+$/) {
return $n+0;
} else {
die "undefined number format!";
return undef;
}
}
while(<>) {
if (/Fragment\s+(\d+)/){
$fragment = "Fragment($1)";
next;
}
if (/Instance\s+(\S+)/){
$instance = "Instance($1)";
next;
}
if (/Pipeline\s+\(id=(\d+)\)/) {
$pipeline = "Pipeline($1)";
$plan->{$fragment}{$instance}{pipelines}{$pipeline}{id}=join "_", ($fragment, $instance, $pipeline);
next;
}
if (/PipelineDriver\s+\(id=(\d+)\):/){
$driver = "Driver($1)";
$plan->{$fragment}{$instance}{pipelines}{$pipeline}{drivers}{$driver}{id}=join "_", ($fragment, $instance, $pipeline, $driver);
next;
}
if (/(\w+)\s+\(plan_node_id=(\d+)\):/){
$operator = "$1($2)";
$opid="plan_node_id=$2";
next;
}
if (/(\w+)\s+\(pseudo_plan_node_id=(-\d+)\):/){
$operator = "$1($2)";
$opid="pseudo_plan_node_id=$2";
next;
}
if (/DegreeOfParallelism:\s+(\d+)/) {
$plan->{$fragment}{$instance}{pipelines}{$pipeline}{DegreeOfParallelism}=$1+0;
next;
}
if (/(DriverActiveTime|DriverPendingTime|DriverInputEmptyTime|DriverFirstInputEmptyTime|DriverFollowupInputEmptyTime|DriverOutputFullTime|DriverPreconditionBlockTime|DriverTotalTime):\s+(\S+)/) {
$plan->{$fragment}{$instance}{pipelines}{$pipeline}{drivers}{$driver}{$1}=norm_time($2);
next;
}
if (/(LocalRfWaitingSet|ScheduleAccumulatedChunkMoved|ScheduleAccumulatedRowsPerChunk|ScheduleCounter|ScheduleEffectiveCounter):\s+(\d+)/){
$plan->{$fragment}{$instance}{pipelines}{$pipeline}{drivers}{$driver}{$1}=$2;
next;
}
if (/(?:Pull|Push)TotalTime:\s+(\S+)/) {
if (!defined($operator)){
next;
}
my $uniq_key = join "_", ($fragment, $instance, $pipeline, $driver, $operator);
if (!exists $opcost{$uniq_key}) {
$opcost{$uniq_key} = 0;
$plan->{$fragment}{$instance}{pipelines}{$pipeline}{drivers}{$driver}{ops}{$uniq_key}{op}=$operator;
$plan->{$fragment}{$instance}{pipelines}{$pipeline}{drivers}{$driver}{ops}{$uniq_key}{key}=$uniq_key;
$plan->{$fragment}{$instance}{pipelines}{$pipeline}{drivers}{$driver}{ops}{$uniq_key}{id}=$opid;
}
$opcost{$uniq_key}+=norm_time($1);
}
if (/(PullChunkNum|PushChunkNum|PullRowNum|PushRowNum):\s+(\S+)/) {
if (!defined($operator)){
next;
}
my $uniq_key = join "_", ($fragment, $instance, $pipeline, $driver, $operator);
$plan->{$fragment}{$instance}{pipelines}{$pipeline}{drivers}{$driver}{ops}{$uniq_key}{$1}=norm_num($2);
}
}
my @opcost=sort {$a->[1] <=> $b->[1]} map{[$_,$opcost{$_}]} keys %opcost;
#print join ("\n", map {sprintf("%0.3f", $_->[1])."\t". $_->[0]} @opcost);
#print "\n";
#print Dumper($plan);
my $ops=[map {values %{$_->{ops}}} map {values %{$_->{drivers}}} map {values %$_} map {values %$_} map {values %$_} values %$plan];
#print Dumper($ops);
use List::Util qw(sum);
for my $op (@$ops) {
$op->{AvgPullChunkSize}=$op->{PullChunkNum}==0? 0 : $op->{PullRowNum}/$op->{PullChunkNum};
$op->{AvgPushChunkSize}=$op->{PushChunkNum}==0? 0 : $op->{PushRowNum}/$op->{PushChunkNum};
}
my $limit = 100;
if ((exists $ENV{limit}) && int($ENV{limit})>0) {
$limit = int($ENV{limit});
}
if ((exists $ENV{type}) && $ENV{type} eq "pull") {
my $index="AvgPullChunkSize";
print join "\n", map {sprintf "%0.3f\t%d\t%s\t%s", $_->{$index}, $_->{PullChunkNum}, $index, $_->{id}} sort{$b->{$index}<=>$a->{$index}} grep {$_->{PullChunkNum}>$limit} @$ops;
print "\n";
} else {
my $index="AvgPushChunkSize";
print join "\n", map {sprintf "%0.3f\t%d\t%s\t%s", $_->{$index}, $_->{PushChunkNum}, $index, $_->{id}} sort{$b->{$index}<=>$a->{$index}} grep {$_->{PushChunkNum}>$limit} @$ops;
print "\n";
}