forked from satanson/cpp_etudes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sr_dop_np.pl
executable file
·118 lines (105 loc) · 3.25 KB
/
sr_dop_np.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
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my ($fragment, $instance, $operator, $opid)=(undef)x4;
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;
}
elsif ($t=~/^-(\d+(?:\.\d+)?)(ns|us|ms)$/){
return -($1+0.0)/$unit{$2};
}
else {
die "undefined time format!'$t'";
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;
}
}
my $pipeline_dop={};
while(<>) {
if (/Fragment\s+(\d+)/){
$fragment = "Fragment($1)";
next;
}
if (/Instance\s+(\S+)/){
$instance = $fragment."_Instance($1)";
next;
}
if (/(\w+)\s+\(id=(\d+)\):\(Active:\s+(\S+?)\[/) {
$operator = "$1($2)";
my $id = join "_", ($fragment, $instance, $operator);
$plan->{$fragment}{instances}{$instance}{operators}{$operator}{op_id}=$operator;
$plan->{$fragment}{instances}{$instance}{operators}{$operator}{id}=$id;
$plan->{$fragment}{instances}{$instance}{operators}{$operator}{plan_node_id}=$2;
$plan->{$fragment}{instances}{$instance}{operators}{$operator}{ActiveTime}=norm_time($3);
next;
}
if (/DataStreamSender\s+\(dst_id=(\d+).*Active:\s+(\S+?)\[/) {
$operator = "DataStreamSender($1)";
my $id = join "_", ($fragment, $instance, $operator);
$plan->{$fragment}{instances}{$instance}{operators}{$operator}{op_id}=$operator;
$plan->{$fragment}{instances}{$instance}{operators}{$operator}{id}=$id;
$plan->{$fragment}{instances}{$instance}{operators}{$operator}{plan_node_id}=$1;
$plan->{$fragment}{instances}{$instance}{operators}{$operator}{ActiveTime}=norm_time($2);
next;
}
if (/ScanTime:\s+(\S+)/) {
$plan->{$fragment}{instances}{$instance}{operators}{$operator}{ActiveTime}=norm_time($1);
}
}
my $instances=[map {values %$_} values %$plan];
my $ops=[map {values %$_} map {$_->{operators}} map {values %$_} @$instances];
my @ops=@$ops;
my $op_dop={};
use List::Util qw(max);
for my $op (@ops) {
my $opid=$op->{op_id};
if (!exists $op_dop->{$opid}){
$op_dop->{$opid}{dop} = 0;
$op_dop->{$opid}{plan_node_id} = $op->{plan_node_id};
$op_dop->{$opid}{instance_num} = 0;
$op_dop->{$opid}{ActiveTime}=$op->{ActiveTime};
$op_dop->{$opid}{id} = $op->{id};
}
$op_dop->{$opid}{dop} += 1;
$op_dop->{$opid}{instance_num} += 1;
if ($op_dop->{$opid}{ActiveTime} < $op->{ActiveTime}) {
$op_dop->{$opid}{ActiveTime} = $op->{ActiveTime};
$op_dop->{$opid}{id} = $op->{id};
}
}
#print Dumper($op_dop);
my $sort_by="plan_node_id";
if (exists $ENV{plan_node_id}) {
$sort_by="ActiveTime";
}
print join "\n", map {
sprintf "id=%s\tdop=%s\tinst=%s\ttime=%0.3f\t%s\t%s",
substr("".$op_dop->{$_}{plan_node_id}." ", 0, 4),
substr("".$op_dop->{$_}{dop}." ", 0, 3),
substr("".$op_dop->{$_}{instance_num}." ", 0, 4),
$op_dop->{$_}{ActiveTime},
$_,
$op_dop->{$_}{id}
} sort{$op_dop->{$a}{$sort_by}<=> $op_dop->{$b}{$sort_by}} keys %$op_dop;
print "\n";