From b204513bbfbac10a826e485f677c7ed77e342d52 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 29 Jan 2009 16:29:14 -0800 Subject: Change name of cpu summary script and rearrange Final answer. --- scripts/vyatta-cpu-summary.pl | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 scripts/vyatta-cpu-summary.pl (limited to 'scripts/vyatta-cpu-summary.pl') diff --git a/scripts/vyatta-cpu-summary.pl b/scripts/vyatta-cpu-summary.pl new file mode 100755 index 0000000..1839a5d --- /dev/null +++ b/scripts/vyatta-cpu-summary.pl @@ -0,0 +1,37 @@ +#! /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 "CPU ", join( " \n", keys %models ), "\n"; +print "Packages ", scalar keys %packages, "\n"; +print "Cores ", scalar keys %cores, "\n"; +print "Threads ", $cpu, "\n"; -- cgit v1.2.3