bench/run-stream-lifecycle-bench.pl

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