Skip Menu |

This queue is for tickets about the Sys-Statistics-Linux CPAN distribution.

Report information
The Basics
Id: 100259
Status: open
Priority: 0/
Queue: Sys-Statistics-Linux

People
Owner: Nobody in particular
Requestors: arfreitas [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.66
Fixed in: (no value)



Subject: new features to Sys::Statistics::Linux::SysInfo
Greetings John, I have some suggestions (patch included) to new features as new methods to Sys::Statistics::Linux::SysInfo: - get_proc_arch Not exactly a statistic, but this is a information about the CPU anyway. This method will return an integer as the architecture of the CPUs: 32 or 64 bits, depending on the flags retrieved for one CPU. It is assumed that all CPUs will have the same flags, so this method will consider only the flags returned by the CPU with "core id" equal to 0 (in other words, the first CPU found). - get_cpu_flags Returns an array reference with all flags retrieve from C</proc/cpuinfo> using the same logic described in C<get_proc_arch> documentation. These should small changes but I believe that they might be useful. If you think they can be added to your distribution I might send new unit tests too. Best regards, Alceu
Subject: patch.txt
--- old/SysInfo.pm 2014-11-11 00:09:37.356387100 -0200 +++ new/SysInfo.pm 2014-11-11 00:10:23.192207500 -0200 @@ -15,7 +15,7 @@ For more information read the documentation of the front-end module L<Sys::Statistics::Linux>. -=head1 SYSTEM INFOMATIONS +=head1 SYSTEM INFORMATIONS Generated by F</proc/sys/kernel/{hostname,domainname,ostype,osrelease,version}> and F</proc/cpuinfo>, F</proc/meminfo>, F</proc/uptime>, F</proc/net/dev>. @@ -62,6 +62,21 @@ my $info = $lxs->get; +=head2 get_proc_arch + +Not exactly a statistic, but this is a information about the CPU anyway. + +This method will return an integer as the architecture of the CPUs: 32 or 64 bits, depending on the flags +retrieve for one CPU. + +It is assumed that all CPUs will have the same flags, so this method will consider only the flags returned +by the CPU with "core id" equal to 0 (in other words, the first CPU found). + +=head2 get_cpu_flags + +Returns an array reference with all flags retrieve from C</proc/cpuinfo> using the same logic described in +C<get_proc_arch> documentation. + =head1 EXPORTS No exports. @@ -92,7 +107,7 @@ use warnings; use Carp qw(croak); -our $VERSION = '0.13'; +our $VERSION = '0.14'; our $RAWTIME = 0; sub new { @@ -129,7 +144,22 @@ return bless \%self, $class; } +sub get_proc_arch { + + my $self = shift; + return $self->{proc_arch}; + +} + +sub get_cpu_flags { + + my $self = shift; + return $self->{cpu_flags}; + +} + sub get { + my $self = shift; my $class = ref $self; my $file = $self->{files}; @@ -137,6 +167,9 @@ $self->{stats} = $stats; + $self->{proc_arch} = undef; + $self->{cpu_flags} = undef; + $self->_get_common; $self->_get_meminfo; $self->_get_uptime; @@ -204,18 +237,60 @@ open my $fh, '<', $filename or croak "$class: unable to open $filename ($!)"; while (my $line = <$fh>) { - if ($line =~ /^physical\s+id\s*:\s*(\d+)/) { - $phyid = $1; - $cpu{$phyid}{count}++; - } elsif ($line =~ /^core\s+id\s*:\s*(\d+)/) { - $cpu{$phyid}{cores}{$1}++; - } elsif ($line =~ /^processor\s*:\s*\d+/) { # x86 - $stats->{countcpus}++; - } elsif ($line =~ /^# processors\s*:\s*(\d+)/) { # s390 - $stats->{countcpus} = $1; - last; - } - } + + chomp($line); + + CASE: { + + if ($line =~ /^physical\s+id\s*:\s*(\d+)/) { + $phyid = $1; + $cpu{$phyid}{count}++; + last CASE; + } + + if ($line =~ /^core\s+id\s*:\s*(\d+)/) { + $cpu{$phyid}{cores}{$1}++; + last CASE; + } + + if ($line =~ /^processor\s*:\s*\d+/) { # x86 + $stats->{countcpus}++; + last CASE; + } + + if ($line =~ /^# processors\s*:\s*(\d+)/) { # s390 + $stats->{countcpus} = $1; + last CASE; + } + + if ($line =~ /^flags\s+\:/) { + + last CASE if ($self->get_cpu_flags); # no use to repeat this + + my ( $attribute, $value ) = split(/\s+:\s/, $line); + my @flags = split(/\s/, $value); + + $self->{cpu_flags} = \@flags; + + #long mode + if ($value =~ /\slm\s/) { + + $self->{proc_arch} = 64; + + } else { + + $self->{proc_arch} = 32; + + } + + last CASE; + + } + + } + +} + close($fh);
Hi Alceu, I push the code of S:S:L to Github: https://github.com/js-bloonix/p5-Sys-Statistics-Linux Can you publish your code there? :-) Cheers, Jonny
Subject: Re: [rt.cpan.org #100259] new features to Sys::Statistics::Linux::SysInfo
Date: Sun, 30 Nov 2014 16:22:19 -0800
To: "bug-Sys-Statistics-Linux [...] rt.cpan.org" <bug-Sys-Statistics-Linux [...] rt.cpan.org>
From: "Alceu R. de Freitas Jr." <glasswalk3r [...] yahoo.com.br>
Done! Sent from Yahoo Mail on Android