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};
}