JobQueue.pm

filter: Statementstmt 81.4% 210 / 258 Branchbran 62.5% 85 / 136 Conditioncond 50.0% 17 / 34 MC/DCmcdc 15.0% 3 / 20 Subroutinesub 90.0% 27 / 30 Podpod 61.9% 13 / 21 totaltotal 71.1% 355 / 499 CC 90 SCAR 28.5
CC
90
Cov
73%
status
56.0
startmore
32.1
startmore_jobs
28.2
CRAP 17.4
↑ Summary JobQueue/Job.pm »
1  
2 package Proc::JobQueue;
3  
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Time::HiRes qw(sleep);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Hash::Util qw(lock_keys unlock_keys);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Object::Dependency;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 require Exporter;
15  
16 3 our $VERSION = 0.903;
17 3 ▶our $debug ||= 0;
Condition50%1/2
our $debug ||= 0
l!l
03
MC/DC0%0/1
our $debug ||= 0
our $debug
Truth table50%1/2
A
A= our $debug
Aresult
11
00
18 3 ▶our $status_frequency ||= 2;
Condition50%1/2
our $status_frequency ||= 2
l!l
03
MC/DC0%0/1
our $status_frequency ||= 2
our $status_frequency
Truth table50%1/2
A
A= our $status_frequency
Aresult
11
00
19 3 ▶our $host_canonicalizer ||= 'File::Slurp::Remote::CanonicalHostnames';
Condition50%1/2
our $host_canonicalizer ||= "File::Slurp::Remote::CanonicalHostnames"
l!l
30
MC/DC0%0/1
our $host_canonicalizer ||= "File::Slurp::Remote::CanonicalHostnames"
our $host_canonicalizer
Truth table50%1/2
A
A= our $host_canonicalizer
Aresult
11
00
20  
21 3 our @ISA = qw(Exporter);
22 3 our @EXPORT_OK = qw(is_remote_host canonicalize my_hostname);
23  
24 sub configure
25 0 ▶{
Subroutine configure: not called CC=1 SCAR=6.9
Pod documented
26 0 my ($queue, %params) = shift;
27 0 @$queue{keys %params} = values %params;
28 }
29  
30 sub addhost
31 6 ▶{
Subroutine addhost: called CC=2 SCAR=6.9
Pod documented
32 6 my ($queue, $host, %params) = @_;
33 6 my $hr;
34 6 ▶ if ($hr = $queue->{status}{$host}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr = $queue->{'status'}{$host}) { } 3 3 6
35 3 @$hr{keys %params} = values %params;
36 } else {
37 $hr = $queue->{status}{$host} = {
38 name => $host,
39 jobs_per_host => $queue->{jobs_per_host},
40 3 in_startmore => 0,
41 %params,
42 running => {},
43 queue => {},
44 };
45 }
46 6 $queue->set_readiness($host);
47 }
48  
49 sub set_readiness
50 439 ▶{
Subroutine set_readiness: called CC=4 SCAR=14.2
Pod undocumented
51 439 my ($queue, $host) = @_;
52 439 my $hr = $queue->{status}{$host};
53 439 ▶ if ($hr->{jobs_per_host} and $hr->{jobs_per_host} > keys %{$hr->{running}}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($hr->{'jobs_per_host'} and $hr->{'jobs_per_host'} > keys %{$$hr{'running'};}) { } 434 5 439
elsif (not keys %{$$hr{'running'};}) { } 0 5 5
Condition66%2/3
$hr->{"jobs_per_host"} and $hr->{"jobs_per_host"} > keys %{$$hr{"running"};}
!ll&&!rl&&r
05434
MC/DC50%1/2
$hr->{"jobs_per_host"} and $hr->{"jobs_per_host"} > keys %{$$hr{"running"};}
$hr->{"jobs_per_host"} $hr->{"jobs_per_host"} > keys %{$$hr{"running"};}
Truth table66%2/3
A and B
A= $hr->{"jobs_per_host"}B= $hr->{"jobs_per_host"} > keys %{$$hr{"running"};}
ABresult
0X0
100
111
54 434 $queue->{ready_hosts}{$host} = $hr;
55 5 } elsif (! keys %{$hr->{running}}) {
56 0 $queue->{ready_hosts}{$host} = $hr;
57 } else {
58 5 delete $queue->{ready_hosts}{$host};
59 }
60 }
61  
62 sub new
63 3 ▶{
Subroutine new: called CC=2 SCAR=6.9
Pod documented
64 3 my ($pkg, %params) = @_;
65 3 my $queue = bless {
66 dependency_graph => undef,
67 startmore_in_progress => undef,
68 host_overload => 120,
69 host_is_over => 0,
70 jobnum => 1000,
71 jobs_per_host => 4,
72 queue => {},
73 status => {},
74 ready_hosts => {},
75 hold_all => 0,
76 hosts => [ my_hostname() ],
77 %params,
78 }, $pkg;
79 3 $queue->addhost($_) for @{$queue->{hosts}};
80 3 lock_keys(%$queue);
81 3 return $queue;
82 }
83  
84 sub hold
85 1 ▶{
Subroutine hold: called CC=2 SCAR=7.1
Pod documented
86 1 my ($self, $new) = @_;
87 1 ▶ $self->{hold_all} = $new if defined $new;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new 1 0 1
88 1 return $self->{hold_all};
89 }
90  
91 sub add
92 135 ▶{
Subroutine add: called CC=7 SCAR=21.1
Pod documented
93 135 my ($queue, $job, $host) = @_;
94 135 ▶ confess "$job not a ref" unless ref $job;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $job 0 135 135
95 135 ▶ confess "$job is not a job" unless $job->isa('Proc::JobQueue::Job');
Branch: 1 branch
BranchTrueFalseTotal
unless $job->isa("Proc::JobQueue::Job") 0 135 135
96  
97 135 ▶ $job->jobnum($queue->{jobnum}++)
Branch: 1 branch
BranchTrueFalseTotal
unless $job->jobnum 79 56 135
98 unless $job->jobnum;
99 135 my $jobnum = $job->jobnum();
100  
101 135 ▶ print STDERR "Adding $jobnum - ".ref($job)." to worklist\n" if $debug > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 2 0 135 135
102 135 my $q;
103 135 ▶ if ($host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host) { } 0 135 135
104 0 ▶ confess "no $host" unless $queue->{status}{$host};
Branch: 1 branch
BranchTrueFalseTotal
unless $queue->{"status"}{$host} 0 0 0
105 0 $q = $queue->{status}{$host}{queue};
106 } else {
107 135 $q = $queue->{queue};
108 }
109  
110 135 $q->{$jobnum} = $job;
111  
112 135 $job->{dependency_graph} = $queue->{dependency_graph}; # TODO: do this with a method
113  
114 135 $job->queue($queue);
115 135 $queue->startmore;
116 }
117  
118 # this looks at the dependency queue. startmore_jobs looks at the
119 # at the jobs queue.
120 sub startmore
121 308 ▶{
Subroutine startmore: called CC=21 SCAR=34.7
Pod documented
122 308 my ($job_queue) = shift;
123  
124 308 ▶ if ($job_queue->{startmore_in_progress}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job_queue->{"startmore_in_progress"}) 187 121 308
125 187 ▶ print STDERR "Re-entry to startmore prevented\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 187 187
126 187 $job_queue->{startmore_in_progress}++;
127 187 return 0;
128 }
129 121 $job_queue->{startmore_in_progress} = 2;
130  
131 121 my $dependency_graph = $job_queue->{dependency_graph};
132  
133 121 my $stuff_started = 0;
134  
135 121 my $jq_done;
136  
137 121 ▶ print STDERR "looking for more depenency graph items to queue up\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 121 121
138 121 eval {
139 121 $job_queue->checkjobs();
140  
141 121 ▶ while ($job_queue->{startmore_in_progress} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job_queue->{"startmore_in_progress"} > 1) 121 121 242
142 163 $job_queue->{startmore_in_progress} = 1;
143 163 ▶ if ($dependency_graph) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dependency_graph) 88 75 163
144 88 ▶ while (my @runnable = $dependency_graph->independent(lock => 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@runnable) = $dependency_graph->independent("lock", 1)) 45 88 133
145 45 $stuff_started++;
146 45 for my $task (@runnable) {
147 83 ▶ print "Queuing $task->{desc}\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 83 83
148 83 ▶ if ($task->can('run_dependency_task')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($task->can('run_dependency_task')) { } 13 70 83
elsif ($task->isa('Proc::JobQueue::Job')) { } 70 0 70
149 13 ▶ $job_queue->{startmore_in_progress}++ if $task->run_dependency_task($dependency_graph);
Branch: 1 branch
BranchTrueFalseTotal
if $task->run_dependency_task($dependency_graph) 13 0 13
150 } elsif ($task->isa('Proc::JobQueue::Job')) {
151 70 $job_queue->add($task, $task->{force_host});
152 } else {
153 0 die "don't know how to handle $task";
154 }
155 }
156 }
157 }
158  
159 163 $jq_done = $job_queue->startmore_jobs();
160  
161 163 ▶ redo if $job_queue->{startmore_in_progress} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $job_queue->{"startmore_in_progress"} > 1 42 121 163
162 }
163 };
164 121 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 121 121
165 0 $job_queue->suicide();
166 };
167  
168 121 $job_queue->{startmore_in_progress} = 0;
169  
170 121 ▶ return $jq_done unless $dependency_graph;
Branch: 1 branch
BranchTrueFalseTotal
unless $dependency_graph 75 46 121
171  
172 46 ▶ if ($jq_done && $dependency_graph->alldone) {
Branch: 2 branches
BranchTrueFalseTotal
if ($jq_done and $dependency_graph->alldone) { } 1 45 46
elsif ($jq_done and not $stuff_started) { } 0 90 90
Condition66%2/3
$jq_done and $dependency_graph->alldone
!ll&&!rl&&r
4501
MC/DC50%1/2
$jq_done and $dependency_graph->alldone
$jq_done $dependency_graph->alldone
Truth table66%2/3
A and B
A= $jq_doneB= $dependency_graph->alldone
ABresult
0X0
100
111
173 1 print STDERR "Nothing more to do\n";
174 1 $job_queue->unloop();
175 1 return 1;
176 ▶ } elsif ($jq_done && ! $stuff_started) {
Condition33%1/3
$jq_done and not $stuff_started
!ll&&!rl&&r
4500
MC/DC0%0/2
$jq_done and not $stuff_started
$jq_done not $stuff_started
Truth table33%1/3
A and not(B)
A= $jq_doneB= not $stuff_started
ABresult
0X0
100
111
177 0 ▶ if (keys %{$dependency_graph->{stuck}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$dependency_graph{'stuck'};}) { } 0 0 0
178 0 print STDERR "All runnable jobs are done, remaining dependencies are stuck:\n";
179 0 for my $o (values %{$dependency_graph->{stuck}}) {
180 0 printf "\t%s\n", $dependency_graph->desc($o);
181 }
182 0 $job_queue->unloop();
183 0 return 1;
184 } else {
185 0 print STDERR "Job queue is empty, but dependency graph doesn't think there is any work to be done!\n";
186 0 $dependency_graph->dump_graph();
187 }
188 }
189 45 return 0;
190 }
191  
192 sub startmore_jobs
193 163 ▶{
Subroutine startmore_jobs: called CC=23 SCAR=33.4
Pod undocumented
194 163 my ($queue) = @_;
195 163 ▶ return 0 if $queue->{hold_all};
Branch: 1 branch
BranchTrueFalseTotal
if $queue->{"hold_all"} 0 163 163
196 163 ▶ print "# Looking to start more\n" if $debug > 8;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 8 0 163 163
197 163 ▶ confess "no hosts added" unless keys %{$queue->{status}};
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$$queue{"status"};} 0 163 163
198 163 my $stuff = 0;
199 163 my $new_host_is_over = 0;
200 163 while(1) {
201 298 my $redo = 0;
202 HOST:
203 298 for my $host (keys %{$queue->{ready_hosts}}) {
204 288 ▶ print STDERR "# checking $host to maybe start more jobs\n" if $debug > 3;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 3 0 288 288
205 288 my $hr = $queue->{ready_hosts}{$host};
206 JOB:
207 0 ▶ while ((! $hr->{jobs_per_host} && ! keys %{$hr->{running}}) || $hr->{jobs_per_host} > (keys %{$hr->{running}} || 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $hr->{"jobs_per_host"} || keys %{$$hr{"running"};} or $hr->{"jobs_per_host"} > (keys %{$$hr{"running"};} || 0)) 288 0 288
Condition50%4/8
not $hr->{"jobs_per_host"} || keys %{$$hr{"running"};} or $hr->{"jobs_per_host"} > (keys %{$$hr{"running"};} || 0)
l!l&&r!l&&!r
02880
$hr->{'jobs_per_host'} || keys %{$$hr{'running'};}
l!l&&r!l&&!r
28800
keys %{$$hr{'running'};} || 0
l!l
26919
MC/DC0%0/3
not $hr->{"jobs_per_host"} || keys %{$$hr{"running"};} or $hr->{"jobs_per_host"} > (keys %{$$hr{"running"};} || 0)
$hr->{'jobs_per_host'} keys %{$$hr{'running'};} $hr->{"jobs_per_host"} > (keys %{$$hr{"running"};} || 0)
MC/DC100%1/1
keys %{$$hr{'running'};} || 0
keys %{$$hr{'running'};}
Truth table20%1/5
not(A || B) or C
A= $hr->{'jobs_per_host'}B= keys %{$$hr{'running'};}C= $hr->{"jobs_per_host"} > (keys %{$$hr{"running"};} || 0)
ABCresult
00X1
1X11
0111
1X00
0100
Truth table100%2/2
A
A= keys %{$$hr{'running'};}
Aresult
11
00
208 288 ▶ print STDERR "# there is room for more on $host\n" if $debug > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 4 0 288 288
209 $new_host_is_over++
210 288 ▶ if keys(%{$hr->{queue}}) > $queue->{host_overload};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$hr{"queue"};} > $queue->{"host_overload"} 0 288 288
211 288 my @q;
212 288 push (@q, $hr->{queue});
213 push (@q, $queue->{queue})
214 288 ▶ if $hr->{jobs_per_host} && ! $queue->{host_is_over};
Branch: 1 branch
BranchTrueFalseTotal
if $hr->{"jobs_per_host"} and not $queue->{"host_is_over"} 288 0 288
Condition33%1/3
$hr->{"jobs_per_host"} and not $queue->{"host_is_over"}
!ll&&!rl&&r
00288
MC/DC0%0/2
$hr->{"jobs_per_host"} and not $queue->{"host_is_over"}
$hr->{"jobs_per_host"} not $queue->{"host_is_over"}
Truth table33%1/3
A and not(B)
A= $hr->{"jobs_per_host"}B= not $queue->{"host_is_over"}
ABresult
0X0
100
111
215 288 for my $q (@q) {
216 576 ▶ next unless keys %$q;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$q 402 174 576
217 174 $stuff = 1;
218 174 ▶ for my $jobnum (reverse sort { $q->{$a}{priority} <=> $q->{$b}{priority} || $a <=> $b } keys %$q) {
Condition66%2/3
$q->{$a}{'priority'} <=> $q->{$b}{'priority'} || $a <=> $b
l!l&&r!l&&!r
521290
MC/DC0%0/2
$q->{$a}{'priority'} <=> $q->{$b}{'priority'} || $a <=> $b
$q->{$a}{'priority'} <=> $q->{$b}{'priority'} $a <=> $b
Truth table66%2/3
A || B
A= $q->{$a}{'priority'} <=> $q->{$b}{'priority'}B= $a <=> $b
ABresult
1X1
011
000
219 185 ▶ print STDERR "# looking to start $jobnum on $host\n" if $debug > 5;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 5 0 185 185
220 185 my $job = $q->{$jobnum};
221 185 ▶ unless ($job->runnable) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($job->runnable) 50 135 185
222 50 ▶ print STDERR "# can't start $jobnum $job->{desc} on $host: not runnable\n" if $debug > 5;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 5 0 50 50
223 50 next;
224 }
225 135 delete $q->{$jobnum};
226 135 $queue->startjob($host, $jobnum, $job);
227 135 $queue->set_readiness($host);
228 135 $redo = 1;
229 135 next HOST;
230 }
231 }
232 153 last;
233 }
234 }
235 298 ▶ last unless $redo;
Branch: 1 branch
BranchTrueFalseTotal
unless $redo 163 135 298
236 }
237 163 $queue->{host_is_over} = $new_host_is_over;
238 163 ▶ return 0 if $stuff;
Branch: 1 branch
BranchTrueFalseTotal
if $stuff 98 65 163
239 65 return $queue->alldone();
240 }
241  
242 sub suicide
243 0 ▶{
Subroutine suicide: not called CC=1 SCAR=6.9
Pod documented
244 0 print STDERR "DIE DIE DIE DIE DIE (DT2): $@";
245 # exit 1; hangs!
246 0 POSIX::_exit(1);
247 }
248  
249 # a hook for EventQueue
250 1 ▶sub unloop { }
Subroutine unloop: called CC=1 SCAR=0.0
Pod undocumented
251  
252  
253 sub startjob
254 135 ▶{
Subroutine startjob: called CC=2 SCAR=7.0
Pod documented
255 135 my ($queue, $host, $jobnum, $job) = @_;
256 135 ▶ print STDERR "# starting $jobnum $job->{desc} on $host\n" if $debug > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 1 0 135 135
257 135 my $hr = $queue->{status}{$host};
258 135 $hr->{running}{$jobnum} = $job;
259 135 $job->host($host);
260 135 $job->start();
261 }
262  
263  
264 # This routine is re-enterant: it may be called from something it calls.
265 sub checkjobs
266 164 ▶{
Subroutine checkjobs: called CC=9 SCAR=22.2
Pod documented
267 164 my ($queue) = @_;
268 164 my $found = 0;
269 164 for my $host (keys %{$queue->{status}}) {
270 164 ▶ print STDERR "# checking jobs on $host\n" if $debug > 7;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 7 0 164 164
271 164 ▶ my $hr = $queue->{status}{$host} || die;
Condition50%1/2
$queue->{'status'}{$host} || die()
l!l
1640
MC/DC0%0/1
$queue->{'status'}{$host} || die()
$queue->{'status'}{$host}
Truth table50%1/2
A
A= $queue->{'status'}{$host}
Aresult
11
00
272 164 for my $jobnum (keys %{$hr->{running}}) {
273 490 my $job = $hr->{running}{$jobnum};
274 490 ▶ if ($job) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job) { } 479 11 490
275 479 ▶ print STDERR "# checking $jobnum $job->{desc} on $host\n" if $debug > 8;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 8 0 479 479
276 479 ▶ $found++
Branch: 1 branch
BranchTrueFalseTotal
if defined $job->checkjob($queue) 120 359 479
277 if defined $job->checkjob($queue);
278 } else {
279 11 ▶ print STDERR "# job $jobnum is undef!\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 11 11
280 11 delete $hr->{running}{$jobnum};
281 11 $found++;
282 }
283  
284 }
285 164 $queue->set_readiness($host);
286 }
287 164 return $found;
288 }
289  
290 sub jobdone
291 128 ▶{
Subroutine jobdone: called CC=3 SCAR=11.4
Pod documented
292 128 my ($job_queue, $job, $do_startmore, @exit_code) = @_;
293 128 ▶ if ($job->{dependency_graph}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job->{"dependency_graph"}) 68 60 128
294 68 ▶ if ($exit_code[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exit_code[0]) { } 0 68 68
295 0 print STDERR "Things dependent on $job->{desc} will never run: @exit_code\n";
296 0 $job->{dependency_graph}->stuck_dependency($job, "exit @exit_code");
297 } else {
298 68 $job->{dependency_graph}->remove_dependency($job);
299 }
300 68 $job->{dependency_graph} = undef;
301 # unlock_keys(%$job);
302 # $job->{this_is_finished} = 1;
303 # lock_keys(%$job);
304 }
305 128 $job_queue->job_part_finished($job, $do_startmore, @exit_code);
306 }
307  
308 sub job_part_finished
309 134 ▶{
Subroutine job_part_finished: called CC=6 SCAR=19.0
Pod documented
310 134 my ($job_queue, $job, $do_startmore, @exit_code) = @_;
311 134 ▶ $do_startmore = 1 unless defined $do_startmore;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $do_startmore 0 134 134
312  
313 134 my $host = $job->host;
314 134 my $jobnum = $job->jobnum;
315  
316 134 ▶ print STDERR "# job $jobnum $job->{desc} on $host is done\n" if $debug > 5;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 5 0 134 134
317  
318 134 ▶ my $hr = $job_queue->{status}{$host} or confess;
Branch: 1 branch
BranchTrueFalseTotal
my $hr = $job_queue->{"status"}{$host} or confess() 134 0 134
319 134 ▶ delete $hr->{running}{$jobnum} or confess;
Branch: 1 branch
BranchTrueFalseTotal
delete $hr->{"running"}{$jobnum} or confess() 134 0 134
320  
321 134 $job_queue->set_readiness($host);
322  
323 134 ▶ $job_queue->startmore() if $do_startmore;
Branch: 1 branch
BranchTrueFalseTotal
if $do_startmore 0 134 134
324 }
325  
326 sub alldone
327 65 ▶{
Subroutine alldone: called CC=9 SCAR=22.4
Pod documented
328 65 my ($queue, $skip_status) = @_;
329 65 ▶ $queue->status() if $debug && ! $skip_status;
Branch: 1 branch
BranchTrueFalseTotal
if $debug and not $skip_status 0 65 65
Condition33%1/3
$debug and not $skip_status
!ll&&!rl&&r
6500
MC/DC0%0/2
$debug and not $skip_status
$debug not $skip_status
Truth table33%1/3
A and not(B)
A= $debugB= not $skip_status
ABresult
0X0
100
111
330 65 ▶ return 0 if keys %{$queue->{queue}};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$queue{"queue"};} 4 61 65
331 61 for my $host (keys %{$queue->{status}}) {
332 61 my $hr = $queue->{status}{$host};
333 61 ▶ return 0 unless $queue->{ready_hosts}{$host};
Branch: 1 branch
BranchTrueFalseTotal
unless $queue->{"ready_hosts"}{$host} 1 60 61
334 60 ▶ return 0 if keys %{$hr->{queue}};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$hr{"queue"};} 0 60 60
335 60 ▶ return 0 if keys %{$hr->{running}};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$hr{"running"};} 56 4 60
336 4 ▶ next unless $hr->{jobs_per_host} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $hr->{"jobs_per_host"} > 0 0 4 4
337 }
338 4 return 1;
339 }
340  
341 3 my $last_dump = time;
342  
343 sub status
344 0 ▶{
Subroutine status: not called CC=7 SCAR=40.3
Pod documented
345 0 my ($queue) = @_;
346 0 ▶ return if time < $last_dump + $status_frequency;
Branch: 1 branch
BranchTrueFalseTotal
if &Proc::JobQueue::time() < $last_dump + $Proc::JobQueue::status_frequency 0 0 0
347 0 $last_dump = time;
348 0 print STDERR "Queue Status\n";
349 0 printf STDERR "\titems in main queue: %d, alldone=%d\n", scalar(keys %{$queue->{queue}}), $queue->alldone(1);
350 0 ▶ print STDERR "\tHost overload condition is true\n" if $queue->{host_is_over};
Branch: 1 branch
BranchTrueFalseTotal
if $queue->{"host_is_over"} 0 0 0
351 0 for my $host (sort keys %{$queue->{status}}) {
352 0 my $hr = $queue->{status}{$host};
353 printf STDERR "\titems in queue for %s: %d, items running: %s, host is %sready\n",
354 $host,
355 0 scalar(keys(%{$hr->{queue}})),
356 0 ▶ scalar(keys(%{$hr->{running}})),
Branch: 1 branch
BranchTrueFalseTotal
$queue->{'ready_hosts'}{$host} ? : 0 0 0
357 0 ($queue->{ready_hosts}{$host} ? "" : "not ");
358 0 for my $job (values %{$hr->{running}}) {
359 0 print STDERR "\t\tRunning: $job->{jobnum} $job->{desc}\n";
360 }
361 }
362 0 my $dg = $queue->{dependency_graph};
363 printf "Dependency Graph items: %d independent (%d locked %d active), %d total, alldone=%s\n",
364 0 scalar(keys(%{$dg->{independent}})),
365 0 scalar(grep { $_->{dg_lock} } values %{$dg->{independent}}),
366 0 scalar(grep { $_->{dg_active} } values %{$dg->{independent}}),
367 0 ▶ scalar(keys(%{$dg->{addrmap}})),
Branch: 1 branch
BranchTrueFalseTotal
if $dg 0 0 0
368 $dg->alldone
369 if $dg;
370 }
371  
372 3 my $canonicalizer;
373 sub get_canonicalizer
374 163 ▶{
Subroutine get_canonicalizer: called CC=2 SCAR=6.9
Pod undocumented
375 163 ▶ return $canonicalizer if $canonicalizer;
Branch: 1 branch
BranchTrueFalseTotal
if $canonicalizer 160 3 163
376 3 load($host_canonicalizer);
377 3 $canonicalizer = $host_canonicalizer->new();
378 }
379  
380 sub canonicalize
381 160 ▶{
Subroutine canonicalize: called CC=1 SCAR=0.0
Pod undocumented
382 160 my ($host) = @_;
383 160 return get_canonicalizer()->canonicalize($host);
384 }
385  
386 my $my_hostname;
387 sub my_hostname
388 203 ▶{
Subroutine my_hostname: called CC=2 SCAR=6.9
Pod undocumented
389 203 ▶ return $my_hostname if $my_hostname;
Branch: 1 branch
BranchTrueFalseTotal
if $my_hostname 200 3 203
390 3 $my_hostname = get_canonicalizer()->myname();
391 }
392  
393 sub is_remote_host
394 160 ▶{
Subroutine is_remote_host: called CC=1 SCAR=0.0
Pod undocumented
395 160 my ($host) = @_;
396 160 return my_hostname() ne canonicalize($host);
397 }
398  
399 sub graph
400 7 ▶{
Subroutine graph: called CC=4 SCAR=16.4
Pod undocumented
401 7 my $queue = shift;
402 7 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 0 7 7
elsif (not $queue->{'dependency_graph'}) { } 1 6 7
403 0 ▶ die "a dependency graph was already set" if $queue->{dependency_graph};
Branch: 1 branch
BranchTrueFalseTotal
if $queue->{"dependency_graph"} 0 0 0
404 0 $queue->{dependency_graph} = shift;
405 } elsif (! $queue->{dependency_graph}) {
406 1 $queue->{dependency_graph} = Object::Dependency->new();
407 }
408 7 return $queue->{dependency_graph};
409 }
410  
411  
412 3 1;
413  
414 __END__
↑ Summary JobQueue/Job.pm »