line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::MacOS::CPU; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
86935287
|
use strict; |
|
2
|
|
|
|
|
24
|
|
|
2
|
|
|
|
|
114
|
|
4
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
26
|
|
|
2
|
|
|
|
|
158
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1129
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
393
|
|
7
|
2
|
|
|
2
|
|
1283
|
use FusionInventory::Agent::Tools::MacOS; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
1381
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub isEnabled { |
10
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
11
|
0
|
0
|
|
|
|
0
|
return 0 if $params{no_category}->{cpu}; |
12
|
0
|
|
|
|
|
0
|
return canRun('/usr/sbin/system_profiler'); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub doInventory { |
16
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
0
|
my $inventory = $params{inventory}; |
19
|
0
|
|
|
|
|
0
|
my $logger = $params{logger}; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
0
|
foreach my $cpu (_getCpus(logger => $logger)) { |
22
|
0
|
|
|
|
|
0
|
$inventory->addEntry( |
23
|
|
|
|
|
|
|
section => 'CPUS', |
24
|
|
|
|
|
|
|
entry => $cpu |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _getCpus { |
30
|
1
|
|
|
1
|
|
13
|
my (%params) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# system profiler informations |
33
|
|
|
|
|
|
|
my $infos = getSystemProfilerInfos( |
34
|
|
|
|
|
|
|
type => 'SPHardwareDataType', |
35
|
|
|
|
|
|
|
logger => $params{logger}, |
36
|
|
|
|
|
|
|
file => $params{file} |
37
|
1
|
|
|
|
|
28
|
); |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
13
|
my $sysprofile_info = $infos->{'Hardware'}->{'Hardware Overview'}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# more informations from sysctl |
42
|
|
|
|
|
|
|
my $handle = getFileHandle( |
43
|
|
|
|
|
|
|
logger => $params{logger}, |
44
|
|
|
|
|
|
|
command => 'sysctl -a machdep.cpu', |
45
|
|
|
|
|
|
|
file => $params{sysctl} |
46
|
1
|
|
|
|
|
6
|
); |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
3
|
my $sysctl_info; |
49
|
1
|
|
|
|
|
20
|
while (my $line = <$handle>) { |
50
|
53
|
|
|
|
|
62
|
chomp $line; |
51
|
53
|
50
|
|
|
|
215
|
next unless $line =~ /([^:]+) : \s (.+)/x; |
52
|
53
|
|
|
|
|
284
|
$sysctl_info->{$1} = $2; |
53
|
|
|
|
|
|
|
} |
54
|
1
|
|
|
|
|
8
|
close $handle; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $type = $sysprofile_info->{'Processor Name'} || |
57
|
1
|
|
33
|
|
|
5
|
$sysprofile_info->{'CPU Type'}; |
58
|
|
|
|
|
|
|
my $procs = $sysprofile_info->{'Number Of Processors'} || |
59
|
1
|
|
0
|
|
|
4
|
$sysprofile_info->{'Number Of CPUs'} || |
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
my $speed = $sysprofile_info->{'Processor Speed'} || |
62
|
1
|
|
33
|
|
|
4
|
$sysprofile_info->{'CPU Speed'}; |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
2
|
my $stepping = $sysctl_info->{'machdep.cpu.stepping'}; |
65
|
1
|
|
|
|
|
2
|
my $family = $sysctl_info->{'machdep.cpu.family'}; |
66
|
1
|
|
|
|
|
3
|
my $model = $sysctl_info->{'machdep.cpu.model'}; |
67
|
1
|
|
|
|
|
8
|
my $threads = $sysctl_info->{'machdep.cpu.thread_count'}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# French Mac returns 2,60 Ghz instead of 2.60 Ghz :D |
70
|
1
|
|
|
|
|
3
|
$speed =~ s/,/./; |
71
|
1
|
50
|
|
|
|
6
|
if ($speed =~ /GHz$/i) { |
|
|
0
|
|
|
|
|
|
72
|
1
|
|
|
|
|
4
|
$speed =~ s/GHz//i; |
73
|
1
|
|
|
|
|
4
|
$speed = $speed * 1000; |
74
|
|
|
|
|
|
|
} elsif ($speed =~ /MHz$/i){ |
75
|
0
|
|
|
|
|
0
|
$speed =~ s/MHz//i; |
76
|
|
|
|
|
|
|
} |
77
|
1
|
|
|
|
|
14
|
$speed =~ s/\s//g; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $cores = $sysprofile_info->{'Total Number Of Cores'} ? |
80
|
|
|
|
|
|
|
$sysprofile_info->{'Total Number Of Cores'} / $procs : |
81
|
1
|
50
|
|
|
|
5
|
$sysctl_info->{'machdep.cpu.core_count'}; |
82
|
|
|
|
|
|
|
|
83
|
1
|
0
|
|
|
|
5
|
my $manufacturer = |
|
|
50
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$type =~ /Intel/i ? "Intel" : |
85
|
|
|
|
|
|
|
$type =~ /AMD/i ? "AMD" : |
86
|
|
|
|
|
|
|
undef ; |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
1
|
my @cpus; |
89
|
1
|
|
|
|
|
8
|
my $cpu = { |
90
|
|
|
|
|
|
|
CORE => $cores, |
91
|
|
|
|
|
|
|
MANUFACTURER => $manufacturer, |
92
|
|
|
|
|
|
|
NAME => $type, |
93
|
|
|
|
|
|
|
THREAD => $threads, |
94
|
|
|
|
|
|
|
FAMILYNUMBER => $family, |
95
|
|
|
|
|
|
|
MODEL => $model, |
96
|
|
|
|
|
|
|
STEPPING => $stepping, |
97
|
|
|
|
|
|
|
SPEED => $speed |
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
4
|
for (my $i=0; $i < $procs; $i++) { |
101
|
1
|
|
|
|
|
4
|
push @cpus, $cpu; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
15
|
return @cpus; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |