| 1 | package FCGI::Engine::ProcManager::Constrained; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Class::Load (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | extends 'FCGI::Engine::ProcManager'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | if ($self->sizecheck_num_requests && ! _can_check_size()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->sizecheck_num_requests and not &_can_check_size()
MC/DC0%0/2
$self->sizecheck_num_requests and not &_can_check_size()
$self->sizecheck_num_requests
not &_can_check_size()
Truth table0%0/3
A and not(B)
A= $self->sizecheck_num_requestsB= not &_can_check_size()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | confess "Cannot load size check modules for your platform: sizecheck_num_requests > 0 unsupported"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | has max_requests => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | is => 'ro', # FIXME - This is fuck ugly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | default => sub { $ENV{PM_MAX_REQUESTS} || 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | has request_count => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | traits => ['Counter'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | _reset_request_counter => 'reset', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | _inc_request_counter => 'inc', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | has [qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | sizecheck_num_requests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | max_process_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | min_share_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | max_unshared_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | /] => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | augment server_init => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $self->_reset_request_counter(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | augment post_dispatch => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $self->exit("safe exit after max_requests (" . $self->max_requests . ")") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->max_requests and $self->_inc_request_counter == $self->max_requests
MC/DC0%0/2
$self->max_requests and $self->_inc_request_counter == $self->max_requests
$self->max_requests
$self->_inc_request_counter == $self->max_requests
Truth table0%0/3
A and B
A= $self->max_requestsB= $self->_inc_request_counter == $self->max_requests
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | if ($self->max_requests and $self->_inc_request_counter == $self->max_requests); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ($self->sizecheck_num_requests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->sizecheck_num_requests and $self->request_count and $self->request_count % $self->sizecheck_num_requests == 0
$self->sizecheck_num_requests and $self->request_count
MC/DC0%0/3
$self->sizecheck_num_requests and $self->request_count and $self->request_count % $self->sizecheck_num_requests == 0
$self->sizecheck_num_requests
$self->request_count
$self->request_count % $self->sizecheck_num_requests == 0
Truth table0%0/4
A and B and C
A= $self->sizecheck_num_requestsB= $self->request_countC= $self->request_count % $self->sizecheck_num_requests == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | and $self->request_count # Not the first request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | and $self->request_count % $self->sizecheck_num_requests == 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $self->exit("safe exit due to memory limits exceeded after " . $self->request_count . " requests") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | if $self->_limits_are_exceeded; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub _limits_are_exceeded { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_limits_are_exceeded: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my ($size, $share, $unshared) = $self->_check_size(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | return 1 if $self->max_process_size && $size > $self->max_process_size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->max_process_size and $size > $self->max_process_size
MC/DC0%0/2
$self->max_process_size and $size > $self->max_process_size
$self->max_process_size
$size > $self->max_process_size
Truth table0%0/3
A and B
A= $self->max_process_sizeB= $size > $self->max_process_size
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | return 0 unless $share; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return 1 if $self->min_share_size && $share < $self->min_share_size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->min_share_size and $share < $self->min_share_size
MC/DC0%0/2
$self->min_share_size and $share < $self->min_share_size
$self->min_share_size
$share < $self->min_share_size
Truth table0%0/3
A and B
A= $self->min_share_sizeB= $share < $self->min_share_size
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return 1 if $self->max_unshared_size && $unshared > $self->max_unshared_size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->max_unshared_size and $unshared > $self->max_unshared_size
MC/DC0%0/2
$self->max_unshared_size and $unshared > $self->max_unshared_size
$self->max_unshared_size
$unshared > $self->max_unshared_size
Truth table0%0/3
A and B
A= $self->max_unshared_sizeB= $unshared > $self->max_unshared_size
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # The following code is wholesale is nicked from Apache::SizeLimit::Core | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub _check_size { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_size: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my ($size, $share) = $class->_platform_check_size(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | return ($size, $share, $size - $share); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | sub _load { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | my $mod = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | try { Class::Load::load_class($mod); 1; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | our $USE_SMAPS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=11 SCAR=42.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | my ($major,$minor) = split(/\./, $Config{'osvers'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | if ($Config{'osname'} eq 'solaris' && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition11%1/9
$FCGI::Engine::ProcManager::Constrained::Config{"osname"} eq "solaris" and $major > 2 || $major == 2 && $minor >= 6
$major > 2 or $major == 2 and $minor >= 6
$major == 2 and $minor >= 6
MC/DC0%0/4
$FCGI::Engine::ProcManager::Constrained::Config{"osname"} eq "solaris" and $major > 2 || $major == 2 && $minor >= 6
$FCGI::Engine::ProcManager::Constrained::Config{"osname"} eq "solaris"
$major > 2
$major == 2
$minor >= 6
Truth table20%1/5
A and B or C and D
A= $FCGI::Engine::ProcManager::Constrained::Config{"osname"} eq "solaris"B= $major > 2C= $major == 2D= $minor >= 6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | (($major > 2) || ($major == 2 && $minor >= 6))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | *_can_check_size = sub () { 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | *_platform_check_size = \&_solaris_2_6_size_check; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | *_platform_getppid = \&_perl_getppid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ▶ | elsif ($Config{'osname'} eq 'linux' && _load('Linux::Pid')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$FCGI::Engine::ProcManager::Constrained::Config{"osname"} eq "linux" and _load("Linux::Pid")
MC/DC0%0/2
$FCGI::Engine::ProcManager::Constrained::Config{"osname"} eq "linux" and _load("Linux::Pid")
$FCGI::Engine::ProcManager::Constrained::Config{"osname"} eq "linux"
_load("Linux::Pid")
Truth table33%1/3
A and B
A= $FCGI::Engine::ProcManager::Constrained::Config{"osname"} eq "linux"B= _load("Linux::Pid")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | *_platform_getppid = \&_linux_getppid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | *_can_check_size = sub () { 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if (_load('Linux::Smaps') && Linux::Smaps->new($$)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
_load("Linux::Smaps") and "Linux::Smaps"->new($$)
MC/DC0%0/2
_load("Linux::Smaps") and "Linux::Smaps"->new($$)
_load("Linux::Smaps")
"Linux::Smaps"->new($$)
Truth table0%0/3
A and B
A= _load("Linux::Smaps")B= "Linux::Smaps"->new($$)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $USE_SMAPS = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | *_platform_check_size = \&_linux_smaps_size_check; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $USE_SMAPS = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | *_platform_check_size = \&_linux_size_check; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ▶ | elsif ($Config{'osname'} =~ /(?:bsd|aix)/i && _load('BSD::Resource')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$FCGI::Engine::ProcManager::Constrained::Config{"osname"} =~ /(?:bsd|aix)/i and _load("BSD::Resource")
MC/DC0%0/2
$FCGI::Engine::ProcManager::Constrained::Config{"osname"} =~ /(?:bsd|aix)/i and _load("BSD::Resource")
$FCGI::Engine::ProcManager::Constrained::Config{"osname"} =~ /(?:bsd|aix)/i
_load("BSD::Resource")
Truth table33%1/3
A and B
A= $FCGI::Engine::ProcManager::Constrained::Config{"osname"} =~ /(?:bsd|aix)/iB= _load("BSD::Resource")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # on OSX, getrusage() is returning 0 for proc & shared size. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | *_can_check_size = sub () { 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | *_platform_check_size = \&_bsd_size_check; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | *_platform_getppid = \&_perl_getppid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | *_can_check_size = sub () { 0 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub _linux_smaps_size_check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_linux_smaps_size_check: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return $class->_linux_size_check() unless $USE_SMAPS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $s = Linux::Smaps->new($$)->all; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | return ($s->size, $s->shared_clean + $s->shared_dirty); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub _linux_size_check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_linux_size_check: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my ($size, $share) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if (open my $fh, '<', '/proc/self/statm') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ($size, $share) = (split /\s/, scalar <$fh>)[0,2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $class->_error_log("Fatal Error: couldn't access /proc/self/status"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # linux on intel x86 has 4KB page size... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | return ($size * 4, $share * 4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub _solaris_2_6_size_check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_solaris_2_6_size_check: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my $size = -s "/proc/self/as" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | or $class->_error_log("Fatal Error: /proc/self/as doesn't exist or is empty"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $size = int($size / 1024); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # return 0 for share, to avoid undef warnings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | return ($size, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # rss is in KB but ixrss is in BYTES. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # This is true on at least FreeBSD, OpenBSD, & NetBSD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub _bsd_size_check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bsd_size_check: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my @results = BSD::Resource::getrusage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $max_rss = $results[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $max_ixrss = int ( $results[3] / 1024 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | return ($max_rss, $max_ixrss); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub _win32_size_check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_win32_size_check: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # get handle on current process | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $get_current_process = Win32::API->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 'kernel32', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 'get_current_process', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 'I' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my $proc = $get_current_process->Call(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # memory usage is bundled up in ProcessMemoryCounters structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # populated by GetProcessMemoryInfo() win32 call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $DWORD = 'B32'; # 32 bits | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $SIZE_T = 'I'; # unsigned integer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # build a buffer structure to populate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my $pmem_struct = "$DWORD" x 2 . "$SIZE_T" x 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $mem_counters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | = pack( $pmem_struct, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # GetProcessMemoryInfo is in "psapi.dll" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $get_process_memory_info = new Win32::API( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 'psapi', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 'GetProcessMemoryInfo', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | [ 'I', 'P', 'I' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 'I' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $bool = $get_process_memory_info->Call( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | $proc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | $mem_counters, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | length $mem_counters, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # unpack ProcessMemoryCounters structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my $peak_working_set_size = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | (unpack($pmem_struct, $mem_counters))[2]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # only care about peak working set size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $size = int($peak_working_set_size / 1024); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | return ($size, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub _perl_getppid { return getppid } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_perl_getppid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | sub _linux_getppid { return Linux::Pid::getppid() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_linux_getppid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||