summaryrefslogtreecommitdiff
path: root/scripts/vyatta-cpu-summary.pl
blob: 771bc5a39efe709cddaf676b64e438c827f2c146 (plain)
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
#! /usr/bin/perl
# implement "show cpu-info"

open my $cpuinfo, '<', '/proc/cpuinfo'
  or die "Can't open /proc/cpuinfo : $!";

my %models;
my %packages;
my %cores;

my %map = (
    'model name'  => \%models,
    'physical id' => \%packages,
    'core id'     => \%cores
);

my $cpu = 0;
while (<$cpuinfo>) {
    chomp;
    my ( $tag, $val ) = split /:/;
    if ( !$tag ) {
        ++$cpu;
        next;
    }

    $tag =~ s/\s+$//;
    $val =~ s/^\s+//;

    my $ref = $map{$tag};
    $ref->{$val} = $cpu  if ($ref);
}
close $cpuinfo;

print "Processors ", $cpu, "\n";
print "Packages   ", scalar keys %packages, "\n" if (%packages);
print "Cores      ", scalar keys %cores,    "\n" if (%cores);

# Handle any attempt to run different CPU models 
print "Model      ", join( "       \n", keys %models ), "\n";