bench/run-stream-lifecycle-bench.pl

filter: Statementstmt 74.3% 203 / 273 Branchbran 37.5% 36 / 96 Conditioncond 23.8% 5 / 21 MC/DCmcdc 7.6% 1 / 13 Subroutinesub 67.3% 31 / 46 Podpod n/a totaltotal 61.4% 276 / 449 CC 44 SCAR 27.2
CC
44
Cov
63%
run_memory_child
62.3
git_commit
30.0
create_loop_option
20.0
CRAP 15.1
« blib/lib/Linux/Event/_ByteStream/Descriptor.pm ↑ Summary blib/lib/Linux/Event/Kernel/Inotify.pm »
1 #!/usr/bin/env perl
2 1 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use File::Basename qw(dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use FindBin qw($Bin);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Getopt::Long qw(GetOptions);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use JSON::PP qw(decode_json encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use POSIX qw(_exit strftime uname);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Socket qw(AF_UNIX SOCK_STREAM PF_UNSPEC);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Time::HiRes qw(time clock_gettime CLOCK_PROCESS_CPUTIME_ID);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use Linux::Event::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Linux::Event::IO::Sock::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Linux::Event::IO::Sock::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 {
21 package Linux::Event::Bench::RawNamed;
22 1 ▶ use parent 'Linux::Event::IO::Sock::Stream';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 0 ▶ sub on_data ($stream, $bytes) { return }
Subroutine on_data: not called CC=1 SCAR=6.9
24 }
25  
26 {
27 1 package Linux::Event::Bench::FramedMinimal;
28 1 ▶ use parent 'Linux::Event::IO::Sock::Stream';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶ use Linux::Event::Framer 'Delimiter', "\n";
Subroutine BEGIN: called CC=1 SCAR=0.0
30 0 ▶ sub on_message ($stream, $message) { return }
Subroutine on_message: not called CC=1 SCAR=6.9
31 }
32  
33 {
34 1 package Linux::Event::Bench::FramedFullNamed;
35 1 ▶ use parent 'Linux::Event::IO::Sock::Stream';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶ use Linux::Event::Framer 'Delimiter', "\n";
Subroutine BEGIN: called CC=1 SCAR=0.0
37 0 ▶ sub on_message ($stream, $message) { return }
Subroutine on_message: not called CC=1 SCAR=6.9
38 0 ▶ sub on_drain ($stream) { return }
Subroutine on_drain: not called CC=1 SCAR=6.9
39 0 ▶ sub on_eof ($stream) { return }
Subroutine on_eof: not called CC=1 SCAR=6.9
40 0 ▶ sub on_error ($stream, $error) { return }
Subroutine on_error: not called CC=1 SCAR=6.9
41 0 ▶ sub on_close ($stream) { return }
Subroutine on_close: not called CC=1 SCAR=6.9
42 }
43  
44 1 my @all_cases = qw(
45 registration
46 raw-named
47 framed-minimal
48 framed-full-named
49 );
50 1 my %known_case = map { $_ => 1 } @all_cases;
51 1 my @default_cases = @all_cases;
52  
53 1 my $contract_version = 2;
54 1 my $api_style = 'loop-add';
55 1 my $iterations = 100_000;
56 1 my $pool_size = 256;
57 1 my @live_counts = (1_000, 10_000, 20_000);
58 1 my $warmup = 1_000;
59 1 my $repeats = 7;
60 1 my $memory_repeats = 3;
61 1 my @cases = @default_cases;
62 1 my $run_memory = 1;
63 1 my $json_path;
64 my $help;
65  
66 GetOptions(
67 'api-style=s' => \$api_style,
68 'iterations=i' => \$iterations,
69 'pool=i' => \$pool_size,
70 1 ▶ 'live=s' => sub { @live_counts = split /,/, $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
71 'warmup=i' => \$warmup,
72 'repeats=i' => \$repeats,
73 'memory-repeats=i' => \$memory_repeats,
74 1 ▶ 'cases=s' => sub { @cases = split /,/, $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
75 1 ▶ 'memory!' => \$run_memory,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("api-style=s", \$api_style, "iterations=i", \$iterations, "pool=i", \$pool_size, "live=s", sub { @live_counts = split(/,/u, $_[1], 0); } , "warmup=i", \$warmup, "repeats=i", \$repeats, "memory-repeats=i", \$memory_repeats, "cases=s", sub { @cases = split(/,/u, $_[1], 0); } , "memory!", \$run_memory, "json=s", \$json_path, "help", \$help) or usage(2) 1 0 1
76 'json=s' => \$json_path,
77 'help' => \$help,
78 ) or usage(2);
79  
80 1 ▶usage(0) if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 1 1
81 1 ▶die "api-style '$api_style' is not implemented by this source revision\n"
Branch: 1 branch
BranchTrueFalseTotal
if $api_style ne "loop-option" and $api_style ne "loop-add" 0 1 1
Condition33%1/3
$api_style ne "loop-option" and $api_style ne "loop-add"
!ll&&!rl&&r
010
MC/DC0%0/2
$api_style ne "loop-option" and $api_style ne "loop-add"
$api_style ne "loop-option" $api_style ne "loop-add"
Truth table33%1/3
A and B
A= $api_style ne "loop-option"B= $api_style ne "loop-add"
ABresult
0X0
100
111
82 if $api_style ne 'loop-option' && $api_style ne 'loop-add';
83 1 ▶die "iterations must be > 0\n" if $iterations <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $iterations <= 0 0 1 1
84 1 ▶die "pool must be > 0\n" if $pool_size <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pool_size <= 0 0 1 1
85 1 ▶die "warmup must be >= 0\n" if $warmup < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $warmup < 0 0 1 1
86 1 ▶die "repeats must be > 0\n" if $repeats <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $repeats <= 0 0 1 1
87 1 ▶die "memory-repeats must be > 0\n" if $memory_repeats <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $memory_repeats <= 0 0 1 1
88 1 ▶die "at least one case is required\n" if !@cases;
Branch: 1 branch
BranchTrueFalseTotal
unless @cases 0 1 1
89 1 die "unknown case: $_\n" for grep { !$known_case{$_} } @cases;
90 1 die "live counts must be > 0\n" for grep { $_ <= 0 } @live_counts;
91  
92 1 my $watch_data = {};
93  
94 1 my @memory_rows;
95 my @lifecycle_rows;
96  
97 1 say "Linux::Event Stream lifecycle benchmark";
98 1 say "version=$Linux::Event::IO::Sock::Stream::VERSION perl=$^V pid=$$";
99 1 say "contract=$contract_version api_style=$api_style";
100 1 say "cases=" . join(',', @cases);
101  
102 # Run retained-memory cases before lifecycle churn changes the parent's Perl
103 # allocator high-water mark. Every sample still gets a fresh child process.
104 1 ▶if ($run_memory) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run_memory) 1 0 1
105 1 say "\nLive retained-memory samples";
106 1 for my $count (@live_counts) {
107 1 for my $repeat (1 .. $memory_repeats) {
108 1 for my $case (rotated_cases($repeat)) {
109 4 my $row = run_memory_child($case, $count, $repeat);
110 4 push @memory_rows, $row;
111 printf "%s live=%d repeat=%d rss_delta=%.3f MiB approx=%.1f bytes/object\n",
112 $case, $count, $repeat,
113 $row->{rss_delta_kb} / 1024,
114 4 $row->{approx_bytes_per_object};
115 }
116 }
117 }
118 }
119  
120 1 say "\nLifecycle construction samples";
121 1 for my $repeat (1 .. $repeats) {
122 1 for my $case (rotated_cases($repeat)) {
123 4 my $row = run_lifecycle_case($case);
124 4 $row->{repeat} = $repeat;
125 4 push @lifecycle_rows, $row;
126 printf "%s repeat=%d %.1f ops/s cpu=%.3f us/op\n",
127 $case, $repeat, $row->{operations_per_second},
128 4 $row->{cpu_us_per_operation};
129 }
130 }
131  
132 1 my @lifecycle_summary;
133 1 say "\nMedian lifecycle construction summary";
134 1 printf "%-24s %16s %16s\n", 'case', 'ops/s', 'cpu us/op';
135 1 for my $case (@cases) {
136 4 my @set = grep { $_->{case} eq $case } @lifecycle_rows;
137 my $summary = {
138 benchmark_contract_version => $contract_version,
139 api_style => $api_style,
140 workload => $case,
141 case => $case,
142 4 operations_per_second => median(map { $_->{operations_per_second} } @set),
143 4 cpu_us_per_operation => median(map { $_->{cpu_us_per_operation} } @set),
144 };
145 4 push @lifecycle_summary, $summary;
146 printf "%-24s %16.1f %16.3f\n", $case,
147 4 $summary->{operations_per_second}, $summary->{cpu_us_per_operation};
148 }
149  
150 1 my @memory_summary;
151 1 ▶if ($run_memory) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run_memory) 1 0 1
152 1 say "\nMedian live retained-memory summary";
153 1 printf "%-24s %10s %16s %18s\n",
154 'case', 'objects', 'rss delta MiB', 'approx bytes/object';
155 1 for my $count (@live_counts) {
156 1 for my $case (@cases) {
157 my @set = grep {
158 4 ▶ $_->{case} eq $case && $_->{objects} == $count
Condition66%2/3
$_->{'case'} eq $case && $_->{'objects'} == $count
!ll&&!rl&&r
1204
MC/DC50%1/2
$_->{'case'} eq $case && $_->{'objects'} == $count
$_->{'case'} eq $case $_->{'objects'} == $count
Truth table66%2/3
A && B
A= $_->{'case'} eq $caseB= $_->{'objects'} == $count
ABresult
0X0
100
111
159 } @memory_rows;
160 my $summary = {
161 benchmark_contract_version => $contract_version,
162 api_style => $api_style,
163 workload => $case,
164 case => $case,
165 objects => $count,
166 4 rss_delta_kb => median(map { $_->{rss_delta_kb} } @set),
167 approx_bytes_per_object => median(
168 4 map { $_->{approx_bytes_per_object} } @set
169 ),
170 };
171 4 push @memory_summary, $summary;
172 printf "%-24s %10d %16.3f %18.1f\n",
173 $case, $count, $summary->{rss_delta_kb} / 1024,
174 4 $summary->{approx_bytes_per_object};
175 }
176 }
177 }
178  
179 1 ▶if (defined $json_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json_path) 0 1 1
180 0 ▶ my $report = {
Branch: 1 branch
BranchTrueFalseTotal
$run_memory ? : 0 0 0
181 benchmark => 'linux-event-stream-lifecycle',
182 benchmark_contract_version => $contract_version,
183 api_style => $api_style,
184 generated_at => strftime('%Y-%m-%dT%H:%M:%SZ', gmtime),
185 environment => environment_info(),
186 configuration => {
187 iterations => $iterations,
188 pool => $pool_size,
189 live => \@live_counts,
190 warmup => $warmup,
191 repeats => $repeats,
192 memory_repeats => $memory_repeats,
193 cases => \@cases,
194 memory_enabled => $run_memory ? JSON::PP::true : JSON::PP::false,
195 },
196 lifecycle_records => \@lifecycle_rows,
197 lifecycle_summary => \@lifecycle_summary,
198 memory_records => \@memory_rows,
199 memory_summary => \@memory_summary,
200 notes => [
201 'Socketpairs are created outside timed regions.',
202 'Stream subclass descriptors are built during warmup, outside timed regions.',
203 'loop-add and loop-option exercise the two supported attachment forms.',
204 'RSS deltas include retained Stream/registration state and the references that keep it live.',
205 'Compare results only when benchmark_contract_version and workload match.',
206 ],
207 };
208  
209 0 my $dir = dirname($json_path);
210 0 ▶ make_path($dir) if $dir ne '.' && !-d $dir;
Branch: 1 branch
BranchTrueFalseTotal
if $dir ne "." and not -d $dir 0 0 0
Condition0%0/3
$dir ne "." and not -d $dir
!ll&&!rl&&r
000
MC/DC0%0/2
$dir ne "." and not -d $dir
$dir ne "." not -d $dir
Truth table0%0/3
A and not(B)
A= $dir ne "."B= not -d $dir
ABresult
0X0
100
111
211 0 ▶ open my $out, '>', $json_path or die "open $json_path: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", $json_path or die "open ${json_path}: $!\n" 0 0 0
212 0 print {$out} JSON::PP->new->canonical->pretty->encode($report);
213 0 ▶ close $out or die "close $json_path: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $out or die "close ${json_path}: $!\n" 0 0 0
214 0 say "\nWrote $json_path";
215 }
216  
217 1 say "\nUse framed-full-named for the main before/after constructor comparison.";
218 1 say "Compare only with contract=2 results for the same workload and settings.";
219  
220 4 ▶sub run_lifecycle_case ($case) {
Subroutine run_lifecycle_case: called CC=6 SCAR=17.9
221 4 my $loop = Linux::Event::Loop->new;
222 4 my ($server_fh, $client_fh) = socket_pool($pool_size);
223  
224 4 for my $i (0 .. $warmup - 1) {
225 8 lifecycle_once($case, $loop, $server_fh->[$i % $pool_size], $i);
226 }
227  
228 4 my $wall_start = time;
229 4 my $cpu_start = clock_gettime(CLOCK_PROCESS_CPUTIME_ID);
230 4 for my $i (0 .. $iterations - 1) {
231 80 lifecycle_once($case, $loop, $server_fh->[$i % $pool_size], $i);
232 }
233 4 my $cpu_seconds = clock_gettime(CLOCK_PROCESS_CPUTIME_ID) - $cpu_start;
234 4 my $elapsed_seconds = time - $wall_start;
235  
236 4 close $_ for @$server_fh;
237 4 close $_ for @$client_fh;
238  
239 4 ▶ die "timer produced a non-positive lifecycle interval\n"
Branch: 1 branch
BranchTrueFalseTotal
if $elapsed_seconds <= 0 0 4 4
240 if $elapsed_seconds <= 0;
241  
242 return {
243 4 benchmark_contract_version => $contract_version,
244 api_style => $api_style,
245 workload => $case,
246 case => $case,
247 operations => $iterations,
248 elapsed_seconds => $elapsed_seconds,
249 cpu_seconds => $cpu_seconds,
250 operations_per_second => $iterations / $elapsed_seconds,
251 cpu_us_per_operation => ($cpu_seconds * 1_000_000) / $iterations,
252 };
253 }
254  
255 88 ▶sub lifecycle_once ($case, $loop, $fh, $token) {
Subroutine lifecycle_once: called CC=3 SCAR=11.0
256 88 my $object = create_object($case, $loop, $fh, $token);
257 88 ▶ if ($case eq 'registration') {
Branch: 1 branch
BranchTrueFalseTotal
if ($case eq 'registration') { } 22 66 88
258 22 $object->cancel;
259 } else {
260 66 my $detached = $object->detach;
261 66 ▶ die "detach returned the wrong filehandle\n"
Branch: 1 branch
BranchTrueFalseTotal
if fileno $detached != fileno $fh 0 66 66
262 if fileno($detached) != fileno($fh);
263 }
264 88 return;
265 }
266  
267 88 ▶sub create_object ($case, $loop, $fh, $token) {
Subroutine create_object: called CC=4 SCAR=14.3
268 88 ▶ if ($case eq 'registration') {
Branch: 1 branch
BranchTrueFalseTotal
if ($case eq "registration") 22 66 88
269 22 my $registration = $loop->watch_fd(
270 fileno($fh),
271 fh => $fh,
272 data => $watch_data,
273 read => \&_watch_read,
274 write => \&_watch_write,
275 error => \&_watch_error,
276 _callback_data_arg => 1,
277 );
278 22 $registration->disable_write;
279 22 return $registration;
280 }
281  
282 66 ▶ return create_loop_option($case, $loop, $fh)
Branch: 1 branch
BranchTrueFalseTotal
if $api_style eq "loop-option" 0 66 66
283 if $api_style eq 'loop-option';
284 66 ▶ return create_loop_add($case, $loop, $fh)
Branch: 1 branch
BranchTrueFalseTotal
if $api_style eq "loop-add" 66 0 66
285 if $api_style eq 'loop-add';
286  
287 0 die "unimplemented api-style adapter: $api_style\n";
288 }
289  
290 # API ADAPTER: the socket preparation, workload names, timing, teardown, RSS
291 # measurement, summaries, and JSON contract around this constructor section
292 # remain unchanged from the object-configured baseline.
293 0 ▶sub create_loop_option ($case, $loop, $fh) {
Subroutine create_loop_option: not called CC=4 SCAR=30.0
294  
295 0 ▶ if ($case eq 'raw-named') {
Branch: 1 branch
BranchTrueFalseTotal
if ($case eq "raw-named") 0 0 0
296 0 return Linux::Event::Bench::RawNamed->new(loop => $loop, fh => $fh);
297 }
298  
299 0 ▶ if ($case eq 'framed-minimal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($case eq "framed-minimal") 0 0 0
300 0 return Linux::Event::Bench::FramedMinimal->new(loop => $loop, fh => $fh);
301 }
302  
303 0 ▶ if ($case eq 'framed-full-named') {
Branch: 1 branch
BranchTrueFalseTotal
if ($case eq "framed-full-named") 0 0 0
304 0 return Linux::Event::Bench::FramedFullNamed->new(loop => $loop, fh => $fh);
305 }
306  
307 0 die "unimplemented case: $case\n";
308 }
309  
310 66 ▶sub create_loop_add ($case, $loop, $fh) {
Subroutine create_loop_add: called CC=4 SCAR=13.9
311 66 ▶ my $class = $case eq 'raw-named'
Branch: 3 branches
BranchTrueFalseTotal
$case eq 'raw-named' ? : 22 44 66
$case eq 'framed-minimal' ? : 22 22 44
$case eq 'framed-full-named' ? : 22 0 22
312 ? 'Linux::Event::Bench::RawNamed'
313 : $case eq 'framed-minimal'
314 ? 'Linux::Event::Bench::FramedMinimal'
315 : $case eq 'framed-full-named'
316 ? 'Linux::Event::Bench::FramedFullNamed'
317 : die "unimplemented case: $case\n";
318 66 my $stream = $class->new(fh => $fh);
319 66 return $loop->add($stream);
320 }
321  
322 4 ▶sub run_memory_child ($case, $count, $repeat) {
Subroutine run_memory_child: called CC=14 SCAR=41.3
323 4 ▶ pipe(my $reader, my $writer) or die "pipe: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
pipe my $reader, my $writer or die "pipe: $!\n" 4 0 4
324 4 my $pid = fork;
325 4 ▶ die "fork: $!\n" if !defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 4 4
326  
327 4 ▶ if ($pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) 0 4 4
328 0 close $reader;
329 0 my $result;
330 0 my $ok = eval {
331 0 my $loop = Linux::Event::Loop->new;
332 0 my ($server_fh, $client_fh) = socket_pool($count);
333  
334 # Allocate the retention vector before the baseline so its capacity
335 # does not get charged to one implementation more than another.
336 0 my @objects;
337 0 $#objects = $count - 1;
338  
339 # Pay one-time XS/Perl allocator and registration initialization
340 # before the baseline. The measured delta should describe retained
341 # per-object state, not the first registration ever created in a process.
342 0 lifecycle_once($case, $loop, $server_fh->[0], -1);
343 0 my $rss_before_kb = vmrss_kb();
344 0 for my $i (0 .. $count - 1) {
345 0 $objects[$i] = create_object(
346 $case, $loop, $server_fh->[$i], $i
347 );
348 }
349 0 my $rss_after_kb = vmrss_kb();
350 0 my $delta_kb = $rss_after_kb - $rss_before_kb;
351 0 $result = {
352 benchmark_contract_version => $contract_version,
353 api_style => $api_style,
354 workload => $case,
355 case => $case,
356 objects => $count,
357 repeat => $repeat,
358 rss_before_kb => $rss_before_kb,
359 rss_after_kb => $rss_after_kb,
360 rss_delta_kb => $delta_kb,
361 approx_bytes_per_object => ($delta_kb * 1024) / $count,
362 };
363 0 1;
364 };
365 0 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
366 0 ▶ my $error = $@ || 'unknown child error';
Condition0%0/2
$@ || 'unknown child error'
l!l
00
MC/DC0%0/1
$@ || 'unknown child error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
367 0 chomp $error;
368 0 $result = { error => $error };
369 }
370 0 print {$writer} encode_json($result), "\n";
371 0 close $writer;
372 0 ▶ _exit($ok ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 0 0
373 }
374  
375 4 close $writer;
376 4 ▶ my $payload = do { local $/; <$reader> // '' };
Condition50%1/2
readline $reader // ""
l!l
40
MC/DC0%0/1
readline $reader // ""
readline $reader
Truth table50%1/2
A
A= readline $reader
Aresult
11
00
377 4 close $reader;
378 4 waitpid($pid, 0);
379 4 my $status = $?;
380 4 ▶ die "memory child produced no result for $case live=$count\n"
Branch: 1 branch
BranchTrueFalseTotal
if $payload eq "" 0 4 4
381 if $payload eq '';
382 4 my $result = eval { decode_json($payload) };
383 4 ▶ die "invalid memory child result for $case live=$count: $@\n" if !$result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 4 4
384 4 ▶ if ($status != 0 || $result->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status != 0 or $result->{"error"}) 0 4 4
Condition33%1/3
$status != 0 or $result->{"error"}
l!l&&r!l&&!r
004
MC/DC0%0/2
$status != 0 or $result->{"error"}
$status != 0 $result->{"error"}
Truth table33%1/3
A or B
A= $status != 0B= $result->{"error"}
ABresult
1X1
011
000
385 0 ▶ my $error = $result->{error} // "exit status $status";
Condition0%0/2
$result->{"error"} // "exit status $status"
l!l
00
MC/DC0%0/1
$result->{"error"} // "exit status $status"
$result->{"error"}
Truth table0%0/2
A
A= $result->{"error"}
Aresult
11
00
386 0 die "memory case $case live=$count failed: $error\n"
387 . "Raise the open-file limit or lower --live if socketpair creation failed.\n";
388 }
389 4 return $result;
390 }
391  
392 4 ▶sub socket_pool ($count) {
Subroutine socket_pool: called CC=3 SCAR=11.0
393 4 my (@server_fh, @client_fh);
394 4 for my $i (0 .. $count - 1) {
395 8 ▶ 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 $i/${count}: $!" 8 0 8
396 or die "socketpair $i/$count: $!";
397 8 set_nonblocking($server);
398 8 set_nonblocking($client);
399 8 push @server_fh, $server;
400 8 push @client_fh, $client;
401 }
402 4 return (\@server_fh, \@client_fh);
403 }
404  
405 16 ▶sub set_nonblocking ($fh) {
Subroutine set_nonblocking: called CC=3 SCAR=11.7
406 16 my $flags = fcntl($fh, F_GETFL, 0);
407 16 ▶ die "fcntl(F_GETFL): $!\n" if !defined $flags;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 0 16 16
408 16 ▶ fcntl($fh, F_SETFL, $flags | O_NONBLOCK)
Branch: 1 branch
BranchTrueFalseTotal
fcntl $fh, 4, $flags | 2048 or die "fcntl(F_SETFL): $!\n" 16 0 16
409 or die "fcntl(F_SETFL): $!\n";
410 }
411  
412 0 ▶sub vmrss_kb () {
Subroutine vmrss_kb: not called CC=4 SCAR=30.0
413 0 ▶ open my $status, '<', '/proc/self/status'
Branch: 1 branch
BranchTrueFalseTotal
open my $status, "<", "/proc/self/status" or die "open /proc/self/status: $!\n" 0 0 0
414 or die "open /proc/self/status: $!\n";
415 0 ▶ while (my $line = <$status>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $status)) 0 0 0
416 0 ▶ return 0 + $1 if $line =~ /^VmRSS:\s+(\d+)\s+kB\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^VmRSS:\s+(\d+)\s+kB\s*$/u 0 0 0
417 }
418 0 die "VmRSS not found in /proc/self/status\n";
419 }
420  
421 2 ▶sub rotated_cases ($repeat) {
Subroutine rotated_cases: called CC=1 SCAR=0.0
422 2 my $shift = ($repeat - 1) % @cases;
423 2 return (@cases[$shift .. $#cases], @cases[0 .. $shift - 1]);
424 }
425  
426 16 ▶sub median (@values) {
Subroutine median: called CC=3 SCAR=12.7
427 16 ▶ die "median requires at least one value\n" if !@values;
Branch: 1 branch
BranchTrueFalseTotal
unless @values 0 16 16
428 0 @values = sort { $a <=> $b } @values;
429 16 my $middle = int(@values / 2);
430 16 ▶ return $values[$middle] if @values % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @values % 2 16 0 16
431 0 return ($values[$middle - 1] + $values[$middle]) / 2;
432 }
433  
434 0 ▶sub environment_info () {
Subroutine environment_info: not called CC=1 SCAR=6.9
435 0 my ($sysname, $nodename, $release, $version, $machine) = uname();
436 return {
437 0 linux_event_version => $Linux::Event::IO::Sock::Stream::VERSION,
438 perl_version => "$^V",
439 perl_executable => $^X,
440 os => $^O,
441 uname => {
442 sysname => $sysname,
443 release => $release,
444 version => $version,
445 machine => $machine,
446 },
447 git_commit => git_commit(),
448 };
449 }
450  
451 0 ▶sub git_commit () {
Subroutine git_commit: not called CC=5 SCAR=34.0
452 0 ▶ return undef if !-e "$Bin/../.git";
Branch: 1 branch
BranchTrueFalseTotal
unless -e "$main::Bin/../.git" 0 0 0
453 0 ▶ open my $git, '-|', 'git', '-C', "$Bin/..", 'rev-parse', 'HEAD'
Branch: 1 branch
BranchTrueFalseTotal
open my $git, "-|", "git", "-C", "$main::Bin/..", "rev-parse", "HEAD" or return undef 0 0 0
454 or return undef;
455 0 my $commit = <$git>;
456 0 my $ok = close $git;
457 0 ▶ return undef if !$ok || !defined $commit;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok and defined $commit 0 0 0
Condition0%0/3
$ok and defined $commit
!ll&&!rl&&r
000
MC/DC0%0/2
$ok and defined $commit
$ok defined $commit
Truth table0%0/3
A and B
A= $okB= defined $commit
ABresult
0X0
100
111
458 0 chomp $commit;
459 0 return $commit;
460 }
461  
462 0 ▶sub usage ($status) {
Subroutine usage: not called CC=2 SCAR=17.9
463 0 ▶ my $fh = $status ? *STDERR : *STDOUT;
Branch: 1 branch
BranchTrueFalseTotal
$status ? : 0 0 0
464 0 print {$fh} <<'USAGE';
465 Usage: perl bench/run-stream-lifecycle-bench.pl [options]
466  
467 --api-style=NAME loop-add (default) or loop-option
468 --iterations=N lifecycle operations per case/repeat (default 100000)
469 --pool=N pre-created socketpairs reused by lifecycle cases (256)
470 --live=N,N retained object counts (1000,10000,20000)
471 --warmup=N untimed lifecycle operations per case (1000)
472 --repeats=N lifecycle repeats (7)
473 --memory-repeats=N fresh-process RSS repeats (3)
474 --cases=A,B selected cases
475 --[no-]memory enable/disable retained-memory measurements
476 --json=PATH write raw records, summaries, and environment as JSON
477 --help show this help
478  
479 Cases:
480 registration opaque native registration baseline
481 raw-named Stream raw-data mode with a named callback
482 framed-minimal delimiter subclass plus named on_message
483 framed-full-named delimiter subclass plus five named lifecycle callbacks
484 USAGE
485 0 exit $status;
486 }
487  
488 0 ▶sub _watch_read ($data) { return }
Subroutine _watch_read: not called CC=1 SCAR=6.9
489 0 ▶sub _watch_write ($data) { return }
Subroutine _watch_write: not called CC=1 SCAR=6.9
490 0 ▶sub _watch_error ($data) { return }
Subroutine _watch_error: not called CC=1 SCAR=6.9
« blib/lib/Linux/Event/_ByteStream/Descriptor.pm ↑ Summary blib/lib/Linux/Event/Kernel/Inotify.pm »