| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Sys::Info::Driver::Linux::Device::CPU; |
|
2
|
|
|
|
|
|
|
$Sys::Info::Driver::Linux::Device::CPU::VERSION = '0.7904'; |
|
3
|
1
|
|
|
1
|
|
932
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
24
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use base qw(Sys::Info::Base); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
110
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Sys::Info::Driver::Linux; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
8
|
1
|
|
|
1
|
|
368
|
use Unix::Processors; |
|
|
1
|
|
|
|
|
1094
|
|
|
|
1
|
|
|
|
|
24
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use POSIX (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
15
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use Carp qw( croak ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
619
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub identify { |
|
13
|
8
|
|
|
8
|
1
|
1472
|
my $self = shift; |
|
14
|
|
|
|
|
|
|
|
|
15
|
8
|
100
|
|
|
|
23
|
if ( ! $self->{META_DATA} ) { |
|
16
|
2
|
|
|
|
|
8
|
my $mach = $self->uname->{machine}; |
|
17
|
2
|
50
|
|
|
|
52
|
my $arch = $mach =~ m{ i [0-9] 86 }xmsi ? 'x86' |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
: $mach =~ m{ ia64 }xmsi ? 'IA64' |
|
19
|
|
|
|
|
|
|
: $mach =~ m{ x86_64 }xmsi ? 'AMD-64' |
|
20
|
|
|
|
|
|
|
: $mach |
|
21
|
|
|
|
|
|
|
; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my @raw = split m{\n\n}xms, |
|
24
|
2
|
|
|
|
|
9
|
$self->trim( $self->slurp( proc->{cpuinfo} ) ); |
|
25
|
2
|
|
|
|
|
1285
|
$self->{META_DATA} = []; |
|
26
|
2
|
|
|
|
|
6
|
foreach my $e ( @raw ) { |
|
27
|
32
|
|
|
|
|
58
|
push @{ $self->{META_DATA} }, |
|
|
32
|
|
|
|
|
73
|
|
|
28
|
|
|
|
|
|
|
{ $self->_parse_cpuinfo($e), architecture => $arch }; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
8
|
|
|
|
|
47
|
return $self->_serve_from_cache(wantarray); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub bitness { |
|
36
|
1
|
|
|
1
|
1
|
263
|
my $self = shift; |
|
37
|
1
|
|
|
|
|
4
|
my @cpu = $self->identify; |
|
38
|
1
|
|
|
|
|
11
|
my $flags = $cpu[0]->{flags}; |
|
39
|
1
|
50
|
|
|
|
3
|
if ( $flags ) { |
|
40
|
1
|
|
|
|
|
2
|
my $lm = grep { $_ eq 'lm' } @{$flags}; |
|
|
31
|
|
|
|
|
42
|
|
|
|
1
|
|
|
|
|
2
|
|
|
41
|
1
|
50
|
|
|
|
7
|
return '64' if $lm; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
0
|
0
|
|
|
|
0
|
return $cpu[0]->{architecture} =~ m{64}xms ? '64' : '32'; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub load { |
|
47
|
5
|
|
|
5
|
1
|
575
|
my $self = shift; |
|
48
|
5
|
|
|
|
|
7
|
my $level = shift; |
|
49
|
5
|
|
|
|
|
13
|
my @loads = split /\s+/xms, $self->slurp( proc->{loadavg} ); |
|
50
|
5
|
|
|
|
|
586
|
return $loads[$level]; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _parse_cpuinfo { |
|
54
|
32
|
|
|
32
|
|
48
|
my $self = shift; |
|
55
|
32
|
|
33
|
|
|
57
|
my $raw = shift || croak 'Parser called without data'; |
|
56
|
32
|
|
|
|
|
65
|
my($k, $v); |
|
57
|
32
|
|
|
|
|
0
|
my %cpu; |
|
58
|
32
|
|
|
|
|
171
|
foreach my $line (split /\n/xms, $raw) { |
|
59
|
832
|
|
|
|
|
2152
|
($k, $v) = split /\s+:\s+/xms, $line; |
|
60
|
832
|
|
|
|
|
1478
|
$cpu{$k} = $v; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
32
|
50
|
|
|
|
425
|
my @flags = $cpu{flags} ? (split /\s+/xms, $cpu{flags}) : (); |
|
64
|
32
|
|
|
|
|
65
|
my %flags = map { $_ => 1 } @flags; |
|
|
992
|
|
|
|
|
1559
|
|
|
65
|
32
|
|
|
|
|
143
|
my $up = Unix::Processors->new; |
|
66
|
32
|
|
|
|
|
289
|
my $name = $cpu{'model name'}; |
|
67
|
32
|
50
|
|
|
|
95
|
$name =~ s[ \s{2,} ][ ]xms if $name; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return( |
|
70
|
|
|
|
|
|
|
processor_id => $cpu{processor}, |
|
71
|
|
|
|
|
|
|
data_width => $flags{lm} ? '64' : '32', # guess |
|
72
|
|
|
|
|
|
|
address_width => $flags{lm} ? '64' : '32', # guess |
|
73
|
|
|
|
|
|
|
bus_speed => undef, |
|
74
|
|
|
|
|
|
|
speed => $cpu{'cpu MHz'}, |
|
75
|
|
|
|
|
|
|
name => $name || q{}, |
|
76
|
|
|
|
|
|
|
family => $cpu{'cpu family'}, |
|
77
|
|
|
|
|
|
|
manufacturer => $cpu{vendor_id}, |
|
78
|
|
|
|
|
|
|
model => $cpu{model}, |
|
79
|
|
|
|
|
|
|
stepping => $cpu{stepping}, |
|
80
|
|
|
|
|
|
|
number_of_cores => $cpu{'cpu cores'} || $up->max_physical, |
|
81
|
|
|
|
|
|
|
number_of_logical_processors => $up->max_online, |
|
82
|
32
|
50
|
50
|
|
|
844
|
L2_cache => {max_cache_size => $cpu{'cache size'}}, |
|
|
|
50
|
33
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
flags => @flags ? [ @flags ] : undef, |
|
84
|
|
|
|
|
|
|
); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=pod |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=encoding UTF-8 |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Sys::Info::Driver::Linux::Device::CPU |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 VERSION |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
version 0.7904 |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
- |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Identifies the CPU with L<Unix::Processors>, L<POSIX> and C<< /proc >>. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 NAME |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Sys::Info::Driver::Linux::Device::CPU - Linux CPU Device Driver |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 METHODS |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 identify |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
See identify in L<Sys::Info::Device::CPU>. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 load |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
See load in L<Sys::Info::Device::CPU>. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 bitness |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
See bitness in L<Sys::Info::Device::CPU>. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L<Sys::Info>, |
|
132
|
|
|
|
|
|
|
L<Sys::Info::Device::CPU>, |
|
133
|
|
|
|
|
|
|
L<Unix::Processors>, L<POSIX>, |
|
134
|
|
|
|
|
|
|
proc filesystem. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Burak Gursoy <burak@cpan.org> |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Burak Gursoy. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
145
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |