Prefork/SpareWorkers.pm

filter: Statementstmt 92.9% 53 / 57 Branchbran 80.0% 8 / 10 Conditioncond 53.8% 7 / 13 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 92.8% 13 / 14 Podpod 75.0% 3 / 4 totaltotal 81.1% 86 / 106 SCAR 24.3
CC
11
Cov
85%
new
7.3
_decide_action
4.0
start
2.2
CRAP 11.4
« Prefork.pm ↑ Summary
1 package Parallel::Prefork::SpareWorkers;
2  
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 Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use List::MoreUtils qw(uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw/Parallel::Prefork/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use constant STATUS_NEXIST => '.';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use constant STATUS_IDLE => '_';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 our %EXPORT_TAGS = (
16 status => [ qw(STATUS_NEXIST STATUS_IDLE) ],
17 );
18 1 our @EXPORT_OK = uniq sort map { @$_ } values %EXPORT_TAGS;
19 1 $EXPORT_TAGS{all} = \@EXPORT_OK;
20  
21 1 __PACKAGE__->mk_accessors(qw/min_spare_workers max_spare_workers scoreboard heartbeat/);
22  
23 sub new {
24 1 ▶ my $klass = shift;
Subroutine new: called CC=6 SCAR=19.9
Pod documented
25 1 my $self = $klass->SUPER::new(@_);
26 die "mandatory option min_spare_workers not set"
27 1 ▶ unless $self->{min_spare_workers};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"min_spare_workers"} 0 1 1
28 1 ▶ $self->{max_spare_workers} ||= $self->max_workers;
Condition33%1/3
$self->{"max_spare_workers"} ||= $self->max_workers
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->{"max_spare_workers"} ||= $self->max_workers
$self->{"max_spare_workers"} $self->max_workers
Truth table33%1/3
A ||= B
A= $self->{"max_spare_workers"}B= $self->max_workers
ABresult
1X1
011
000
29 1 ▶ $self->{heartbeat} ||= 0.25;
Condition50%1/2
$self->{"heartbeat"} ||= "0.25"
l!l
01
MC/DC0%0/1
$self->{"heartbeat"} ||= "0.25"
$self->{"heartbeat"}
Truth table50%1/2
A
A= $self->{"heartbeat"}
Aresult
11
00
30 1 ▶ $self->{scoreboard} ||= do {
Condition33%1/3
$self->{"scoreboard"} ||= do { require "Parallel/Prefork/SpareWorkers/Scoreboard.pm"; "Parallel::Prefork::SpareWorkers::Scoreboard"->new($self->{"scoreboard_file"} || undef, $self->max_workers) }
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"scoreboard"} ||= do { require "Parallel/Prefork/SpareWorkers/Scoreboard.pm"; "Parallel::Prefork::SpareWorkers::Scoreboard"->new($self->{"scoreboard_file"} || undef, $self->max_workers) }
$self->{"scoreboard"} do { require "Parallel/Prefork/SpareWorkers/Scoreboard.pm"; "Parallel::Prefork::SpareWorkers::Scoreboard"->new($self->{"scoreboard_file"} || undef, $self->max_workers) }
Truth table33%1/3
A ||= B
A= $self->{"scoreboard"}B= do { require "Parallel/Prefork/SpareWorkers/Scoreboard.pm"; "Parallel::Prefork::SpareWorkers::Scoreboard"->new($self->{"scoreboard_file"} || undef, $self->max_workers) }
ABresult
1X1
011
000
31 1 require 'Parallel/Prefork/SpareWorkers/Scoreboard.pm';
32 Parallel::Prefork::SpareWorkers::Scoreboard->new(
33 $self->{scoreboard_file} || undef,
34 1 ▶ $self->max_workers,
Condition50%1/2
$self->{'scoreboard_file'} || undef
l!l
01
MC/DC0%0/1
$self->{'scoreboard_file'} || undef
$self->{'scoreboard_file'}
Truth table50%1/2
A
A= $self->{'scoreboard_file'}
Aresult
11
00
35 );
36 };
37 1 $self;
38 }
39  
40 sub start {
41 1 ▶ my $self = shift;
Subroutine start: called CC=2 SCAR=7.9
Pod documented
42 1 my $ret = $self->SUPER::start();
43 1 ▶ unless ($ret) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret) 0 1 1
44 # child process
45 0 $self->scoreboard->child_start();
46 0 return;
47 }
48 1 return 1;
49 }
50  
51 sub num_active_workers {
52 99 ▶ my $self = shift;
Subroutine num_active_workers: called CC=2 SCAR=6.9
Pod undocumented
53 scalar grep {
54 99 ▶ $_ ne STATUS_NEXIST && $_ ne STATUS_IDLE
Branch: 1 branch
BranchTrueFalseTotal
$_ ne "." and $_ ne "_" 577 413 990
55 } $self->scoreboard->get_statuses;
56 }
57  
58 sub set_status {
59 0 ▶ my ($self, $status) = @_;
Subroutine set_status: not called CC=1 SCAR=6.9
Pod documented
60 0 $self->scoreboard->set_status($status);
61 }
62  
63 sub _decide_action {
64 95 ▶ my $self = shift;
Subroutine _decide_action: called CC=4 SCAR=13.9
65 95 my $spare_workers = $self->num_workers - $self->num_active_workers;
66 95 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if $spare_workers < $self->min_spare_workers and $self->num_workers < $self->max_workers 12 83 95
Condition100%3/3
$spare_workers < $self->min_spare_workers and $self->num_workers < $self->max_workers
!ll&&!rl&&r
572612
MC/DC100%2/2
$spare_workers < $self->min_spare_workers and $self->num_workers < $self->max_workers
$spare_workers < $self->min_spare_workers $self->num_workers < $self->max_workers
Truth table100%3/3
A and B
A= $spare_workers < $self->min_spare_workersB= $self->num_workers < $self->max_workers
ABresult
0X0
100
111
67 if $spare_workers < $self->min_spare_workers
68 && $self->num_workers < $self->max_workers;
69 83 ▶ return -1
Branch: 1 branch
BranchTrueFalseTotal
if $spare_workers > $self->max_spare_workers 10 73 83
70 if $spare_workers > $self->max_spare_workers;
71 73 return 0;
72 }
73  
74 sub _on_child_reap {
75 10 ▶ my ($self, $exit_pid, $status) = @_;
Subroutine _on_child_reap: called CC=1 SCAR=0.0
76 10 $self->SUPER::_on_child_reap($exit_pid, $status);
77 10 $self->scoreboard->clear_child($exit_pid);
78 }
79  
80 sub _max_wait {
81 45 ▶ my $self = shift;
Subroutine _max_wait: called CC=1 SCAR=0.0
82 45 return $self->{heartbeat};
83 }
84  
85 1 1;
86 __END__
« Prefork.pm ↑ Summary