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