Skip Menu |

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

Report information
The Basics
Id: 67459
Status: resolved
Priority: 0/
Queue: Sys-Statistics-Linux

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

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



Subject: [PATCH] To add /proc/<pid>/io/* info to Sys/Statistics/Linux/Processes.pm
Hello and thank you for Sys::Statistics::Linux I needed to obtain the information found in /proc/<pid>/io/* and so patched Sys::Statistics::Linux::Process to do this. Would you consider adding this? Many thanks, Peter (Stig) Edwards Example data from raw() ... 'cminflt' => '0', 'io' => { 'write_bytes' => '0', 'syscw' => '0', 'read_bytes' => '0', 'wchar' => '0', 'syscr' => '103', 'cancelled_write_bytes' => '0', 'rchar' => '229317' }, 'cpu' => '3', ... Example data from get() ... 'cminflt' => '0.00', 'io' => { 'write_bytes' => '0.00', 'syscw' => '0.00', 'read_bytes' => '0.00', 'wchar' => '0.00', 'syscr' => '9.99', 'cancelled_write_bytes' => '0.00', 'rchar' => '1307.51' }, 'cpu' => '0', ... I have attached the patch (against Sys-Statistics-Linux- 0.59/lib/Sys/Statistics/Linux/Processes.pm), but also include it here: @@ -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', } ); @@ -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; @@ -389,6 +410,15 @@ } } } + + 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; @@ -439,6 +469,23 @@ } } $lpid->{ttime} = sprintf('%.2f', $lpid->{stime} + $lpid-> {utime}); + foreach my $k (qw(rchar wchar syscr syscw read_bytes write_bytes cancelled_write_bytes)) { + use Data::Dumper; + print Dumper($ipid); + if(defined $ipid->{'io'}->{$k} && defined $lpid->{'io'}- Show quoted text
>{$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 +498,18 @@ $lpid->{$k} = sprintf('%.2f', $lpid->{$k}); } } + + foreach 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'}- Show quoted text
>{$k} / $p_uptime);
+ } else { + $lpid->{'io'}->{$k} = sprintf('%.2f', $lpid->{'io'}- Show quoted text
>{$k});
+ } + } + $lpid->{ttime} = sprintf('%.2f', $lpid->{stime} + $lpid-> {utime}); $istat->{$pid}->{sttime} = $lpid->{sttime}; }
Subject: process_pm_patch.txt
@@ -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', } ); @@ -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; @@ -389,6 +410,15 @@ } } } + + 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; @@ -439,6 +469,23 @@ } } $lpid->{ttime} = sprintf('%.2f', $lpid->{stime} + $lpid->{utime}); + foreach my $k (qw(rchar wchar syscr syscw read_bytes write_bytes cancelled_write_bytes)) { + use Data::Dumper; + print Dumper($ipid); + 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 +498,18 @@ $lpid->{$k} = sprintf('%.2f', $lpid->{$k}); } } + + foreach 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}; }
Sorry, these 2 lines should be removed from the patch: use Data::Dumper; print Dumper($ipid);
Developer release 0.59_01 uploaded to CPAN. Please install and test it if it's available for download. Cheers
On Thu Apr 14 10:26:42 2011, BLOONIX wrote: Show quoted text
> Developer release 0.59_01 uploaded to CPAN. > > Please install and test it if it's available for download. > > Cheers
Thanks for the very quick response. I am testing 0.59_01, and raw() is working as I expected, but get() is not. I think because the: Show quoted text
> lines
below did not get added: sub _init { my $self = shift; my $class = ref $self; my $file = $self->{files}; my ($pids, %stats); $stats{time} = Time::HiRes::gettimeofday(); if ($self->{pids}) { $pids = $self->{pids}; } else { opendir my $pdir, $file->{path} or croak "$class: unable to open directory $file->{path} ($!)"; $pids = [(grep /^\d+\z/, readdir $pdir)]; closedir $pdir; } foreach my $pid (@$pids) { if (open my $fh, '<', "$file->{path}/$pid/$file->{stat}") { @{$stats{$pid}}{qw( minflt cminflt mayflt cmayflt utime stime cutime cstime sttime )} = (split /\s+/, <$fh>)[9..16,21]; close($fh); } else { delete $stats{$pid}; next; } Show quoted text
> 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; } Thanks.
It's fixed.
Thanks for the very quick response (again). I tested 0.59_02, and both raw() and get() are now working as I expected. Cheers.