line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::OS::Detect::MachineCores; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
2
|
|
|
2
|
|
92095
|
$App::OS::Detect::MachineCores::AUTHORITY = 'cpan:DBR'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
$App::OS::Detect::MachineCores::VERSION = '1.1.2'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# PODNAME: App::OS::Detect::MachineCores |
10
|
|
|
|
|
|
|
# ABSTRACT: Detect how many cores your machine has (OS-independently) |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
2004
|
use true; |
|
2
|
|
|
|
|
29711
|
|
|
2
|
|
|
|
|
16
|
|
13
|
2
|
|
|
2
|
|
2255
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
182
|
|
14
|
2
|
|
|
2
|
|
52
|
use 5.010; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
80
|
|
15
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
73
|
|
16
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
80
|
|
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
2280
|
use Moo; |
|
2
|
|
|
|
|
97065
|
|
|
2
|
|
|
|
|
19
|
|
19
|
2
|
|
|
2
|
|
8656
|
use MooX::Options skip_options => [qw]; |
|
2
|
|
|
|
|
3521
|
|
|
2
|
|
|
|
|
172
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has os => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
required => 1, |
24
|
|
|
|
|
|
|
default => sub { $^O }, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has cores => ( |
28
|
|
|
|
|
|
|
is => 'rw', |
29
|
|
|
|
|
|
|
isa => sub { die "$_[0] is not a reasonable number of cores!" unless $_[0] > 0 and $_[0] < 100 }, |
30
|
|
|
|
|
|
|
lazy => 1, |
31
|
|
|
|
|
|
|
builder => '_build_cores', |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
option add_one => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
isa => sub { die "Invalid bool!" unless $_[0] == 0 or $_[0] == 1 }, |
37
|
|
|
|
|
|
|
default => sub { '0' }, |
38
|
|
|
|
|
|
|
short => 'i', |
39
|
|
|
|
|
|
|
doc => q{add one to the number of cores (useful in scripts)}, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _build_cores { |
43
|
2
|
50
|
|
2
|
|
86
|
if ($_[0]->os =~ 'darwin') { $_ = `sysctl hw.ncpu | awk '{print \$2}'`; chomp; $_ } |
|
0
|
50
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
44
|
2
|
|
|
|
|
38710
|
elsif ($_[0]->os =~ 'linux') { $_ = `grep processor < /proc/cpuinfo | wc -l`; chomp; $_ } |
|
2
|
|
|
|
|
49
|
|
|
2
|
|
|
|
|
421
|
|
45
|
0
|
|
|
|
|
|
else { carp "Can't detect the cores for your system/OS, sorry." } |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
around cores => sub { |
49
|
|
|
|
|
|
|
my ($orig, $self) = (shift, shift); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return $self->$orig() + 1 if $self->add_one; |
52
|
|
|
|
|
|
|
return $self->$orig(); |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
2
|
|
824601
|
no Moo; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
14
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |