| 1 | package Brackup::GPGProcManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use Brackup::GPGProcess; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use POSIX ":sys_wait_h"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 0 | my ($class, $iter, $target) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | return bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | chunkiter => $iter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | procs => {}, # "addr(pchunk)" => GPGProcess | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | target => $target, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | procs_running => {}, # pid -> GPGProcess | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | uncollected_bytes => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | uncollected_chunks => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub enc_chunkref_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enc_chunkref_of: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my ($self, $pchunk) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $proc = $self->{procs}{$pchunk}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | unless ($proc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # catch iterator up to the point that was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # requested, or blow up. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $iters = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | while (my $ich = $self->{chunkiter}->next) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if ($ich == $pchunk) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $iters++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | warn "iters = $iters\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | die "Not found" unless $found; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $proc = $self->gen_process_for($pchunk); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | while ($proc->running) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $pid = $self->wait_for_a_process(1) or die | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | "No processes were reaped!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $self->_proc_summary_dump; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my ($cref, $enc_length) = $self->get_proc_chunkref($proc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $self->_proc_summary_dump; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $self->start_some_processes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return ($cref, $enc_length); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub start_some_processes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_some_processes: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # eat up any pending zombies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | while ($self->wait_for_a_process(0)) {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $pchunk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # TODO: make this stuff configurable/auto-tuned | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | while ($self->num_running_procs < 5 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$self->num_running_procs < 5 and $self->uncollected_chunks < 20 and $self->num_uncollected_bytes < 134217728 and $pchunk = $self->next_chunk_to_encrypt
$self->num_running_procs < 5 and $self->uncollected_chunks < 20 and $self->num_uncollected_bytes < 134217728
$self->num_running_procs < 5 and $self->uncollected_chunks < 20
MC/DC0%0/4
$self->num_running_procs < 5 and $self->uncollected_chunks < 20 and $self->num_uncollected_bytes < 134217728 and $pchunk = $self->next_chunk_to_encrypt
$self->num_running_procs < 5
$self->uncollected_chunks < 20
$self->num_uncollected_bytes < 134217728
$pchunk = $self->next_chunk_to_encrypt
Truth table0%0/5
A and B and C and D
A= $self->num_running_procs < 5B= $self->uncollected_chunks < 20C= $self->num_uncollected_bytes < 134217728D= $pchunk = $self->next_chunk_to_encrypt
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | $self->uncollected_chunks < 20 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | $self->num_uncollected_bytes < 128 * 1024 * 1024 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ($pchunk = $self->next_chunk_to_encrypt)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $self->_proc_summary_dump; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->gen_process_for($pchunk); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $self->_proc_summary_dump; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub _proc_summary_dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_proc_summary_dump: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return unless $ENV{GPG_DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | printf STDERR "num_running=%d, num_outstanding_bytes=%d uncollected_chunks=%d\n", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | $self->num_running_procs, $self->num_uncollected_bytes, $self->uncollected_chunks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub next_chunk_to_encrypt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_chunk_to_encrypt: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | while (my $ev = $self->{chunkiter}->next) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | next if $ev->isa("Brackup::File"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $pchunk = $ev; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | next if $self->{target}->stored_chunk_from_inventory($pchunk); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return $pchunk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub get_proc_chunkref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_proc_chunkref: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my ($self, $proc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $cref = $proc->chunkref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | delete $self->{procs}{$proc}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $self->{uncollected_bytes} -= $proc->size_on_disk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $self->{uncollected_chunks}--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return ($cref, $proc->size_on_disk); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # returns PID of a process that finished | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub wait_for_a_process { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wait_for_a_process: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my ($self, $block) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $flags = $block ? 0 : WNOHANG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $kid = waitpid(-1, $flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | return 0 if ! $block && $kid <= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $block and $kid <= 0
MC/DC0%0/2
not $block and $kid <= 0
not $block
$kid <= 0
Truth table0%0/3
not(A) and B
A= not $blockB= $kid <= 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | die "no child?" if $kid < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | return 0 unless $kid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my $proc = $self->{procs_running}{$kid} or die "Unknown child | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | process $kid finished!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | delete $self->{procs_running}{$proc->pid} or die; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $proc->note_stopped; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $self->{uncollected_bytes} += $proc->size_on_disk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return $kid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub num_uncollected_bytes { $_[0]{uncollected_bytes} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num_uncollected_bytes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub uncollected_chunks { $_[0]{uncollected_chunks} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uncollected_chunks: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub gen_process_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_process_for: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my ($self, $pchunk) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $proc = Brackup::GPGProcess->new($pchunk); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $self->{procs_running}{$proc->pid} = $proc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $self->{procs}{$pchunk} = $proc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $self->{uncollected_chunks}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return $proc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub num_running_procs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num_running_procs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | return scalar keys %{$self->{procs_running}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||