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