File: CPU.pm

package info (click to toggle)
ocsinventory-agent 2%3A2.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,424 kB
  • sloc: perl: 26,492; xml: 773; objc: 528; sh: 386; ansic: 333; makefile: 12
file content (77 lines) | stat: -rw-r--r-- 2,407 bytes parent folder | download | duplicates (2)
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
package Ocsinventory::Agent::Backend::OS::Linux::Archs::i386::CPU;

use strict;
use warnings;
use Data::Dumper;

sub check { 
    my $params = shift;
    my $common = $params->{common};
    $common->can_run("lscpu"); 
}

sub run {

    my $params = shift;
    my $common = $params->{common};

    my @cpuinfos=`LANG=C lscpu`;
    my $cpu;
    my $nbcpus;

    foreach my $info (@cpuinfos){
        chomp $info;
        $cpu->{CPUARCH}=$1 if ($info =~ /Architecture:\s*(.*)/i);
        $cpu->{NBCPUS}=$1 if ($info =~ /^CPU\(s\):\s*(\d+)/i);
        $cpu->{THREADS}=$1 if ($info =~ /Thread\(s\)\sper\score:\s*(\d+)/i);
        $cpu->{CORES}=$1 if ($info =~ /Core\(s\)\sper\ssocket:\s*(\d+)/i);
        $cpu->{NBSOCKET}=$1 if ($info =~ /Socket\(s\):\s*(\d+)/i);
        $cpu->{TYPE}=$1 if ($info =~ /Model\sname:\s*(.*)/i);
        if ($info =~ /Vendor ID:\s*(Authentic|Genuine|)(.+)/i){
            $cpu->{MANUFACTURER} = $2;
            $cpu->{MANUFACTURER} =~ s/(TMx86|TransmetaCPU)/Transmeta/;
            $cpu->{MANUFACTURER} =~ s/CyrixInstead/Cyrix/;
            $cpu->{MANUFACTURER} =~ s/CentaurHauls/VIA/;
        }

        $cpu->{CURRENT_SPEED} = $1 if ($info =~ /CPU\sMHz:\s*(\d+)(|\.\d+)$/i);
        $cpu->{L2CACHESIZE} = $1 if ($info =~ /L2\scache:\s*(.*)/i);
        if ($cpu->{CPUARCH} && $cpu->{CPUARCH} eq 'x86_64'){
            $cpu->{DATA_WIDTH}='64';
        } else {
            $cpu->{DATA_WIDTH}='32';
        }
        
        if ($cpu->{TYPE}) {
            if ($cpu->{TYPE} =~ /([\d\.]+)MHz$/){
                $cpu->{SPEED}=$1;
            } elsif ($cpu->{TYPE} =~ /([\d\.]+)GHz$/){
                $cpu->{SPEED}=$1*1000;
            }
        }
    }
   
    # Total Threads = number of cores x number of threads per core
    $cpu->{THREADS}=$cpu->{CORES}*$cpu->{THREADS};

    # Set LOGICAL_CPUS with THREADS value
    $cpu->{LOGICAL_CPUS}=$cpu->{THREADS};

    # set CURRENT_ADDRESS_WIDTH with DATA_WIDTH value
    $cpu->{CURRENT_ADDRESS_WIDTH}=$cpu->{DATA_WIDTH};

    my $infos=$common->getDmidecodeInfos();
    foreach my $info (@{$infos->{4}}) {
        next if $info->{Status} && $info->{Status} =~ /Unpopulated|Disabled/i;
        $cpu->{SERIALNUMBER}=$info->{'Serial Number'};
        $cpu->{VOLTAGE}=$info->{'Voltage'};
        $cpu->{SOCKET}=$info->{'Socket Designation'};
    }

    for (my $i=0;$i<$cpu->{NBSOCKET};$i++) {
        $common->addCPU($cpu);
    }

}

1;