bench/run-performance-regression.pl

filter: Statementstmt 96.3% 399 / 414 Branchbran 65.4% 89 / 136 Conditioncond 43.1% 22 / 51 MC/DCmcdc 9.0% 3 / 33 Subroutinesub 86.3% 63 / 73 Podpod n/a totaltotal 81.4% 576 / 707 CC 79 SCAR 14.7
CC
79
Cov
85%
compare_reports
12.0
stream_throughput
10.1
throughput_client_read
10.0
CRAP 4.4
« bench/run-stream-watcher-state-bench.pl ↑ Summary bench/run-resolver-microbench.pl »
1 #!/usr/bin/env perl
2 2 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use File::Basename qw(dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use FindBin qw($Bin);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Getopt::Long qw(GetOptions);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use JSON::PP qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use POSIX qw(strftime uname);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Socket qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 AF_INET AF_UNIX INADDR_LOOPBACK PF_UNSPEC
14 SOCK_STREAM SOCK_NONBLOCK SOCK_CLOEXEC
15 SOL_SOCKET SO_LINGER
16 2 );
17 2 ▶use Time::HiRes qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
18 clock_gettime CLOCK_MONOTONIC CLOCK_PROCESS_CPUTIME_ID
19 2 );
20  
21 2 ▶use lib "$Bin/../blib/lib", "$Bin/../blib/arch", "$Bin/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 my @all_workloads = qw(
24 registration-lifecycle
25 timer-lifecycle
26 timer-expiration
27 raw-stream-lifecycle
28 framed-stream-lifecycle
29 raw-stream-throughput
30 deadline-stream-throughput
31 framed-stream-throughput
32 connect-listener-lifecycle
33 );
34 2 my %known_workload = map { $_ => 1 } @all_workloads;
35  
36 2 my $contract_version = 3;
37 2 my $quick = 0;
38 2 my $repeats;
39 my $iterations;
40 2 my $pool;
41 2 my $clients;
42 2 my $messages;
43 2 my $connections;
44 2 my $warmup_iterations;
45 2 my $warmup_messages;
46 2 my $warmup_connections;
47 2 my @workloads = @all_workloads;
48 2 my $json_path = 'bench/results/performance-regression.json';
49 2 my $baseline_path;
50 2 my $threshold_percent = 10;
51 2 my $fail_on_regression = 0;
52 2 my $help = 0;
53  
54 GetOptions(
55 'quick!' => \$quick,
56 'repeats=i' => \$repeats,
57 'iterations=i' => \$iterations,
58 'pool=i' => \$pool,
59 'clients=i' => \$clients,
60 'messages=i' => \$messages,
61 'connections=i' => \$connections,
62 'warmup-iterations=i' => \$warmup_iterations,
63 'warmup-messages=i' => \$warmup_messages,
64 'warmup-connections=i' => \$warmup_connections,
65 0 ▶ 'workloads=s' => sub { @workloads = split /,/, $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 2 ▶ 'json=s' => \$json_path,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("quick!", \$quick, "repeats=i", \$repeats, "iterations=i", \$iterations, "pool=i", \$pool, "clients=i", \$clients, "messages=i", \$messages, "connections=i", \$connections, "warmup-iterations=i", \$warmup_iterations, "warmup-messages=i", \$warmup_messages, "warmup-connections=i", \$warmup_connections, "workloads=s", sub { @workloads = split(/,/u, $_[1], 0); } , "json=s", \$json_path, "baseline=s", \$baseline_path, "threshold-percent=f", \$threshold_percent, "fail-on-regression!", \$fail_on_regression, "help", \$help) or usage(2) 2 0 2
67 'baseline=s' => \$baseline_path,
68 'threshold-percent=f' => \$threshold_percent,
69 'fail-on-regression!' => \$fail_on_regression,
70 'help' => \$help,
71 ) or usage(2);
72 2 ▶usage(0) if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 2 2
73  
74 2 ▶my %preset = $quick
Branch: 1 branch
BranchTrueFalseTotal
$quick ? : 0 2 2
75 ? (
76 repeats => 3,
77 iterations => 10_000,
78 pool => 64,
79 clients => 16,
80 messages => 100,
81 connections => 500,
82 warmup_iterations => 500,
83 warmup_messages => 10,
84 warmup_connections => 50,
85 )
86 : (
87 repeats => 7,
88 iterations => 100_000,
89 pool => 256,
90 clients => 100,
91 messages => 1_000,
92 connections => 10_000,
93 warmup_iterations => 5_000,
94 warmup_messages => 100,
95 warmup_connections => 1_000,
96 );
97  
98 2 ▶$repeats //= $preset{repeats};
Condition33%1/3
$repeats //= $preset{"repeats"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$repeats //= $preset{"repeats"}
$repeats $preset{"repeats"}
Truth table33%1/3
A //= B
A= $repeatsB= $preset{"repeats"}
ABresult
1X1
011
000
99 2 ▶$iterations //= $preset{iterations};
Condition33%1/3
$iterations //= $preset{"iterations"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$iterations //= $preset{"iterations"}
$iterations $preset{"iterations"}
Truth table33%1/3
A //= B
A= $iterationsB= $preset{"iterations"}
ABresult
1X1
011
000
100 2 ▶$pool //= $preset{pool};
Condition33%1/3
$pool //= $preset{"pool"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$pool //= $preset{"pool"}
$pool $preset{"pool"}
Truth table33%1/3
A //= B
A= $poolB= $preset{"pool"}
ABresult
1X1
011
000
101 2 ▶$clients //= $preset{clients};
Condition33%1/3
$clients //= $preset{"clients"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$clients //= $preset{"clients"}
$clients $preset{"clients"}
Truth table33%1/3
A //= B
A= $clientsB= $preset{"clients"}
ABresult
1X1
011
000
102 2 ▶$messages //= $preset{messages};
Condition33%1/3
$messages //= $preset{"messages"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$messages //= $preset{"messages"}
$messages $preset{"messages"}
Truth table33%1/3
A //= B
A= $messagesB= $preset{"messages"}
ABresult
1X1
011
000
103 2 ▶$connections //= $preset{connections};
Condition33%1/3
$connections //= $preset{"connections"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$connections //= $preset{"connections"}
$connections $preset{"connections"}
Truth table33%1/3
A //= B
A= $connectionsB= $preset{"connections"}
ABresult
1X1
011
000
104 2 ▶$warmup_iterations //= $preset{warmup_iterations};
Condition33%1/3
$warmup_iterations //= $preset{"warmup_iterations"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$warmup_iterations //= $preset{"warmup_iterations"}
$warmup_iterations $preset{"warmup_iterations"}
Truth table33%1/3
A //= B
A= $warmup_iterationsB= $preset{"warmup_iterations"}
ABresult
1X1
011
000
105 2 ▶$warmup_messages //= $preset{warmup_messages};
Condition33%1/3
$warmup_messages //= $preset{"warmup_messages"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$warmup_messages //= $preset{"warmup_messages"}
$warmup_messages $preset{"warmup_messages"}
Truth table33%1/3
A //= B
A= $warmup_messagesB= $preset{"warmup_messages"}
ABresult
1X1
011
000
106 2 ▶$warmup_connections //= $preset{warmup_connections};
Condition33%1/3
$warmup_connections //= $preset{"warmup_connections"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$warmup_connections //= $preset{"warmup_connections"}
$warmup_connections $preset{"warmup_connections"}
Truth table33%1/3
A //= B
A= $warmup_connectionsB= $preset{"warmup_connections"}
ABresult
1X1
011
000
107  
108 2 ▶die "at least one workload is required\n" if !@workloads;
Branch: 1 branch
BranchTrueFalseTotal
unless @workloads 0 2 2
109 die "unknown workload: $_\n"
110 2 for grep { !$known_workload{$_} } @workloads;
111 2 my %seen;
112 die "workloads must not contain duplicates\n"
113 2 ▶ if grep { $seen{$_}++ } @workloads;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$seen{$_}++;} @workloads 0 2 2
114 2 ▶die "repeats must be positive\n" if $repeats < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $repeats < 1 0 2 2
115 2 ▶die "iterations must be positive\n" if $iterations < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $iterations < 1 0 2 2
116 2 ▶die "pool must be positive\n" if $pool < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $pool < 1 0 2 2
117 2 ▶die "clients must be positive\n" if $clients < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $clients < 1 0 2 2
118 2 ▶die "messages must be positive\n" if $messages < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $messages < 1 0 2 2
119 2 ▶die "connections must be positive\n" if $connections < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $connections < 1 0 2 2
120 die "warmup values must be non-negative\n"
121 2 ▶ if grep { $_ < 0 }
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ < 0;} $warmup_iterations, $warmup_messages, $warmup_connections 0 2 2
122 ($warmup_iterations, $warmup_messages, $warmup_connections);
123 2 ▶die "threshold-percent must be non-negative\n" if $threshold_percent < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $threshold_percent < 0 0 2 2
124  
125 2 require Linux::Event;
126 2 require Linux::Event::Listener;
127 2 require Linux::Event::Loop;
128 2 require Linux::Event::Stream;
129 2 require Linux::Event::Timer;
130 2 define_benchmark_classes();
131  
132 2 my %configuration = (
133 repeats => $repeats,
134 iterations => $iterations,
135 pool => $pool,
136 clients => $clients,
137 messages => $messages,
138 connections => $connections,
139 warmup_iterations => $warmup_iterations,
140 warmup_messages => $warmup_messages,
141 warmup_connections => $warmup_connections,
142 workloads => \@workloads,
143 );
144  
145 2 say 'Linux::Event performance-regression benchmark';
146 2 say "version=$Linux::Event::VERSION perl=$^V contract=$contract_version";
147 2 say 'workloads=' . join(',', @workloads);
148 2 say "repeats=$repeats threshold=$threshold_percent%";
149  
150 2 my @records;
151 2 for my $repeat (1 .. $repeats) {
152 2 my @order = rotated_workloads($repeat);
153 2 for my $position (0 .. $#order) {
154 18 my $workload = $order[$position];
155 18 my $row = run_workload($workload);
156 18 $row->{workload} = $workload;
157 18 $row->{repeat} = $repeat;
158 18 $row->{order_position} = $position + 1;
159 18 push @records, $row;
160 printf "%-30s repeat=%d %12.1f %-13s cpu=%9.3f us/%s\n",
161 $workload,
162 $repeat,
163 $row->{operations_per_second},
164 "$row->{unit}/s",
165 $row->{cpu_us_per_operation},
166 18 $row->{unit};
167 }
168 }
169  
170 2 my @summary = summarize(\@records);
171 2 say "\nMedian summary";
172 2 printf "%-30s %14s %16s\n", 'workload', 'rate', 'cpu us/op';
173 2 for my $row (@summary) {
174 printf "%-30s %14.1f %16.3f\n",
175 $row->{workload},
176 $row->{operations_per_second},
177 18 $row->{cpu_us_per_operation};
178 }
179  
180 2 my $report = {
181 benchmark => 'linux-event-performance-regression',
182 benchmark_contract_version => $contract_version,
183 generated_at => strftime('%Y-%m-%dT%H:%M:%SZ', gmtime),
184 linux_event_version => "$Linux::Event::VERSION",
185 environment => environment_info(),
186 configuration => \%configuration,
187 records => \@records,
188 summary => \@summary,
189 notes => [
190 'Each summary value is the median of rotated-order repeats.',
191 'Lifecycle socketpairs are allocated outside timed regions.',
192 'Timer lifecycle measures attach plus cancellation on one shared timerfd.',
193 'Timer expiration measures zero-delay delivery through the native heap.',
194 'Throughput workloads use one outstanding message per client.',
195 'Deadline throughput enables idle tracking without allowing expiration.',
196 'The connection workload measures the complete public connect/listen handoff.',
197 'Compare only reports with the same contract and configuration.',
198 ],
199 };
200  
201 2 my $regression_count = 0;
202 2 ▶if (defined $baseline_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $baseline_path) 1 1 2
203 1 my $baseline = read_json($baseline_path);
204 1 my $comparison = compare_reports($baseline, $report);
205 1 $report->{comparison} = $comparison;
206 9 $regression_count = scalar grep { $_->{regression} }
207 1 @{ $comparison->{workloads} };
208 1 print_comparison($comparison);
209 }
210  
211 2 write_json($json_path, $report);
212 2 say "\nWrote $json_path";
213  
214 2 ▶exit 2 if $fail_on_regression && $regression_count;
Branch: 1 branch
BranchTrueFalseTotal
if $fail_on_regression and $regression_count 0 2 2
Condition66%2/3
$fail_on_regression and $regression_count
!ll&&!rl&&r
110
MC/DC0%0/2
$fail_on_regression and $regression_count
$fail_on_regression $regression_count
Truth table66%2/3
A and B
A= $fail_on_regressionB= $regression_count
ABresult
0X0
100
111
215 2 exit 0;
216  
217 0 ▶sub usage ($status) {
Subroutine usage: not called CC=1 SCAR=6.9
218 0 print <<'USAGE';
219 Usage:
220 perl -Mblib bench/run-performance-regression.pl [options]
221  
222 Capture a stable full baseline:
223 perl -Mblib bench/run-performance-regression.pl \
224 --json bench/results/performance-baseline.json
225  
226 Compare a later build with the same configuration:
227 perl -Mblib bench/run-performance-regression.pl \
228 --baseline bench/results/performance-baseline.json \
229 --threshold-percent 10 --fail-on-regression \
230 --json bench/results/performance-candidate.json
231  
232 Useful options:
233 --quick shorter development preset
234 --repeats N median sample count
235 --iterations N lifecycle operations per repeat
236 --pool N reusable socketpairs for lifecycle workloads
237 --clients N concurrent throughput/connection clients
238 --messages N measured messages per throughput client
239 --connections N measured connect/listen lifecycles
240 --warmup-iterations N lifecycle warmup operations
241 --warmup-messages N throughput warmup messages per client
242 --warmup-connections N connect/listen warmup operations
243 --workloads LIST comma-separated workload subset
244 --json PATH output report
245 --baseline PATH compatible report to compare
246 --threshold-percent N regression threshold, default 10
247 --fail-on-regression exit 2 when any metric crosses the threshold
248  
249 The full preset is intended for release decisions. The quick preset verifies
250 the harness and is useful during development, but is too short for a final
251 performance claim.
252 USAGE
253 0 exit $status;
254 }
255  
256 2 ▶sub define_benchmark_classes () {
Subroutine define_benchmark_classes: called CC=3 SCAR=11.3
257 2 my $framer_declaration;
258 2 ▶ if (eval { require Linux::Event::Framer; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Linux::Event::Framer; 1 } }) { } 2 0 2
259 2 $framer_declaration = q{use Linux::Event::Framer 'Delimiter', "\n";};
260 } else {
261 0 require Linux::Event::Stream::Framer;
262 0 $framer_declaration
263 = q{use Linux::Event::Stream::Framer 'Delimiter', "\n";};
264 }
265  
266 2 my $source = qq{
267 package Linux::Event::Bench::Regression::Raw;
268 use parent -norequire, 'Linux::Event::Stream';
269 sub on_data (\$stream, \$bytes) { \$stream->write(\$bytes) }
270 sub on_error (\$stream, \$error) { die "raw Stream error: \$error\\n" }
271  
272 package Linux::Event::Bench::Regression::Framed;
273 use parent -norequire, 'Linux::Event::Stream';
274 $framer_declaration
275 sub on_message (\$stream, \$message) { \$stream->send(\$message) }
276 sub on_error (\$stream, \$error) { die "framed Stream error: \$error\\n" }
277  
278 package Linux::Event::Bench::Regression::DeadlineRaw;
279 use parent -norequire, 'Linux::Event::Bench::Regression::Raw';
280 sub stream_options (\$class) { return idle_timeout => 3_600 }
281  
282 package Linux::Event::Bench::Regression::Timer;
283 use parent -norequire, 'Linux::Event::Timer';
284 sub on_timer (\$timer) { main::timer_expired(\$timer) }
285  
286 package Linux::Event::Bench::Regression::ConnectionServer;
287 use parent -norequire, 'Linux::Event::Stream';
288 sub on_data (\$stream, \$bytes) { return }
289 sub on_ready (\$stream) { main::connection_server_ready(\$stream) }
290 sub on_error (\$stream, \$error) { die "server Stream error: \$error\\n" }
291  
292 package Linux::Event::Bench::Regression::ConnectionListener;
293 use parent -norequire, 'Linux::Event::Listener';
294 sub on_error (\$listener, \$error) {
295 die "Listener error: \$error\\n";
296 }
297  
298 package Linux::Event::Bench::Regression::ConnectionClient;
299 use parent -norequire, 'Linux::Event::Stream';
300 sub on_data (\$stream, \$bytes) { return }
301 sub on_ready (\$stream) { main::connection_client_ready(\$stream) }
302 sub on_error (\$stream, \$error) { die "client Stream error: \$error\\n" }
303 1;
304 };
305 0 ▶ eval $source or die "define benchmark classes: $@";
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine on_data: called CC=1 SCAR=0.1
Subroutine on_data: not called CC=1 SCAR=0.1
Subroutine on_data: not called CC=1 SCAR=0.1
Subroutine on_error: not called CC=1 SCAR=0.1
Subroutine on_error: not called CC=1 SCAR=0.1
Subroutine on_error: not called CC=1 SCAR=0.1
Subroutine on_error: not called CC=1 SCAR=0.1
Subroutine on_error: not called CC=1 SCAR=0.1
Subroutine on_message: called CC=1 SCAR=0.1
Subroutine on_ready: called CC=1 SCAR=0.1
Subroutine on_ready: called CC=1 SCAR=0.1
Subroutine on_timer: called CC=1 SCAR=0.1
Subroutine stream_options: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
eval $source or die "define benchmark classes: $@" 2 0 2
306 2 return;
307 }
308  
309 2 ▶sub rotated_workloads ($repeat) {
Subroutine rotated_workloads: called CC=1 SCAR=0.0
310 2 my $offset = ($repeat - 1) % @workloads;
311 2 return (@workloads[$offset .. $#workloads], @workloads[0 .. $offset - 1]);
312 }
313  
314 18 ▶sub run_workload ($name) {
Subroutine run_workload: called CC=9 SCAR=22.0
315 18 ▶ return registration_lifecycle() if $name eq 'registration-lifecycle';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "registration-lifecycle" 2 16 18
316 16 ▶ return timer_lifecycle() if $name eq 'timer-lifecycle';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "timer-lifecycle" 2 14 16
317 14 ▶ return timer_expiration() if $name eq 'timer-expiration';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "timer-expiration" 2 12 14
318 12 ▶ return stream_lifecycle('Linux::Event::Bench::Regression::Raw')
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "raw-stream-lifecycle" 2 10 12
319 if $name eq 'raw-stream-lifecycle';
320 10 ▶ return stream_lifecycle('Linux::Event::Bench::Regression::Framed')
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "framed-stream-lifecycle" 2 8 10
321 if $name eq 'framed-stream-lifecycle';
322 8 ▶ return stream_throughput('Linux::Event::Bench::Regression::Raw', 0)
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "raw-stream-throughput" 2 6 8
323 if $name eq 'raw-stream-throughput';
324 6 ▶ return stream_throughput(
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "deadline-stream-throughput" 2 4 6
325 'Linux::Event::Bench::Regression::DeadlineRaw', 0,
326 ) if $name eq 'deadline-stream-throughput';
327 4 ▶ return stream_throughput('Linux::Event::Bench::Regression::Framed', 1)
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "framed-stream-throughput" 2 2 4
328 if $name eq 'framed-stream-throughput';
329 2 return connection_lifecycle();
330 }
331  
332 2 ▶sub registration_lifecycle () {
Subroutine registration_lifecycle: called CC=2 SCAR=6.9
333 2 my $loop = Linux::Event::Loop->new;
334 2 my ($server, $client) = socket_pool($pool);
335 2 register_churn($loop, $server, $warmup_iterations);
336 2 ▶ my ($wall, $cpu) = timed(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
337 2 register_churn($loop, $server, $iterations);
338 2 });
339 2 close $_ for @$server, @$client;
340 2 return measurement($iterations, 'registration', $wall, $cpu);
341 }
342  
343 4 ▶sub register_churn ($loop, $handles, $count) {
Subroutine register_churn: called CC=2 SCAR=6.9
344 4 for my $i (0 .. $count - 1) {
345 50200 my $registration = $loop->watch(
346 fh => $handles->[$i % @$handles],
347 read => \&no_ready,
348 );
349 50200 $registration->cancel;
350 }
351 4 return;
352 }
353  
354 0 ▶sub no_ready ($registration) { return }
Subroutine no_ready: not called CC=1 SCAR=6.9
355  
356 2 ▶sub timer_lifecycle () {
Subroutine timer_lifecycle: called CC=1 SCAR=0.0
357 2 my $loop = Linux::Event::Loop->new;
358 2 timer_churn($loop, $warmup_iterations);
359 2 ▶ my ($wall, $cpu) = timed(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
360 2 timer_churn($loop, $iterations);
361 2 });
362 2 return measurement($iterations, 'timer', $wall, $cpu);
363 }
364  
365 4 ▶sub timer_churn ($loop, $count) {
Subroutine timer_churn: called CC=2 SCAR=6.9
366 4 for (1 .. $count) {
367 50200 my $timer = $loop->add(
368 Linux::Event::Bench::Regression::Timer->new(after => 3_600)
369 );
370 50200 $timer->cancel;
371 }
372 4 return;
373 }
374  
375 2 ▶sub timer_expiration () {
Subroutine timer_expiration: called CC=2 SCAR=7.1
376 2 ▶ run_timer_expirations($warmup_iterations) if $warmup_iterations;
Branch: 1 branch
BranchTrueFalseTotal
if $warmup_iterations 2 0 2
377 2 my ($wall, $cpu) = run_timer_expirations($iterations);
378 2 return measurement($iterations, 'timer', $wall, $cpu);
379 }
380  
381 4 ▶sub run_timer_expirations ($count) {
Subroutine run_timer_expirations: called CC=3 SCAR=11.0
382 4 my $loop = Linux::Event::Loop->new;
383 4 my $run = {
384 loop => $loop,
385 target => $count,
386 completed => 0,
387 };
388 4 for (1 .. $count) {
389 50200 $loop->add(Linux::Event::Bench::Regression::Timer->new(
390 after => 0,
391 data => $run,
392 ));
393 }
394 4 ▶ my ($wall, $cpu) = timed(sub { $loop->run });
Subroutine __ANON__: called CC=1 SCAR=0.0
395 die "timer expiration completed $run->{completed} of $count Timers\n"
396 4 ▶ if $run->{completed} != $count;
Branch: 1 branch
BranchTrueFalseTotal
if $run->{"completed"} != $count 0 4 4
397 4 return ($wall, $cpu);
398 }
399  
400 50200 ▶sub timer_expired ($timer) {
Subroutine timer_expired: called CC=2 SCAR=6.9
401 50200 my $run = $timer->data;
402 50200 $run->{completed}++;
403 50200 ▶ $run->{loop}->stop if $run->{completed} == $run->{target};
Branch: 1 branch
BranchTrueFalseTotal
if $run->{"completed"} == $run->{"target"} 4 50196 50200
404 50200 return;
405 }
406  
407 4 ▶sub stream_lifecycle ($class) {
Subroutine stream_lifecycle: called CC=2 SCAR=6.9
408 4 my $loop = Linux::Event::Loop->new;
409 4 my ($server, $client) = socket_pool($pool);
410 4 stream_churn($loop, $class, $server, $warmup_iterations);
411 4 ▶ my ($wall, $cpu) = timed(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
412 4 stream_churn($loop, $class, $server, $iterations);
413 4 });
414 4 close $_ for @$server, @$client;
415 4 return measurement($iterations, 'stream', $wall, $cpu);
416 }
417  
418 8 ▶sub stream_churn ($loop, $class, $handles, $count) {
Subroutine stream_churn: called CC=2 SCAR=6.9
419 8 for my $i (0 .. $count - 1) {
420 100400 my $stream = $class->new(fh => $handles->[$i % @$handles]);
421 100400 $loop->add($stream);
422 100400 $stream->detach;
423 }
424 8 return;
425 }
426  
427 6 ▶sub socket_pool ($count) {
Subroutine socket_pool: called CC=3 SCAR=11.0
428 6 my (@server, @client);
429 6 for (1 .. $count) {
430 384 ▶ socketpair(my $a, my $b, AF_UNIX, SOCK_STREAM, PF_UNSPEC)
Branch: 1 branch
BranchTrueFalseTotal
socketpair my $a, my $b, 1, 1, 0 or die "socketpair: $!\n" 384 0 384
431 or die "socketpair: $!\n";
432 384 push @server, $a;
433 384 push @client, $b;
434 }
435 6 return (\@server, \@client);
436 }
437  
438 6 ▶sub stream_throughput ($class, $framed) {
Subroutine stream_throughput: called CC=10 SCAR=23.1
439 6 my $loop = Linux::Event::Loop->new;
440 6 my $payload = 'x' x 64;
441 6 ▶ my $wire = $framed ? "$payload\n" : $payload;
Branch: 1 branch
BranchTrueFalseTotal
$framed ? : 2 4 6
442 6 ▶ my $bench = {
Branch: 1 branch
BranchTrueFalseTotal
$warmup_messages ? : 6 0 6
443 loop => $loop,
444 phase => $warmup_messages ? 'warmup' : 'measure',
445 clients => $clients,
446 messages => $messages,
447 warmup_messages => $warmup_messages,
448 wire => $wire,
449 wire_length => length($wire),
450 warmup_ready => 0,
451 measured_ready => 0,
452 states => [],
453 streams => [],
454 registrations => [],
455 client_handles => [],
456 };
457  
458 6 for my $index (0 .. $clients - 1) {
459 96 ▶ socketpair(my $server, my $client, AF_UNIX, SOCK_STREAM, PF_UNSPEC)
Branch: 1 branch
BranchTrueFalseTotal
socketpair my $server, my $client, 1, 1, 0 or die "socketpair: $!\n" 96 0 96
460 or die "socketpair: $!\n";
461 96 my $stream = $class->new(loop => $loop, fh => $server);
462 96 my $state = {
463 bench => $bench,
464 fh => $client,
465 buffer => '',
466 completed => 0,
467 };
468 96 my $registration = $loop->watch(
469 fh => $client,
470 data => $state,
471 read => \&throughput_client_read,
472 );
473 96 push @{ $bench->{streams} }, $stream;
474 96 push @{ $bench->{client_handles} }, $client;
475 96 push @{ $bench->{states} }, $state;
476 96 push @{ $bench->{registrations} }, $registration;
477 }
478  
479 6 ▶ if ($warmup_messages) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warmup_messages) { } 6 0 6
480 6 write_wire($_) for @{ $bench->{states} };
481 } else {
482 0 begin_throughput_measurement($bench);
483 }
484 6 $loop->run;
485  
486 6 my $wall = $bench->{wall_end} - $bench->{wall_start};
487 6 my $cpu = $bench->{cpu_end} - $bench->{cpu_start};
488 6 $_->cancel for @{ $bench->{registrations} };
489 6 $_->close for @{ $bench->{streams} };
490 6 close $_ for @{ $bench->{client_handles} };
491 6 return measurement($clients * $messages, 'message', $wall, $cpu);
492 }
493  
494 48960 ▶sub throughput_client_read ($registration) {
Subroutine throughput_client_read: called CC=10 SCAR=23.1
495 48960 my $state = $registration->data;
496 48960 my $bench = $state->{bench};
497 48960 my $read = sysread($state->{fh}, my $chunk, 65_536);
498 48960 ▶ die "throughput client read: $!\n" if !defined $read;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $read 0 48960 48960
499 48960 ▶ die "throughput peer closed early\n" if !$read;
Branch: 1 branch
BranchTrueFalseTotal
unless $read 0 48960 48960
500 48960 $state->{buffer} .= $chunk;
501  
502 48960 ▶ while (length($state->{buffer}) >= $bench->{wire_length}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $state->{"buffer"} >= $bench->{"wire_length"}) 48960 48960 97920
503 my $message = substr(
504 48960 $state->{buffer}, 0, $bench->{wire_length}, '',
505 );
506 48960 ▶ die "throughput payload mismatch\n" if $message ne $bench->{wire};
Branch: 1 branch
BranchTrueFalseTotal
if $message ne $bench->{"wire"} 0 48960 48960
507 48960 $state->{completed}++;
508  
509 48960 ▶ if ($bench->{phase} eq 'warmup') {
Branch: 1 branch
BranchTrueFalseTotal
if ($bench->{"phase"} eq "warmup") 960 48000 48960
510 960 ▶ if ($state->{completed} == $bench->{warmup_messages}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{'completed'} == $bench->{'warmup_messages'}) { } 96 864 960
511 96 $bench->{warmup_ready}++;
512 begin_throughput_measurement($bench)
513 96 ▶ if $bench->{warmup_ready} == $bench->{clients};
Branch: 1 branch
BranchTrueFalseTotal
if $bench->{"warmup_ready"} == $bench->{"clients"} 6 90 96
514 } else {
515 864 write_wire($state);
516 }
517 960 next;
518 }
519  
520 48000 ▶ if ($state->{completed} == $bench->{messages}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{'completed'} == $bench->{'messages'}) { } 96 47904 48000
521 96 $bench->{measured_ready}++;
522 96 ▶ if ($bench->{measured_ready} == $bench->{clients}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bench->{"measured_ready"} == $bench->{"clients"}) 6 90 96
523 6 $bench->{wall_end} = clock_gettime(CLOCK_MONOTONIC);
524 $bench->{cpu_end}
525 6 = clock_gettime(CLOCK_PROCESS_CPUTIME_ID);
526 6 $bench->{loop}->stop;
527 }
528 } else {
529 47904 write_wire($state);
530 }
531 }
532 48960 return;
533 }
534  
535 6 ▶sub begin_throughput_measurement ($bench) {
Subroutine begin_throughput_measurement: called CC=4 SCAR=13.9
536 6 $bench->{phase} = 'measure';
537 6 $bench->{measured_ready} = 0;
538 6 for my $state (@{ $bench->{states} }) {
539 96 $state->{completed} = 0;
540 96 ▶ die "warmup left a partial message\n" if length $state->{buffer};
Branch: 1 branch
BranchTrueFalseTotal
if length $state->{"buffer"} 0 96 96
541 }
542 6 $bench->{wall_start} = clock_gettime(CLOCK_MONOTONIC);
543 6 $bench->{cpu_start} = clock_gettime(CLOCK_PROCESS_CPUTIME_ID);
544 6 write_wire($_) for @{ $bench->{states} };
545 6 return;
546 }
547  
548 48960 ▶sub write_wire ($state) {
Subroutine write_wire: called CC=3 SCAR=11.3
549 48960 my $wire = $state->{bench}{wire};
550 48960 my $written = syswrite($state->{fh}, $wire);
551 48960 ▶ die "throughput client write: $!\n" if !defined $written;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $written 0 48960 48960
552 48960 ▶ die "throughput client short write\n" if $written != length($wire);
Branch: 1 branch
BranchTrueFalseTotal
if $written != length $wire 0 48960 48960
553 48960 return;
554 }
555  
556 2 ▶sub connection_lifecycle () {
Subroutine connection_lifecycle: called CC=2 SCAR=7.1
557 2 ▶ run_connections($warmup_connections) if $warmup_connections;
Branch: 1 branch
BranchTrueFalseTotal
if $warmup_connections 2 0 2
558 2 my ($wall, $cpu) = run_connections($connections);
559 2 return measurement($connections, 'connection', $wall, $cpu);
560 }
561  
562 4 ▶sub run_connections ($count) {
Subroutine run_connections: called CC=4 SCAR=13.9
563 4 my $loop = Linux::Event::Loop->new;
564 4 $loop->enable_watcher_reclaim(1);
565 4 ▶ my $run = {
Branch: 1 branch
BranchTrueFalseTotal
$clients < $count ? : 2 2 4
566 loop => $loop,
567 connections => $count,
568 concurrency => $clients < $count ? $clients : $count,
569 started => 0,
570 active => 0,
571 client_done => 0,
572 server_done => 0,
573 };
574 4 my $listener = Linux::Event::Bench::Regression::ConnectionListener->new(
575 stream_class => 'Linux::Event::Bench::Regression::ConnectionServer',
576 host => '127.0.0.1', port => 0, data => $run,
577 );
578 4 $loop->add($listener);
579 4 $run->{port} = $listener->port;
580  
581 4 my $wall_start = clock_gettime(CLOCK_MONOTONIC);
582 4 my $cpu_start = clock_gettime(CLOCK_PROCESS_CPUTIME_ID);
583 4 launch_connections($run);
584 4 $loop->run;
585 4 my $cpu = clock_gettime(CLOCK_PROCESS_CPUTIME_ID) - $cpu_start;
586 4 my $wall = clock_gettime(CLOCK_MONOTONIC) - $wall_start;
587  
588 4 $listener->close;
589 die "connection workload completed $run->{client_done} of $count clients\n"
590 4 ▶ if $run->{client_done} != $count;
Branch: 1 branch
BranchTrueFalseTotal
if $run->{"client_done"} != $count 0 4 4
591 die "connection workload accepted $run->{server_done} of $count peers\n"
592 4 ▶ if $run->{server_done} != $count;
Branch: 1 branch
BranchTrueFalseTotal
if $run->{"server_done"} != $count 0 4 4
593 4 return ($wall, $cpu);
594 }
595  
596 1024 ▶sub launch_connections ($run) {
Subroutine launch_connections: called CC=3 SCAR=11.0
597 1024 ▶ while ($run->{active} < $run->{concurrency}
Branch: 1 branch
BranchTrueFalseTotal
if ($run->{"active"} < $run->{"concurrency"} and $run->{"started"} < $run->{"connections"}) 1020 1024 2044
Condition100%3/3
$run->{"active"} < $run->{"concurrency"} and $run->{"started"} < $run->{"connections"}
!ll&&!rl&&r
972521020
MC/DC100%2/2
$run->{"active"} < $run->{"concurrency"} and $run->{"started"} < $run->{"connections"}
$run->{"active"} < $run->{"concurrency"} $run->{"started"} < $run->{"connections"}
Truth table100%3/3
A and B
A= $run->{"active"} < $run->{"concurrency"}B= $run->{"started"} < $run->{"connections"}
ABresult
0X0
100
111
598 && $run->{started} < $run->{connections}) {
599 1020 $run->{active}++;
600 1020 $run->{started}++;
601 my $stream
602 = Linux::Event::Bench::Regression::ConnectionClient->connect(
603 host => '127.0.0.1',
604 port => $run->{port},
605 1020 timeout => 30,
606 data => $run,
607 );
608 1020 $run->{loop}->add($stream);
609 }
610 1024 return;
611 }
612  
613 1020 ▶sub connection_server_ready ($stream) {
Subroutine connection_server_ready: called CC=1 SCAR=0.0
614 1020 my $run = $stream->data;
615 1020 $stream->close;
616 1020 $run->{server_done}++;
617 1020 finish_connections($run);
618 1020 return;
619 }
620  
621 1020 ▶sub connection_client_ready ($stream) {
Subroutine connection_client_ready: called CC=2 SCAR=7.0
622 1020 my $run = $stream->data;
623 1020 ▶ setsockopt($stream->fh, SOL_SOCKET, SO_LINGER, pack('ii', 1, 0))
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $stream->fh, 1, 13, "\1\0\0\0\0\0\0\0" or die "connection client SO_LINGER: $!\n" 1020 0 1020
624 or die "connection client SO_LINGER: $!\n";
625 1020 $stream->close;
626 1020 $run->{active}--;
627 1020 $run->{client_done}++;
628 1020 launch_connections($run);
629 1020 finish_connections($run);
630 1020 return;
631 }
632  
633 2040 ▶sub finish_connections ($run) {
Subroutine finish_connections: called CC=3 SCAR=11.1
634 $run->{loop}->stop
635 if $run->{client_done} == $run->{connections}
636 2040 ▶ && $run->{server_done} == $run->{connections};
Branch: 1 branch
BranchTrueFalseTotal
if $run->{"client_done"} == $run->{"connections"} and $run->{"server_done"} == $run->{"connections"} 4 2036 2040
Condition66%2/3
$run->{"client_done"} == $run->{"connections"} and $run->{"server_done"} == $run->{"connections"}
!ll&&!rl&&r
203604
MC/DC50%1/2
$run->{"client_done"} == $run->{"connections"} and $run->{"server_done"} == $run->{"connections"}
$run->{"client_done"} == $run->{"connections"} $run->{"server_done"} == $run->{"connections"}
Truth table66%2/3
A and B
A= $run->{"client_done"} == $run->{"connections"}B= $run->{"server_done"} == $run->{"connections"}
ABresult
0X0
100
111
637 2040 return;
638 }
639  
640 12 ▶sub timed ($code) {
Subroutine timed: called CC=1 SCAR=0.0
641 12 my $wall_start = clock_gettime(CLOCK_MONOTONIC);
642 12 my $cpu_start = clock_gettime(CLOCK_PROCESS_CPUTIME_ID);
643 12 $code->();
644 12 my $cpu = clock_gettime(CLOCK_PROCESS_CPUTIME_ID) - $cpu_start;
645 12 my $wall = clock_gettime(CLOCK_MONOTONIC) - $wall_start;
646 12 return ($wall, $cpu);
647 }
648  
649 18 ▶sub measurement ($operations, $unit, $wall, $cpu) {
Subroutine measurement: called CC=3 SCAR=13.1
650 18 ▶ die "benchmark clock returned a non-positive duration\n"
Branch: 1 branch
BranchTrueFalseTotal
if $wall <= 0 or $cpu <= 0 0 18 18
Condition33%1/3
$wall <= 0 or $cpu <= 0
l!l&&r!l&&!r
0018
MC/DC0%0/2
$wall <= 0 or $cpu <= 0
$wall <= 0 $cpu <= 0
Truth table33%1/3
A or B
A= $wall <= 0B= $cpu <= 0
ABresult
1X1
011
000
651 if $wall <= 0 || $cpu <= 0;
652 return {
653 18 operations => $operations,
654 unit => $unit,
655 elapsed_seconds => $wall,
656 cpu_seconds => $cpu,
657 operations_per_second => $operations / $wall,
658 cpu_us_per_operation => $cpu * 1_000_000 / $operations,
659 };
660 }
661  
662 2 ▶sub summarize ($records) {
Subroutine summarize: called CC=2 SCAR=6.9
663 2 my @result;
664 2 for my $workload (@workloads) {
665 18 my @set = grep { $_->{workload} eq $workload } @$records;
666 push @result, {
667 workload => $workload,
668 unit => $set[0]{unit},
669 operations_per_second => median(
670 18 map { $_->{operations_per_second} } @set
671 ),
672 cpu_us_per_operation => median(
673 18 map { $_->{cpu_us_per_operation} } @set
674 ),
675 };
676 }
677 2 return @result;
678 }
679  
680 36 ▶sub median (@values) {
Subroutine median: called CC=2 SCAR=7.6
681 0 @values = sort { $a <=> $b } @values;
682 36 my $middle = int(@values / 2);
683 36 ▶ return @values % 2
Branch: 1 branch
BranchTrueFalseTotal
@values % 2 ? : 36 0 36
684 ? $values[$middle]
685 : ($values[$middle - 1] + $values[$middle]) / 2;
686 }
687  
688 1 ▶sub compare_reports ($baseline, $candidate) {
Subroutine compare_reports: called CC=10 SCAR=24.9
689 die "baseline is not a performance-regression report\n"
690 1 ▶ if ($baseline->{benchmark} // '') ne $candidate->{benchmark};
Branch: 1 branch
BranchTrueFalseTotal
if ($baseline->{"benchmark"} // "") ne $candidate->{"benchmark"} 0 1 1
Condition50%1/2
$baseline->{"benchmark"} // ""
l!l
10
MC/DC0%0/1
$baseline->{"benchmark"} // ""
$baseline->{"benchmark"}
Truth table50%1/2
A
A= $baseline->{"benchmark"}
Aresult
11
00
691 die "baseline contract does not match candidate contract\n"
692 if ($baseline->{benchmark_contract_version} // -1)
693 1 ▶ != $candidate->{benchmark_contract_version};
Branch: 1 branch
BranchTrueFalseTotal
if ($baseline->{"benchmark_contract_version"} // -1) != $candidate->{"benchmark_contract_version"} 0 1 1
Condition50%1/2
$baseline->{"benchmark_contract_version"} // -1
l!l
10
MC/DC0%0/1
$baseline->{"benchmark_contract_version"} // -1
$baseline->{"benchmark_contract_version"}
Truth table50%1/2
A
A= $baseline->{"benchmark_contract_version"}
Aresult
11
00
694 1 my $json = JSON::PP->new->canonical;
695 die "baseline configuration does not match candidate configuration\n"
696 if $json->encode($baseline->{configuration})
697 1 ▶ ne $json->encode($candidate->{configuration});
Branch: 1 branch
BranchTrueFalseTotal
if $json->encode($baseline->{"configuration"}) ne $json->encode($candidate->{"configuration"}) 0 1 1
698  
699 1 my %baseline = map { $_->{workload} => $_ } @{ $baseline->{summary} };
700 1 my @comparison;
701 1 for my $current (@{ $candidate->{summary} }) {
702 my $before = $baseline{$current->{workload}}
703 9 ▶ // die "baseline is missing workload $current->{workload}\n";
Condition50%1/2
$baseline{$current->{"workload"}} // die(qq[baseline is missing workload $current->{"workload"}\n])
l!l
90
MC/DC0%0/1
$baseline{$current->{"workload"}} // die(qq[baseline is missing workload $current->{"workload"}\n])
$baseline{$current->{"workload"}}
Truth table50%1/2
A
A= $baseline{$current->{"workload"}}
Aresult
11
00
704 my $rate_delta = percent_delta(
705 $before->{operations_per_second},
706 $current->{operations_per_second},
707 9 );
708 my $cpu_delta = percent_delta(
709 $before->{cpu_us_per_operation},
710 $current->{cpu_us_per_operation},
711 9 );
712 9 ▶ my $regression = $rate_delta <= -$threshold_percent
Condition33%1/3
$rate_delta <= -$threshold_percent || $cpu_delta >= $threshold_percent
l!l&&r!l&&!r
009
MC/DC0%0/2
$rate_delta <= -$threshold_percent || $cpu_delta >= $threshold_percent
$rate_delta <= -$threshold_percent $cpu_delta >= $threshold_percent
Truth table33%1/3
A || B
A= $rate_delta <= -$threshold_percentB= $cpu_delta >= $threshold_percent
ABresult
1X1
011
000
713 || $cpu_delta >= $threshold_percent;
714 push @comparison, {
715 workload => $current->{workload},
716 unit => $current->{unit},
717 baseline_operations_per_second
718 => $before->{operations_per_second},
719 candidate_operations_per_second
720 => $current->{operations_per_second},
721 throughput_delta_percent => $rate_delta,
722 baseline_cpu_us_per_operation
723 => $before->{cpu_us_per_operation},
724 candidate_cpu_us_per_operation
725 => $current->{cpu_us_per_operation},
726 9 ▶ cpu_delta_percent => $cpu_delta,
Branch: 1 branch
BranchTrueFalseTotal
$regression ? : 0 9 9
727 regression => $regression ? JSON::PP::true : JSON::PP::false,
728 };
729 }
730 return {
731 baseline_version => $baseline->{linux_event_version},
732 candidate_version => $candidate->{linux_event_version},
733 1 threshold_percent => $threshold_percent,
734 workloads => \@comparison,
735 };
736 }
737  
738 18 ▶sub percent_delta ($before, $after) {
Subroutine percent_delta: called CC=2 SCAR=7.2
739 18 ▶ die "cannot compare a zero baseline metric\n" if !$before;
Branch: 1 branch
BranchTrueFalseTotal
unless $before 0 18 18
740 18 return ($after / $before - 1) * 100;
741 }
742  
743 1 ▶sub print_comparison ($comparison) {
Subroutine print_comparison: called CC=3 SCAR=11.0
744 1 say "\nRegression comparison";
745 1 say "baseline=$comparison->{baseline_version} "
746 . "candidate=$comparison->{candidate_version} "
747 . "threshold=$comparison->{threshold_percent}%";
748 1 printf "%-30s %12s %12s %10s\n",
749 'workload', 'rate delta', 'cpu delta', 'status';
750 1 for my $row (@{ $comparison->{workloads} }) {
751 printf "%-30s %+11.2f%% %+11.2f%% %10s\n",
752 $row->{workload},
753 $row->{throughput_delta_percent},
754 $row->{cpu_delta_percent},
755 9 ▶ $row->{regression} ? 'REGRESSION' : 'ok';
Branch: 1 branch
BranchTrueFalseTotal
$row->{'regression'} ? : 0 9 9
756 }
757 1 return;
758 }
759  
760 2 ▶sub environment_info () {
Subroutine environment_info: called CC=4 SCAR=14.0
761 2 my ($sysname, $nodename, $release, $version, $machine) = uname();
762 2 my $cpu_model;
763 2 ▶ if (open my $cpu, '<', '/proc/cpuinfo') {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $cpu, "<", "/proc/cpuinfo") 2 0 2
764 2 ▶ while (my $line = <$cpu>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $cpu)) 10 0 10
765 10 ▶ if ($line =~ /^model name\s*:\s*(.+?)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^model name\s*:\s*(.+?)\s*$/u) 2 8 10
766 2 $cpu_model = $1;
767 2 last;
768 }
769 }
770 2 close $cpu;
771 }
772 return {
773 2 perl => "$^V",
774 perl_path => $^X,
775 os => $sysname,
776 kernel => $release,
777 machine => $machine,
778 hostname => $nodename,
779 cpu_model => $cpu_model,
780 };
781 }
782  
783 1 ▶sub read_json ($path) {
Subroutine read_json: called CC=3 SCAR=11.3
784 1 ▶ open my $fh, '<', $path or die "open $path: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $path or die "open ${path}: $!\n" 1 0 1
785 1 local $/;
786 1 my $document = <$fh>;
787 1 ▶ close $fh or die "close $path: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "close ${path}: $!\n" 1 0 1
788 1 return JSON::PP->new->decode($document);
789 }
790  
791 2 ▶sub write_json ($path, $document) {
Subroutine write_json: called CC=5 SCAR=17.5
792 2 my $dir = dirname($path);
793 2 ▶ make_path($dir) if $dir ne '.' && !-d $dir;
Branch: 1 branch
BranchTrueFalseTotal
if $dir ne "." and not -d $dir 0 2 2
Condition33%1/3
$dir ne "." and not -d $dir
!ll&&!rl&&r
020
MC/DC0%0/2
$dir ne "." and not -d $dir
$dir ne "." not -d $dir
Truth table33%1/3
A and not(B)
A= $dir ne "."B= not -d $dir
ABresult
0X0
100
111
794 2 ▶ open my $fh, '>', $path or die "open $path: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $path or die "open ${path}: $!\n" 2 0 2
795 2 print {$fh} JSON::PP->new->canonical->pretty->encode($document);
796 2 ▶ close $fh or die "close $path: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "close ${path}: $!\n" 2 0 2
797 2 return;
798 }
« bench/run-stream-watcher-state-bench.pl ↑ Summary bench/run-resolver-microbench.pl »