| 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 Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use File::Basename qw(dirname); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use File::Path qw(make_path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Getopt::Long qw(GetOptions); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use JSON::PP qw(encode_json decode_json); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use POSIX qw(_exit uname); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Socket qw(AF_UNIX SOCK_STREAM PF_UNSPEC SOL_SOCKET SO_RCVBUF SO_SNDBUF); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC CLOCK_PROCESS_CPUTIME_ID); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Linux::Event::Loop; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Linux::Event::IO::Sock::Stream; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | our $READ_SIZE = 262_144; | |||||||||||||||||||||||||||
| 19 | 1 | our $READ_BUDGET_BYTES; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | { | ||||||||||||||||||||||||||||
| 22 | package Linux::Event::Bench::PayloadSweep::Base; | ||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use parent 'Linux::Event::IO::Sock::Stream'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | sub stream_tuning ($class) { | ||||||||||||||||||||||||||
|
Subroutine
stream_tuning: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | my $budget = defined($main::READ_BUDGET_BYTES) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | ? $main::READ_BUDGET_BYTES : $main::READ_SIZE; | ||||||||||||||||||||||||||||
| 28 | 2 | return read_size => $main::READ_SIZE, | |||||||||||||||||||||||||||
| 29 | read_budget_bytes => $budget; | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub on_error ($stream, $error) { die "Stream error: $error\n" } | ||||||||||||||||||||||||||
|
Subroutine
on_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub on_eof ($stream) { | ||||||||||||||||||||||||||
|
Subroutine
on_eof: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 34 | 0 | my $state = $stream->data; | |||||||||||||||||||||||||||
| 35 | die "producer EOF after $state->{received_bytes} of " | ||||||||||||||||||||||||||||
| 36 | . "$state->{target_bytes} payload bytes\n" | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if $state->{received_bytes} != $state->{target_bytes}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 1 | package Linux::Event::Bench::PayloadSweep::Raw; | |||||||||||||||||||||||||||
| 43 | 1 | ▶ | use parent -norequire, 'Linux::Event::Bench::PayloadSweep::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub on_data ($stream, $bytes) { main::receive_raw($stream, $bytes) } | ||||||||||||||||||||||||||
|
Subroutine
on_data: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||
| 48 | 1 | package Linux::Event::Bench::PayloadSweep::Delimiter; | |||||||||||||||||||||||||||
| 49 | 1 | ▶ | use parent -norequire, 'Linux::Event::Bench::PayloadSweep::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | use Linux::Event::Framer 'Delimiter', "\n"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 10 | ▶ | sub on_message ($stream, $message) { | ||||||||||||||||||||||||||
|
Subroutine
on_message: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 10 | main::receive_message($stream, $message); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | my @command_argv = @ARGV; | |||||||||||||||||||||||||||
| 57 | 1 | my $sizes = '64,256,1024,4096,16384,32768,65536,131072,200000'; | |||||||||||||||||||||||||||
| 58 | 1 | my $modes = 'raw,delimiter'; | |||||||||||||||||||||||||||
| 59 | 1 | my $repeats = 5; | |||||||||||||||||||||||||||
| 60 | 1 | my $warmup = 1; | |||||||||||||||||||||||||||
| 61 | 1 | my $target_bytes = 256 * 1024 * 1024; | |||||||||||||||||||||||||||
| 62 | 1 | my $min_messages = 2_000; | |||||||||||||||||||||||||||
| 63 | 1 | my $max_messages = 1_000_000; | |||||||||||||||||||||||||||
| 64 | 1 | my $variant = 'unspecified'; | |||||||||||||||||||||||||||
| 65 | 1 | my $commit = 'unknown'; | |||||||||||||||||||||||||||
| 66 | 1 | my $output; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | ▶ | GetOptions( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 'sizes=s' => \$sizes, | ||||||||||||||||||||||||||||
| 70 | 'modes=s' => \$modes, | ||||||||||||||||||||||||||||
| 71 | 'repeats=i' => \$repeats, | ||||||||||||||||||||||||||||
| 72 | 'warmup=i' => \$warmup, | ||||||||||||||||||||||||||||
| 73 | 'target-bytes=i' => \$target_bytes, | ||||||||||||||||||||||||||||
| 74 | 'min-messages=i' => \$min_messages, | ||||||||||||||||||||||||||||
| 75 | 'max-messages=i' => \$max_messages, | ||||||||||||||||||||||||||||
| 76 | 'read-size=i' => \$READ_SIZE, | ||||||||||||||||||||||||||||
| 77 | 'read-budget-bytes=i' => \$READ_BUDGET_BYTES, | ||||||||||||||||||||||||||||
| 78 | 'variant=s' => \$variant, | ||||||||||||||||||||||||||||
| 79 | 'commit=s' => \$commit, | ||||||||||||||||||||||||||||
| 80 | 'output=s' => \$output, | ||||||||||||||||||||||||||||
| 81 | ) or die "invalid options\n"; | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | ▶ | die "--output is required\n" if !defined($output) || $output eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $output or $output eq ""
MC/DC0%0/2
not defined $output or $output eq ""
not defined $output
$output eq ""
Truth table33%1/3
not(A) or B
A= not defined $outputB= $output eq ""
| |||||||||||||||||||||||||||||
| 84 | 1 | ▶ | die "repeats must be positive\n" if $repeats < 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 1 | ▶ | die "warmup must be non-negative\n" if $warmup < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | die "target-bytes, min-messages, max-messages, and read-size must be positive\n" | ||||||||||||||||||||||||||||
| 87 | 1 | ▶ | if grep { $_ < 1 } ($target_bytes, $min_messages, $max_messages, $READ_SIZE); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 1 | ▶ | die "read-budget-bytes must be non-negative\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $main::READ_BUDGET_BYTES and $main::READ_BUDGET_BYTES < 0
MC/DC0%0/2
defined $main::READ_BUDGET_BYTES and $main::READ_BUDGET_BYTES < 0
defined $main::READ_BUDGET_BYTES
$main::READ_BUDGET_BYTES < 0
Truth table33%1/3
A and B
A= defined $main::READ_BUDGET_BYTESB= $main::READ_BUDGET_BYTES < 0
| |||||||||||||||||||||||||||||
| 89 | if defined($READ_BUDGET_BYTES) && $READ_BUDGET_BYTES < 0; | ||||||||||||||||||||||||||||
| 90 | 1 | ▶ | die "min-messages must not exceed max-messages\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | if $min_messages > $max_messages; | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | my @sizes = map { 0 + $_ } split /,/, $sizes; | |||||||||||||||||||||||||||
| 94 | die "sizes must contain positive integers\n" | ||||||||||||||||||||||||||||
| 95 | 1 | ▶ | if !@sizes || grep { $_ < 1 } @sizes; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not @sizes or grep {$_ < 1;} @sizes
MC/DC0%0/2
not @sizes or grep {$_ < 1;} @sizes
not @sizes
grep {$_ < 1;} @sizes
Truth table33%1/3
not(A) or B
A= not @sizesB= grep {$_ < 1;} @sizes
| |||||||||||||||||||||||||||||
| 96 | 1 | my @modes = split /,/, $modes; | |||||||||||||||||||||||||||
| 97 | 1 | my %known_mode = map { $_ => 1 } qw(raw delimiter); | |||||||||||||||||||||||||||
| 98 | die "modes must contain raw and/or delimiter\n" | ||||||||||||||||||||||||||||
| 99 | 1 | ▶ | if !@modes || grep { !$known_mode{$_} } @modes; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not @modes or grep {not $known_mode{$_};} @modes
MC/DC0%0/2
not @modes or grep {not $known_mode{$_};} @modes
not @modes
grep {not $known_mode{$_};} @modes
Truth table33%1/3
not(A) or B
A= not @modesB= grep {not $known_mode{$_};} @modes
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 2 | ▶ | sub messages_for_size ($size) { | ||||||||||||||||||||||||||
|
Subroutine
messages_for_size: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 102 | 2 | my $messages = int($target_bytes / $size); | |||||||||||||||||||||||||||
| 103 | 2 | ▶ | $messages = $min_messages if $messages < $min_messages; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | $messages = $max_messages if $messages > $max_messages; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 2 | return $messages; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 16 | ▶ | sub median (@values) { | ||||||||||||||||||||||||||
|
Subroutine
median: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||
| 109 | 0 | @values = sort { $a <=> $b } @values; | |||||||||||||||||||||||||||
| 110 | 16 | return $values[int(@values / 2)]; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub write_all ($fh, $bytes, $calls) { | ||||||||||||||||||||||||||
|
Subroutine
write_all: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 114 | 0 | my $offset = 0; | |||||||||||||||||||||||||||
| 115 | 0 | my $length = length $bytes; | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | while ($offset < $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | my $written = syswrite($fh, $bytes, $length - $offset, $offset); | |||||||||||||||||||||||||||
| 118 | 0 | ▶ | die "producer write: $!" if !defined $written; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | $$calls++; | |||||||||||||||||||||||||||
| 120 | 0 | $offset += $written; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | ▶ | sub receive_raw ($stream, $bytes) { | ||||||||||||||||||||||||||
|
Subroutine
receive_raw: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 125 | 1 | my $state = $stream->data; | |||||||||||||||||||||||||||
| 126 | 1 | $state->{received_bytes} += length $bytes; | |||||||||||||||||||||||||||
| 127 | 1 | $state->{perl_callbacks}++; | |||||||||||||||||||||||||||
| 128 | die "raw receiver exceeded expected payload bytes\n" | ||||||||||||||||||||||||||||
| 129 | 1 | ▶ | if $state->{received_bytes} > $state->{target_bytes}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | $state->{loop}->stop | ||||||||||||||||||||||||||||
| 131 | 1 | ▶ | if $state->{received_bytes} == $state->{target_bytes}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 10 | ▶ | sub receive_message ($stream, $message) { | ||||||||||||||||||||||||||
|
Subroutine
receive_message: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||
| 135 | 10 | my $state = $stream->data; | |||||||||||||||||||||||||||
| 136 | die "framed payload mismatch\n" | ||||||||||||||||||||||||||||
| 137 | if length($message) != $state->{payload_size} | ||||||||||||||||||||||||||||
| 138 | 10 | ▶ | || $message ne $state->{payload}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $message != $state->{"payload_size"} or $message ne $state->{"payload"}
MC/DC0%0/2
length $message != $state->{"payload_size"} or $message ne $state->{"payload"}
length $message != $state->{"payload_size"}
$message ne $state->{"payload"}
Truth table33%1/3
A or B
A= length $message != $state->{"payload_size"}B= $message ne $state->{"payload"}
| |||||||||||||||||||||||||||||
| 139 | 10 | $state->{received_messages}++; | |||||||||||||||||||||||||||
| 140 | 10 | $state->{received_bytes} += length $message; | |||||||||||||||||||||||||||
| 141 | 10 | $state->{perl_callbacks}++; | |||||||||||||||||||||||||||
| 142 | $state->{loop}->stop | ||||||||||||||||||||||||||||
| 143 | 10 | ▶ | if $state->{received_messages} == $state->{messages}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 2 | ▶ | sub run_once ($mode, $payload_size, $messages) { | ||||||||||||||||||||||||||
|
Subroutine
run_once: called CC=25 SCAR=44.6
| |||||||||||||||||||||||||||||
| 147 | 2 | ▶ | socketpair(my $receiver_fh, my $producer_fh, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "socketpair: $!"; | ||||||||||||||||||||||||||||
| 149 | 2 | ▶ | pipe(my $barrier_r, my $barrier_w) or die "barrier pipe: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 2 | ▶ | pipe(my $metrics_r, my $metrics_w) or die "metrics pipe: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 2 | ▶ | my $receiver_socket_buffer = unpack('i', getsockopt( | ||||||||||||||||||||||||||
|
Condition50%1/2
getsockopt($receiver_fh, 1, 8) // "\0\0\0\0"
MC/DC0%0/1
getsockopt($receiver_fh, 1, 8) // "\0\0\0\0"
getsockopt($receiver_fh, 1, 8)
Truth table50%1/2
A
A= getsockopt($receiver_fh, 1, 8)
| |||||||||||||||||||||||||||||
| 153 | $receiver_fh, SOL_SOCKET, SO_RCVBUF) // pack('i', 0)); | ||||||||||||||||||||||||||||
| 154 | 2 | ▶ | my $producer_socket_buffer = unpack('i', getsockopt( | ||||||||||||||||||||||||||
|
Condition50%1/2
getsockopt($producer_fh, 1, 7) // "\0\0\0\0"
MC/DC0%0/1
getsockopt($producer_fh, 1, 7) // "\0\0\0\0"
getsockopt($producer_fh, 1, 7)
Truth table50%1/2
A
A= getsockopt($producer_fh, 1, 7)
| |||||||||||||||||||||||||||||
| 155 | $producer_fh, SOL_SOCKET, SO_SNDBUF) // pack('i', 0)); | ||||||||||||||||||||||||||||
| 156 | 2 | my $payload = 'x' x $payload_size; | |||||||||||||||||||||||||||
| 157 | 2 | ▶ | my $wire = $mode eq 'delimiter' ? "$payload\n" : $payload; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 2 | my $pid = fork(); | |||||||||||||||||||||||||||
| 160 | 2 | ▶ | die "fork: $!" if !defined $pid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 2 | ▶ | if ($pid == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 0 | close $receiver_fh; | |||||||||||||||||||||||||||
| 163 | 0 | close $barrier_w; | |||||||||||||||||||||||||||
| 164 | 0 | close $metrics_r; | |||||||||||||||||||||||||||
| 165 | 0 | my $go = ''; | |||||||||||||||||||||||||||
| 166 | 0 | ▶ | sysread($barrier_r, $go, 1) == 1 or _exit(2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | 0 | close $barrier_r; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | my $batch_messages = int(262_144 / length($wire)); | |||||||||||||||||||||||||||
| 170 | 0 | ▶ | $batch_messages = 1 if $batch_messages < 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $batch_messages = 64 if $batch_messages > 64; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | my $batch = $wire x $batch_messages; | |||||||||||||||||||||||||||
| 173 | 0 | my $remaining = $messages; | |||||||||||||||||||||||||||
| 174 | 0 | my $write_calls = 0; | |||||||||||||||||||||||||||
| 175 | 0 | my $cpu_start = clock_gettime(CLOCK_PROCESS_CPUTIME_ID); | |||||||||||||||||||||||||||
| 176 | 0 | my $ok = eval { | |||||||||||||||||||||||||||
| 177 | 0 | ▶ | while ($remaining >= $batch_messages) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 0 | write_all($producer_fh, $batch, \$write_calls); | |||||||||||||||||||||||||||
| 179 | 0 | $remaining -= $batch_messages; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | 0 | ▶ | write_all($producer_fh, $wire x $remaining, \$write_calls) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | if $remaining; | ||||||||||||||||||||||||||||
| 183 | 0 | 1; | |||||||||||||||||||||||||||
| 184 | }; | ||||||||||||||||||||||||||||
| 185 | 0 | my $producer_cpu = clock_gettime(CLOCK_PROCESS_CPUTIME_ID) - $cpu_start; | |||||||||||||||||||||||||||
| 186 | 0 | ▶ | _exit(3) if !$ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 0 | my $metrics = encode_json({ | |||||||||||||||||||||||||||
| 188 | write_calls => $write_calls, | ||||||||||||||||||||||||||||
| 189 | cpu_seconds => 0 + sprintf('%.9f', $producer_cpu), | ||||||||||||||||||||||||||||
| 190 | batch_messages => $batch_messages, | ||||||||||||||||||||||||||||
| 191 | }); | ||||||||||||||||||||||||||||
| 192 | 0 | ▶ | syswrite($metrics_w, $metrics) == length($metrics) or _exit(4); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | close $metrics_w; | |||||||||||||||||||||||||||
| 194 | 0 | close $producer_fh; | |||||||||||||||||||||||||||
| 195 | 0 | _exit(0); | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 2 | close $producer_fh; | |||||||||||||||||||||||||||
| 199 | 2 | close $barrier_r; | |||||||||||||||||||||||||||
| 200 | 2 | close $metrics_w; | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 2 | my $loop = Linux::Event::Loop->new; | |||||||||||||||||||||||||||
| 203 | 2 | my $state = { | |||||||||||||||||||||||||||
| 204 | loop => $loop, | ||||||||||||||||||||||||||||
| 205 | messages => $messages, | ||||||||||||||||||||||||||||
| 206 | payload => $payload, | ||||||||||||||||||||||||||||
| 207 | payload_size => $payload_size, | ||||||||||||||||||||||||||||
| 208 | target_bytes => $messages * $payload_size, | ||||||||||||||||||||||||||||
| 209 | received_messages => 0, | ||||||||||||||||||||||||||||
| 210 | received_bytes => 0, | ||||||||||||||||||||||||||||
| 211 | perl_callbacks => 0, | ||||||||||||||||||||||||||||
| 212 | }; | ||||||||||||||||||||||||||||
| 213 | 2 | ▶ | my $class = $mode eq 'raw' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | ? 'Linux::Event::Bench::PayloadSweep::Raw' | ||||||||||||||||||||||||||||
| 215 | : 'Linux::Event::Bench::PayloadSweep::Delimiter'; | ||||||||||||||||||||||||||||
| 216 | 2 | my $stream = $class->new( | |||||||||||||||||||||||||||
| 217 | loop => $loop, | ||||||||||||||||||||||||||||
| 218 | fh => $receiver_fh, | ||||||||||||||||||||||||||||
| 219 | data => $state, | ||||||||||||||||||||||||||||
| 220 | ); | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 2 | my $cpu_start = clock_gettime(CLOCK_PROCESS_CPUTIME_ID); | |||||||||||||||||||||||||||
| 223 | 2 | my $wall_start = clock_gettime(CLOCK_MONOTONIC); | |||||||||||||||||||||||||||
| 224 | 2 | ▶ | syswrite($barrier_w, 'G') == 1 or die "barrier release: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 2 | close $barrier_w; | |||||||||||||||||||||||||||
| 226 | 2 | $loop->run; | |||||||||||||||||||||||||||
| 227 | 2 | my $wall_seconds = clock_gettime(CLOCK_MONOTONIC) - $wall_start; | |||||||||||||||||||||||||||
| 228 | 2 | my $receiver_cpu = clock_gettime(CLOCK_PROCESS_CPUTIME_ID) - $cpu_start; | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 2 | waitpid($pid, 0); | |||||||||||||||||||||||||||
| 231 | 2 | ▶ | die "producer failed with status $?\n" if $? != 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 2 | ▶ | my $metric_text = do { local $/; <$metrics_r> // '' }; | ||||||||||||||||||||||||||
|
Condition50%1/2
readline $metrics_r // ""
MC/DC0%0/1
readline $metrics_r // ""
readline $metrics_r
Truth table50%1/2
A
A= readline $metrics_r
| |||||||||||||||||||||||||||||
| 233 | 2 | close $metrics_r; | |||||||||||||||||||||||||||
| 234 | 2 | my $producer_metrics = decode_json($metric_text); | |||||||||||||||||||||||||||
| 235 | die "received $state->{received_bytes} of $state->{target_bytes} bytes\n" | ||||||||||||||||||||||||||||
| 236 | 2 | ▶ | if $state->{received_bytes} != $state->{target_bytes}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | die "received $state->{received_messages} of $messages messages\n" | ||||||||||||||||||||||||||||
| 238 | 2 | ▶ | if $mode eq 'delimiter' && $state->{received_messages} != $messages; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mode eq "delimiter" and $state->{"received_messages"} != $messages
MC/DC0%0/2
$mode eq "delimiter" and $state->{"received_messages"} != $messages
$mode eq "delimiter"
$state->{"received_messages"} != $messages
Truth table66%2/3
A and B
A= $mode eq "delimiter"B= $state->{"received_messages"} != $messages
| |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 2 | my $stats = $stream->{xs_state}->stats; | |||||||||||||||||||||||||||
| 241 | 2 | my $options = $stream->{descriptor}{options}; | |||||||||||||||||||||||||||
| 242 | 2 | my $bytes = $state->{target_bytes}; | |||||||||||||||||||||||||||
| 243 | my $sample = { | ||||||||||||||||||||||||||||
| 244 | mode => $mode, | ||||||||||||||||||||||||||||
| 245 | payload_bytes => $payload_size, | ||||||||||||||||||||||||||||
| 246 | wire_bytes_per_message => length($wire), | ||||||||||||||||||||||||||||
| 247 | messages => $messages, | ||||||||||||||||||||||||||||
| 248 | wall_seconds => 0 + sprintf('%.9f', $wall_seconds), | ||||||||||||||||||||||||||||
| 249 | receiver_cpu_seconds => 0 + sprintf('%.9f', $receiver_cpu), | ||||||||||||||||||||||||||||
| 250 | producer_cpu_seconds => $producer_metrics->{cpu_seconds}, | ||||||||||||||||||||||||||||
| 251 | messages_per_second => 0 + sprintf('%.3f', $messages / $wall_seconds), | ||||||||||||||||||||||||||||
| 252 | mebibytes_per_second => 0 + sprintf('%.3f', | ||||||||||||||||||||||||||||
| 253 | $bytes / $wall_seconds / 1_048_576), | ||||||||||||||||||||||||||||
| 254 | receiver_cpu_nanoseconds_per_byte => 0 + sprintf('%.6f', | ||||||||||||||||||||||||||||
| 255 | $receiver_cpu * 1_000_000_000 / $bytes), | ||||||||||||||||||||||||||||
| 256 | producer_cpu_nanoseconds_per_byte => 0 + sprintf('%.6f', | ||||||||||||||||||||||||||||
| 257 | $producer_metrics->{cpu_seconds} * 1_000_000_000 / $bytes), | ||||||||||||||||||||||||||||
| 258 | read_calls => 0 + $stats->{read_calls}, | ||||||||||||||||||||||||||||
| 259 | reads_per_message => 0 + sprintf('%.9f', | ||||||||||||||||||||||||||||
| 260 | $stats->{read_calls} / $messages), | ||||||||||||||||||||||||||||
| 261 | producer_write_calls => 0 + $producer_metrics->{write_calls}, | ||||||||||||||||||||||||||||
| 262 | writes_per_message => 0 + sprintf('%.9f', | ||||||||||||||||||||||||||||
| 263 | $producer_metrics->{write_calls} / $messages), | ||||||||||||||||||||||||||||
| 264 | perl_callbacks => 0 + $state->{perl_callbacks}, | ||||||||||||||||||||||||||||
| 265 | callbacks_per_message => 0 + sprintf('%.9f', | ||||||||||||||||||||||||||||
| 266 | $state->{perl_callbacks} / $messages), | ||||||||||||||||||||||||||||
| 267 | input_peak_bytes => 0 + $stats->{input_peak_bytes}, | ||||||||||||||||||||||||||||
| 268 | input_compactions => 0 + $stats->{input_compactions}, | ||||||||||||||||||||||||||||
| 269 | 2 | }; | |||||||||||||||||||||||||||
| 270 | my $effective = { | ||||||||||||||||||||||||||||
| 271 | delivery_mode => $mode eq 'raw' ? 'on_data' : 'on_message', | ||||||||||||||||||||||||||||
| 272 | framer => $mode eq 'raw' ? undef : { | ||||||||||||||||||||||||||||
| 273 | family => 'Delimiter', | ||||||||||||||||||||||||||||
| 274 | delimiter_hex => '0a', | ||||||||||||||||||||||||||||
| 275 | include_delimiter => JSON::PP::false, | ||||||||||||||||||||||||||||
| 276 | max_frame => undef, | ||||||||||||||||||||||||||||
| 277 | }, | ||||||||||||||||||||||||||||
| 278 | transport => 'AF_UNIX SOCK_STREAM socketpair', | ||||||||||||||||||||||||||||
| 279 | topology => 'forked blocking producer; parent Loop/Stream receiver; start barrier', | ||||||||||||||||||||||||||||
| 280 | concurrency => 1, | ||||||||||||||||||||||||||||
| 281 | tls => { enabled => JSON::PP::false }, | ||||||||||||||||||||||||||||
| 282 | edge_triggered => JSON::PP::false, | ||||||||||||||||||||||||||||
| 283 | read_size => 0 + $options->{read_size}, | ||||||||||||||||||||||||||||
| 284 | read_budget_bytes => 0 + $options->{read_budget_bytes}, | ||||||||||||||||||||||||||||
| 285 | read_batch_bytes => 0 + $options->{read_batch_bytes}, | ||||||||||||||||||||||||||||
| 286 | message_batch_size => 0 + $options->{message_batch_size}, | ||||||||||||||||||||||||||||
| 287 | max_buffer => 0 + $options->{max_buffer}, | ||||||||||||||||||||||||||||
| 288 | high_watermark => 0 + $options->{high_watermark}, | ||||||||||||||||||||||||||||
| 289 | low_watermark => 0 + $options->{low_watermark}, | ||||||||||||||||||||||||||||
| 290 | max_pending_bytes => 0 + $options->{max_pending_bytes}, | ||||||||||||||||||||||||||||
| 291 | producer_batch_messages => 0 + $producer_metrics->{batch_messages}, | ||||||||||||||||||||||||||||
| 292 | 2 | ▶ | receiver_socket_buffer => $receiver_socket_buffer, | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 293 | producer_socket_buffer => $producer_socket_buffer, | ||||||||||||||||||||||||||||
| 294 | socket_options => 'OS defaults; TCP_NODELAY not applicable', | ||||||||||||||||||||||||||||
| 295 | latency => 'not sampled; saturated one-way throughput baseline', | ||||||||||||||||||||||||||||
| 296 | cpu_affinity => 'not set', | ||||||||||||||||||||||||||||
| 297 | }; | ||||||||||||||||||||||||||||
| 298 | 2 | $stream->close; | |||||||||||||||||||||||||||
| 299 | 2 | return ($sample, $effective); | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 1 | my @samples; | |||||||||||||||||||||||||||
| 303 | my %effective_config_by_mode; | ||||||||||||||||||||||||||||
| 304 | 1 | for my $mode (@modes) { | |||||||||||||||||||||||||||
| 305 | 2 | for my $payload_size (@sizes) { | |||||||||||||||||||||||||||
| 306 | 2 | my $messages = messages_for_size($payload_size); | |||||||||||||||||||||||||||
| 307 | 2 | run_once($mode, $payload_size, $messages) for 1 .. $warmup; | |||||||||||||||||||||||||||
| 308 | 2 | for my $repeat (1 .. $repeats) { | |||||||||||||||||||||||||||
| 309 | 2 | my ($sample, $effective) = run_once( | |||||||||||||||||||||||||||
| 310 | $mode, $payload_size, $messages, | ||||||||||||||||||||||||||||
| 311 | ); | ||||||||||||||||||||||||||||
| 312 | 2 | $sample->{repeat} = $repeat; | |||||||||||||||||||||||||||
| 313 | 2 | push @samples, $sample; | |||||||||||||||||||||||||||
| 314 | 2 | ▶ | $effective_config_by_mode{$mode} //= $effective; | ||||||||||||||||||||||||||
|
Condition33%1/3
$effective_config_by_mode{$mode} //= $effective
MC/DC0%0/2
$effective_config_by_mode{$mode} //= $effective
$effective_config_by_mode{$mode}
$effective
Truth table33%1/3
A //= B
A= $effective_config_by_mode{$mode}B= $effective
| |||||||||||||||||||||||||||||
| 315 | printf "%s %7d B repeat=%d %11.1f msg/s %9.1f MiB/s cpu=%8.3f ns/B\n", | ||||||||||||||||||||||||||||
| 316 | $mode, $payload_size, $repeat, | ||||||||||||||||||||||||||||
| 317 | $sample->{messages_per_second}, | ||||||||||||||||||||||||||||
| 318 | $sample->{mebibytes_per_second}, | ||||||||||||||||||||||||||||
| 319 | 2 | $sample->{receiver_cpu_nanoseconds_per_byte}; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 1 | my @summary; | |||||||||||||||||||||||||||
| 325 | 1 | for my $mode (@modes) { | |||||||||||||||||||||||||||
| 326 | 2 | for my $payload_size (@sizes) { | |||||||||||||||||||||||||||
| 327 | my @set = grep { | ||||||||||||||||||||||||||||
| 328 | 2 | ▶ | $_->{mode} eq $mode && $_->{payload_bytes} == $payload_size | ||||||||||||||||||||||||||
|
Condition66%2/3
$_->{'mode'} eq $mode && $_->{'payload_bytes'} == $payload_size
MC/DC50%1/2
$_->{'mode'} eq $mode && $_->{'payload_bytes'} == $payload_size
$_->{'mode'} eq $mode
$_->{'payload_bytes'} == $payload_size
Truth table66%2/3
A && B
A= $_->{'mode'} eq $modeB= $_->{'payload_bytes'} == $payload_size
| |||||||||||||||||||||||||||||
| 329 | } @samples; | ||||||||||||||||||||||||||||
| 330 | push @summary, { | ||||||||||||||||||||||||||||
| 331 | mode => $mode, | ||||||||||||||||||||||||||||
| 332 | payload_bytes => $payload_size, | ||||||||||||||||||||||||||||
| 333 | messages => $set[0]{messages}, | ||||||||||||||||||||||||||||
| 334 | median_messages_per_second => median( | ||||||||||||||||||||||||||||
| 335 | 2 | map { $_->{messages_per_second} } @set), | |||||||||||||||||||||||||||
| 336 | median_mebibytes_per_second => median( | ||||||||||||||||||||||||||||
| 337 | 2 | map { $_->{mebibytes_per_second} } @set), | |||||||||||||||||||||||||||
| 338 | median_receiver_cpu_nanoseconds_per_byte => median( | ||||||||||||||||||||||||||||
| 339 | 2 | map { $_->{receiver_cpu_nanoseconds_per_byte} } @set), | |||||||||||||||||||||||||||
| 340 | median_producer_cpu_nanoseconds_per_byte => median( | ||||||||||||||||||||||||||||
| 341 | 2 | map { $_->{producer_cpu_nanoseconds_per_byte} } @set), | |||||||||||||||||||||||||||
| 342 | median_reads_per_message => median( | ||||||||||||||||||||||||||||
| 343 | 2 | map { $_->{reads_per_message} } @set), | |||||||||||||||||||||||||||
| 344 | median_writes_per_message => median( | ||||||||||||||||||||||||||||
| 345 | 2 | map { $_->{writes_per_message} } @set), | |||||||||||||||||||||||||||
| 346 | median_callbacks_per_message => median( | ||||||||||||||||||||||||||||
| 347 | 2 | map { $_->{callbacks_per_message} } @set), | |||||||||||||||||||||||||||
| 348 | median_input_peak_bytes => median( | ||||||||||||||||||||||||||||
| 349 | 2 | map { $_->{input_peak_bytes} } @set), | |||||||||||||||||||||||||||
| 350 | }; | ||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 1 | my @uname = uname(); | |||||||||||||||||||||||||||
| 355 | my $report = { | ||||||||||||||||||||||||||||
| 356 | schema_version => 1, | ||||||||||||||||||||||||||||
| 357 | benchmark => 'stream-payload-sweep', | ||||||||||||||||||||||||||||
| 358 | variant => $variant, | ||||||||||||||||||||||||||||
| 359 | commit => $commit, | ||||||||||||||||||||||||||||
| 360 | generated_at_epoch => time, | ||||||||||||||||||||||||||||
| 361 | command => join(' ', $^X, $0, @command_argv), | ||||||||||||||||||||||||||||
| 362 | runtime => { | ||||||||||||||||||||||||||||
| 363 | perl => "$^V", | ||||||||||||||||||||||||||||
| 364 | os => $^O, | ||||||||||||||||||||||||||||
| 365 | archname => $Config{archname}, | ||||||||||||||||||||||||||||
| 366 | compiler => $Config{cc}, | ||||||||||||||||||||||||||||
| 367 | compiler_flags => $Config{ccflags}, | ||||||||||||||||||||||||||||
| 368 | optimize => $Config{optimize}, | ||||||||||||||||||||||||||||
| 369 | 1 | ▶ | uname => join(' ', @uname), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | }, | ||||||||||||||||||||||||||||
| 371 | configuration => { | ||||||||||||||||||||||||||||
| 372 | modes => \@modes, | ||||||||||||||||||||||||||||
| 373 | payload_sizes => \@sizes, | ||||||||||||||||||||||||||||
| 374 | repeats => $repeats, | ||||||||||||||||||||||||||||
| 375 | warmups => $warmup, | ||||||||||||||||||||||||||||
| 376 | target_payload_bytes => $target_bytes, | ||||||||||||||||||||||||||||
| 377 | minimum_messages => $min_messages, | ||||||||||||||||||||||||||||
| 378 | maximum_messages => $max_messages, | ||||||||||||||||||||||||||||
| 379 | read_size => $READ_SIZE, | ||||||||||||||||||||||||||||
| 380 | read_budget_bytes => defined($READ_BUDGET_BYTES) | ||||||||||||||||||||||||||||
| 381 | ? $READ_BUDGET_BYTES : $READ_SIZE, | ||||||||||||||||||||||||||||
| 382 | }, | ||||||||||||||||||||||||||||
| 383 | effective_config_by_mode => \%effective_config_by_mode, | ||||||||||||||||||||||||||||
| 384 | samples => \@samples, | ||||||||||||||||||||||||||||
| 385 | summary => \@summary, | ||||||||||||||||||||||||||||
| 386 | }; | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 1 | make_path(dirname($output)); | |||||||||||||||||||||||||||
| 389 | 1 | ▶ | open my $fh, '>:raw', $output or die "open $output: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | 1 | print {$fh} JSON::PP->new->canonical->pretty->encode($report); | |||||||||||||||||||||||||||
| 391 | 1 | ▶ | close $fh or die "close $output: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | 1 | say "Wrote $output"; | |||||||||||||||||||||||||||