| 1 | package AnyEvent::ProcessPool::Util; | ||||||||||||
| 2 | # ABSTRACT: A multi-process pool for Perl | ||||||||||||
| 3 | 3 | $AnyEvent::ProcessPool::Util::VERSION = '0.06'; | |||||||||||
| 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 | 3 | ▶ | use v5.10; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 3 | ▶ | use parent 'Exporter'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 3 | ▶ | use Data::UUID::MT; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 3 | our @EXPORT_OK = qw( | |||||||||||
| 12 | next_id | ||||||||||||
| 13 | cpu_count | ||||||||||||
| 14 | ); | ||||||||||||
| 15 | |||||||||||||
| 16 | sub next_id { | ||||||||||||
| 17 | 71 | ▶ | state $ug = Data::UUID::MT->new(version => 4); | ||||||||||
|
Subroutine
next_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 18 | 71 | $ug->create_hex; | |||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | #------------------------------------------------------------------------------- | ||||||||||||
| 22 | # "Borrowed" from Test::Smoke::Util::get_ncpus. | ||||||||||||
| 23 | # | ||||||||||||
| 24 | # Modifications: | ||||||||||||
| 25 | # * Use $^O in place of an input argument | ||||||||||||
| 26 | # * Return number instead of string | ||||||||||||
| 27 | #------------------------------------------------------------------------------- | ||||||||||||
| 28 | sub cpu_count { | ||||||||||||
| 29 | # Only *nixy osses need this, so use ':' | ||||||||||||
| 30 | 3 | ▶ | local $ENV{PATH} = "$ENV{PATH}:/usr/sbin:/sbin"; | ||||||||||
|
Subroutine
cpu_count: called CC=14 SCAR=41.7
Pod
undocumented
| |||||||||||||
| 31 | |||||||||||||
| 32 | 3 | my $cpus = "?"; | |||||||||||
| 33 | OS_CHECK: { | ||||||||||||
| 34 | 3 | local $_ = $^O; | |||||||||||
| 35 | |||||||||||||
| 36 | 3 | ▶ | /aix/i && do { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 0 | my @output = `lsdev -C -c processor -S Available`; | |||||||||||
| 38 | 0 | $cpus = scalar @output; | |||||||||||
| 39 | 0 | last OS_CHECK; | |||||||||||
| 40 | }; | ||||||||||||
| 41 | |||||||||||||
| 42 | 3 | ▶ | /(?:darwin|.*bsd)/i && do { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 0 | chomp( my @output = `sysctl -n hw.ncpu` ); | |||||||||||
| 44 | 0 | $cpus = $output[0]; | |||||||||||
| 45 | 0 | last OS_CHECK; | |||||||||||
| 46 | }; | ||||||||||||
| 47 | |||||||||||||
| 48 | 3 | ▶ | /hp-?ux/i && do { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | 0 | my @output = grep /^processor/ => `ioscan -fnkC processor`; | |||||||||||
| 50 | 0 | $cpus = scalar @output; | |||||||||||
| 51 | 0 | last OS_CHECK; | |||||||||||
| 52 | }; | ||||||||||||
| 53 | |||||||||||||
| 54 | 3 | ▶ | /irix/i && do { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | 0 | my @output = grep /\s+processors?$/i => `hinv -c processor`; | |||||||||||
| 56 | 0 | $cpus = (split " ", $output[0])[0]; | |||||||||||
| 57 | 0 | last OS_CHECK; | |||||||||||
| 58 | }; | ||||||||||||
| 59 | |||||||||||||
| 60 | 3 | ▶ | /linux/i && do { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | 3 | my @output; local *PROC; | |||||||||||
| 62 | 3 | ▶ | if ( open PROC, "< /proc/cpuinfo" ) { ## no critic | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | 3 | @output = grep /^processor/ => <PROC>; | |||||||||||
| 64 | 3 | close PROC; | |||||||||||
| 65 | } | ||||||||||||
| 66 | 3 | ▶ | $cpus = @output ? scalar @output : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 3 | last OS_CHECK; | |||||||||||
| 68 | }; | ||||||||||||
| 69 | |||||||||||||
| 70 | 0 | ▶ | /solaris|sunos|osf/i && do { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 71 | 0 | my @output = grep /on-line/ => `psrinfo`; | |||||||||||
| 72 | 0 | $cpus = scalar @output; | |||||||||||
| 73 | 0 | last OS_CHECK; | |||||||||||
| 74 | }; | ||||||||||||
| 75 | |||||||||||||
| 76 | 0 | ▶ | /mswin32|cygwin/i && do { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | $cpus = exists $ENV{NUMBER_OF_PROCESSORS} | ||||||||||||
| 78 | 0 | ▶ | ? $ENV{NUMBER_OF_PROCESSORS} : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | 0 | last OS_CHECK; | |||||||||||
| 80 | }; | ||||||||||||
| 81 | |||||||||||||
| 82 | 0 | ▶ | /vms/i && do { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | 0 | my @output = grep /CPU \d+ is in RUN state/ => `show cpu/active`; | |||||||||||
| 84 | 0 | ▶ | $cpus = @output ? scalar @output : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | 0 | last OS_CHECK; | |||||||||||
| 86 | }; | ||||||||||||
| 87 | |||||||||||||
| 88 | 0 | $cpus = ""; | |||||||||||
| 89 | 0 | require Carp; | |||||||||||
| 90 | 0 | Carp::carp( "get_ncpu: unknown operationg system" ); | |||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | 3 | ▶ | return sprintf '%d', ($cpus || 1); | ||||||||||
|
Condition50%1/2
$cpus || 1
MC/DC0%0/1
$cpus || 1
$cpus
Truth table50%1/2
A
A= $cpus
| |||||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | 3 | 1; | |||||||||||
| 97 | |||||||||||||
| 98 | __END__ | ||||||||||||