blib/lib/Unix/Processors.pm

filter: Statementstmt 100% 30 / 30 Branchbran 75.0% 6 / 8 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 5 / 5 Podpod 50.0% 1 / 2 totaltotal 80.0% 44 / 55 CC 7 SCAR 12.4
CC
7
Cov
86%
processors
5.1
new
3.2
BEGIN
1.0
CRAP 3.5
↑ Summary Processors.xs »
1 # Unix::Processors
2 # See copyright, etc in below POD section.
3 ######################################################################
4  
5 =head1 NAME
6  
7 Unix::Processors - Interface to processor (CPU) information
8  
9 =head1 SYNOPSIS
10  
11 use Unix::Processors;
12  
13 my $procs = new Unix::Processors;
14 print "There are ", $procs->max_online, " CPUs at ", $procs->max_clock, "\n";
15 if ($procs->max_online != $procs->max_physical) {
16 print "Hyperthreading between ",$procs->max_physical," physical CPUs.\n";
17 }
18 (my $FORMAT = "%2s %-8s %4s \n") =~ s/\s\s+/ /g;
19 printf($FORMAT, "#", "STATE", "CLOCK", "TYPE", );
20 foreach my $proc (@{$procs->processors}) {
21 printf ($FORMAT, $proc->id, $proc->state, $proc->clock, $proc->type);
22 }
23  
24 =head1 DESCRIPTION
25  
26 This package provides accessors to per-processor (CPU) information.
27 The object is obtained with the Unix::Processors::processors call.
28 the operating system in a OS independent manner.
29  
30 =over 4
31  
32 =item max_online
33  
34 Return number of threading processors currently online. On hyperthreaded
35 Linux systems, this indicates the maximum number of simultaneous threads
36 that may execute; see max_physical for the real physical CPU count.
37  
38 =item max_physical
39  
40 Return number of physical processor cores currently online. For example, a
41 single chip quad-core processor returns four.
42  
43 =item max_socket
44  
45 Returns the number of populated CPU sockets, if known, else the same number
46 as max_physical. For example, a single chip quad-core processor returns
47 one.
48  
49 =item max_clock
50  
51 Return the maximum clock speed across all online processors. Not all OSes support this call.
52  
53 =item processors
54  
55 Return an array of processor references. See the Unix::Processors::Info
56 manual page. Not all OSes support this call.
57  
58 =back
59  
60 =head1 DISTRIBUTION
61  
62 The latest version is available from CPAN and from L<http://www.veripool.org/>.
63  
64 Copyright 1999-2017 by Wilson Snyder. This package is free software; you
65 you can redistribute it and/or modify it under the terms of either the GNU
66 Lesser General Public License Version 3 or the Perl Artistic License Version 2.0.
67  
68 =head1 AUTHORS
69  
70 Wilson Snyder <wsnyder@wsnyder.org>
71  
72 =head1 SEE ALSO
73  
74 L<Unix::Processors::Info>, L<Sys::Sysconf>
75  
76 =cut
77  
78 package Unix::Processors;
79 1 ▶use Unix::Processors::Info;
Subroutine BEGIN: called CC=1 SCAR=0.0
80  
81 1 $VERSION = '2.046';
82  
83 1 require DynaLoader;
84 1 @ISA = qw(DynaLoader);
85  
86 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 ######################################################################
90 #### Configuration Section
91  
92 1 bootstrap Unix::Processors;
93  
94 ######################################################################
95 #### Accessors
96  
97 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.6
Pod undocumented
98 # NOP for now, just need a handle for other routines
99 1 ▶ @_ >= 1 or croak 'usage: Unix::Processors->new ({options})';
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or croak("usage: Unix::Processors->new ({options})") 1 0 1
100 1 my $proto = shift;
101 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
102 1 my $self = {@_,};
103 1 bless $self, $class;
104 1 return $self;
105 }
106  
107 2 ▶sub processors {
Subroutine processors: called CC=5 SCAR=16.3
Pod documented
108 2 ▶ my $self = shift; ($self && ref($self)) or croak 'usage: $self->max_online()';
Branch: 1 branch
BranchTrueFalseTotal
$self and ref $self or croak("usage: \$self->max_online()") 2 0 2
Condition33%1/3
$self and ref $self
!ll&&!rl&&r
002
MC/DC0%0/2
$self and ref $self
$self ref $self
Truth table33%1/3
A and B
A= $selfB= ref $self
ABresult
0X0
100
111
109 2 my @list;
110 2 ▶ for (my $cnt=0; $cnt<64; $cnt++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cnt < 64) 128 2 130
111 128 my $val = $cnt;
112 128 my $vref = \$val; # Just a reference to a cpu number
113 128 bless $vref, 'Unix::Processors::Info';
114 128 ▶ if ($vref->type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vref->type) 26 102 128
115 26 push @list, $vref;
116 }
117 }
118 2 return \@list;
119 }
120  
121 ######################################################################
122 #### Package return
123 1 1;
↑ Summary Processors.xs »