Brackup/GPGProcManager.pm

filter: Statementstmt 16.2% 13 / 80 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 26.6% 4 / 15 Podpod 0.0% 0 / 10 totaltotal 10.6% 17 / 159 CC 23 SCAR 35.8
CC
23
Cov
10%
wait_for_a_process
72.0
enc_chunkref_of
56.0
start_some_processes
42.0
CRAP 35.9
« Brackup/Chunker/MP3.pm ↑ Summary Brackup/GPGProcess.pm »
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
BranchTrueFalseTotal
unless ($proc) 0 0 0
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
BranchTrueFalseTotal
if (my $ich = $self->{"chunkiter"}->next) 0 0 0
29 0 ▶ if ($ich == $pchunk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ich == $pchunk) 0 0 0
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
BranchTrueFalseTotal
unless $found 0 0 0
37 0 $proc = $self->gen_process_for($pchunk);
38 }
39  
40 0 ▶ while ($proc->running) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proc->running) 0 0 0
41 0 ▶ my $pid = $self->wait_for_a_process(1) or die
Branch: 1 branch
BranchTrueFalseTotal
my $pid = $self->wait_for_a_process(1) or die "No processes were reaped!" 0 0 0
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
BranchTrueFalseTotal
if ($self->wait_for_a_process(0)) 0 0 0
58  
59 0 my $pchunk;
60 # TODO: make this stuff configurable/auto-tuned
61 0 ▶ while ($self->num_running_procs < 5 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->num_running_procs < 5 and $self->uncollected_chunks < 20 and $self->num_uncollected_bytes < 134217728 and $pchunk = $self->next_chunk_to_encrypt) 0 0 0
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
!ll&&!rl&&r
000
$self->num_running_procs < 5 and $self->uncollected_chunks < 20 and $self->num_uncollected_bytes < 134217728
!ll&&!rl&&r
000
$self->num_running_procs < 5 and $self->uncollected_chunks < 20
!ll&&!rl&&r
000
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
ABCDresult
0XXX0
10XX0
110X0
11100
11111
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
BranchTrueFalseTotal
unless $ENV{"GPG_DEBUG"} 0 0 0
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
BranchTrueFalseTotal
if (my $ev = $self->{"chunkiter"}->next) 0 0 0
82 0 ▶ next if $ev->isa("Brackup::File");
Branch: 1 branch
BranchTrueFalseTotal
if $ev->isa("Brackup::File") 0 0 0
83 0 my $pchunk = $ev;
84 0 ▶ next if $self->{target}->stored_chunk_from_inventory($pchunk);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"target"}->stored_chunk_from_inventory($pchunk) 0 0 0
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
BranchTrueFalseTotal
$block ? : 0 0 0
103 0 my $kid = waitpid(-1, $flags);
104 0 ▶ return 0 if ! $block && $kid <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $block and $kid <= 0 0 0 0
Condition0%0/3
not $block and $kid <= 0
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
105 0 ▶ die "no child?" if $kid < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $kid < 0 0 0 0
106 0 ▶ return 0 unless $kid;
Branch: 1 branch
BranchTrueFalseTotal
unless $kid 0 0 0
107  
108 0 ▶ my $proc = $self->{procs_running}{$kid} or die "Unknown child
Branch: 1 branch
BranchTrueFalseTotal
my $proc = $self->{"procs_running"}{$kid} or die "Unknown child\n process $kid finished!\n" 0 0 0
109 process $kid finished!\n";
110  
111 0 ▶ delete $self->{procs_running}{$proc->pid} or die;
Branch: 1 branch
BranchTrueFalseTotal
delete $self->{"procs_running"}{$proc->pid} or die 0 0 0
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  
« Brackup/Chunker/MP3.pm ↑ Summary Brackup/GPGProcess.pm »