Skip to content

Commit

Permalink
access registry only once, using dedicated function
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Rousse authored and Guillaume Rousse committed Mar 4, 2012
1 parent 53fcf60 commit ee55a45
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions lib/FusionInventory/Agent/Task/Inventory/Input/Win32/CPU.pm
Expand Up @@ -4,12 +4,6 @@ use strict;
use warnings;

use English qw(-no_match_vars);
use Win32;
use Win32::TieRegistry (
Delimiter => '/',
ArrayValues => 0,
qw/KEY_READ/
);

use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Win32;
Expand Down Expand Up @@ -44,7 +38,13 @@ sub doInventory {
sub _getCPUs {
my ($logger) = @_;

my @dmidecodeCpu = getCpusFromDmidecode();
my @dmidecodeInfos = getCpusFromDmidecode();
# the CPU description in WMI is false, we use the registry instead
my $registryInfos = getRegistryKey(
path => "HKEY_LOCAL_MACHINE/Hardware/Description/System/CentralProcessor",
logger => $logger
);

my $cpuId = 0;
my @cpus;

Expand All @@ -53,22 +53,15 @@ sub _getCPUs {
properties => [ qw/NumberOfCores ProcessorId MaxClockSpeed/ ]
)) {

# the CPU description in WMI is false, we use the registry instead
# Hardware\Description\System\CentralProcessor\1
# thank you Nicolas Richard
my $registryInfo = getRegistryValue(
path => "HKEY_LOCAL_MACHINE/Hardware/Description/System/CentralProcessor/$cpuId",
logger => $logger
);

my $dmidecodeInfo = $dmidecodeCpu[$cpuId];
my $dmidecodeInfo = $dmidecodeInfos[$cpuId];
my $registryInfo = $registryInfos->{"$cpuId/"};

my $cpu = {
CORE => $dmidecodeInfo->{CORE} || $object->{NumberOfCores},
THREAD => $dmidecodeInfo->{THREAD},
DESCRIPTION => $registryInfo->{Identifier},
NAME => $registryInfo->{ProcessorNameString},
MANUFACTURER => $registryInfo->{VendorIdentifier},
DESCRIPTION => $registryInfo->{'/Identifier'},
NAME => $registryInfo->{'/ProcessorNameString'},
MANUFACTURER => $registryInfo->{'/VendorIdentifier'},
SERIAL => $dmidecodeInfo->{SERIAL},
SPEED => $dmidecodeInfo->{SPEED} || $object->{MaxClockSpeed},
ID => $dmidecodeInfo->{ID} || $object->{ProcessorId}
Expand Down

0 comments on commit ee55a45

Please sign in to comment.