| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::OS::Detect::MachineCores; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
1
|
|
|
1
|
|
22207
|
$App::OS::Detect::MachineCores::AUTHORITY = 'cpan:DBR'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
{ |
|
6
|
|
|
|
|
|
|
$App::OS::Detect::MachineCores::VERSION = '0.012'; # TRIAL |
|
7
|
|
|
|
|
|
|
} |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# PODNAME: App::OS::Detect::MachineCores |
|
10
|
|
|
|
|
|
|
# ABSTRACT: Detect how many cores your machine has (OS-independently) |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
371
|
use Any::Moose; |
|
|
1
|
|
|
|
|
20467
|
|
|
|
1
|
|
|
|
|
4
|
|
|
13
|
1
|
|
|
1
|
|
368
|
use 5.010; |
|
|
1
|
|
|
|
|
2
|
|
|
14
|
1
|
|
|
1
|
|
407
|
use true; |
|
|
1
|
|
|
|
|
5329
|
|
|
|
1
|
|
|
|
|
3
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
do { |
|
17
|
|
|
|
|
|
|
with 'MooseX::Getopt'; |
|
18
|
|
|
|
|
|
|
with 'MooseX::Getopt::Dashes'; |
|
19
|
|
|
|
|
|
|
with 'MooseX::Traits'; |
|
20
|
|
|
|
|
|
|
} if Any::Moose::_is_moose_loaded(); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
do { |
|
23
|
|
|
|
|
|
|
with 'MouseX::Getopt'; |
|
24
|
|
|
|
|
|
|
with 'MouseX::Getopt::Dashes'; |
|
25
|
|
|
|
|
|
|
with 'MouseX::Traits'; |
|
26
|
|
|
|
|
|
|
} unless Any::Moose::_is_moose_loaded(); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has cores => ( |
|
30
|
|
|
|
|
|
|
is => 'ro', |
|
31
|
|
|
|
|
|
|
isa => 'Int', |
|
32
|
|
|
|
|
|
|
traits => [ 'NoGetopt' ], |
|
33
|
|
|
|
|
|
|
lazy_build => 1, |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
has os => ( |
|
36
|
|
|
|
|
|
|
is => 'ro', |
|
37
|
|
|
|
|
|
|
isa => 'Str', |
|
38
|
|
|
|
|
|
|
traits => ['NoGetopt'], |
|
39
|
|
|
|
|
|
|
lazy_build => 1, |
|
40
|
|
|
|
|
|
|
); |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has add_one => ( |
|
43
|
|
|
|
|
|
|
is => 'ro', |
|
44
|
|
|
|
|
|
|
isa => 'Bool', |
|
45
|
|
|
|
|
|
|
default => 0, |
|
46
|
|
|
|
|
|
|
traits => [ 'Getopt', 'Bool' ], |
|
47
|
|
|
|
|
|
|
cmd_aliases => ['i'], |
|
48
|
|
|
|
|
|
|
documentation => q{add one to the number of cores (useful in scripts)}, |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _build_cores { |
|
52
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
53
|
0
|
|
|
|
|
|
given ($self->os) { |
|
54
|
0
|
|
|
|
|
|
when ('darwin') { $_ = `sysctl hw.ncpu | awk '{print \$2}'`; chomp; $_ } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
when ('linux') { $_ = `grep cores < /proc/cpuinfo | tail -n 1 | awk '{print \$4}'`; chomp; $_ } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
0
|
|
|
sub _build_os { $^O } |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
around 'cores' => sub { |
|
62
|
|
|
|
|
|
|
my ($orig, $self, $set) = @_; |
|
63
|
|
|
|
|
|
|
return $self->$orig() + 1 if $self->add_one and not defined $set; |
|
64
|
|
|
|
|
|
|
return $self->$orig(); # otherwise |
|
65
|
|
|
|
|
|
|
}; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
1
|
|
|
1
|
|
913
|
no Any::Moose; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |
|
74
|
|
|
|
|
|
|
=pod |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=encoding utf-8 |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 NAME |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
App::OS::Detect::MachineCores - Detect how many cores your machine has (OS-independently) |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 VERSION |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
version 0.012 |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
On different systems, different approaches are needed to detect the number of cores for that machine. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This Module is a wrapper around these different approaches. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 USAGE |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This module will install one executable, C<<< mcores >>>, in your bin. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
It is really simple and straightforward: |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
usage: mcores [-?i] [long options...] |
|
99
|
|
|
|
|
|
|
-? --usage --help Prints this usage information. |
|
100
|
|
|
|
|
|
|
-i --add-one add one to the number of cores (useful in scripts) |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 WARNING |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Some questions with Dist::Zilla are still open, and although this module attempts to load L<Mouse> instead of L<Moose>, |
|
105
|
|
|
|
|
|
|
unfortuantely, however, B<both> modules are installed as prerequisites. This will change soon. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 AUTHOR |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Daniel B. <dbr@cpan.org> |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Daniel B.. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
118
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
|
121
|
|
|
|
|
|
|
|