System/Linux/Cpuinfo.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« System/Libvirt.pm ↑ Summary System/Linux/Pps.pm »
1 #
2 # $Id$
3 #
4 # system::linux::cpuinfo Brik
5 #
6 package Metabrik::System::Linux::Cpuinfo;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik::File::Text);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 attributes_default => {
19 as_array => 1,
20 strip_crlf => 1,
21 },
22 commands => {
23 read => [ ],
24 count_processors => [ ],
25 },
26 };
27 }
28  
29 sub read {
30 my $self = shift;
31  
32 my $cpuinfo = '/proc/cpuinfo';
33 if (! -f $cpuinfo) {
34 return $self->log->info("read: cpuinfo file [$cpuinfo] not found");
35 }
36  
37 my $lines = $self->SUPER::read($cpuinfo) or return;
38  
39 my $current = 0;
40 my @infos = ();
41 for (@$lines) {
42 my ($k, $v) = split(/\s*:\s*/, $_);
43 if (! defined($v)) { # New line
44 $current++;
45 next;
46 }
47 $infos[$current]->{$k} = $v;
48 }
49  
50 return \@infos;
51 }
52  
53 sub count_processors {
54 my $self = shift;
55  
56 my $infos = $self->read or return;
57  
58 my $count = 0;
59 for my $this (@$infos) {
60 if (exists($this->{processor})) {
61 $count++;
62 }
63 }
64  
65 return $count;
66 }
67  
68 1;
69  
70 __END__
« System/Libvirt.pm ↑ Summary System/Linux/Pps.pm »