line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sys::Info::Driver::Linux::Device::CPU; |
2
|
1
|
|
|
1
|
|
1522
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
5
|
1
|
|
|
1
|
|
6
|
use base qw(Sys::Info::Base); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
116
|
|
6
|
1
|
|
|
1
|
|
6
|
use Sys::Info::Driver::Linux; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
7
|
1
|
|
|
1
|
|
1161
|
use Unix::Processors; |
|
1
|
|
|
|
|
5439
|
|
|
1
|
|
|
|
|
42
|
|
8
|
1
|
|
|
1
|
|
12
|
use POSIX (); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
23
|
|
9
|
1
|
|
|
1
|
|
8
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2412
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.7903'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub identify { |
14
|
8
|
|
|
8
|
1
|
2474
|
my $self = shift; |
15
|
|
|
|
|
|
|
|
16
|
8
|
100
|
|
|
|
35
|
if ( ! $self->{META_DATA} ) { |
17
|
2
|
|
|
|
|
11
|
my $mach = $self->uname->{machine}; |
18
|
2
|
50
|
|
|
|
74
|
my $arch = $mach =~ m{ i [0-9] 86 }xmsi ? 'x86' |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
19
|
|
|
|
|
|
|
: $mach =~ m{ ia64 }xmsi ? 'IA64' |
20
|
|
|
|
|
|
|
: $mach =~ m{ x86_64 }xmsi ? 'AMD-64' |
21
|
|
|
|
|
|
|
: $mach |
22
|
|
|
|
|
|
|
; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
13
|
my @raw = split m{\n\n}xms, |
25
|
|
|
|
|
|
|
$self->trim( $self->slurp( proc->{cpuinfo} ) ); |
26
|
2
|
|
|
|
|
1634
|
$self->{META_DATA} = []; |
27
|
2
|
|
|
|
|
7
|
foreach my $e ( @raw ) { |
28
|
32
|
|
|
|
|
108
|
push @{ $self->{META_DATA} }, |
|
32
|
|
|
|
|
98
|
|
29
|
|
|
|
|
|
|
{ $self->_parse_cpuinfo($e), architecture => $arch }; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
8
|
|
|
|
|
32
|
return $self->_serve_from_cache(wantarray); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub bitness { |
37
|
1
|
|
|
1
|
1
|
300
|
my $self = shift; |
38
|
1
|
|
|
|
|
5
|
my @cpu = $self->identify; |
39
|
1
|
|
|
|
|
148
|
my $flags = $cpu[0]->{flags}; |
40
|
1
|
50
|
|
|
|
5
|
if ( $flags ) { |
41
|
1
|
|
|
|
|
3
|
my $lm = grep { $_ eq 'lm' } @{$flags}; |
|
32
|
|
|
|
|
51
|
|
|
1
|
|
|
|
|
3
|
|
42
|
1
|
50
|
|
|
|
7
|
return '64' if $lm; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
0
|
|
|
|
0
|
return $cpu[0]->{architecture} =~ m{64}xms ? '64' : '32'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub load { |
48
|
5
|
|
|
5
|
1
|
874
|
my $self = shift; |
49
|
5
|
|
|
|
|
8
|
my $level = shift; |
50
|
5
|
|
|
|
|
24
|
my @loads = split /\s+/xms, $self->slurp( proc->{loadavg} ); |
51
|
5
|
|
|
|
|
824
|
return $loads[$level]; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _parse_cpuinfo { |
55
|
32
|
|
|
32
|
|
41
|
my $self = shift; |
56
|
32
|
|
33
|
|
|
70
|
my $raw = shift || croak 'Parser called without data'; |
57
|
32
|
|
|
|
|
34
|
my($k, $v); |
58
|
0
|
|
|
|
|
0
|
my %cpu; |
59
|
32
|
|
|
|
|
252
|
foreach my $line (split /\n/xms, $raw) { |
60
|
832
|
|
|
|
|
2618
|
($k, $v) = split /\s+:\s+/xms, $line; |
61
|
832
|
|
|
|
|
1560
|
$cpu{$k} = $v; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
32
|
50
|
|
|
|
598
|
my @flags = $cpu{flags} ? (split /\s+/xms, $cpu{flags}) : (); |
65
|
32
|
|
|
|
|
85
|
my %flags = map { $_ => 1 } @flags; |
|
1024
|
|
|
|
|
2657
|
|
66
|
32
|
|
|
|
|
211
|
my $up = Unix::Processors->new; |
67
|
32
|
|
|
|
|
437
|
my $name = $cpu{'model name'}; |
68
|
32
|
50
|
|
|
|
118
|
$name =~ s[ \s{2,} ][ ]xms if $name; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return( |
71
|
32
|
50
|
50
|
|
|
1498
|
processor_id => $cpu{processor}, |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
|
|
|
|
|
72
|
|
|
|
|
|
|
data_width => $flags{lm} ? '64' : '32', # guess |
73
|
|
|
|
|
|
|
address_width => $flags{lm} ? '64' : '32', # guess |
74
|
|
|
|
|
|
|
bus_speed => undef, |
75
|
|
|
|
|
|
|
speed => $cpu{'cpu MHz'}, |
76
|
|
|
|
|
|
|
name => $name || q{}, |
77
|
|
|
|
|
|
|
family => $cpu{'cpu family'}, |
78
|
|
|
|
|
|
|
manufacturer => $cpu{vendor_id}, |
79
|
|
|
|
|
|
|
model => $cpu{model}, |
80
|
|
|
|
|
|
|
stepping => $cpu{stepping}, |
81
|
|
|
|
|
|
|
number_of_cores => $cpu{'cpu cores'} || $up->max_physical, |
82
|
|
|
|
|
|
|
number_of_logical_processors => $up->max_online, |
83
|
|
|
|
|
|
|
L2_cache => {max_cache_size => $cpu{'cache size'}}, |
84
|
|
|
|
|
|
|
flags => @flags ? [ @flags ] : undef, |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |