bench/run-performance-regression.pl

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