line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::ProcessPool::Util; |
2
|
|
|
|
|
|
|
# ABSTRACT: A multi-process pool for Perl |
3
|
|
|
|
|
|
|
$AnyEvent::ProcessPool::Util::VERSION = '0.07'; |
4
|
3
|
|
|
3
|
|
31
|
use v5.10; |
|
3
|
|
|
|
|
9
|
|
5
|
3
|
|
|
3
|
|
13
|
use common::sense; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
23
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
189
|
use parent 'Exporter'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
32
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1369
|
use Data::UUID::MT; |
|
3
|
|
|
|
|
166671
|
|
|
3
|
|
|
|
|
1940
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
12
|
|
|
|
|
|
|
next_id |
13
|
|
|
|
|
|
|
cpu_count |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub next_id { |
17
|
80
|
|
|
80
|
0
|
181
|
state $ug = Data::UUID::MT->new(version => 4); |
18
|
80
|
|
|
|
|
11245
|
$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
|
|
|
3
|
0
|
30
|
local $ENV{PATH} = "$ENV{PATH}:/usr/sbin:/sbin"; |
31
|
|
|
|
|
|
|
|
32
|
3
|
|
|
|
|
10
|
my $cpus = "?"; |
33
|
|
|
|
|
|
|
OS_CHECK: { |
34
|
3
|
|
|
|
|
7
|
local $_ = $^O; |
|
3
|
|
|
|
|
10
|
|
35
|
|
|
|
|
|
|
|
36
|
3
|
50
|
|
|
|
18
|
/aix/i && do { |
37
|
0
|
|
|
|
|
0
|
my @output = `lsdev -C -c processor -S Available`; |
38
|
0
|
|
|
|
|
0
|
$cpus = scalar @output; |
39
|
0
|
|
|
|
|
0
|
last OS_CHECK; |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
3
|
50
|
|
|
|
21
|
/(?:darwin|.*bsd)/i && do { |
43
|
0
|
|
|
|
|
0
|
chomp( my @output = `sysctl -n hw.ncpu` ); |
44
|
0
|
|
|
|
|
0
|
$cpus = $output[0]; |
45
|
0
|
|
|
|
|
0
|
last OS_CHECK; |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
3
|
50
|
|
|
|
11
|
/hp-?ux/i && do { |
49
|
0
|
|
|
|
|
0
|
my @output = grep /^processor/ => `ioscan -fnkC processor`; |
50
|
0
|
|
|
|
|
0
|
$cpus = scalar @output; |
51
|
0
|
|
|
|
|
0
|
last OS_CHECK; |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
3
|
50
|
|
|
|
14
|
/irix/i && do { |
55
|
0
|
|
|
|
|
0
|
my @output = grep /\s+processors?$/i => `hinv -c processor`; |
56
|
0
|
|
|
|
|
0
|
$cpus = (split " ", $output[0])[0]; |
57
|
0
|
|
|
|
|
0
|
last OS_CHECK; |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
3
|
50
|
|
|
|
26
|
/linux|android/i && do { |
61
|
3
|
|
|
|
|
10
|
my @output; local *PROC; |
|
3
|
|
|
|
|
9
|
|
62
|
3
|
50
|
|
|
|
129
|
if ( open PROC, "< /proc/cpuinfo" ) { ## no critic |
63
|
3
|
|
|
|
|
1174
|
@output = grep /^processor/ => ; |
64
|
3
|
|
|
|
|
82
|
close PROC; |
65
|
|
|
|
|
|
|
} |
66
|
3
|
50
|
|
|
|
16
|
$cpus = @output ? scalar @output : ''; |
67
|
3
|
|
|
|
|
30
|
last OS_CHECK; |
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
0
|
/solaris|sunos|osf/i && do { |
71
|
0
|
|
|
|
|
0
|
my @output = grep /on-line/ => `psrinfo`; |
72
|
0
|
|
|
|
|
0
|
$cpus = scalar @output; |
73
|
0
|
|
|
|
|
0
|
last OS_CHECK; |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
0
|
/mswin32|cygwin/i && do { |
77
|
|
|
|
|
|
|
$cpus = exists $ENV{NUMBER_OF_PROCESSORS} |
78
|
0
|
0
|
|
|
|
0
|
? $ENV{NUMBER_OF_PROCESSORS} : ''; |
79
|
0
|
|
|
|
|
0
|
last OS_CHECK; |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
0
|
/vms/i && do { |
83
|
0
|
|
|
|
|
0
|
my @output = grep /CPU \d+ is in RUN state/ => `show cpu/active`; |
84
|
0
|
0
|
|
|
|
0
|
$cpus = @output ? scalar @output : ''; |
85
|
0
|
|
|
|
|
0
|
last OS_CHECK; |
86
|
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
$cpus = ""; |
89
|
0
|
|
|
|
|
0
|
require Carp; |
90
|
0
|
|
|
|
|
0
|
Carp::carp('cpu_count: unknown operating system'); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
3
|
|
50
|
|
|
60
|
return sprintf '%d', ($cpus || 1); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |