r76285 - in /branches/upstream/libsys-statistics-linux-perl/current: ChangeLog MANIFEST META.yml README examples/processes.pl examples/processes.pm examples/pstop.pl lib/Sys/Statistics/Linux.pm lib/Sys/Statistics/Linux/Processes.pm

carnil at users.alioth.debian.org carnil at users.alioth.debian.org
Wed Jun 22 21:15:11 UTC 2011


Author: carnil
Date: Wed Jun 22 21:15:09 2011
New Revision: 76285

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=76285
Log:
[svn-upgrade] new version libsys-statistics-linux-perl (0.60)

Added:
    branches/upstream/libsys-statistics-linux-perl/current/examples/processes.pl   (with props)
    branches/upstream/libsys-statistics-linux-perl/current/examples/pstop.pl
Removed:
    branches/upstream/libsys-statistics-linux-perl/current/examples/processes.pm
Modified:
    branches/upstream/libsys-statistics-linux-perl/current/ChangeLog
    branches/upstream/libsys-statistics-linux-perl/current/MANIFEST
    branches/upstream/libsys-statistics-linux-perl/current/META.yml
    branches/upstream/libsys-statistics-linux-perl/current/README
    branches/upstream/libsys-statistics-linux-perl/current/lib/Sys/Statistics/Linux.pm
    branches/upstream/libsys-statistics-linux-perl/current/lib/Sys/Statistics/Linux/Processes.pm

Modified: branches/upstream/libsys-statistics-linux-perl/current/ChangeLog
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsys-statistics-linux-perl/current/ChangeLog?rev=76285&op=diff
==============================================================================
--- branches/upstream/libsys-statistics-linux-perl/current/ChangeLog (original)
+++ branches/upstream/libsys-statistics-linux-perl/current/ChangeLog Wed Jun 22 21:15:09 2011
@@ -1,3 +1,12 @@
+0.60    Released at 2011-06-22.
+        - Just a full release. Have fun :-)
+
+0.59_02 Released at 2011-04-16.
+        - Fixed a little bug in Processes.pm (_init).
+
+0.59_01 Released at 2011-04-14.
+        - Added statistics from /proc/pid/io to Processes.pm. See RT #67459.
+
 0.59    Released at 2010-09-28.
         - Added key "arch" to SysInfo.pm.
 

Modified: branches/upstream/libsys-statistics-linux-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsys-statistics-linux-perl/current/MANIFEST?rev=76285&op=diff
==============================================================================
--- branches/upstream/libsys-statistics-linux-perl/current/MANIFEST (original)
+++ branches/upstream/libsys-statistics-linux-perl/current/MANIFEST Wed Jun 22 21:15:09 2011
@@ -2,7 +2,8 @@
 ChangeLog
 examples/diskusage.pl
 examples/loadavg.pl
-examples/processes.pm
+examples/processes.pl
+examples/pstop.pl
 INSTALL
 lib/Sys/Statistics/Linux.pm
 lib/Sys/Statistics/Linux/Compilation.pm

Modified: branches/upstream/libsys-statistics-linux-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsys-statistics-linux-perl/current/META.yml?rev=76285&op=diff
==============================================================================
--- branches/upstream/libsys-statistics-linux-perl/current/META.yml (original)
+++ branches/upstream/libsys-statistics-linux-perl/current/META.yml Wed Jun 22 21:15:09 2011
@@ -1,24 +1,19 @@
 ---
+abstract: 'Front-end module to collect system statistics'
+author:
+  - 'Jonny Schulz'
+configure_requires:
+  Module::Build: 0.36
+generated_by: 'Module::Build version 0.3607'
+license: perl
+meta-spec:
+  url: http://module-build.sourceforge.net/META-spec-v1.4.html
+  version: 1.4
 name: Sys-Statistics-Linux
-version: 0.59
-author:
-  - Jonny Schulz
-abstract: Front-end module to collect system statistics
-license: perl
-resources:
-  license: http://dev.perl.org/licenses/
-requires:
-  Carp: 0
-  POSIX: 0
-  Test::More: 0
-  Time::HiRes: 0
-  UNIVERSAL: 0
-recommends:
-  YAML::Syck: 0
 provides:
   Sys::Statistics::Linux:
     file: lib/Sys/Statistics/Linux.pm
-    version: 0.59
+    version: 0.60
   Sys::Statistics::Linux::Compilation:
     file: lib/Sys/Statistics/Linux/Compilation.pm
     version: 0.10
@@ -51,14 +46,21 @@
     version: 0.20
   Sys::Statistics::Linux::Processes:
     file: lib/Sys/Statistics/Linux/Processes.pm
-    version: 0.32
+    version: 0.34
   Sys::Statistics::Linux::SockStats:
     file: lib/Sys/Statistics/Linux/SockStats.pm
     version: 0.09
   Sys::Statistics::Linux::SysInfo:
     file: lib/Sys/Statistics/Linux/SysInfo.pm
     version: 0.13
-generated_by: Module::Build version 0.280801
-meta-spec:
-  url: http://module-build.sourceforge.net/META-spec-v1.2.html
-  version: 1.2
+recommends:
+  YAML::Syck: 0
+requires:
+  Carp: 0
+  POSIX: 0
+  Test::More: 0
+  Time::HiRes: 0
+  UNIVERSAL: 0
+resources:
+  license: http://dev.perl.org/licenses/
+version: 0.60

Modified: branches/upstream/libsys-statistics-linux-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsys-statistics-linux-perl/current/README?rev=76285&op=diff
==============================================================================
--- branches/upstream/libsys-statistics-linux-perl/current/README (original)
+++ branches/upstream/libsys-statistics-linux-perl/current/README Wed Jun 22 21:15:09 2011
@@ -48,7 +48,7 @@
     long time ago) on kernel versions 2.4 and/or 2.6. It's possible that it
     doesn't run on all linux distributions if some procfs features are
     deactivated or too much modified. As example the linux kernel 2.4 can
-    compiled with the option "CONFIG_BLK_STATS" what turn on or off block
+    compiled with the option `CONFIG_BLK_STATS' what turn on or off block
     statistics for devices.
 
     Don't give up if some of the modules doesn't run on your hardware! Tell
@@ -56,9 +56,9 @@
     first move and to send me a mail. :-)
 
 VIRTUAL MACHINES
-    Note that if you try to install or run "Sys::Statistics::Linux" under
+    Note that if you try to install or run `Sys::Statistics::Linux' under
     virtual machines on guest systems that some statistics are not
-    available, such as "SockStats", "PgSwStats" and "DiskStats". The reason
+    available, such as `SockStats', `PgSwStats' and `DiskStats'. The reason
     is that not all /proc data are passed to the guests.
 
     If the installation fails then try to force the installation with
@@ -69,24 +69,24 @@
     available on the virtual machine - sorry.
 
 DELTAS
-    The statistics for "CpuStats", "ProcStats", "PgSwStats", "NetStats",
-    "DiskStats" and "Processes" are deltas, for this reason it's necessary
-    to initialize the statistics before the data can be prepared by "get()".
-    These statistics can be initialized with the methods "new()", "set()"
-    and "init()". For any option that is set to 1, the statistics will be
-    initialized by the call of "new()" or "set()". The call of init()
+    The statistics for `CpuStats', `ProcStats', `PgSwStats', `NetStats',
+    `DiskStats' and `Processes' are deltas, for this reason it's necessary
+    to initialize the statistics before the data can be prepared by `get()'.
+    These statistics can be initialized with the methods `new()', `set()'
+    and `init()'. For any option that is set to 1, the statistics will be
+    initialized by the call of `new()' or `set()'. The call of init()
     re-initialize all statistics that are set to 1 or 2. By the call of
-    "get()" the initial statistics will be updated automatically. Please
-    refer the section "METHODS" to get more information about the usage of
-    "new()", "set()", "init()" and "get()".
+    `get()' the initial statistics will be updated automatically. Please
+    refer the section METHODS to get more information about the usage of
+    `new()', `set()', `init()' and `get()'.
 
     Another exigence is to sleep for a while - at least for one second -
-    before the call of "get()" if you want to get useful statistics. The
-    statistics for "SysInfo", "MemStats", "SockStats", "DiskUsage",
-    "LoadAVG" and "FileStats" are no deltas. If you need only one of these
-    information you don't need to sleep before the call of "get()".
-
-    The method "get()" prepares all requested statistics and returns the
+    before the call of `get()' if you want to get useful statistics. The
+    statistics for `SysInfo', `MemStats', `SockStats', `DiskUsage',
+    `LoadAVG' and `FileStats' are no deltas. If you need only one of these
+    information you don't need to sleep before the call of `get()'.
+
+    The method `get()' prepares all requested statistics and returns the
     statistics as a Sys::Statistics::Linux::Compilation object. The inital
     statistics will be updated.
 
@@ -101,8 +101,8 @@
 OPTIONS
     All options are identical with the package names of the distribution in
     lowercase. To activate the gathering of statistics you have to set the
-    options by the call of "new()" or "set()". In addition you can
-    deactivate statistics with "set()".
+    options by the call of `new()' or `set()'. In addition you can
+    deactivate statistics with `set()'.
 
     The options must be set with one of the following values:
 
@@ -123,7 +123,7 @@
             },
         );
 
-    Option "initfile" is useful if you want to store initial statistics on
+    Option `initfile' is useful if you want to store initial statistics on
     the filesystem.
 
         my $lxs = Sys::Statistics::Linux->new(
@@ -200,9 +200,9 @@
 
 METHODS
   new()
-    Call "new()" to create a new Sys::Statistics::Linux object. You can call
-    "new()" with options. This options would be passed to the method
-    "set()".
+    Call `new()' to create a new Sys::Statistics::Linux object. You can call
+    `new()' with options. This options would be passed to the method
+    `set()'.
 
     Without options
 
@@ -216,7 +216,7 @@
 
         my $lxs = Sys::Statistics::Linux->new( cpustats => 0 );
 
-    It's possible to call "new()" with a hash reference of options.
+    It's possible to call `new()' with a hash reference of options.
 
         my %options = (
             cpustats => 1,
@@ -226,11 +226,11 @@
         my $lxs = Sys::Statistics::Linux->new(\%options);
 
   set()
-    Call "set()" to activate or deactivate options.
-
-    The following example would call "new()" and initialize
-    "Sys::Statistics::Linux::CpuStats" and delete the object of
-    "Sys::Statistics::Linux::SysInfo".
+    Call `set()' to activate or deactivate options.
+
+    The following example would call `new()' and initialize
+    `Sys::Statistics::Linux::CpuStats' and delete the object of
+    `Sys::Statistics::Linux::SysInfo'.
 
         $lxs->set(
             processes =>  0, # deactivate this statistic
@@ -238,7 +238,7 @@
             netstats  =>  2, # activate the statistic and call new() if necessary but not init()
         );
 
-    It's possible to call "set()" with a hash reference of options.
+    It's possible to call `set()' with a hash reference of options.
 
         my %options = (
             cpustats => 2,
@@ -248,14 +248,14 @@
         $lxs->set(\%options);
 
   get()
-    Call "get()" to get the collected statistics. "get()" returns a
+    Call `get()' to get the collected statistics. `get()' returns a
     Sys::Statistics::Linux::Compilation object.
 
         my $lxs  = Sys::Statistics::Linux->new(\%options);
         sleep(1);
         my $stat = $lxs->get();
 
-    Or you can pass the time to sleep with the call of "get()".
+    Or you can pass the time to sleep with the call of `get()'.
 
         my $stat = $lxs->get($time_to_sleep);
 
@@ -271,10 +271,10 @@
     for more information.
 
   init()
-    The call of "init()" initiate all activated statistics that are
+    The call of `init()' initiate all activated statistics that are
     necessary for deltas. That could be helpful if your script runs in a
     endless loop with a high sleep interval. Don't forget that if you call
-    "get()" that the statistics are deltas since the last time they were
+    `get()' that the statistics are deltas since the last time they were
     initiated.
 
     The following example would calculate average statistics for 30 minutes:
@@ -315,19 +315,19 @@
         }
 
   settime()
-    Call "settime()" to define a POSIX formatted time stamp, generated with
+    Call `settime()' to define a POSIX formatted time stamp, generated with
     localtime().
 
         $lxs->settime('%Y/%m/%d %H:%M:%S');
 
-    To get more information about the formats take a look at "strftime()" of
-    POSIX.pm or the manpage strftime(3).
+    To get more information about the formats take a look at `strftime()' of
+    POSIX.pm or the manpage `strftime(3)'.
 
   gettime()
-    "gettime()" returns a POSIX formatted time stamp, @foo in list and $bar
+    `gettime()' returns a POSIX formatted time stamp, @foo in list and $bar
     in scalar context. If the time format isn't set then the default format
     "%Y-%m-%d %H:%M:%S" will be set automatically. You can also set a time
-    format with "gettime()".
+    format with `gettime()'.
 
         my $date_time = $lxs->gettime;
 
@@ -370,7 +370,7 @@
         print $lxs->gettime, "\n";
 
     If you want to know how the data structure looks like you can use
-    "Data::Dumper" to check it:
+    `Data::Dumper' to check it:
 
         use strict;
         use warnings;
@@ -398,7 +398,7 @@
     The old options and keys - CpuStats, NetStats, etc - are still available
     but deprecated! It's not possible to access the statistics via
     Sys::Statistics::Linux::Compilation and it's not possible to call
-    "search()" and "psfind()" if you use the old options.
+    `search()' and `psfind()' if you use the old options.
 
     You should use the new options and access the statistics over the
     accessors

Added: branches/upstream/libsys-statistics-linux-perl/current/examples/processes.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsys-statistics-linux-perl/current/examples/processes.pl?rev=76285&op=file
==============================================================================
--- branches/upstream/libsys-statistics-linux-perl/current/examples/processes.pl (added)
+++ branches/upstream/libsys-statistics-linux-perl/current/examples/processes.pl Wed Jun 22 21:15:09 2011
@@ -1,0 +1,19 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Data::Dumper;
+use Sys::Statistics::Linux;
+use Sys::Statistics::Linux::Processes;
+
+# the default value for the following keys are pages:
+#   size, resident, share, trs, drs, lrs, dtp
+#
+# set PAGES_TO_BYTES to the pagesize of your system if
+# you want bytes instead of pages
+$Sys::Statistics::Linux::Processes::PAGES_TO_BYTES = 4096;
+
+my $sys  = Sys::Statistics::Linux->new(processes => 1);
+sleep 1;
+my $stat = $sys->get();
+
+print Dumper($stat->{processes});

Propchange: branches/upstream/libsys-statistics-linux-perl/current/examples/processes.pl
------------------------------------------------------------------------------
    svn:executable = *

Added: branches/upstream/libsys-statistics-linux-perl/current/examples/pstop.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsys-statistics-linux-perl/current/examples/pstop.pl?rev=76285&op=file
==============================================================================
--- branches/upstream/libsys-statistics-linux-perl/current/examples/pstop.pl (added)
+++ branches/upstream/libsys-statistics-linux-perl/current/examples/pstop.pl Wed Jun 22 21:15:09 2011
@@ -1,0 +1,82 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Getopt::Long;
+use Sys::Statistics::Linux;
+
+my $o_file  = ();
+my $o_help  = ();
+my %pstop   = ();
+my $fh      = ();
+my $format  = "%6s %-8s %5s %5s %5s %1s %4s %5s %12s %s";
+my $time    = qx{date};
+
+GetOptions(
+    "f|file=s" => \$o_file,
+    "h|help"   => \$o_help,
+);
+
+if ($o_help) {
+    print "\nUsage: $0 [ OPTIONS ]\n\n";
+    print "-f, --file <file>\n";
+    print "    Print the output to a file instead to STDOUT.\n";
+    print "-h, --help\n";
+    print "    Print the help and exit.\n\n";
+    exit 0;
+}
+
+my $sys  = Sys::Statistics::Linux->new(
+    memstats  => 1,
+    processes => {
+        init => 1,
+        pages_to_bytes => 4,
+    },
+);
+
+my $stat = $sys->get(1);
+
+%pstop = map { $_ => 1 }
+    $stat->pstop(ttime => 10),
+    $stat->pstop(resident => 10),
+    $stat->psfind({state => qr/[DR]/});
+
+if ($o_file) {
+    open $fh, ">>", $o_file
+        or die "unable to open '$o_file'";
+} else {
+    $fh = \*STDOUT;
+}
+
+print $fh "$time\n";
+printf $fh "$format\n",
+    qw(PID USER VIRT RES SHR S %CPU %MEM TIME COMMAND);
+
+foreach my $pid (keys %pstop) {
+    my $vsize = $stat->processes($pid => "vsize");
+    my $res   = $stat->processes($pid => "resident");
+    my $share = $stat->processes($pid => "share");
+    my $owner = substr($stat->processes($pid => "owner"), 0, 8);
+    my $size  = sprintf("%.1f", $stat->processes($pid => "resident") * 100 / $stat->memstats->{memtotal});
+
+    foreach my $s ($vsize) {
+        if ($s > 9999) {
+            $s = int($s / 1024 / 1024) . "M";
+        }
+    }
+
+    foreach my $s ($res, $share) {
+        if ($s > 9999) {
+            $s = int($s / 1024) . "M";
+        }
+    }
+
+    printf $fh "$format\n",
+        $pid, $owner, $vsize, $res, $share,
+        $stat->processes($pid => "state"),
+        int($stat->processes($pid => "ttime")),
+        $size, $stat->processes($pid => "actime"),
+        $stat->processes($pid => "cmd");
+}
+
+print $fh "\n";
+

Modified: branches/upstream/libsys-statistics-linux-perl/current/lib/Sys/Statistics/Linux.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsys-statistics-linux-perl/current/lib/Sys/Statistics/Linux.pm?rev=76285&op=diff
==============================================================================
--- branches/upstream/libsys-statistics-linux-perl/current/lib/Sys/Statistics/Linux.pm (original)
+++ branches/upstream/libsys-statistics-linux-perl/current/lib/Sys/Statistics/Linux.pm Wed Jun 22 21:15:09 2011
@@ -433,7 +433,7 @@
 =cut
 
 package Sys::Statistics::Linux;
-our $VERSION = '0.59';
+our $VERSION = '0.60';
 
 use strict;
 use warnings;

Modified: branches/upstream/libsys-statistics-linux-perl/current/lib/Sys/Statistics/Linux/Processes.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsys-statistics-linux-perl/current/lib/Sys/Statistics/Linux/Processes.pm?rev=76285&op=diff
==============================================================================
--- branches/upstream/libsys-statistics-linux-perl/current/lib/Sys/Statistics/Linux/Processes.pm (original)
+++ branches/upstream/libsys-statistics-linux-perl/current/lib/Sys/Statistics/Linux/Processes.pm Wed Jun 22 21:15:09 2011
@@ -80,6 +80,18 @@
     # or with
     Sys::Statistics::Linux::Processes->new(pages_to_bytes => 4096);
 
+Generated by F</proc/E<lt>pidE<gt>/io>.
+
+    rchar                 -  Bytes read from storage (might have been from pagecache).
+    wchar                 -  Bytes written.
+    syscr                 -  Number of read syscalls.
+    syscw                 -  Numner of write syscalls.
+    read_bytes            -  Bytes really fetched from storage layer.
+    write_bytes           -  Bytes sent to the storage layer.
+    cancelled_write_bytes -  Refer to docs.
+
+See Documentation/filesystems/proc.txt for more (from kernel 2.6.20)
+
 =head1 METHODS
 
 =head2 new()
@@ -105,6 +117,7 @@
             cmdline => 'cmdline',
             wchan   => 'wchan',
             fd      => 'fd',
+            io      => 'io',
         }
     );
 
@@ -165,7 +178,7 @@
 use Time::HiRes;
 use constant NUMBER => qr/^-{0,1}\d+(?:\.\d+){0,1}\z/;
 
-our $VERSION = '0.32';
+our $VERSION = '0.34';
 our $PAGES_TO_BYTES = 0;
 
 sub new {
@@ -182,6 +195,7 @@
             cmdline => 'cmdline',
             wchan   => 'wchan',
             fd      => 'fd',
+            io      => 'io',
         },
     );
 
@@ -267,6 +281,13 @@
             delete $stats{$pid};
             next;
         }
+        if (open my $fh, '<', "$file->{path}/$pid/$file->{io}") {
+            while (my $line = <$fh>) {
+                next unless $line =~ /^([a-z_]+): (\d+)/;
+                $stats{$pid}{io}{$1} = $2;
+            }
+            close($fh);
+        }
     }
 
     return \%stats;
@@ -295,6 +316,14 @@
     }
 
     PID: foreach my $pid (@$pids) {
+
+        if (open my $fh, '<', "$file->{path}/$pid/$file->{io}") {
+            while (my $line = <$fh>) {
+                next unless $line =~ /^([a-z_]+):\s+(\d+)/;
+                $stats{$pid}{io}{$1} = $2;
+            }
+            close($fh);
+        }
 
         # memory usage for each process
         if (open my $fh, '<', "$file->{path}/$pid/$file->{statm}") {
@@ -438,7 +467,23 @@
                     $lpid->{$k} = sprintf('%.2f', $lpid->{$k});
                 }
             }
+
             $lpid->{ttime} = sprintf('%.2f', $lpid->{stime} + $lpid->{utime});
+
+            for my $k (qw(rchar wchar syscr syscw read_bytes write_bytes cancelled_write_bytes)) {
+                if(defined $ipid->{io}->{$k} && defined $lpid->{io}->{$k}){
+                    if($ipid->{io}->{$k} !~ NUMBER || $lpid->{io}->{$k} !~ NUMBER){
+                        croak "$class: invalid value for io key '$k'";
+                    }
+                    $lpid->{io}->{$k} -= $ipid->{io}->{$k};
+                    $ipid->{io}->{$k} += $lpid->{io}->{$k};
+                    if ($lpid->{io}->{$k} > 0 && $time > 0) { 
+                        $lpid->{io}->{$k} = sprintf('%.2f', $lpid->{io}->{$k} / $time);
+                    } else {
+                        $lpid->{io}->{$k} = sprintf('%.2f', $lpid->{io}->{$k});
+                    }
+                }
+            }
         } else {
             # calculate the statistics since process creation
             for my $k (qw(minflt cminflt mayflt cmayflt utime stime cutime cstime)) {
@@ -451,6 +496,18 @@
                     $lpid->{$k} = sprintf('%.2f', $lpid->{$k});
                 }
             }
+
+            for my $k (qw(rchar wchar syscr syscw read_bytes write_bytes cancelled_write_bytes)) {
+                my $p_uptime = $uptime - $lpid->{sttime} / 100;
+                $istat->{$pid}->{io}->{$k} = $lpid->{io}->{$k};
+
+                if ($p_uptime > 0) {
+                    $lpid->{io}->{$k} = sprintf('%.2f', $lpid->{io}->{$k} / $p_uptime);
+                } else {
+                    $lpid->{io}->{$k} = sprintf('%.2f', $lpid->{io}->{$k});
+                }
+            }
+
             $lpid->{ttime} = sprintf('%.2f', $lpid->{stime} + $lpid->{utime});
             $istat->{$pid}->{sttime} = $lpid->{sttime};
         }




More information about the Pkg-perl-cvs-commits mailing list