← Index
NYTProf Performance Profile   « line view »
For runner.pl
  Run on Thu Jul 3 15:14:19 2014
Reported on Thu Jul 3 15:16:35 2014

Filename/home/rjamet/Work/Code/sinalgo/runnerv3/Runner/Stats.pm
StatementsExecuted 355884 statements in 10.7s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11813110.5s10.7sRunner::Stats::::computeOnMessagesRunner::Stats::computeOnMessages
1116.67ms7.04msRunner::Stats::::computeAtTheEndRunner::Stats::computeAtTheEnd
1111.67ms10.6msRunner::Stats::::BEGIN@8Runner::Stats::BEGIN@8
50211189µs189µsRunner::Stats::::CORE:matchRunner::Stats::CORE:match (opcode)
11163µs63µsRunner::Stats::::CORE:sortRunner::Stats::CORE:sort (opcode)
11137µs70µsRunner::Stats::::BEGIN@3Runner::Stats::BEGIN@3
11131µs148µsRunner::Stats::::BEGIN@7Runner::Stats::BEGIN@7
11119µs19µsRunner::Stats::::BEGIN@6Runner::Stats::BEGIN@6
11117µs29µsRunner::Stats::::BEGIN@4Runner::Stats::BEGIN@4
11117µs92µsRunner::Stats::::BEGIN@5Runner::Stats::BEGIN@5
0000s0sRunner::Stats::::__ANON__[Runner/Stats.pm:107]Runner::Stats::__ANON__[Runner/Stats.pm:107]
0000s0sRunner::Stats::::__ANON__[Runner/Stats.pm:52]Runner::Stats::__ANON__[Runner/Stats.pm:52]
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Runner::Stats;
2
3266µs2102µs
# spent 70µs (37+33) within Runner::Stats::BEGIN@3 which was called: # once (37µs+33µs) by Runner::IO::BEGIN@47 at line 3
use strict;
# spent 70µs making 1 call to Runner::Stats::BEGIN@3 # spent 33µs making 1 call to strict::import
4277µs240µs
# spent 29µs (17+11) within Runner::Stats::BEGIN@4 which was called: # once (17µs+11µs) by Runner::IO::BEGIN@47 at line 4
use warnings;
# spent 29µs making 1 call to Runner::Stats::BEGIN@4 # spent 11µs making 1 call to warnings::import
5261µs2167µs
# spent 92µs (17+75) within Runner::Stats::BEGIN@5 which was called: # once (17µs+75µs) by Runner::IO::BEGIN@47 at line 5
use Carp qw/ confess carp /;
# spent 92µs making 1 call to Runner::Stats::BEGIN@5 # spent 75µs making 1 call to Exporter::import
6283µs119µs
# spent 19µs within Runner::Stats::BEGIN@6 which was called: # once (19µs+0s) by Runner::IO::BEGIN@47 at line 6
use Runner::IO;
# spent 19µs making 1 call to Runner::Stats::BEGIN@6
7278µs2166µs
# spent 148µs (31+117) within Runner::Stats::BEGIN@7 which was called: # once (31µs+117µs) by Runner::IO::BEGIN@47 at line 7
use List::Util qw/reduce sum max min any first/;
# spent 148µs making 1 call to Runner::Stats::BEGIN@7 # spent 18µs making 1 call to List::Util::import
824.78ms210.8ms
# spent 10.6ms (1.67+8.94) within Runner::Stats::BEGIN@8 which was called: # once (1.67ms+8.94ms) by Runner::IO::BEGIN@47 at line 8
use List::MoreUtils qw/first_index/;
# spent 10.6ms making 1 call to Runner::Stats::BEGIN@8 # spent 213µs making 1 call to Exporter::import
9
1011µsmy $RA_SAMPLES = 500;
11#my $RA_SAMPLES = 10;
121200nsmy $RD_SAMPLES = 500;
13#my $RD_SAMPLES = 10;
141200nsmy $RE_TIMEWINDOW = 100;
15
16#Used to compute all the means and stddev and so on
17
# spent 10.7s (10.5+259ms) within Runner::Stats::computeOnMessages which was called 1181 times, avg 9.07ms/call: # 1179 times (10.4s+259ms) by main::RUNTIME at line 106 of runner.pl, avg 9.08ms/call # once (5.61ms+30µs) by main::RUNTIME at line 130 of runner.pl # once (3.99ms+36µs) by main::RUNTIME at line 112 of runner.pl
sub computeOnMessages($$) {
18
1911811.10ms my $data = shift;
2011811.57ms my $command = shift;
21
2211813.61ms if (!exists $data->{inc_vars}) {
23 #first run, create the data
2415µs $data->{inc_vars}->{last_id_RA} = 0;
2511µs $data->{inc_vars}->{last_id_RA_ack} = 0;
261800ns $data->{inc_vars}->{last_id_RD} = 0;
2712µs $data->{inc_vars}->{last_id_RD_ack} = 0;
28 } else {
29 #reuse old data
30 }
31
32 #Runner::IO::tprint "### Extracting the uniques send times\n";
33
3411811.08ms $data->{average_rolling} = [] unless exists $data->{average_rolling};
351181804µs $data->{average_rolling_ack} = [] unless exists $data->{average_rolling_ack};
361181748µs $data->{delivery_rolling} = [] unless exists $data->{delivery_rolling};
371181825µs $data->{delivery_rolling_ack} = [] unless exists $data->{delivery_rolling_ack};
381181689µs $data->{energy_rolling} = [] unless exists $data->{energy_rolling};
39
40 ###################################
41 # NUMBER OF HOPS FOR MSG
42 ###################################
43
44 #Runner::IO::tprint "### Computing averages on send times\n";
45
46
47 #The following thing is not noticeably faster than a simple grep,
48 #strangely
4911811.29ms my $lid = $data->{inc_vars}->{last_id_RA};
50 my $fi =
51 first_index
52294632178ms { $_->{id} > $lid }
53118117.5ms1181174ms @{$data->{msg_data}};
# spent 174ms making 1181 calls to List::MoreUtils::firstidx, avg 147µs/call
54
5511812.15ms if (!defined($fi) || $fi eq "") {die()}
561181420µs my @sorted;
5711811.14ms if($fi >= 0) {
58 @sorted = grep {
59
60 $_->{d} == 1 &&
61 $_->{type} eq "basic"
6211811.17s } @{$data->{msg_data}}[$fi .. @{$data->{msg_data}}-1 ];
63
- -
6611812.37ms while( scalar @sorted >= $RA_SAMPLES) {
6780035.6ms my @cur = splice @sorted, 0, $RA_SAMPLES;
68800195ms8007.16ms my $h_r = ( sum map{$_->{h}} @cur ) / @cur;
# spent 7.16ms making 800 calls to List::Util::sum, avg 9µs/call
69800173ms8005.40ms my $o_r = ( sum map{$_->{o}} @cur ) / @cur;
# spent 5.40ms making 800 calls to List::Util::sum, avg 7µs/call
70800175ms8004.84ms my $t_r = ( sum map{$_->{tb}} @cur ) / @cur;
# spent 4.84ms making 800 calls to List::Util::sum, avg 6µs/call
71800359ms8005.78ms my $tph_r =( sum map{ ($_->{te} - $_->{tb})/$_->{h} } @cur ) / @cur;
# spent 5.78ms making 800 calls to List::Util::sum, avg 7µs/call
72
738005.66ms push @{$data->{average_rolling}}, {"h" => $h_r, "t" => $t_r, "tph" => $tph_r, "o"=> $o_r};
74800148ms8004.56ms $data->{inc_vars}->{last_id_RA} = max map{$_->{id}} @cur;
# spent 4.56ms making 800 calls to List::Util::max, avg 6µs/call
75 }
76}
77
78 ###################################
79 # DELIVERY RATE FOR MSG
80 ###################################
81
82 #Runner::IO::tprint "### Computing average delivery rates\n";
83 @sorted = grep {
84 $_->{type} eq "basic" &&
85 $_->{id} > $data->{inc_vars}->{last_id_RD}
8611811.20s } @{$data->{msg_data}};
8711811.86ms while (scalar @sorted >= $RD_SAMPLES) {
88100041.2ms my @cur = splice @sorted, 0, $RD_SAMPLES;
891000133ms my $eaten_r = ( scalar grep { $_->{d} == 0 } @cur ) / @cur;
90100093.1ms my $ok_r = ( scalar grep { $_->{d} == 1 } @cur ) / @cur;
91100084.9ms my $ttl_r = ( scalar grep { $_->{d} == 2 } @cur ) / @cur;
92100083.8ms my $other_r = ( scalar grep { $_->{d} >= 3 } @cur ) / @cur;
93
941000227ms10009.70ms my $t_r = ( sum map{$_->{tb}} @cur ) / @cur;
# spent 9.70ms making 1000 calls to List::Util::sum, avg 10µs/call
9510007.16ms push @{$data->{delivery_rolling}},
96 {"eaten" => $eaten_r, "ok" => $ok_r,"ttl"=>$ttl_r, "other"=>$other_r, "t" => $t_r};
97
981000170ms10005.47ms $data->{inc_vars}->{last_id_RD} = max map{$_->{id}} @cur;
# spent 5.47ms making 1000 calls to List::Util::max, avg 5µs/call
99 }
100
101 ####################################
102 # NBHOPS + DELIVERY RATE FOR ACKS
103 ####################################
104
105
106 #FIXME : could be faster by 1/3 if we remove this when not used
107475529.1ms11817.00ms if (any {$_->{type} eq "ack"} @{$data->{msg_data}}) {
# spent 7.00ms making 1181 calls to List::Util::any, avg 6µs/call
108
109 my @sorted = grep {
110 ($_->{d} == 1 || $_->{d} == 3) &&
111 $_->{id} > $data->{inc_vars}->{last_id_RA_ack} &&
112 $_->{type} eq "ack"
11311811.56s } @{$data->{msg_data}};
114
11511812.30ms while( scalar @sorted >= $RA_SAMPLES) {
11677040.1ms my @cur = splice @sorted, 0, $RA_SAMPLES;
117770167ms7706.04ms my $h_r = ( sum map{$_->{h}} @cur ) / @cur;
# spent 6.04ms making 770 calls to List::Util::sum, avg 8µs/call
118770179ms7705.27ms my $t_r = ( sum map{$_->{tb}} @cur ) / @cur;
# spent 5.27ms making 770 calls to List::Util::sum, avg 7µs/call
119770338ms7705.68ms my $tph_r =( sum map{ ($_->{te} - $_->{tb})/$_->{h} } @cur ) / @cur;
# spent 5.68ms making 770 calls to List::Util::sum, avg 7µs/call
120
1217705.40ms push @{$data->{average_rolling_ack}}, {"h" => $h_r, "t" => $t_r, "tph" => $tph_r};
122770141ms7704.30ms $data->{inc_vars}->{last_id_RA_ack} = max map{$_->{id}} @cur;
# spent 4.30ms making 770 calls to List::Util::max, avg 6µs/call
123
124 }
125
126 #Runner::IO::tprint "### Computing average delivery rates for acks\n";
127 @sorted = grep {
128 $_->{id} > $data->{inc_vars}->{last_id_RD_ack} &&
129 $_->{type} eq "ack"
13011811.31s } @{$data->{msg_data}};
131118110.9ms while (scalar @sorted >= $RD_SAMPLES) {
13280032.2ms my @cur = splice @sorted, 0, $RD_SAMPLES;
133800104ms my $eaten_r = ( scalar grep { $_->{d} == 0 } @cur ) / @cur;
13480071.8ms my $ok_r = ( scalar grep { $_->{d} == 1 } @cur ) / @cur;
13580067.9ms my $ttl_r = ( scalar grep { $_->{d} == 2 } @cur ) / @cur;
13680066.1ms my $forgot_r =( scalar grep { $_->{d} == 3 } @cur ) / @cur;
13780065.7ms my $other_r = ( scalar grep { $_->{d} >= 4 } @cur ) / @cur;
138
139800180ms8007.45ms my $t_r = ( sum map{$_->{tb}} @cur ) / @cur;
# spent 7.45ms making 800 calls to List::Util::sum, avg 9µs/call
1408005.46ms push @{$data->{delivery_rolling_ack}}, {
141 "eaten" => $eaten_r,
142 "ok" => $ok_r,
143 "ttl"=>$ttl_r,
144 "for"=>$forgot_r,
145 "other"=>$other_r,
146 "t" => $t_r
147 };
148
149800136ms8004.32ms $data->{inc_vars}->{last_id_RD_ack} = max map{$_->{id}} @cur;
# spent 4.32ms making 800 calls to List::Util::max, avg 5µs/call
150 }
151 } else {
152 $data->{inc_vars}->{last_id_RD_ack} = $data->{msg_data}->[-1]->{id};
153 $data->{inc_vars}->{last_id_RA_ack} = $data->{msg_data}->[-1]->{id};
154 }
155
- -
15911819.99ms11812.15ms my $last_useful_id = min(
# spent 2.15ms making 1181 calls to List::Util::min, avg 2µs/call
160 (
161 $data->{inc_vars}->{last_id_RA},
162 $data->{inc_vars}->{last_id_RA_ack},
163 $data->{inc_vars}->{last_id_RD},
164 $data->{inc_vars}->{last_id_RD_ack}
165 )
166 );
167
1681181640ms my @newdata = grep {$_->{id} > $last_useful_id} @{$data->{msg_data}};
16911811.01s undef @{$data->{msg_data}};
17011814.28ms $data->{msg_data} = \@newdata;
171
172118126.5ms 1;
173}
174
- -
178
# spent 7.04ms (6.67+365µs) within Runner::Stats::computeAtTheEnd which was called: # once (6.67ms+365µs) by main::RUNTIME at line 134 of runner.pl
sub computeAtTheEnd($$) {
179
1801900ns my $data = shift;
18112µs my $command = shift;
182
183 ####################################
184 # STUFF COMPUTED AFTER EVERYTHING ELSE
185 ####################################
186
187134µs if (@{$data->{average_rolling}}) {
188 $data->{simulation}->{mean_nbh} =
1891705µs117µs ( sum map {$_->{h}} @{$data->{average_rolling}} ) / @{$data->{average_rolling}};
# spent 17µs making 1 call to List::Util::sum
190 $data->{simulation}->{mean_overhead} =
1911464µs114µs ( sum map {$_->{o}} @{$data->{average_rolling}} ) / @{$data->{average_rolling}};
# spent 14µs making 1 call to List::Util::sum
192 } else {
193 Runner::IO::tprint("Problem : too few delivered messages to make an average of the nbhops, possibly they all got lost\n");
194 $data->{simulation}->{mean_nbh} = -1;
195 }
196
197143µs if (@{$data->{delivery_rolling_ack}}) {
198 $data->{simulation}->{total_dr_ack_received} =
19911.08ms117µs ( sum map {$_->{ok} + $_->{for}} @{$data->{delivery_rolling_ack}} ) / @{$data->{delivery_rolling_ack}};
# spent 17µs making 1 call to List::Util::sum
200 $data->{simulation}->{total_dr_ack_remembered} =
2011392µs115µs ( sum map {$_->{ok}} @{$data->{delivery_rolling_ack}} ) / @{$data->{delivery_rolling_ack}};
# spent 15µs making 1 call to List::Util::sum
202 }
203
204 #Fairness as we do it
205 my @cleandata = #BEURK
2061318µs grep {($_->{t} ne "blackhole") && ($_->{t} ne "sink") && ($_->{t} ne "SFnode")} @{$data->{nodes}};
207
20812µs unless(@cleandata) {
209 carp("No nodes which are not BH ?\n");
210 $data->{simulation}->{nothing_delivered}=1;
211 return 1;
212 } else {
213
21414µs $data->{simulation}->{nothing_delivered}=0;
215
2161114µs17µs my $sqfairness = ((sum map {$_->{dr}} @cleandata) / @cleandata)**2;
# spent 7µs making 1 call to List::Util::sum
2171118µs14µs my $fairnesssq = (sum map {$_->{dr}**2} @cleandata) / @cleandata;
# spent 4µs making 1 call to List::Util::sum
218111µs $data->{simulation}->{fairness} = sqrt($fairnesssq - $sqfairness);
219 }
220
221 #Moustache plot DR/node
222 @cleandata =
223 sort {$a <=> $b}
224 map {$_->{dr}}
2251385µs163µs grep {$_->{t} ne "blackhole" && $_->{t} ne "sink" && ($_->{t} ne "SFnode")} @{$data->{nodes}};
# spent 63µs making 1 call to Runner::Stats::CORE:sort
22616µs $data->{simulation}->{boxplot}->[0] = $cleandata[int (@cleandata*0.1)];
22712µs $data->{simulation}->{boxplot}->[1] = $cleandata[int (@cleandata*0.25)];
22812µs $data->{simulation}->{boxplot}->[2] = $cleandata[int (@cleandata*0.5)];
22911µs $data->{simulation}->{boxplot}->[3] = $cleandata[int (@cleandata*0.75)];
23012µs $data->{simulation}->{boxplot}->[4] = $cleandata[int (@cleandata*0.9)];
231
232 #Stacks ORANGE-like
2333221.65ms502189µs @cleandata = grep {$_->{t} !~ /blackhole/ && $_->{t} !~ /sink/ && ($_->{t} ne "SFnode")} @{$data->{nodes}};
# spent 189µs making 502 calls to Runner::Stats::CORE:match, avg 377ns/call
234168µs $data->{simulation}->{classes}->[0] = grep {$_->{dr} <= 0} @cleandata;
235187µs $data->{simulation}->{classes}->[1] = grep {$_->{dr} > 0.0 && $_->{dr} <= 0.33} @cleandata;
236183µs $data->{simulation}->{classes}->[2] = grep {$_->{dr} > 0.33 && $_->{dr} <= 0.66} @cleandata;
237187µs $data->{simulation}->{classes}->[3] = grep {$_->{dr} > 0.66 && $_->{dr} < 1} @cleandata;
238152µs $data->{simulation}->{classes}->[4] = grep {$_->{dr} >= 1} @cleandata;
239
240142µs if ( @{$data->{delivery_rolling}} ) {
241 $data->{simulation}->{total_dr} =
2421788µs120µs ( sum map {$_->{ok}} @{$data->{delivery_rolling}} ) / @{$data->{delivery_rolling}};
# spent 20µs making 1 call to List::Util::sum
243 $data->{simulation}->{total_ttl} =
2441477µs118µs ( sum map {$_->{ttl}} @{$data->{delivery_rolling}} ) / @{$data->{delivery_rolling}};
# spent 18µs making 1 call to List::Util::sum
245
246 } else {
247 carp("Everything is terrible, no delivered messages ? ...");
248 }
249
250
251120µs return 1;
252}
253
- -
25619µs1;
 
# spent 189µs within Runner::Stats::CORE:match which was called 502 times, avg 377ns/call: # 502 times (189µs+0s) by Runner::Stats::computeAtTheEnd at line 233, avg 377ns/call
sub Runner::Stats::CORE:match; # opcode
# spent 63µs within Runner::Stats::CORE:sort which was called: # once (63µs+0s) by Runner::Stats::computeAtTheEnd at line 225
sub Runner::Stats::CORE:sort; # opcode