bench/run-reactor-comparison.pl

filter: Statementstmt 68.8% 522 / 758 Branchbran 40.3% 146 / 362 Conditioncond 30.1% 72 / 239 MC/DCmcdc 7.7% 10 / 129 Subroutinesub 47.6% 51 / 107 Podpod n/a totaltotal 50.2% 801 / 1595 CC 292 SCAR 40.9
CC
292
Cov
54%
check_deps
306.0
run_case
131.5
client_run_phase
110.2
CRAP 59.9
« blib/lib/Linux/Event/Loop.pm ↑ Summary blib/lib/Linux/Event/_Socket/Listener.pm »
1 #!/usr/bin/env perl
2 7 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use IO::Poll qw(POLLIN POLLOUT POLLERR POLLHUP);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Time::HiRes qw(time usleep);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use POSIX qw(:sys_wait_h);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Getopt::Long qw(GetOptions);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use JSON::PP qw(encode_json decode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use FindBin qw($Bin);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use lib "$Bin/../blib/lib", "$Bin/../blib/arch", "$Bin/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 7 my $systems = 'linuxevent,ev,anyevent-ae,uv,ioasync-epoll,mojo-epoll';
20 7 my $clients = '1000,2500,5000,10000,15000,20000';
21 7 my $messages = 10;
22 7 my $warmup = 1;
23 7 my $bytes = 64;
24 7 my $host = '127.0.0.1';
25 7 my $timeout = 90;
26 7 my $repeats = 6;
27 7 my $client_workers = 4;
28 7 my $build = 0;
29 7 my $check_deps = 0;
30 7 my $out = 'bench/results/reactor-comparison.html';
31 7 my $json_out = 'bench/results/reactor-comparison.json';
32  
33 7 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("systems=s", \$systems, "clients=s", \$clients, "messages=i", \$messages, "warmup=i", \$warmup, "bytes=i", \$bytes, "timeout=f", \$timeout, "repeats=i", \$repeats, "client-workers=i", \$client_workers, "build!", \$build, "check-deps!", \$check_deps, "out=s", \$out, "json=s", \$json_out) or die usage() 7 0 7
34 'systems=s' => \$systems,
35 'clients=s' => \$clients,
36 'messages=i' => \$messages,
37 'warmup=i' => \$warmup,
38 'bytes=i' => \$bytes,
39 'timeout=f' => \$timeout,
40 'repeats=i' => \$repeats,
41 'client-workers=i' => \$client_workers,
42 'build!' => \$build,
43 'check-deps!' => \$check_deps,
44 'out=s' => \$out,
45 'json=s' => \$json_out,
46 ) or die usage();
47  
48 7 my @systems = grep length, split /,/, $systems;
49 7 my @clients = map { int($_) } grep length, split /,/, $clients;
50 7 my %known = map { $_ => 1 } qw(
51 linuxevent
52 ev
53 anyevent-ae
54 uv
55 ioasync-epoll
56 mojo-epoll
57 anyevent-method
58 anyevent-ae-evrun
59 );
60 7 ▶die "unknown system in --systems\n" if grep { !$known{$_} } @systems;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $known{$_};} @systems 0 7 7
61 7 ▶die "messages must be > 0\n" unless $messages > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $messages > 0 0 7 7
62 7 ▶die "warmup must be >= 0\n" unless $warmup >= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $warmup >= 0 0 7 7
63 7 ▶die "bytes must be > 0\n" unless $bytes > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $bytes > 0 0 7 7
64 7 ▶die "repeats must be > 0\n" unless $repeats > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $repeats > 0 0 7 7
65 7 ▶die "client-workers must be > 0\n" unless $client_workers > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $client_workers > 0 0 7 7
66 7 ▶warn "NOTE: --repeats=$repeats is not a multiple of the selected system count (" . scalar(@systems) . "); execution positions will rotate but will not be perfectly balanced.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $repeats % @systems 0 7 7
67 if $repeats % @systems;
68  
69 7 ▶if ($build) {
Branch: 1 branch
BranchTrueFalseTotal
if ($build) 0 7 7
70 0 ▶ system($^X, 'Makefile.PL') == 0 or die "Makefile.PL failed\n";
Branch: 1 branch
BranchTrueFalseTotal
system($^X, "Makefile.PL") == 0 or die "Makefile.PL failed\n" 0 0 0
71 0 ▶ system('make') == 0 or die "make failed\n";
Branch: 1 branch
BranchTrueFalseTotal
system("make") == 0 or die "make failed\n" 0 0 0
72 }
73  
74 7 ▶if ($check_deps) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check_deps) 0 7 7
75 0 check_deps();
76 0 exit 0;
77 }
78  
79 7 my @results;
80 # Run systems in a deterministic balanced rotation instead of system-by-system.
81 # When repeats is a multiple of the selected system count, every system occupies
82 # every execution position equally for each client count. This prevents long-run CPU
83 # frequency, thermal, and scheduler drift from being confounded with a
84 # particular reactor implementation.
85 7 for my $client_index (0 .. $#clients) {
86 7 my $count = $clients[$client_index];
87 7 for my $repeat (1 .. $repeats) {
88 7 my $offset = (($repeat - 1) + $client_index) % @systems;
89 7 my @order = (@systems[$offset .. $#systems], @systems[0 .. $offset - 1]);
90 7 for my $position (0 .. $#order) {
91 7 my $system = $order[$position];
92 7 my $order_position = $position + 1;
93 7 warn "== $system clients=$count repeat=$repeat order=$order_position/" . scalar(@order) . " ==\n";
94 7 my $result = eval { run_case_isolated($system, $count, $repeat) };
95 2 ▶ if (!$result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 0 2 2
96 0 ▶ my $err = $@ || 'unknown case error';
Condition0%0/2
$@ || 'unknown case error'
l!l
00
MC/DC0%0/1
$@ || 'unknown case error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
97 0 chomp $err;
98 0 $result = failure_result($system, $count, $repeat, $err);
99 0 warn "FAILED: $err\n";
100 }
101 2 $result->{execution_order_mode} = 'balanced-rotation';
102 2 $result->{execution_order_position} = $order_position;
103 2 $result->{execution_order_width} = scalar @order;
104 2 $result->{execution_block} = "clients=$count/repeat=$repeat";
105 2 push @results, $result;
106 }
107 }
108 }
109  
110 2 my @summary = summarize(\@results);
111 2 write_json($json_out, {
112 benchmark => 'strict preconnected same-work reactor comparison (balanced order)',
113 fairness_contract => fairness_contract(),
114 results => \@results,
115 summary => \@summary,
116 });
117 2 write_html($out, \@results, \@summary);
118 2 print "wrote $json_out\n";
119 2 print "wrote $out\n";
120  
121 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
122 0 return <<'USAGE';
123 Usage:
124 perl bench/run-reactor-comparison.pl --build \
125 --systems linuxevent,ev,anyevent-ae,uv,ioasync-epoll,mojo-epoll \
126 --clients 1000,2500,5000,10000,15000,20000 \
127 --warmup 1 --messages 10 --bytes 64 \
128 --client-workers 4 --repeats 6 --timeout 90 \
129 --out bench/results/reactor-comparison.html \
130 --json bench/results/reactor-comparison.json
131  
132 Strict fairness contract:
133 * every TCP connection is established and accepted before reactor timing
134 * every server uses the exact same Perl echo_read() function
135 * every client uses the same serial one-request/one-reply protocol
136 * warmup exchanges complete before server counters and timing are reset
137 * clients stay connected after their final measured reply
138 * connection teardown happens only after the measured server loop stops
139 * no framework timeout watcher runs during the measured interval
140 * an external parent process provides catastrophic timeout protection
141 * reactor cases use a balanced rotating execution order across repeats
142  
143 Systems:
144 linuxevent Linux::Event XSLoop run_once(-1) loop
145 ev direct EV::io watchers + EV::run
146 anyevent-ae AE::io fast API + AnyEvent condition variable
147 uv UV::Poll watchers + dedicated libuv loop
148 ioasync-epoll IO::Async::Loop::Epoll low-level watch_io API
149 mojo-epoll Mojo::Reactor::Epoll low-level reactor API
150  
151 Diagnostic systems (not in the default leaderboard):
152 anyevent-method AnyEvent->io method API + AnyEvent condition variable
153 anyevent-ae-evrun AE::io watchers driven directly by EV::run
154  
155 For perfect execution-position balance, make --repeats a multiple of the
156 number of selected systems. The six-system default therefore uses 6 repeats.
157  
158 Use --check-deps to report installed competitor versions and backend selection.
159 USAGE
160 }
161  
162 2 ▶sub fairness_contract {
Subroutine fairness_contract: called CC=1 SCAR=0.0
163 return {
164 2 transport => 'TCP IPv4 loopback',
165 protocol => 'serial request/reply; at most one outstanding request per client',
166 payload_bytes => $bytes,
167 server_read_size_bytes => 8192,
168 server_echo_body => 'identical Perl echo_read() for all ranked systems',
169 preconnected => JSON::PP::true,
170 accept_outside_timing => JSON::PP::true,
171 watcher_registration_outside_timing => JSON::PP::true,
172 warmup_outside_timing => JSON::PP::true,
173 teardown_outside_timing => JSON::PP::true,
174 framework_timer_outside_timing => JSON::PP::true,
175 client_workers => $client_workers,
176 warmup_per_client => $warmup,
177 measured_messages_per_client => $messages,
178 };
179 }
180  
181 0 ▶sub check_deps {
Subroutine check_deps: not called CC=17 SCAR=57.2
182 0 printf "Perl %s\n", $^V;
183 0 my $le = eval { require Linux::Event::Loop; 1 };
184 0 ▶ print $le ? "Linux::Event::Loop: available\n" : "Linux::Event::Loop: MISSING ($@)\n";
Branch: 1 branch
BranchTrueFalseTotal
$le ? : 0 0 0
185  
186 0 my $ev = eval { require EV; 1 };
187 0 ▶ if ($ev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ev) { } 0 0 0
188 0 ▶ printf "EV: %s backend=%s\n", ($EV::VERSION // 'unknown'), ev_backend_name();
Condition0%0/2
$EV::VERSION // "unknown"
l!l
00
MC/DC0%0/1
$EV::VERSION // "unknown"
$EV::VERSION
Truth table0%0/2
A
A= $EV::VERSION
Aresult
11
00
189 }
190 else {
191 0 print "EV: MISSING ($@)\n";
192 }
193  
194 0 my $ae = eval {
195 0 local $ENV{PERL_ANYEVENT_MODEL} = 'EV';
196 0 require AnyEvent;
197 0 AnyEvent::detect();
198 0 1;
199 };
200 0 ▶ if ($ae) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ae) { } 0 0 0
201 0 ▶ printf "AnyEvent: %s model=%s AE::io=%s\n",
Branch: 1 branch
BranchTrueFalseTotal
defined &EV::_ae_io && defined &AE::io && builtin::refaddr(\&AE::io) == builtin::refaddr(\&EV::_ae_io) ? : 0 0 0
Condition0%0/10
$AnyEvent::VERSION // "unknown"
l!l
00
$AnyEvent::MODEL // "unknown"
l!l
00
defined &EV::_ae_io and defined &AE::io and builtin::refaddr(\&AE::io) == builtin::refaddr(\&EV::_ae_io)
!ll&&!rl&&r
000
defined &EV::_ae_io and defined &AE::io
!ll&&!rl&&r
000
MC/DC0%0/1
$AnyEvent::VERSION // "unknown"
$AnyEvent::VERSION
MC/DC0%0/1
$AnyEvent::MODEL // "unknown"
$AnyEvent::MODEL
MC/DC0%0/3
defined &EV::_ae_io and defined &AE::io and builtin::refaddr(\&AE::io) == builtin::refaddr(\&EV::_ae_io)
defined &EV::_ae_io defined &AE::io builtin::refaddr(\&AE::io) == builtin::refaddr(\&EV::_ae_io)
Truth table0%0/2
A
A= $AnyEvent::VERSION
Aresult
11
00
Truth table0%0/2
A
A= $AnyEvent::MODEL
Aresult
11
00
Truth table0%0/4
A and B and C
A= defined &EV::_ae_ioB= defined &AE::ioC= builtin::refaddr(\&AE::io) == builtin::refaddr(\&EV::_ae_io)
ABCresult
0XX0
10X0
1100
1111
202 ($AnyEvent::VERSION // 'unknown'),
203 ($AnyEvent::MODEL // 'unknown'),
204 (defined &EV::_ae_io && defined &AE::io && refaddr(\&AE::io) == refaddr(\&EV::_ae_io) ? 'EV::_ae_io direct alias' : 'other');
205 }
206 else {
207 0 print "AnyEvent: MISSING ($@)\n";
208 }
209  
210 0 my $uv = eval {
211 0 require UV;
212 0 require UV::Loop;
213 0 require UV::Poll;
214 0 1;
215 };
216 0 ▶ if ($uv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uv) { } 0 0 0
217 printf "UV: %s libuv=%s\n",
218 ($UV::VERSION // 'unknown'),
219 0 ▶ (eval { UV::version_string() } // 'unknown');
Condition0%0/4
$UV::VERSION // "unknown"
l!l
00
eval { do { UV::version_string() } } // "unknown"
l!l
00
MC/DC0%0/1
$UV::VERSION // "unknown"
$UV::VERSION
MC/DC0%0/1
eval { do { UV::version_string() } } // "unknown"
eval { do { UV::version_string() } }
Truth table0%0/2
A
A= $UV::VERSION
Aresult
11
00
Truth table0%0/2
A
A= eval { do { UV::version_string() } }
Aresult
11
00
220 }
221 else {
222 0 print "UV: MISSING ($@)\n";
223 }
224  
225 0 my $ioa = eval { require IO::Async::Loop::Epoll; 1 };
226 0 ▶ if ($ioa) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ioa) { } 0 0 0
227 0 ▶ printf "IO::Async::Loop::Epoll: %s\n",
Condition0%0/2
$IO::Async::Loop::Epoll::VERSION // "unknown"
l!l
00
MC/DC0%0/1
$IO::Async::Loop::Epoll::VERSION // "unknown"
$IO::Async::Loop::Epoll::VERSION
Truth table0%0/2
A
A= $IO::Async::Loop::Epoll::VERSION
Aresult
11
00
228 ($IO::Async::Loop::Epoll::VERSION // 'unknown');
229 }
230 else {
231 0 print "IO::Async::Loop::Epoll: MISSING ($@)\n";
232 }
233  
234 0 my $mojo = eval { require Mojo::Reactor::Epoll; 1 };
235 0 ▶ if ($mojo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mojo) { } 0 0 0
236 0 ▶ printf "Mojo::Reactor::Epoll: %s\n",
Condition0%0/2
$Mojo::Reactor::Epoll::VERSION // "unknown"
l!l
00
MC/DC0%0/1
$Mojo::Reactor::Epoll::VERSION // "unknown"
$Mojo::Reactor::Epoll::VERSION
Truth table0%0/2
A
A= $Mojo::Reactor::Epoll::VERSION
Aresult
11
00
237 ($Mojo::Reactor::Epoll::VERSION // 'unknown');
238 }
239 else {
240 0 print "Mojo::Reactor::Epoll: MISSING ($@)\n";
241 }
242 }
243  
244 7 ▶sub run_case_isolated ($system, $count, $repeat) {
Subroutine run_case_isolated: called CC=13 SCAR=31.3
245 7 ▶ pipe(my $read_fh, my $write_fh) or die "case pipe failed: $!";
Branch: 1 branch
BranchTrueFalseTotal
pipe my $read_fh, my $write_fh or die "case pipe failed: $!" 7 0 7
246 7 my $pid = fork();
247 7 ▶ die "case fork failed: $!" unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 7 7
248  
249 7 ▶ if ($pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) 5 2 7
250 5 close $read_fh;
251 5 $SIG{PIPE} = 'IGNORE';
252 5 my $payload;
253 5 my $ok = eval {
254 5 my $result = run_case($system, $count, $repeat);
255 2 $payload = encode_json({ worker_ok => JSON::PP::true, result => $result });
256 2 1;
257 };
258 2 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 2 2
259 0 ▶ my $err = $@ || 'unknown worker error';
Condition0%0/2
$@ || 'unknown worker error'
l!l
00
MC/DC0%0/1
$@ || 'unknown worker error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
260 0 chomp $err;
261 0 $payload = encode_json({ worker_ok => JSON::PP::false, error => $err });
262 }
263 2 print {$write_fh} $payload;
264 2 close $write_fh;
265 2 ▶ exit($ok ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 2 0 2
266 }
267  
268 2 close $write_fh;
269 2 my $guard = $timeout + 180 + int($count / 500);
270 2 my $select = IO::Select->new($read_fh);
271 2 ▶ if (!$select->can_read($guard)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($select->can_read($guard)) 0 2 2
272 0 kill 'TERM', $pid;
273 0 usleep(100_000);
274 0 ▶ kill 'KILL', $pid if kill 0, $pid;
Branch: 1 branch
BranchTrueFalseTotal
if kill 0, $pid 0 0 0
275 0 waitpid($pid, 0);
276 0 close $read_fh;
277 0 die "case worker exceeded external timeout (${guard}s)";
278 }
279  
280 2 local $/;
281 2 my $txt = <$read_fh>;
282 2 close $read_fh;
283 2 waitpid($pid, 0);
284  
285 2 ▶ die "case worker produced no result" unless defined $txt && length $txt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $txt and length $txt 0 2 2
Condition33%1/3
defined $txt and length $txt
!ll&&!rl&&r
002
MC/DC0%0/2
defined $txt and length $txt
defined $txt length $txt
Truth table33%1/3
A and B
A= defined $txtB= length $txt
ABresult
0X0
100
111
286 2 my $envelope = decode_json($txt);
287 2 ▶ die ($envelope->{error} || 'case worker failed') unless $envelope->{worker_ok};
Branch: 1 branch
BranchTrueFalseTotal
unless $envelope->{"worker_ok"} 0 2 2
Condition0%0/2
$envelope->{'error'} || 'case worker failed'
l!l
00
MC/DC0%0/1
$envelope->{'error'} || 'case worker failed'
$envelope->{'error'}
Truth table0%0/2
A
A= $envelope->{'error'}
Aresult
11
00
288 2 return $envelope->{result};
289 }
290  
291 5 ▶sub run_case ($system, $count, $repeat) {
Subroutine run_case: called CC=55 SCAR=48.8
292 5 ▶ my $server = IO::Socket::INET->new(
Branch: 1 branch
BranchTrueFalseTotal
my $server = "IO::Socket::INET"->new("LocalAddr", $host, "LocalPort", 0, "Proto", "tcp", "Listen", 8192, "ReuseAddr", 1) or die "listen failed: $!" 5 0 5
293 LocalAddr => $host,
294 LocalPort => 0,
295 Proto => 'tcp',
296 Listen => 8192,
297 ReuseAddr => 1,
298 ) or die "listen failed: $!";
299 5 $server->blocking(0);
300 5 my $port = $server->sockport;
301  
302 5 my $tmp = tempdir(CLEANUP => 1);
303 5 my $warmup_gate = "$tmp/warmup-go";
304 5 my $measure_gate = "$tmp/measure-go";
305 5 my $teardown_gate = "$tmp/teardown-go";
306 5 my @ready_files;
307 my @warmup_done_files;
308 5 my @measure_done_files;
309 5 my @client_files;
310 5 my @pids;
311 5 my $msg = 'x' x $bytes;
312  
313 5 ▶ my $workers = $client_workers > $count ? $count : $client_workers;
Branch: 1 branch
BranchTrueFalseTotal
$client_workers > $count ? : 0 5 5
314 5 my $base = int($count / $workers);
315 5 my $extra = $count % $workers;
316 5 for my $worker (1 .. $workers) {
317 7 ▶ my $worker_clients = $base + ($worker <= $extra ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$worker <= $extra ? : 0 7 7
318 7 my $ready = "$tmp/ready-$worker";
319 7 my $warm_done = "$tmp/warmup-done-$worker";
320 7 my $measure_done = "$tmp/measure-done-$worker";
321 7 my $result = "$tmp/client-$worker.json";
322 7 push @ready_files, $ready;
323 7 push @warmup_done_files, $warm_done;
324 7 push @measure_done_files, $measure_done;
325 7 push @client_files, $result;
326 7 my $pid = fork();
327 7 ▶ die "client worker fork failed: $!" unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 7 7
328 7 ▶ if ($pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) 3 4 7
329 3 $SIG{PIPE} = 'IGNORE';
330 0 ▶ $SIG{TERM} = sub { exit 143 };
Subroutine __ANON__: not called CC=1 SCAR=1.2
331 3 strict_client_worker(
332 $port, $worker_clients, $msg,
333 $ready, $warmup_gate, $warm_done,
334 $measure_gate, $measure_done,
335 $teardown_gate, $result,
336 );
337 0 exit 0;
338 }
339 4 push @pids, $pid;
340 }
341  
342 # Accept every connection directly, before any event framework is loaded or
343 # any watcher is registered. This removes accept-loop differences entirely.
344 2 my @sockets;
345 2 my $setup_deadline = time + $timeout + 120;
346 2 ▶ while (@sockets < $count && time < $setup_deadline) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sockets < $count and &main::time() < $setup_deadline) 23 2 25
Condition66%2/3
@sockets < $count and &main::time() < $setup_deadline
!ll&&!rl&&r
2023
MC/DC50%1/2
@sockets < $count and &main::time() < $setup_deadline
@sockets < $count &main::time() < $setup_deadline
Truth table66%2/3
A and B
A= @sockets < $countB= &main::time() < $setup_deadline
ABresult
0X0
100
111
347 23 my $accepted = 0;
348 23 ▶ while (my $sock = $server->accept) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sock = $server->accept) 24 23 47
349 24 $sock->blocking(0);
350 24 push @sockets, $sock;
351 24 $accepted++;
352 }
353 23 ▶ usleep(100) unless $accepted;
Branch: 1 branch
BranchTrueFalseTotal
unless $accepted 13 10 23
354 }
355 2 ▶ die "setup accepted=" . scalar(@sockets) . "/$count" if @sockets != $count;
Branch: 1 branch
BranchTrueFalseTotal
if @sockets != $count 0 2 2
356  
357 2 wait_for_files(\@ready_files, $setup_deadline, 'client ready barrier');
358 2 close $server;
359  
360 2 my %c;
361 2 reset_app_counters(\%c);
362 2 ▶ my %phase = (target_bytes => 0, done => 0, failed => 0, stop => sub { });
Subroutine __ANON__: not called CC=1 SCAR=0.0
363 2 my $driver = setup_reactor($system, \@sockets, \%c, \%phase);
364  
365 # Real warmup: it runs through the same registered watchers and exact same
366 # Perl echo body, but completes before counters/timing are reset.
367 2 ▶ if ($warmup > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warmup > 0) { } 1 1 2
368 1 $phase{target_bytes} = $count * $warmup * $bytes;
369 1 $phase{done} = 0;
370 1 $phase{failed} = 0;
371 1 $phase{stop} = $driver->{make_stop}->(\%phase);
372 1 touch_gate($warmup_gate);
373 1 $driver->{run}->(\%phase);
374 1 ▶ die "warmup failed" if $phase{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $phase{"failed"} 0 1 1
375 die "warmup bytes=$c{bytes_written}/$phase{target_bytes}"
376 1 ▶ if $c{bytes_written} != $phase{target_bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $c{"bytes_written"} != $phase{"target_bytes"} 0 1 1
377 1 wait_for_files(\@warmup_done_files, $setup_deadline, 'warmup done barrier');
378 }
379 else {
380 1 touch_gate($warmup_gate);
381 1 wait_for_files(\@warmup_done_files, $setup_deadline, 'warmup done barrier');
382 }
383  
384 2 reset_app_counters(\%c);
385 2 $driver->{reset_stats}->();
386  
387 2 my $target_bytes = $count * $messages * $bytes;
388 2 $phase{target_bytes} = $target_bytes;
389 2 $phase{done} = 0;
390 2 $phase{failed} = 0;
391 2 $phase{stop} = $driver->{make_stop}->(\%phase);
392  
393 2 my $cs_before = context_switches();
394 2 my @times_before = times();
395 2 my $reactor_before = $driver->{iterations}->();
396 2 my $start = time;
397 2 touch_gate($measure_gate);
398 2 $driver->{run}->(\%phase);
399 2 my $elapsed = time - $start;
400 2 my $reactor_after = $driver->{iterations}->();
401 2 my @times_after = times();
402 2 my $cs_after = context_switches();
403  
404 # Clients have received all measured replies but deliberately remain open.
405 # Their close/EOF/RDHUP behaviour is therefore outside the measured window.
406 2 my $post_deadline = time + 30;
407 2 wait_for_files(\@measure_done_files, $post_deadline, 'measure done barrier');
408 2 touch_gate($teardown_gate);
409  
410 2 my $client_failures = reap_clients(\@pids, 30);
411 2 my ($client_results, $file_failures) = load_client_results(\@client_files);
412 2 $client_failures += $file_failures;
413  
414 2 my @lat;
415 2 my $client_measured = 0;
416 2 for my $cr (@$client_results) {
417 3 ▶ $client_measured += $cr->{measured_messages} // 0;
Condition50%1/2
$cr->{"measured_messages"} // 0
l!l
30
MC/DC0%0/1
$cr->{"measured_messages"} // 0
$cr->{"measured_messages"}
Truth table50%1/2
A
A= $cr->{"measured_messages"}
Aresult
11
00
418 3 ▶ push @lat, @{ $cr->{latency_us} || [] };
Condition50%1/2
$cr->{'latency_us'} || []
l!l
30
MC/DC0%0/1
$cr->{'latency_us'} || []
$cr->{'latency_us'}
Truth table50%1/2
A
A= $cr->{'latency_us'}
Aresult
11
00
419 }
420 2 @lat = sort { $a <=> $b } @lat;
421  
422 2 my $total_messages = $count * $messages;
423 my $ok = !$phase{failed}
424 && !$client_failures
425 && $client_measured == $total_messages
426 && $c{bytes_read} == $target_bytes
427 && $c{bytes_written} == $target_bytes
428 && $c{echoed_bytes} == $target_bytes
429 && $c{unexpected_closes} == 0
430 && $c{write_eagain} == 0
431 2 ▶ && $c{partial_writes} == 0;
Condition33%8/24
!($phase{'failed'} || $client_failures) && $client_measured == $total_messages && $c{'bytes_read'} == $target_bytes && $c{'bytes_written'} == $target_bytes && $c{'echoed_bytes'} == $target_bytes && $c{'unexpected_closes'} == 0 && $c{'write_eagain'} == 0 && $c{'partial_writes'} == 0
!ll&&!rl&&r
002
not $phase{"failed"} || $client_failures and $client_measured == $total_messages and $c{"bytes_read"} == $target_bytes and $c{"bytes_written"} == $target_bytes and $c{"echoed_bytes"} == $target_bytes and $c{"unexpected_closes"} == 0 and $c{"write_eagain"} == 0
!ll&&!rl&&r
002
not $phase{"failed"} || $client_failures and $client_measured == $total_messages and $c{"bytes_read"} == $target_bytes and $c{"bytes_written"} == $target_bytes and $c{"echoed_bytes"} == $target_bytes and $c{"unexpected_closes"} == 0
!ll&&!rl&&r
002
not $phase{"failed"} || $client_failures and $client_measured == $total_messages and $c{"bytes_read"} == $target_bytes and $c{"bytes_written"} == $target_bytes and $c{"echoed_bytes"} == $target_bytes
!ll&&!rl&&r
002
not $phase{"failed"} || $client_failures and $client_measured == $total_messages and $c{"bytes_read"} == $target_bytes and $c{"bytes_written"} == $target_bytes
!ll&&!rl&&r
002
not $phase{"failed"} || $client_failures and $client_measured == $total_messages and $c{"bytes_read"} == $target_bytes
!ll&&!rl&&r
002
not $phase{"failed"} || $client_failures and $client_measured == $total_messages
!ll&&!rl&&r
002
$phase{'failed'} || $client_failures
l!l&&r!l&&!r
002
MC/DC0%0/9
!($phase{'failed'} || $client_failures) && $client_measured == $total_messages && $c{'bytes_read'} == $target_bytes && $c{'bytes_written'} == $target_bytes && $c{'echoed_bytes'} == $target_bytes && $c{'unexpected_closes'} == 0 && $c{'write_eagain'} == 0 && $c{'partial_writes'} == 0
$phase{'failed'} $client_failures $client_measured == $total_messages $c{"bytes_read"} == $target_bytes $c{"bytes_written"} == $target_bytes $c{"echoed_bytes"} == $target_bytes $c{"unexpected_closes"} == 0 $c{"write_eagain"} == 0 $c{'partial_writes'} == 0
Truth table10%1/10
not(A || B) and C and D and E and F and G and H && I
A= $phase{'failed'}B= $client_failuresC= $client_measured == $total_messagesD= $c{"bytes_read"} == $target_bytesE= $c{"bytes_written"} == $target_bytesF= $c{"echoed_bytes"} == $target_bytesG= $c{"unexpected_closes"} == 0H= $c{"write_eagain"} == 0I= $c{'partial_writes'} == 0
ABCDEFGHIresult
1XXXXXXXX0
01XXXXXXX0
000XXXXXX0
0010XXXXX0
00110XXXX0
001110XXX0
0011110XX0
00111110X0
0011111100
0011111111
432  
433 2 my $user_cpu = $times_after[0] - $times_before[0];
434 2 my $sys_cpu = $times_after[1] - $times_before[1];
435 2 my $total_cpu = $user_cpu + $sys_cpu;
436 2 ▶ my $reactor_iterations = defined($reactor_after) && defined($reactor_before)
Branch: 1 branch
BranchTrueFalseTotal
defined $reactor_after && defined $reactor_before ? : 2 0 2
Condition33%1/3
defined $reactor_after and defined $reactor_before
!ll&&!rl&&r
002
MC/DC0%0/2
defined $reactor_after and defined $reactor_before
defined $reactor_after defined $reactor_before
Truth table33%1/3
A and B
A= defined $reactor_afterB= defined $reactor_before
ABresult
0X0
100
111
437 ? $reactor_after - $reactor_before
438 : undef;
439 2 my $meta = $driver->{metadata}->();
440  
441 my %result = (
442 system => display_system($system),
443 system_key => $system,
444 clients => $count,
445 messages => $total_messages,
446 messages_per_client => $messages,
447 warmup_messages => $count * $warmup,
448 warmup_per_client => $warmup,
449 bytes => $bytes,
450 client_workers => $workers,
451 repeat => $repeat,
452 preconnected => JSON::PP::true,
453 warmup_outside_timing => JSON::PP::true,
454 teardown_outside_timing => JSON::PP::true,
455 shared_perl_echo_body => JSON::PP::true,
456 elapsed_seconds => num($elapsed),
457 messages_per_second => $ok ? num($total_messages / $elapsed) : undef,
458 attempt_messages_per_second => num($total_messages / $elapsed),
459 mib_per_second => $ok ? num((($total_messages * $bytes) / 1048576) / $elapsed) : undef,
460 ok => $ok ? JSON::PP::true : JSON::PP::false,
461 rankable => $ok ? JSON::PP::true : JSON::PP::false,
462 failure_reason => $ok ? undef : join('; ', grep length,
463 ($phase{failed} ? 'reactor phase failed' : ''),
464 ($client_failures ? "client failures=$client_failures" : ''),
465 ($client_measured != $total_messages ? "client_measured=$client_measured/$total_messages" : ''),
466 ($c{bytes_read} != $target_bytes ? "bytes_read=$c{bytes_read}/$target_bytes" : ''),
467 ($c{bytes_written} != $target_bytes ? "bytes_written=$c{bytes_written}/$target_bytes" : ''),
468 ($c{unexpected_closes} ? "unexpected_closes=$c{unexpected_closes}" : ''),
469 ($c{write_eagain} ? "write_eagain=$c{write_eagain}" : ''),
470 ($c{partial_writes} ? "partial_writes=$c{partial_writes}" : ''),
471 ),
472 client_failures => $client_failures,
473 client_measured_messages => $client_measured,
474 lat_p50_us => pct(\@lat, 50),
475 lat_p95_us => pct(\@lat, 95),
476 lat_p99_us => pct(\@lat, 99),
477 lat_max_us => @lat ? $lat[-1] : undef,
478 perl_version => "$^V",
479 linux_kernel => scalar(`uname -r`) =~ s/\s+\z//r,
480 max_rss_kb => max_rss_kb(),
481 server_user_cpu_seconds => num($user_cpu),
482 server_system_cpu_seconds => num($sys_cpu),
483 server_total_cpu_seconds => num($total_cpu),
484 server_cpu_us_per_message => $total_messages ? num(($total_cpu / $total_messages) * 1_000_000) : undef,
485 server_cpu_percent => $elapsed > 0 ? num(($total_cpu / $elapsed) * 100) : 0,
486 voluntary_ctxt_switches => ($cs_after->{voluntary} // 0) - ($cs_before->{voluntary} // 0),
487 nonvoluntary_ctxt_switches => ($cs_after->{nonvoluntary} // 0) - ($cs_before->{nonvoluntary} // 0),
488 reactor_iterations => $reactor_iterations,
489 read_callbacks_per_message => $total_messages ? num($c{read_callbacks} / $total_messages) : undef,
490 sysread_calls_per_message => $total_messages ? num($c{sysread_calls} / $total_messages) : undef,
491 syswrite_calls_per_message => $total_messages ? num($c{syswrite_calls} / $total_messages) : undef,
492 2 ▶ read_eagain_per_message => $total_messages ? num($c{read_eagain} / $total_messages) : undef,
Branch: 20 branches
BranchTrueFalseTotal
$ok ? : 2 0 2
$ok ? : 2 0 2
$ok ? : 2 0 2
$ok ? : 2 0 2
$ok ? : 2 0 2
$phase{'failed'} ? : 0 0 0
$client_failures ? : 0 0 0
$client_measured != $total_messages ? : 0 0 0
$c{'bytes_read'} != $target_bytes ? : 0 0 0
$c{'bytes_written'} != $target_bytes ? : 0 0 0
$c{'unexpected_closes'} ? : 0 0 0
$c{'write_eagain'} ? : 0 0 0
$c{'partial_writes'} ? : 0 0 0
@lat ? : 2 0 2
$total_messages ? : 2 0 2
$elapsed > 0 ? : 2 0 2
$total_messages ? : 2 0 2
$total_messages ? : 2 0 2
$total_messages ? : 2 0 2
$total_messages ? : 2 0 2
Condition50%4/8
$cs_after->{"voluntary"} // 0
l!l
20
$cs_before->{"voluntary"} // 0
l!l
20
$cs_after->{"nonvoluntary"} // 0
l!l
20
$cs_before->{"nonvoluntary"} // 0
l!l
20
MC/DC0%0/1
$cs_after->{"voluntary"} // 0
$cs_after->{"voluntary"}
MC/DC0%0/1
$cs_before->{"voluntary"} // 0
$cs_before->{"voluntary"}
MC/DC0%0/1
$cs_after->{"nonvoluntary"} // 0
$cs_after->{"nonvoluntary"}
MC/DC0%0/1
$cs_before->{"nonvoluntary"} // 0
$cs_before->{"nonvoluntary"}
Truth table50%1/2
A
A= $cs_after->{"voluntary"}
Aresult
11
00
Truth table50%1/2
A
A= $cs_before->{"voluntary"}
Aresult
11
00
Truth table50%1/2
A
A= $cs_after->{"nonvoluntary"}
Aresult
11
00
Truth table50%1/2
A
A= $cs_before->{"nonvoluntary"}
Aresult
11
00
493 work_signature => sprintf('tcp64=%d;serial=1;preconnected=1;perl_echo=v1;readbuf=8192', $bytes),
494 %c,
495 %$meta,
496 );
497  
498 2 ▶ if ($driver->{stats}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($driver->{"stats"}) 2 0 2
499 2 my $st = $driver->{stats}->();
500 2 for my $key (keys %$st) {
501 36 $result{$key} = $st->{$key};
502 }
503 }
504  
505 2 $driver->{cleanup}->();
506 2 close $_ for @sockets;
507 2 return \%result;
508 }
509  
510 2 ▶sub setup_reactor ($system, $sockets, $c, $phase) {
Subroutine setup_reactor: called CC=9 SCAR=42.8
511 2 ▶ return setup_linuxevent($sockets, $c, $phase) if $system eq 'linuxevent';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "linuxevent" 2 0 2
512 0 ▶ return setup_ev($sockets, $c, $phase) if $system eq 'ev';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "ev" 0 0 0
513 0 ▶ return setup_uv($sockets, $c, $phase) if $system eq 'uv';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "uv" 0 0 0
514 0 ▶ return setup_ioasync_epoll($sockets, $c, $phase) if $system eq 'ioasync-epoll';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "ioasync-epoll" 0 0 0
515 0 ▶ return setup_mojo_epoll($sockets, $c, $phase) if $system eq 'mojo-epoll';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "mojo-epoll" 0 0 0
516 0 ▶ return setup_anyevent($system, $sockets, $c, $phase)
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "anyevent-ae" or $system eq "anyevent-method" or $system eq "anyevent-ae-evrun" 0 0 0
Condition0%0/6
$system eq "anyevent-ae" or $system eq "anyevent-method" or $system eq "anyevent-ae-evrun"
l!l&&r!l&&!r
000
$system eq "anyevent-ae" or $system eq "anyevent-method"
l!l&&r!l&&!r
000
MC/DC0%0/3
$system eq "anyevent-ae" or $system eq "anyevent-method" or $system eq "anyevent-ae-evrun"
$system eq "anyevent-ae" $system eq "anyevent-method" $system eq "anyevent-ae-evrun"
Truth table0%0/4
A or B or C
A= $system eq "anyevent-ae"B= $system eq "anyevent-method"C= $system eq "anyevent-ae-evrun"
ABCresult
1XX1
01X1
0011
0000
517 if $system eq 'anyevent-ae' || $system eq 'anyevent-method' || $system eq 'anyevent-ae-evrun';
518 0 die "unsupported system $system";
519 }
520  
521 2 ▶sub setup_linuxevent ($sockets, $c, $phase) {
Subroutine setup_linuxevent: called CC=2 SCAR=7.0
522 2 require Linux::Event::Loop;
523 2 my $loop = Linux::Event::Loop->new;
524 2 $loop->set_callback_scope_limit(128);
525 2 my @watchers;
526  
527 2 for my $sock (@$sockets) {
528 my $w = $loop->watch(
529 fh => $sock,
530 no_args => 1,
531 lean => 1,
532 64 ▶ read => sub { echo_read($sock, $c, $phase); },
Subroutine __ANON__: called CC=1 SCAR=0.0
533 0 ▶ error => sub { reactor_error($c, $phase); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
534 24 );
535 24 push @watchers, $w;
536 }
537  
538 return {
539 3 ▶ make_stop => sub ($p) { return sub { $p->{done} = 1; }; },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
540 3 ▶ run => sub ($p) {
Subroutine __ANON__: called CC=3 SCAR=11.1
541 3 ▶ while (!$p->{done} && !$p->{failed}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $p->{"done"} || $p->{"failed"}) 9 3 12
Condition66%2/3
$p->{'done'} || $p->{'failed'}
l!l&&r!l&&!r
309
MC/DC50%1/2
$p->{'done'} || $p->{'failed'}
$p->{'done'} $p->{'failed'}
Truth table66%2/3
A || B
A= $p->{'done'}B= $p->{'failed'}
ABresult
1X1
011
000
542 9 $loop->run_once(-1);
543 }
544 },
545 4 ▶ iterations => sub { return $loop->stats->{epoll_wait_calls} // 0; },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$loop->stats->{"epoll_wait_calls"} // 0
l!l
40
MC/DC0%0/1
$loop->stats->{"epoll_wait_calls"} // 0
$loop->stats->{"epoll_wait_calls"}
Truth table50%1/2
A
A= $loop->stats->{"epoll_wait_calls"}
Aresult
11
00
546 2 ▶ reset_stats => sub { $loop->reset_stats; },
Subroutine __ANON__: called CC=1 SCAR=0.0
547 2 ▶ metadata => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
548 return {
549 2 backend => 'Linux::Event::Loop epoll',
550 backend_runtime => 'epoll',
551 callback_api => 'Linux::Event no-argument CV fast path',
552 loop_drive => 'Perl while + XS run_once(-1)',
553 callback_scope_limit => 128,
554 };
555 },
556 2 ▶ stats => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
557 2 my $st = $loop->stats;
558 2 my %out;
559 2 for my $key (qw(
560 epoll_wait_calls epoll_wait_empty_calls epoll_wait_full_batches epoll_wait_max_batch
561 ready_events_returned callback_calls read_callback_calls error_callback_calls
562 callback_noarg_calls callback_direct_cv_calls callback_batch_scope_enters
563 callback_scope_rotations callback_scope_max_callbacks callback_scope_limit
564 run_once_calls run_calls run_for_calls event_capacity
565 )) {
566 36 ▶ $out{"linuxevent_$key"} = $st->{$key} if exists $st->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $st->{$key} 36 0 36
567 }
568 2 return \%out;
569 },
570 2 ▶ cleanup => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
571 2 $_->cancel for @watchers;
572 2 @watchers = ();
573 },
574 2 };
575 }
576  
577 0 ▶sub setup_ev ($sockets, $c, $phase) {
Subroutine setup_ev: not called CC=2 SCAR=17.9
578 0 require EV;
579 0 my @watchers;
580 0 for my $sock (@$sockets) {
581 0 ▶ push @watchers, EV::io($sock, EV::READ(), sub { echo_read($sock, $c, $phase); });
Subroutine __ANON__: not called CC=1 SCAR=6.9
582 }
583  
584 return {
585 0 ▶ make_stop => sub ($p) { return sub { $p->{done} = 1; EV::break(EV::BREAK_ALL()); }; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
586 0 ▶ run => sub ($p) { EV::run() unless $p->{done} || $p->{failed}; },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
unless $p->{"done"} or $p->{"failed"} 0 0 0
Condition0%0/3
$p->{"done"} or $p->{"failed"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{"done"} or $p->{"failed"}
$p->{"done"} $p->{"failed"}
Truth table0%0/3
A or B
A= $p->{"done"}B= $p->{"failed"}
ABresult
1X1
011
000
587 0 ▶ iterations => sub { return EV::iteration(); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
588 0 ▶ reset_stats => sub { },
Subroutine __ANON__: not called CC=1 SCAR=0.0
589 0 ▶ metadata => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
590 return {
591 0 backend => 'EV/libev',
592 backend_runtime => ev_backend_name(),
593 ev_version => version_text($EV::VERSION),
594 callback_api => 'EV::io public API (watcher + revents supplied by EV)',
595 loop_drive => 'EV::run',
596 };
597 },
598 0 ▶ cleanup => sub { @watchers = (); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
599 0 };
600 }
601  
602 0 ▶sub setup_uv ($sockets, $c, $phase) {
Subroutine setup_uv: not called CC=2 SCAR=17.9
603 0 require UV;
604 0 require UV::Loop;
605 0 require UV::Poll;
606  
607 0 my $loop = UV::Loop->new();
608 0 my @polls;
609  
610 0 for my $sock (@$sockets) {
611 0 my $poll = UV::Poll->new(
612 socket => $sock,
613 loop => $loop,
614 );
615 0 ▶ $poll->start(UV::Poll::UV_READABLE(), sub ($invocant, $status, $events) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
616 0 ▶ if ($status < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status < 0) 0 0 0
617 0 reactor_error($c, $phase);
618 0 return;
619 }
620 0 ▶ echo_read($sock, $c, $phase) if $events & UV::Poll::UV_READABLE();
Branch: 1 branch
BranchTrueFalseTotal
if $events & UV::Poll::UV_READABLE() 0 0 0
621 0 });
622 0 push @polls, $poll;
623 }
624  
625 return {
626 0 ▶ make_stop => sub ($p) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
627 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
628 0 $p->{done} = 1;
629 0 $loop->stop();
630 0 };
631 },
632 0 ▶ run => sub ($p) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
633 0 ▶ $loop->run() unless $p->{done} || $p->{failed};
Branch: 1 branch
BranchTrueFalseTotal
unless $p->{"done"} or $p->{"failed"} 0 0 0
Condition0%0/3
$p->{"done"} or $p->{"failed"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{"done"} or $p->{"failed"}
$p->{"done"} $p->{"failed"}
Truth table0%0/3
A or B
A= $p->{"done"}B= $p->{"failed"}
ABresult
1X1
011
000
634 },
635 # libuv does not expose a directly comparable event-loop iteration
636 # counter through this Perl API. Do not substitute callback count.
637 0 ▶ iterations => sub { return undef; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
638 0 ▶ reset_stats => sub { },
Subroutine __ANON__: not called CC=1 SCAR=0.0
639 0 ▶ metadata => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
640 return {
641 backend => 'UV::Poll/libuv',
642 backend_runtime => 'epoll via libuv',
643 uv_version => version_text($UV::VERSION),
644 0 libuv_version => version_text(eval { UV::version_string() }),
645 callback_api => 'UV::Poll UV_READABLE callback (handle + status + events)',
646 loop_drive => 'UV::Loop->run (UV_RUN_DEFAULT)',
647 };
648 },
649 0 ▶ cleanup => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
650 0 $_->stop for @polls;
651 0 @polls = ();
652 },
653 0 };
654 }
655  
656 0 ▶sub setup_ioasync_epoll ($sockets, $c, $phase) {
Subroutine setup_ioasync_epoll: not called CC=2 SCAR=17.9
657 0 require IO::Async::Loop::Epoll;
658 0 my $loop = IO::Async::Loop::Epoll->new;
659  
660 0 for my $sock (@$sockets) {
661 $loop->watch_io(
662 handle => $sock,
663 0 ▶ on_read_ready => sub { echo_read($sock, $c, $phase); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
664 0 );
665 }
666  
667 return {
668 0 ▶ make_stop => sub ($p) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
669 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
670 0 $p->{done} = 1;
671 0 $loop->stop;
672 0 };
673 },
674 0 ▶ run => sub ($p) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
675 0 ▶ $loop->run unless $p->{done} || $p->{failed};
Branch: 1 branch
BranchTrueFalseTotal
unless $p->{"done"} or $p->{"failed"} 0 0 0
Condition0%0/3
$p->{"done"} or $p->{"failed"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{"done"} or $p->{"failed"}
$p->{"done"} $p->{"failed"}
Truth table0%0/3
A or B
A= $p->{"done"}B= $p->{"failed"}
ABresult
1X1
011
000
676 },
677 # IO::Async loop_once return values are not a cross-framework syscall
678 # counter, and run() does not expose a directly comparable total.
679 0 ▶ iterations => sub { return undef; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
680 0 ▶ reset_stats => sub { },
Subroutine __ANON__: not called CC=1 SCAR=0.0
681 0 ▶ metadata => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
682 return {
683 0 backend => 'IO::Async::Loop::Epoll',
684 backend_runtime => 'epoll',
685 ioasync_loop_epoll_version => version_text($IO::Async::Loop::Epoll::VERSION),
686 callback_api => 'IO::Async low-level watch_io on_read_ready',
687 loop_drive => 'IO::Async::Loop::Epoll->run',
688 };
689 },
690 0 ▶ cleanup => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
691 0 for my $sock (@$sockets) {
692 0 $loop->unwatch_io(handle => $sock, on_read_ready => 1);
693 }
694 },
695 0 };
696 }
697  
698 0 ▶sub setup_mojo_epoll ($sockets, $c, $phase) {
Subroutine setup_mojo_epoll: not called CC=2 SCAR=17.9
699 0 require Mojo::Reactor::Epoll;
700 0 my $reactor = Mojo::Reactor::Epoll->new;
701  
702 0 for my $sock (@$sockets) {
703 0 ▶ $reactor->io($sock => sub ($r, $writable) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
704 0 ▶ return if $writable;
Branch: 1 branch
BranchTrueFalseTotal
if $writable 0 0 0
705 0 echo_read($sock, $c, $phase);
706 0 })->watch($sock, 1, 0);
707 }
708  
709 return {
710 0 ▶ make_stop => sub ($p) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
711 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
712 0 $p->{done} = 1;
713 0 $reactor->stop;
714 0 };
715 },
716 0 ▶ run => sub ($p) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
717 0 ▶ $reactor->start unless $p->{done} || $p->{failed};
Branch: 1 branch
BranchTrueFalseTotal
unless $p->{"done"} or $p->{"failed"} 0 0 0
Condition0%0/3
$p->{"done"} or $p->{"failed"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{"done"} or $p->{"failed"}
$p->{"done"} $p->{"failed"}
Truth table0%0/3
A or B
A= $p->{"done"}B= $p->{"failed"}
ABresult
1X1
011
000
718 },
719 # Mojo::Reactor::Epoll does not publish a comparable loop-iteration
720 # total for a start()/stop() run.
721 0 ▶ iterations => sub { return undef; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
722 0 ▶ reset_stats => sub { },
Subroutine __ANON__: not called CC=1 SCAR=0.0
723 0 ▶ metadata => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
724 return {
725 0 backend => 'Mojo::Reactor::Epoll',
726 backend_runtime => 'epoll',
727 mojo_reactor_epoll_version => version_text($Mojo::Reactor::Epoll::VERSION),
728 callback_api => 'Mojo::Reactor::Epoll readable io callback',
729 loop_drive => 'Mojo::Reactor::Epoll->start',
730 };
731 },
732 0 ▶ cleanup => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
733 0 $reactor->remove($_) for @$sockets;
734 0 $reactor->reset;
735 },
736 0 };
737 }
738  
739 0 ▶sub setup_anyevent ($system, $sockets, $c, $phase) {
Subroutine setup_anyevent: not called CC=7 SCAR=40.3
740 0 local $ENV{PERL_ANYEVENT_MODEL} = 'EV';
741 0 require AnyEvent;
742 0 AnyEvent::detect();
743 0 ▶ die "AnyEvent backend is not EV: " . ($AnyEvent::MODEL // 'undef')
Branch: 1 branch
BranchTrueFalseTotal
unless ($AnyEvent::MODEL // "") eq "AnyEvent::Impl::EV" 0 0 0
Condition0%0/4
$AnyEvent::MODEL // ""
l!l
00
$AnyEvent::MODEL // "undef"
l!l
00
MC/DC0%0/1
$AnyEvent::MODEL // ""
$AnyEvent::MODEL
MC/DC0%0/1
$AnyEvent::MODEL // "undef"
$AnyEvent::MODEL
Truth table0%0/2
A
A= $AnyEvent::MODEL
Aresult
11
00
Truth table0%0/2
A
A= $AnyEvent::MODEL
Aresult
11
00
744 unless ($AnyEvent::MODEL // '') eq 'AnyEvent::Impl::EV';
745 0 require EV;
746  
747 0 my @watchers;
748 0 ▶ if ($system eq 'anyevent-method') {
Branch: 1 branch
BranchTrueFalseTotal
if ($system eq 'anyevent-method') { } 0 0 0
749 0 for my $sock (@$sockets) {
750 push @watchers, AnyEvent->io(
751 fh => $sock,
752 poll => 'r',
753 0 ▶ cb => sub { echo_read($sock, $c, $phase); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
754 0 );
755 }
756 }
757 else {
758 0 for my $sock (@$sockets) {
759 0 ▶ push @watchers, AE::io($sock, 0, sub { echo_read($sock, $c, $phase); });
Subroutine __ANON__: not called CC=1 SCAR=6.9
760 }
761 }
762  
763 0 my $current_cv;
764 return {
765 0 ▶ make_stop => sub ($p) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
766 0 ▶ if ($system eq 'anyevent-ae-evrun') {
Branch: 1 branch
BranchTrueFalseTotal
if ($system eq "anyevent-ae-evrun") 0 0 0
767 0 ▶ return sub { $p->{done} = 1; EV::break(EV::BREAK_ALL()); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
768 }
769 0 $current_cv = AE::cv();
770 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
771 0 $p->{done} = 1;
772 0 ▶ $current_cv->send unless $current_cv->ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $current_cv->ready 0 0 0
773 0 };
774 },
775 0 ▶ run => sub ($p) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
776 0 ▶ return if $p->{done} || $p->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $p->{"done"} or $p->{"failed"} 0 0 0
Condition0%0/3
$p->{"done"} or $p->{"failed"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{"done"} or $p->{"failed"}
$p->{"done"} $p->{"failed"}
Truth table0%0/3
A or B
A= $p->{"done"}B= $p->{"failed"}
ABresult
1X1
011
000
777 0 ▶ if ($system eq 'anyevent-ae-evrun') {
Branch: 1 branch
BranchTrueFalseTotal
if ($system eq 'anyevent-ae-evrun') { } 0 0 0
778 0 EV::run();
779 }
780 else {
781 0 $current_cv->recv;
782 }
783 },
784 0 ▶ iterations => sub { return EV::iteration(); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
785 0 ▶ reset_stats => sub { },
Subroutine __ANON__: not called CC=1 SCAR=0.0
786 0 ▶ metadata => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
787 0 ▶ my $fast_alias = defined &EV::_ae_io && defined &AE::io && refaddr(\&AE::io) == refaddr(\&EV::_ae_io);
Condition0%0/6
defined &EV::_ae_io && defined &AE::io && builtin::refaddr(\&AE::io) == builtin::refaddr(\&EV::_ae_io)
!ll&&!rl&&r
000
defined &EV::_ae_io and defined &AE::io
!ll&&!rl&&r
000
MC/DC0%0/3
defined &EV::_ae_io && defined &AE::io && builtin::refaddr(\&AE::io) == builtin::refaddr(\&EV::_ae_io)
defined &EV::_ae_io defined &AE::io builtin::refaddr(\&AE::io) == builtin::refaddr(\&EV::_ae_io)
Truth table0%0/4
A and B && C
A= defined &EV::_ae_ioB= defined &AE::ioC= builtin::refaddr(\&AE::io) == builtin::refaddr(\&EV::_ae_io)
ABCresult
0XX0
10X0
1100
1111
788 return {
789 0 ▶ backend => 'AnyEvent with EV adaptor',
Branch: 3 branches
BranchTrueFalseTotal
$fast_alias ? : 0 0 0
$system eq 'anyevent-method' ? : 0 0 0
$system eq 'anyevent-ae-evrun' ? : 0 0 0
790 backend_runtime => ev_backend_name(),
791 anyevent_version => version_text($AnyEvent::VERSION),
792 anyevent_model => $AnyEvent::MODEL,
793 ae_io_direct_ev_alias => $fast_alias ? JSON::PP::true : JSON::PP::false,
794 callback_api => $system eq 'anyevent-method'
795 ? 'AnyEvent->io method API -> EV::io'
796 : 'AE::io fast API',
797 loop_drive => $system eq 'anyevent-ae-evrun'
798 ? 'diagnostic direct EV::run'
799 : 'AnyEvent condvar recv (EV adaptor _wait uses RUN_ONCE)',
800 };
801 },
802 0 ▶ cleanup => sub { @watchers = (); undef $current_cv; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
803 0 };
804 }
805  
806 64 ▶sub echo_read ($fh, $c, $phase) {
Subroutine echo_read: called CC=20 SCAR=42.5
807 64 $c->{read_callbacks}++;
808 64 while (1) {
809 128 $c->{sysread_calls}++;
810 128 my $n = sysread($fh, my $buf, 8192);
811 128 ▶ if (defined $n && $n > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n and $n > 0) 64 64 128
Condition66%2/3
defined $n and $n > 0
!ll&&!rl&&r
64064
MC/DC50%1/2
defined $n and $n > 0
defined $n $n > 0
Truth table66%2/3
A and B
A= defined $nB= $n > 0
ABresult
0X0
100
111
812 64 $c->{bytes_read} += $n;
813 64 $c->{echoed_bytes} += $n;
814 64 my $off = 0;
815 64 my $len = length($buf);
816 64 ▶ while ($off < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($off < $len) 64 64 128
817 64 $c->{syswrite_calls}++;
818 64 my $remain = $len - $off;
819 64 my $wr = syswrite($fh, $buf, $remain, $off);
820 64 ▶ if (defined $wr && $wr > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $wr and $wr > 0) 64 0 64
Condition33%1/3
defined $wr and $wr > 0
!ll&&!rl&&r
0064
MC/DC0%0/2
defined $wr and $wr > 0
defined $wr $wr > 0
Truth table33%1/3
A and B
A= defined $wrB= $wr > 0
ABresult
0X0
100
111
821 64 $c->{bytes_written} += $wr;
822 64 ▶ $c->{partial_writes}++ if $wr < $remain;
Branch: 1 branch
BranchTrueFalseTotal
if $wr < $remain 0 64 64
823 64 $off += $wr;
824 64 ▶ if (!$phase->{done} && $c->{bytes_written} >= $phase->{target_bytes}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $phase->{"done"} and $c->{"bytes_written"} >= $phase->{"target_bytes"}) 3 61 64
Condition66%2/3
not $phase->{"done"} and $c->{"bytes_written"} >= $phase->{"target_bytes"}
!ll&&!rl&&r
0613
MC/DC50%1/2
not $phase->{"done"} and $c->{"bytes_written"} >= $phase->{"target_bytes"}
not $phase->{"done"} $c->{"bytes_written"} >= $phase->{"target_bytes"}
Truth table66%2/3
not(A) and B
A= not $phase->{"done"}B= $c->{"bytes_written"} >= $phase->{"target_bytes"}
ABresult
0X0
100
111
825 3 $phase->{stop}->();
826 }
827 64 next;
828 }
829 0 ▶ if (!defined $wr && ($!{EAGAIN} || $!{EWOULDBLOCK})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $wr and $!{"EAGAIN"} || $!{"EWOULDBLOCK"}) 0 0 0
Condition0%0/6
not defined $wr and $!{"EAGAIN"} || $!{"EWOULDBLOCK"}
!ll&&!rl&&r
000
$!{"EAGAIN"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $wr and $!{"EAGAIN"} || $!{"EWOULDBLOCK"}
not defined $wr $!{"EAGAIN"} $!{"EWOULDBLOCK"}
Truth table0%0/4
not(A) and B or C
A= not defined $wrB= $!{"EAGAIN"}C= $!{"EWOULDBLOCK"}
ABCresult
0XX0
1000
11X1
1011
830 0 $c->{write_eagain}++;
831 0 last;
832 }
833 0 $c->{write_errors}++;
834 0 $phase->{failed} = 1;
835 0 ▶ $phase->{stop}->() unless $phase->{done};
Branch: 1 branch
BranchTrueFalseTotal
unless $phase->{"done"} 0 0 0
836 0 last;
837 }
838 64 next;
839 }
840 64 ▶ if (defined $n && $n == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n and $n == 0) 0 64 64
Condition33%1/3
defined $n and $n == 0
!ll&&!rl&&r
6400
MC/DC0%0/2
defined $n and $n == 0
defined $n $n == 0
Truth table33%1/3
A and B
A= defined $nB= $n == 0
ABresult
0X0
100
111
841 0 $c->{unexpected_closes}++;
842 0 $phase->{failed} = 1;
843 0 ▶ $phase->{stop}->() unless $phase->{done};
Branch: 1 branch
BranchTrueFalseTotal
unless $phase->{"done"} 0 0 0
844 0 last;
845 }
846 64 ▶ if (!defined $n && ($!{EAGAIN} || $!{EWOULDBLOCK})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $n and $!{"EAGAIN"} || $!{"EWOULDBLOCK"}) 64 0 64
Condition33%2/6
not defined $n and $!{"EAGAIN"} || $!{"EWOULDBLOCK"}
!ll&&!rl&&r
0064
$!{"EAGAIN"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
6400
MC/DC0%0/3
not defined $n and $!{"EAGAIN"} || $!{"EWOULDBLOCK"}
not defined $n $!{"EAGAIN"} $!{"EWOULDBLOCK"}
Truth table25%1/4
not(A) and B or C
A= not defined $nB= $!{"EAGAIN"}C= $!{"EWOULDBLOCK"}
ABCresult
0XX0
1000
11X1
1011
847 64 $c->{read_eagain}++;
848 64 last;
849 }
850 0 $c->{read_errors}++;
851 0 $phase->{failed} = 1;
852 0 ▶ $phase->{stop}->() unless $phase->{done};
Branch: 1 branch
BranchTrueFalseTotal
unless $phase->{"done"} 0 0 0
853 0 last;
854 }
855 }
856  
857 0 ▶sub reactor_error ($c, $phase) {
Subroutine reactor_error: not called CC=2 SCAR=17.9
858 0 $c->{error_callbacks}++;
859 0 $phase->{failed} = 1;
860 0 ▶ $phase->{stop}->() unless $phase->{done};
Branch: 1 branch
BranchTrueFalseTotal
unless $phase->{"done"} 0 0 0
861 }
862  
863 4 ▶sub reset_app_counters ($c) {
Subroutine reset_app_counters: called CC=1 SCAR=0.0
864 4 %$c = (
865 read_callbacks => 0,
866 error_callbacks => 0,
867 sysread_calls => 0,
868 syswrite_calls => 0,
869 read_eagain => 0,
870 write_eagain => 0,
871 partial_writes => 0,
872 read_errors => 0,
873 write_errors => 0,
874 unexpected_closes => 0,
875 bytes_read => 0,
876 bytes_written => 0,
877 echoed_bytes => 0,
878 );
879 }
880  
881 3 ▶sub strict_client_worker (
Subroutine strict_client_worker: called CC=13 SCAR=26.6
882 $port, $count, $msg,
883 $ready_file, $warmup_gate, $warmup_done_file,
884 $measure_gate, $measure_done_file,
885 $teardown_gate, $out_file,
886 ) {
887 3 my $poll = IO::Poll->new;
888 3 my %state;
889 3 my $failed = 0;
890  
891 3 for my $id (1 .. $count) {
892 24 my $sock;
893 24 for (1 .. 5000) {
894 24 $sock = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Proto => 'tcp');
895 24 ▶ last if $sock;
Branch: 1 branch
BranchTrueFalseTotal
if $sock 24 0 24
896 0 usleep(1000);
897 }
898 24 ▶ if (!$sock) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sock) 0 24 24
899 0 $failed++;
900 0 next;
901 }
902 24 $sock->blocking(0);
903 24 my $fd = fileno($sock);
904 24 $state{$fd} = { sock => $sock };
905 24 $poll->mask($sock => POLLIN | POLLERR | POLLHUP);
906 }
907  
908 3 write_marker($ready_file, scalar keys %state);
909 3 wait_for_gate($warmup_gate, $timeout + 120);
910  
911 3 ▶ if ($warmup > 0 && %state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warmup > 0 and %state) 2 1 3
Condition66%2/3
$warmup > 0 and %state
!ll&&!rl&&r
102
MC/DC50%1/2
$warmup > 0 and %state
$warmup > 0 %state
Truth table66%2/3
A and B
A= $warmup > 0B= %state
ABresult
0X0
100
111
912 2 my ($ok) = client_run_phase($poll, \%state, $msg, $warmup, 0);
913 2 ▶ $failed++ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 2 2
914 }
915 3 write_marker($warmup_done_file, 1);
916  
917 3 wait_for_gate($measure_gate, $timeout + 120);
918 3 my @lat;
919 3 my $measured = 0;
920 3 ▶ if (%state) {
Branch: 1 branch
BranchTrueFalseTotal
if (%state) 3 0 3
921 3 my ($ok, $done, $lats) = client_run_phase($poll, \%state, $msg, $messages, 1);
922 3 ▶ $failed++ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 3 3
923 3 $measured = $done;
924 3 @lat = @$lats;
925 }
926  
927 3 ▶ write_json($out_file, {
Branch: 1 branch
BranchTrueFalseTotal
$failed ? : 0 3 3
928 ok => $failed ? JSON::PP::false : JSON::PP::true,
929 measured_messages => $measured,
930 latency_us => \@lat,
931 failures => $failed,
932 });
933 3 write_marker($measure_done_file, 1);
934  
935 3 wait_for_gate($teardown_gate, 60);
936 3 for my $st (values %state) {
937 24 close $st->{sock};
938 }
939 3 ▶ exit($failed ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$failed ? : 0 3 3
940 }
941  
942 5 ▶sub client_run_phase ($poll, $state, $msg, $phase_messages, $record_latency) {
Subroutine client_run_phase: called CC=35 SCAR=47.0
943 5 my $active = 0;
944 5 my $failed = 0;
945 5 my $total_done = 0;
946 5 my @lat;
947  
948 5 for my $st (values %$state) {
949 44 $st->{phase_sent} = 0;
950 44 $st->{phase_done} = 0;
951 44 $st->{recv_len} = 0;
952 44 $st->{write_off} = 0;
953 44 $st->{write_active} = 1;
954 44 $st->{awaiting_reply} = 0;
955 44 ▶ $st->{lat_start} = $record_latency ? time : undef;
Branch: 1 branch
BranchTrueFalseTotal
$record_latency ? : 24 20 44
956 44 $poll->mask($st->{sock} => POLLIN | POLLOUT | POLLERR | POLLHUP);
957 44 $active++;
958 }
959  
960 5 my $deadline = time + $timeout + 30;
961 5 ▶ while ($active > 0 && time < $deadline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($active > 0 and &main::time() < $deadline) 62 5 67
Condition66%2/3
$active > 0 and &main::time() < $deadline
!ll&&!rl&&r
5062
MC/DC50%1/2
$active > 0 and &main::time() < $deadline
$active > 0 &main::time() < $deadline
Truth table66%2/3
A and B
A= $active > 0B= &main::time() < $deadline
ABresult
0X0
100
111
962 62 my $nready = $poll->poll(0.05);
963 62 ▶ next unless $nready;
Branch: 1 branch
BranchTrueFalseTotal
unless $nready 0 62 62
964 62 for my $fh ($poll->handles(POLLERR | POLLHUP | POLLIN | POLLOUT)) {
965 128 my $fd = fileno($fh);
966 128 ▶ my $st = $state->{$fd} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $st = $state->{$fd} or next 128 0 128
967 128 ▶ next if $st->{phase_done} >= $phase_messages;
Branch: 1 branch
BranchTrueFalseTotal
if $st->{"phase_done"} >= $phase_messages 0 128 128
968 128 my $ev = $poll->events($fh);
969  
970 128 ▶ if (($ev & (POLLERR | POLLHUP)) && !($ev & POLLIN)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ev & 24 and not $ev & 1) 0 128 128
Condition33%1/3
$ev & 24 and not $ev & 1
!ll&&!rl&&r
12800
MC/DC0%0/2
$ev & 24 and not $ev & 1
$ev & 24 not $ev & 1
Truth table33%1/3
A and not(B)
A= $ev & 24B= not $ev & 1
ABresult
0X0
100
111
971 0 $failed++;
972 0 $st->{phase_done} = $phase_messages;
973 0 $active--;
974 0 $poll->mask($fh => POLLIN | POLLERR | POLLHUP);
975 0 next;
976 }
977  
978 128 ▶ if (($ev & POLLOUT) && $st->{write_active}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ev & 4 and $st->{"write_active"}) 64 64 128
Condition66%2/3
$ev & 4 and $st->{"write_active"}
!ll&&!rl&&r
64064
MC/DC50%1/2
$ev & 4 and $st->{"write_active"}
$ev & 4 $st->{"write_active"}
Truth table66%2/3
A and B
A= $ev & 4B= $st->{"write_active"}
ABresult
0X0
100
111
979 64 my $remain = $bytes - $st->{write_off};
980 64 my $wr = syswrite($fh, $msg, $remain, $st->{write_off});
981 64 ▶ if (defined $wr && $wr > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $wr and $wr > 0) { } 64 0 64
elsif (not defined $wr and $!{'EAGAIN'} || $!{'EWOULDBLOCK'}) { } 0 0 0
Condition33%1/3
defined $wr and $wr > 0
!ll&&!rl&&r
0064
MC/DC0%0/2
defined $wr and $wr > 0
defined $wr $wr > 0
Truth table33%1/3
A and B
A= defined $wrB= $wr > 0
ABresult
0X0
100
111
982 64 $st->{write_off} += $wr;
983 64 ▶ if ($st->{write_off} >= $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($st->{"write_off"} >= $bytes) 64 0 64
984 64 $st->{write_active} = 0;
985 64 $st->{awaiting_reply} = 1;
986 64 $st->{write_off} = 0;
987 64 $st->{phase_sent}++;
988 64 $poll->mask($fh => POLLIN | POLLERR | POLLHUP);
989 }
990 }
991 ▶ elsif (!defined $wr && ($!{EAGAIN} || $!{EWOULDBLOCK})) {
Condition0%0/6
not defined $wr and $!{"EAGAIN"} || $!{"EWOULDBLOCK"}
!ll&&!rl&&r
000
$!{"EAGAIN"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $wr and $!{"EAGAIN"} || $!{"EWOULDBLOCK"}
not defined $wr $!{"EAGAIN"} $!{"EWOULDBLOCK"}
Truth table0%0/4
not(A) and B or C
A= not defined $wrB= $!{"EAGAIN"}C= $!{"EWOULDBLOCK"}
ABCresult
0XX0
1000
11X1
1011
992 }
993 else {
994 0 $failed++;
995 0 $st->{phase_done} = $phase_messages;
996 0 $active--;
997 0 $poll->mask($fh => POLLIN | POLLERR | POLLHUP);
998 0 next;
999 }
1000 }
1001  
1002 128 ▶ if (($ev & POLLIN) && $st->{awaiting_reply}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ev & 1 and $st->{"awaiting_reply"}) 64 64 128
Condition66%2/3
$ev & 1 and $st->{"awaiting_reply"}
!ll&&!rl&&r
64064
MC/DC50%1/2
$ev & 1 and $st->{"awaiting_reply"}
$ev & 1 $st->{"awaiting_reply"}
Truth table66%2/3
A and B
A= $ev & 1B= $st->{"awaiting_reply"}
ABresult
0X0
100
111
1003 64 my $need = $bytes - $st->{recv_len};
1004 64 my $n = sysread($fh, my $buf, $need);
1005 64 ▶ if (defined $n && $n > 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $n and $n > 0) { } 64 0 64
elsif (defined $n and $n == 0) { } 0 0 0
elsif (not defined $n and $!{'EAGAIN'} || $!{'EWOULDBLOCK'}) { } 0 0 0
Condition33%1/3
defined $n and $n > 0
!ll&&!rl&&r
0064
MC/DC0%0/2
defined $n and $n > 0
defined $n $n > 0
Truth table33%1/3
A and B
A= defined $nB= $n > 0
ABresult
0X0
100
111
1006 64 $st->{recv_len} += $n;
1007 64 ▶ if ($st->{recv_len} >= $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($st->{"recv_len"} >= $bytes) 64 0 64
1008 64 ▶ if ($record_latency && defined $st->{lat_start}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record_latency and defined $st->{"lat_start"}) 44 20 64
Condition66%2/3
$record_latency and defined $st->{"lat_start"}
!ll&&!rl&&r
20044
MC/DC50%1/2
$record_latency and defined $st->{"lat_start"}
$record_latency defined $st->{"lat_start"}
Truth table66%2/3
A and B
A= $record_latencyB= defined $st->{"lat_start"}
ABresult
0X0
100
111
1009 44 push @lat, int((time - $st->{lat_start}) * 1_000_000);
1010 }
1011 64 $st->{recv_len} = 0;
1012 64 $st->{awaiting_reply} = 0;
1013 64 $st->{phase_done}++;
1014 64 $total_done++;
1015 64 ▶ if ($st->{phase_done} >= $phase_messages) {
Branch: 1 branch
BranchTrueFalseTotal
if ($st->{'phase_done'} >= $phase_messages) { } 44 20 64
1016 44 $active--;
1017 44 $poll->mask($fh => POLLIN | POLLERR | POLLHUP);
1018 }
1019 else {
1020 20 $st->{write_active} = 1;
1021 20 ▶ $st->{lat_start} = $record_latency ? time : undef;
Branch: 1 branch
BranchTrueFalseTotal
$record_latency ? : 20 0 20
1022 20 $poll->mask($fh => POLLIN | POLLOUT | POLLERR | POLLHUP);
1023 }
1024 }
1025 }
1026 ▶ elsif (defined $n && $n == 0) {
Condition0%0/3
defined $n and $n == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $n and $n == 0
defined $n $n == 0
Truth table0%0/3
A and B
A= defined $nB= $n == 0
ABresult
0X0
100
111
1027 0 $failed++;
1028 0 $st->{phase_done} = $phase_messages;
1029 0 $active--;
1030 }
1031 ▶ elsif (!defined $n && ($!{EAGAIN} || $!{EWOULDBLOCK})) {
Condition0%0/6
not defined $n and $!{"EAGAIN"} || $!{"EWOULDBLOCK"}
!ll&&!rl&&r
000
$!{"EAGAIN"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $n and $!{"EAGAIN"} || $!{"EWOULDBLOCK"}
not defined $n $!{"EAGAIN"} $!{"EWOULDBLOCK"}
Truth table0%0/4
not(A) and B or C
A= not defined $nB= $!{"EAGAIN"}C= $!{"EWOULDBLOCK"}
ABCresult
0XX0
1000
11X1
1011
1032 }
1033 else {
1034 0 $failed++;
1035 0 $st->{phase_done} = $phase_messages;
1036 0 $active--;
1037 }
1038 }
1039 }
1040 }
1041  
1042 5 ▶ $failed++ if $active > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $active > 0 0 5 5
1043 5 ▶ return ($failed ? 0 : 1, $total_done, \@lat);
Branch: 1 branch
BranchTrueFalseTotal
$failed ? : 0 5 5
1044 }
1045  
1046 6 ▶sub touch_gate ($path) {
Subroutine touch_gate: called CC=2 SCAR=7.0
1047 6 ▶ open my $fh, '>', $path or die "write gate $path: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $path or die "write gate ${path}: $!" 6 0 6
1048 6 print {$fh} "go\n";
1049 6 close $fh;
1050 }
1051  
1052 9 ▶sub write_marker ($path, $value) {
Subroutine write_marker: called CC=2 SCAR=7.0
1053 9 ▶ open my $fh, '>', $path or die "write marker $path: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $path or die "write marker ${path}: $!" 9 0 9
1054 9 print {$fh} "$value\n";
1055 9 close $fh;
1056 }
1057  
1058 9 ▶sub wait_for_gate ($path, $seconds) {
Subroutine wait_for_gate: called CC=3 SCAR=11.0
1059 9 my $deadline = time + $seconds;
1060 9 ▶ until (-e $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $path) 305 9 314
1061 305 ▶ die "gate timeout: $path" if time >= $deadline;
Branch: 1 branch
BranchTrueFalseTotal
if &main::time() >= $deadline 0 305 305
1062 305 usleep(100);
1063 }
1064 }
1065  
1066 6 ▶sub wait_for_files ($files, $deadline, $label) {
Subroutine wait_for_files: called CC=4 SCAR=16.4
1067 6 ▶ while (time < $deadline) {
Branch: 1 branch
BranchTrueFalseTotal
if (&main::time() < $deadline) 28 0 28
1068 28 ▶ return unless grep { !-e $_ } @$files;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {not -e $_;} @$files 6 22 28
1069 22 usleep(100);
1070 }
1071 0 ▶ die "$label timeout" if grep { !-e $_ } @$files;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not -e $_;} @$files 0 0 0
1072 }
1073  
1074 2 ▶sub reap_clients ($pids, $seconds) {
Subroutine reap_clients: called CC=9 SCAR=24.8
1075 2 my $failures = 0;
1076 2 for my $pid (@$pids) {
1077 3 my $deadline = time + $seconds;
1078 3 my $done = 0;
1079 3 ▶ while (time < $deadline) {
Branch: 1 branch
BranchTrueFalseTotal
if (&main::time() < $deadline) 93 0 93
1080 93 my $wp = waitpid($pid, WNOHANG);
1081 93 ▶ if ($wp == $pid || $wp == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wp == $pid or $wp == -1) 3 90 93
Condition66%2/3
$wp == $pid or $wp == -1
l!l&&r!l&&!r
3090
MC/DC50%1/2
$wp == $pid or $wp == -1
$wp == $pid $wp == -1
Truth table66%2/3
A or B
A= $wp == $pidB= $wp == -1
ABresult
1X1
011
000
1082 3 $done = 1;
1083 3 ▶ $failures++ if $wp == $pid && $? != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $wp == $pid and $? != 0 0 3 3
Condition33%1/3
$wp == $pid and $? != 0
!ll&&!rl&&r
030
MC/DC0%0/2
$wp == $pid and $? != 0
$wp == $pid $? != 0
Truth table33%1/3
A and B
A= $wp == $pidB= $? != 0
ABresult
0X0
100
111
1084 3 last;
1085 }
1086 90 usleep(10_000);
1087 }
1088 3 ▶ if (!$done && kill 0, $pid) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $done and kill 0, $pid) 0 3 3
Condition33%1/3
not $done and kill 0, $pid
!ll&&!rl&&r
300
MC/DC0%0/2
not $done and kill 0, $pid
not $done kill 0, $pid
Truth table33%1/3
not(A) and B
A= not $doneB= kill 0, $pid
ABresult
0X0
100
111
1089 0 $failures++;
1090 0 kill 'TERM', $pid;
1091 0 waitpid($pid, 0);
1092 }
1093 }
1094 2 return $failures;
1095 }
1096  
1097 2 ▶sub load_client_results ($files) {
Subroutine load_client_results: called CC=6 SCAR=21.3
1098 2 my @results;
1099 2 my $failures = 0;
1100 2 for my $file (@$files) {
1101 3 ▶ if (!-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 3 3
1102 0 $failures++;
1103 0 next;
1104 }
1105 0 ▶ open my $fh, '<', $file or do { $failures++; next; };
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or do { ++$failures; next } 3 0 3
1106 3 local $/;
1107 3 my $cr = eval { decode_json(<$fh>) };
1108 3 close $fh;
1109 3 ▶ if (!$cr || !$cr->{ok}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cr and $cr->{"ok"}) 0 3 3
Condition33%1/3
$cr and $cr->{"ok"}
!ll&&!rl&&r
003
MC/DC0%0/2
$cr and $cr->{"ok"}
$cr $cr->{"ok"}
Truth table33%1/3
A and B
A= $crB= $cr->{"ok"}
ABresult
0X0
100
111
1110 0 $failures++;
1111 0 next;
1112 }
1113 3 push @results, $cr;
1114 }
1115 2 return (\@results, $failures);
1116 }
1117  
1118 0 ▶sub ev_backend_name {
Subroutine ev_backend_name: not called CC=6 SCAR=37.4
1119 0 ▶ return 'unknown' unless defined &EV::backend;
Branch: 1 branch
BranchTrueFalseTotal
unless defined &EV::backend 0 0 0
1120 0 my $backend = EV::backend();
1121 0 for my $name (qw(SELECT POLL EPOLL KQUEUE DEVPOLL PORT LINUXAIO IOURING)) {
1122 0 ▶ my $sub = EV->can("BACKEND_$name") or next;
Branch: 1 branch
BranchTrueFalseTotal
my $sub = "EV"->can("BACKEND_$name") or next 0 0 0
1123 0 my $value = eval { $sub->() };
1124 0 ▶ return "${name}($backend)" if defined $value && $value == $backend;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and $value == $backend 0 0 0
Condition0%0/3
defined $value and $value == $backend
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and $value == $backend
defined $value $value == $backend
Truth table0%0/3
A and B
A= defined $valueB= $value == $backend
ABresult
0X0
100
111
1125 }
1126 0 return "backend-$backend";
1127 }
1128  
1129 4 ▶sub display_system ($system) {
Subroutine display_system: called CC=9 SCAR=42.8
1130 4 ▶ return 'Linux::Event XSLoop same-work Perl echo' if $system eq 'linuxevent';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "linuxevent" 4 0 4
1131 0 ▶ return 'EV direct same-work Perl echo' if $system eq 'ev';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "ev" 0 0 0
1132 0 ▶ return 'AnyEvent AE::io fast API on EV' if $system eq 'anyevent-ae';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "anyevent-ae" 0 0 0
1133 0 ▶ return 'UV::Poll same-work Perl echo on libuv' if $system eq 'uv';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "uv" 0 0 0
1134 0 ▶ return 'IO::Async::Loop::Epoll same-work Perl echo' if $system eq 'ioasync-epoll';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "ioasync-epoll" 0 0 0
1135 0 ▶ return 'Mojo::Reactor::Epoll same-work Perl echo' if $system eq 'mojo-epoll';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "mojo-epoll" 0 0 0
1136 0 ▶ return 'AnyEvent->io method API on EV' if $system eq 'anyevent-method';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "anyevent-method" 0 0 0
1137 0 ▶ return 'AnyEvent AE::io on EV, direct EV::run diagnostic' if $system eq 'anyevent-ae-evrun';
Branch: 1 branch
BranchTrueFalseTotal
if $system eq "anyevent-ae-evrun" 0 0 0
1138 0 return $system;
1139 }
1140  
1141 0 ▶sub failure_result ($system, $count, $repeat, $err) {
Subroutine failure_result: not called CC=1 SCAR=6.9
1142 return {
1143 0 system => display_system($system),
1144 system_key => $system,
1145 clients => $count,
1146 messages => $count * $messages,
1147 messages_per_client => $messages,
1148 warmup_per_client => $warmup,
1149 bytes => $bytes,
1150 client_workers => $client_workers,
1151 repeat => $repeat,
1152 ok => JSON::PP::false,
1153 rankable => JSON::PP::false,
1154 failure_reason => $err,
1155 messages_per_second => undef,
1156 };
1157 }
1158  
1159 2 ▶sub summarize ($results) {
Subroutine summarize: called CC=8 SCAR=21.5
1160 2 my @summary;
1161 2 for my $system (@systems) {
1162 2 for my $count (@clients) {
1163 my @r = grep {
1164 2 $_->{system_key} eq $system && $_->{clients} == $count && $_->{ok}
1165 2 ▶ } @$results;
Condition33%2/6
$_->{'system_key'} eq $system && $_->{'clients'} == $count && $_->{'ok'}
!ll&&!rl&&r
002
$_->{"system_key"} eq $system and $_->{"clients"} == $count
!ll&&!rl&&r
002
MC/DC0%0/3
$_->{'system_key'} eq $system && $_->{'clients'} == $count && $_->{'ok'}
$_->{"system_key"} eq $system $_->{"clients"} == $count $_->{'ok'}
Truth table25%1/4
A and B && C
A= $_->{"system_key"} eq $systemB= $_->{"clients"} == $countC= $_->{'ok'}
ABCresult
0XX0
10X0
1100
1111
1166 2 ▶ next unless @r;
Branch: 1 branch
BranchTrueFalseTotal
unless @r 0 2 2
1167 push @summary, {
1168 system => display_system($system),
1169 system_key => $system,
1170 backend => ($r[0]{backend_runtime} // $r[0]{backend} // ''),
1171 clients => $count,
1172 repeats => scalar @r,
1173 2 median_messages_per_second => median(map { $_->{messages_per_second} } @r),
1174 2 mean_messages_per_second => mean(map { $_->{messages_per_second} } @r),
1175 2 median_elapsed_seconds => median(map { $_->{elapsed_seconds} } @r),
1176 2 median_lat_p50_us => median(grep { defined } map { $_->{lat_p50_us} } @r),
1177 2 median_lat_p95_us => median(grep { defined } map { $_->{lat_p95_us} } @r),
1178 2 median_lat_p99_us => median(grep { defined } map { $_->{lat_p99_us} } @r),
1179 2 median_server_cpu_us_per_message => median(map { $_->{server_cpu_us_per_message} } @r),
1180 2 median_server_cpu_percent => median(map { $_->{server_cpu_percent} } @r),
1181 2 median_max_rss_kb => median(map { $_->{max_rss_kb} } @r),
1182 2 median_reactor_iterations => median(grep { defined } map { $_->{reactor_iterations} } @r),
1183 2 median_read_callbacks_per_message => median(map { $_->{read_callbacks_per_message} } @r),
1184 2 median_sysread_calls_per_message => median(map { $_->{sysread_calls_per_message} } @r),
1185 2 ▶ median_syswrite_calls_per_message => median(map { $_->{syswrite_calls_per_message} } @r),
Condition40%2/5
($r[0]{"backend_runtime"} // $r[0]{"backend"}) // ""
l!l
20
$r[0]{"backend_runtime"} // $r[0]{"backend"}
l!l&&r!l&&!r
200
MC/DC0%0/2
($r[0]{"backend_runtime"} // $r[0]{"backend"}) // ""
$r[0]{"backend_runtime"} $r[0]{"backend"}
Truth table33%1/3
A // B
A= $r[0]{"backend_runtime"}B= $r[0]{"backend"}
ABresult
1X1
011
000
1186 };
1187 }
1188 }
1189 2 return @summary;
1190 }
1191  
1192 24 ▶sub median (@values) {
Subroutine median: called CC=3 SCAR=12.7
1193 24 ▶ return undef unless @values;
Branch: 1 branch
BranchTrueFalseTotal
unless @values 0 24 24
1194 0 @values = sort { $a <=> $b } @values;
1195 24 my $n = @values;
1196 24 ▶ return $values[int($n / 2)] if $n % 2;
Branch: 1 branch
BranchTrueFalseTotal
if $n % 2 24 0 24
1197 0 return ($values[$n / 2 - 1] + $values[$n / 2]) / 2;
1198 }
1199  
1200 2 ▶sub mean (@values) {
Subroutine mean: called CC=3 SCAR=11.1
1201 2 ▶ return undef unless @values;
Branch: 1 branch
BranchTrueFalseTotal
unless @values 0 2 2
1202 2 my $sum = 0;
1203 2 $sum += $_ for @values;
1204 2 return $sum / @values;
1205 }
1206  
1207 6 ▶sub pct ($arr, $p) {
Subroutine pct: called CC=2 SCAR=7.1
1208 6 ▶ return undef unless @$arr;
Branch: 1 branch
BranchTrueFalseTotal
unless @$arr 0 6 6
1209 6 my $idx = int((@$arr - 1) * ($p / 100));
1210 6 return $arr->[$idx];
1211 }
1212  
1213 0 ▶sub version_text ($value) {
Subroutine version_text: not called CC=2 SCAR=17.9
1214 0 ▶ return 'unknown' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
1215 0 return "$value";
1216 }
1217  
1218 26 ▶sub num ($value) {
Subroutine num: called CC=1 SCAR=0.0
1219 26 return 0 + sprintf('%.6f', $value);
1220 }
1221  
1222 2 ▶sub max_rss_kb {
Subroutine max_rss_kb: called CC=5 SCAR=17.5
1223 2 ▶ return 0 unless -r '/proc/self/status';
Branch: 1 branch
BranchTrueFalseTotal
unless -r "/proc/self/status" 0 2 2
1224 2 ▶ open my $fh, '<', '/proc/self/status' or return 0;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", "/proc/self/status" or return 0 2 0 2
1225 2 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 44 0 44
1226 44 ▶ return 0 + $1 if /^VmHWM:\s+(\d+)\s+kB/;
Branch: 1 branch
BranchTrueFalseTotal
if /^VmHWM:\s+(\d+)\s+kB/u 2 42 44
1227 }
1228 0 return 0;
1229 }
1230  
1231 4 ▶sub context_switches {
Subroutine context_switches: called CC=6 SCAR=18.0
1232 4 my %r = (voluntary => 0, nonvoluntary => 0);
1233 4 ▶ return \%r unless -r '/proc/self/status';
Branch: 1 branch
BranchTrueFalseTotal
unless -r "/proc/self/status" 0 4 4
1234 4 ▶ open my $fh, '<', '/proc/self/status' or return \%r;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", "/proc/self/status" or return \%r 4 0 4
1235 4 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 244 4 248
1236 244 ▶ $r{voluntary} = 0 + $1 if /^voluntary_ctxt_switches:\s+(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^voluntary_ctxt_switches:\s+(\d+)/u 4 240 244
1237 244 ▶ $r{nonvoluntary} = 0 + $1 if /^nonvoluntary_ctxt_switches:\s+(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^nonvoluntary_ctxt_switches:\s+(\d+)/u 4 240 244
1238 }
1239 4 return \%r;
1240 }
1241  
1242 5 ▶sub write_json ($path, $data) {
Subroutine write_json: called CC=4 SCAR=14.5
1243 5 ▶ if ($path =~ m{^(.+)/[^/]+$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[^(.+)/[^/]+$]u) 5 0 5
1244 5 ▶ make_path($1) unless -d $1;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $1 0 5 5
1245 }
1246 5 ▶ open my $fh, '>', $path or die "write $path: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $path or die "write ${path}: $!" 5 0 5
1247 5 print {$fh} JSON::PP->new->canonical(1)->pretty(1)->encode($data);
1248 5 close $fh;
1249 }
1250  
1251 2 ▶sub write_html ($path, $results, $summary) {
Subroutine write_html: called CC=36 SCAR=42.7
1252 2 ▶ if ($path =~ m{^(.+)/[^/]+$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[^(.+)/[^/]+$]u) 2 0 2
1253 2 ▶ make_path($1) unless -d $1;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $1 0 2 2
1254 }
1255 2 ▶ open my $fh, '>', $path or die "write $path: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $path or die "write ${path}: $!" 2 0 2
1256  
1257 0 my @system_names = sort { lc($a) cmp lc($b) }
1258 2 ▶ do { my %seen; grep { !$seen{$_}++ } map { $_->{system} // '' } @$results };
Condition50%1/2
$_->{"system"} // ""
l!l
20
MC/DC0%0/1
$_->{"system"} // ""
$_->{"system"}
Truth table50%1/2
A
A= $_->{"system"}
Aresult
11
00
1259 0 my @client_counts = sort { $a <=> $b }
1260 2 ▶ do { my %seen; grep { !$seen{$_}++ } map { $_->{clients} // 0 } @$results };
Condition50%1/2
$_->{"clients"} // 0
l!l
20
MC/DC0%0/1
$_->{"clients"} // 0
$_->{"clients"}
Truth table50%1/2
A
A= $_->{"clients"}
Aresult
11
00
1261  
1262 2 print {$fh} <<'HTML';
1263 <!doctype html>
1264 <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Strict same-work reactor comparison</title>
1265 <style>
1266 :root{color-scheme:light dark}body{font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;margin:2rem;line-height:1.4;max-width:1800px}h1,h2{line-height:1.2}.note{background:color-mix(in srgb,Canvas 94%,#0969da 6%);border:1px solid color-mix(in srgb,CanvasText 20%,transparent);border-radius:8px;padding:1rem;margin:1rem 0}.toolbar{display:flex;gap:.8rem;align-items:end;flex-wrap:wrap;margin:1rem 0;padding:.8rem;border:1px solid color-mix(in srgb,CanvasText 20%,transparent);border-radius:8px}.toolbar label{display:flex;flex-direction:column;gap:.25rem;font-size:.9rem}.toolbar input,.toolbar select,.toolbar button{font:inherit;padding:.4rem .55rem;border:1px solid color-mix(in srgb,CanvasText 30%,transparent);border-radius:6px;background:Canvas;color:CanvasText}.toolbar button{cursor:pointer}.status{margin-left:auto;font-size:.9rem;opacity:.8}.table-wrap{overflow:auto;margin:1rem 0 2rem}table{border-collapse:collapse;width:100%;min-width:1000px}th,td{border:1px solid color-mix(in srgb,CanvasText 20%,transparent);padding:.4rem .55rem;text-align:right;white-space:nowrap}th:first-child,td:first-child{text-align:left}th{background:color-mix(in srgb,Canvas 90%,CanvasText 10%);cursor:pointer;user-select:none;position:sticky;top:0;z-index:1}th:hover{background:color-mix(in srgb,Canvas 82%,#0969da 18%)}th::after{content:" \21C5";font-size:.75em;opacity:.5}th.sort-asc::after{content:" \25B2";opacity:1}th.sort-desc::after{content:" \25BC";opacity:1}tbody tr:nth-child(even){background:color-mix(in srgb,Canvas 96%,CanvasText 4%)}tbody tr:hover{background:color-mix(in srgb,Canvas 88%,#0969da 12%)}code{background:color-mix(in srgb,Canvas 90%,CanvasText 10%);padding:.1rem .25rem;border-radius:4px}.small{font-size:.9rem;opacity:.8}.hidden{display:none!important}
1267 </style>
1268 <script>
1269 (function(){
1270 'use strict';
1271 function text(el){ return String(el && (el.textContent || el.innerText) || '').trim(); }
1272 function normalize(raw){
1273 raw = String(raw == null ? '' : raw).trim();
1274 if (raw === '') return {type:'text', value:''};
1275 var low = raw.toLowerCase();
1276 if (low === 'yes' || low === 'true' || low === 'ok') return {type:'number', value:1};
1277 if (low === 'no' || low === 'false' || low === 'fail') return {type:'number', value:0};
1278 var numeric = raw.replace(/,/g,'');
1279 if (numeric !== '' && !isNaN(Number(numeric))) return {type:'number', value:Number(numeric)};
1280 return {type:'text', value:low};
1281 }
1282 function sortTable(th){
1283 var table = th.closest ? th.closest('table') : null;
1284 if (!table) { var n=th; while(n && n.tagName !== 'TABLE') n=n.parentNode; table=n; }
1285 if (!table || !table.tBodies.length) return;
1286 var headers = Array.prototype.slice.call(th.parentNode.cells);
1287 var col = headers.indexOf(th);
1288 var same = table.getAttribute('data-sort-col') === String(col);
1289 var dir = same && table.getAttribute('data-sort-dir') === 'desc' ? 'asc' : 'desc';
1290 table.setAttribute('data-sort-col', String(col));
1291 table.setAttribute('data-sort-dir', dir);
1292 headers.forEach(function(h){ h.classList.remove('sort-asc','sort-desc'); });
1293 th.classList.add(dir === 'desc' ? 'sort-desc' : 'sort-asc');
1294 var rows = Array.prototype.slice.call(table.tBodies[0].rows);
1295 rows.sort(function(a,b){
1296 var av = normalize(a.cells[col] && (a.cells[col].getAttribute('data-sort') || text(a.cells[col])));
1297 var bv = normalize(b.cells[col] && (b.cells[col].getAttribute('data-sort') || text(b.cells[col])));
1298 var cmp = (av.type === 'number' && bv.type === 'number') ? av.value - bv.value : String(av.value).localeCompare(String(bv.value));
1299 return dir === 'desc' ? -cmp : cmp;
1300 });
1301 rows.forEach(function(r){ table.tBodies[0].appendChild(r); });
1302 }
1303 function applyFilters(){
1304 var q = document.getElementById('row-filter').value.toLowerCase().trim();
1305 var system = document.getElementById('system-filter').value;
1306 var clients = document.getElementById('clients-filter').value;
1307 var tables = document.querySelectorAll('table[data-filterable="1"]');
1308 var shown = 0, total = 0;
1309 Array.prototype.forEach.call(tables,function(table){
1310 Array.prototype.forEach.call(table.tBodies[0].rows,function(row){
1311 total++;
1312 var match = (!q || text(row).toLowerCase().indexOf(q) !== -1)
1313 && (!system || row.getAttribute('data-system') === system)
1314 && (!clients || row.getAttribute('data-clients') === clients);
1315 row.classList.toggle('hidden', !match);
1316 if (match) shown++;
1317 });
1318 });
1319 document.getElementById('filter-status').textContent = shown + ' of ' + total + ' rows visible';
1320 }
1321 function resetFilters(){
1322 document.getElementById('row-filter').value='';
1323 document.getElementById('system-filter').value='';
1324 document.getElementById('clients-filter').value='';
1325 applyFilters();
1326 }
1327 window.addEventListener('DOMContentLoaded',function(){
1328 Array.prototype.forEach.call(document.querySelectorAll('table.sortable th'),function(th){
1329 th.tabIndex = 0;
1330 th.title = 'Sort by ' + text(th);
1331 th.addEventListener('click',function(){ sortTable(th); });
1332 th.addEventListener('keydown',function(ev){ if (ev.key === 'Enter' || ev.key === ' ') { ev.preventDefault(); sortTable(th); } });
1333 });
1334 ['row-filter','system-filter','clients-filter'].forEach(function(id){
1335 document.getElementById(id).addEventListener(id === 'row-filter' ? 'input' : 'change', applyFilters);
1336 });
1337 document.getElementById('reset-filters').addEventListener('click', resetFilters);
1338 applyFilters();
1339 });
1340 })();
1341 </script></head><body>
1342 <h1>Strict same-work reactor comparison</h1>
1343 <p class="small">Offline report. Workload parameters and the full fairness contract are recorded in the companion JSON file. Click any column heading to sort. Use the controls below to filter both the summary and raw-repeat tables.</p>
1344 <div class="note"><strong>Fairness contract:</strong> all TCP connections are established and accepted before timing; all watchers are registered before timing; warmup finishes before counters/timing reset; every ranked server invokes the exact same Perl <code>echo_read()</code> body; every client has at most one request outstanding; clients remain connected after the last measured reply; teardown and EOF/RDHUP handling occur after timing; no framework timer watcher is active in the measured interval.</div>
1345 <div class="toolbar">
1346 <label>Search rows<input id="row-filter" type="search" placeholder="system, backend, value..."></label>
1347 <label>System<select id="system-filter"><option value="">All systems</option>
1348 HTML
1349 2 for my $name (@system_names) {
1350 2 printf {$fh} '<option value="%s">%s</option>\n', html_escape($name), html_escape($name);
1351 }
1352 2 print {$fh} <<'HTML';
1353 </select></label>
1354 <label>Clients<select id="clients-filter"><option value="">All client counts</option>
1355 HTML
1356 2 for my $count (@client_counts) {
1357 2 printf {$fh} '<option value="%d">%d</option>\n', $count, $count;
1358 }
1359 2 print {$fh} <<'HTML';
1360 </select></label>
1361 <button id="reset-filters" type="button">Reset</button><span id="filter-status" class="status"></span>
1362 </div>
1363 <h2>Median summary</h2><div class="table-wrap"><table class="sortable" data-filterable="1"><thead><tr><th>System</th><th>Backend</th><th>Clients</th><th>Repeats</th><th>median msg/s</th><th>mean msg/s</th><th>p50 us</th><th>p95 us</th><th>p99 us</th><th>CPU us/msg</th><th>CPU %</th><th>RSS KiB</th><th>iterations</th><th>read cb/msg</th><th>read syscalls/msg</th><th>write syscalls/msg</th></tr></thead><tbody>
1364 HTML
1365 2 for my $r (@$summary) {
1366 2 ▶ my $system = $r->{system} // '';
Condition50%1/2
$r->{"system"} // ""
l!l
20
MC/DC0%0/1
$r->{"system"} // ""
$r->{"system"}
Truth table50%1/2
A
A= $r->{"system"}
Aresult
11
00
1367 2 ▶ my $clients = $r->{clients} // 0;
Condition50%1/2
$r->{"clients"} // 0
l!l
20
MC/DC0%0/1
$r->{"clients"} // 0
$r->{"clients"}
Truth table50%1/2
A
A= $r->{"clients"}
Aresult
11
00
1368 2 printf {$fh} '<tr data-system="%s" data-clients="%d">', html_escape($system), $clients;
1369 2 ▶ print {$fh} join('',
Branch: 1 branch
BranchTrueFalseTotal
defined $r->{'median_reactor_iterations'} ? : 2 0 2
Condition50%4/8
$r->{"backend"} // ""
l!l
20
$r->{"median_lat_p50_us"} // 0
l!l
20
$r->{"median_lat_p95_us"} // 0
l!l
20
$r->{"median_lat_p99_us"} // 0
l!l
20
MC/DC0%0/1
$r->{"backend"} // ""
$r->{"backend"}
MC/DC0%0/1
$r->{"median_lat_p50_us"} // 0
$r->{"median_lat_p50_us"}
MC/DC0%0/1
$r->{"median_lat_p95_us"} // 0
$r->{"median_lat_p95_us"}
MC/DC0%0/1
$r->{"median_lat_p99_us"} // 0
$r->{"median_lat_p99_us"}
Truth table50%1/2
A
A= $r->{"backend"}
Aresult
11
00
Truth table50%1/2
A
A= $r->{"median_lat_p50_us"}
Aresult
11
00
Truth table50%1/2
A
A= $r->{"median_lat_p95_us"}
Aresult
11
00
Truth table50%1/2
A
A= $r->{"median_lat_p99_us"}
Aresult
11
00
1370 html_td($system), html_td($r->{backend} // ''), html_td($clients), html_td($r->{repeats}),
1371 html_td(sprintf('%.2f', $r->{median_messages_per_second})),
1372 html_td(sprintf('%.2f', $r->{mean_messages_per_second})),
1373 html_td(sprintf('%.0f', $r->{median_lat_p50_us} // 0)),
1374 html_td(sprintf('%.0f', $r->{median_lat_p95_us} // 0)),
1375 html_td(sprintf('%.0f', $r->{median_lat_p99_us} // 0)),
1376 html_td(sprintf('%.3f', $r->{median_server_cpu_us_per_message})),
1377 html_td(sprintf('%.2f', $r->{median_server_cpu_percent})),
1378 html_td(sprintf('%.0f', $r->{median_max_rss_kb})),
1379 html_td(defined $r->{median_reactor_iterations} ? sprintf('%.0f', $r->{median_reactor_iterations}) : 'n/a'),
1380 html_td(sprintf('%.4f', $r->{median_read_callbacks_per_message})),
1381 html_td(sprintf('%.4f', $r->{median_sysread_calls_per_message})),
1382 2 html_td(sprintf('%.4f', $r->{median_syswrite_calls_per_message})),
1383 );
1384 2 print {$fh} "</tr>\n";
1385 }
1386 2 print {$fh} <<'HTML';
1387 </tbody></table></div>
1388 <h2>Raw repeats</h2><div class="table-wrap"><table class="sortable" data-filterable="1"><thead><tr><th>System</th><th>Clients</th><th>Repeat</th><th>Order</th><th>OK</th><th>msg/s</th><th>elapsed s</th><th>CPU us/msg</th><th>CPU %</th><th>p50 us</th><th>p95 us</th><th>p99 us</th><th>RSS KiB</th><th>iterations</th><th>read cb</th><th>sysread</th><th>syswrite</th><th>backend</th></tr></thead><tbody>
1389 HTML
1390 2 for my $r (@$results) {
1391 2 ▶ my $system = $r->{system} // '';
Condition50%1/2
$r->{"system"} // ""
l!l
20
MC/DC0%0/1
$r->{"system"} // ""
$r->{"system"}
Truth table50%1/2
A
A= $r->{"system"}
Aresult
11
00
1392 2 ▶ my $clients = $r->{clients} // 0;
Condition50%1/2
$r->{"clients"} // 0
l!l
20
MC/DC0%0/1
$r->{"clients"} // 0
$r->{"clients"}
Truth table50%1/2
A
A= $r->{"clients"}
Aresult
11
00
1393 2 printf {$fh} '<tr data-system="%s" data-clients="%d">', html_escape($system), $clients;
1394 2 ▶ print {$fh} join('',
Branch: 6 branches
BranchTrueFalseTotal
defined $r->{'execution_order_position'} ? : 2 0 2
$r->{'ok'} ? : 2 0 2
defined $r->{'messages_per_second'} ? : 2 0 2
defined $r->{'server_cpu_us_per_message'} ? : 2 0 2
defined $r->{'server_cpu_percent'} ? : 2 0 2
defined $r->{'reactor_iterations'} ? : 2 0 2
Condition47%11/23
$r->{"execution_order_width"} // ""
l!l
20
$r->{"elapsed_seconds"} // 0
l!l
20
$r->{"lat_p50_us"} // ""
l!l
20
$r->{"lat_p95_us"} // ""
l!l
20
$r->{"lat_p99_us"} // ""
l!l
20
$r->{"max_rss_kb"} // ""
l!l
20
$r->{"read_callbacks"} // ""
l!l
20
$r->{"sysread_calls"} // ""
l!l
20
$r->{"syswrite_calls"} // ""
l!l
20
($r->{"backend_runtime"} // $r->{"backend"}) // ""
l!l
20
$r->{"backend_runtime"} // $r->{"backend"}
l!l&&r!l&&!r
200
MC/DC0%0/1
$r->{"execution_order_width"} // ""
$r->{"execution_order_width"}
MC/DC0%0/1
$r->{"elapsed_seconds"} // 0
$r->{"elapsed_seconds"}
MC/DC0%0/1
$r->{"lat_p50_us"} // ""
$r->{"lat_p50_us"}
MC/DC0%0/1
$r->{"lat_p95_us"} // ""
$r->{"lat_p95_us"}
MC/DC0%0/1
$r->{"lat_p99_us"} // ""
$r->{"lat_p99_us"}
MC/DC0%0/1
$r->{"max_rss_kb"} // ""
$r->{"max_rss_kb"}
MC/DC0%0/1
$r->{"read_callbacks"} // ""
$r->{"read_callbacks"}
MC/DC0%0/1
$r->{"sysread_calls"} // ""
$r->{"sysread_calls"}
MC/DC0%0/1
$r->{"syswrite_calls"} // ""
$r->{"syswrite_calls"}
MC/DC0%0/2
($r->{"backend_runtime"} // $r->{"backend"}) // ""
$r->{"backend_runtime"} $r->{"backend"}
Truth table50%1/2
A
A= $r->{"execution_order_width"}
Aresult
11
00
Truth table50%1/2
A
A= $r->{"elapsed_seconds"}
Aresult
11
00
Truth table50%1/2
A
A= $r->{"lat_p50_us"}
Aresult
11
00
Truth table50%1/2
A
A= $r->{"lat_p95_us"}
Aresult
11
00
Truth table50%1/2
A
A= $r->{"lat_p99_us"}
Aresult
11
00
Truth table50%1/2
A
A= $r->{"max_rss_kb"}
Aresult
11
00
Truth table50%1/2
A
A= $r->{"read_callbacks"}
Aresult
11
00
Truth table50%1/2
A
A= $r->{"sysread_calls"}
Aresult
11
00
Truth table50%1/2
A
A= $r->{"syswrite_calls"}
Aresult
11
00
Truth table33%1/3
A // B
A= $r->{"backend_runtime"}B= $r->{"backend"}
ABresult
1X1
011
000
1395 html_td($system), html_td($clients), html_td($r->{repeat}),
1396 html_td(defined $r->{execution_order_position} ? ($r->{execution_order_position} . '/' . ($r->{execution_order_width} // '')) : ''),
1397 html_td($r->{ok} ? 'yes' : 'no'),
1398 html_td(defined $r->{messages_per_second} ? sprintf('%.2f', $r->{messages_per_second}) : ''),
1399 html_td(sprintf('%.6f', $r->{elapsed_seconds} // 0)),
1400 html_td(defined $r->{server_cpu_us_per_message} ? sprintf('%.3f', $r->{server_cpu_us_per_message}) : ''),
1401 html_td(defined $r->{server_cpu_percent} ? sprintf('%.2f', $r->{server_cpu_percent}) : ''),
1402 html_td($r->{lat_p50_us} // ''), html_td($r->{lat_p95_us} // ''), html_td($r->{lat_p99_us} // ''),
1403 html_td($r->{max_rss_kb} // ''),
1404 html_td(defined $r->{reactor_iterations} ? $r->{reactor_iterations} : 'n/a'),
1405 html_td($r->{read_callbacks} // ''), html_td($r->{sysread_calls} // ''), html_td($r->{syswrite_calls} // ''),
1406 2 html_td($r->{backend_runtime} // $r->{backend} // ''),
1407 );
1408 2 print {$fh} "</tr>\n";
1409 }
1410 2 print {$fh} "</tbody></table></div></body></html>\n";
1411 2 close $fh;
1412 }
1413  
1414 76 ▶sub html_escape ($value) {
Subroutine html_escape: called CC=2 SCAR=7.0
1415 76 ▶ $value = '' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 76 76
1416 76 $value = "$value";
1417 76 $value =~ s/&/&amp;/g;
1418 76 $value =~ s/</&lt;/g;
1419 76 $value =~ s/>/&gt;/g;
1420 76 $value =~ s/\"/&quot;/g;
1421 76 $value =~ s/'/&#39;/g;
1422 76 return $value;
1423 }
1424  
1425 68 ▶sub html_td ($value) {
Subroutine html_td: called CC=1 SCAR=0.0
1426 68 return '<td>' . html_escape($value) . '</td>';
1427 }
« blib/lib/Linux/Event/Loop.pm ↑ Summary blib/lib/Linux/Event/_Socket/Listener.pm »