added a warning if a process vanished during the accouting in 'process.pm'

This commit is contained in:
Jordi Sanfeliu 2019-04-12 09:06:36 +02:00
parent 2b578d626d
commit 2c4e1ae855
1 changed files with 20 additions and 16 deletions

View File

@ -162,7 +162,7 @@ sub process_update {
my $ics = 0; my $ics = 0;
my $str; my $str;
my @pid; my @pids;
my $p = trim($lp[$n] || ""); my $p = trim($lp[$n] || "");
my $val; my $val;
my $s_usage = 0; my $s_usage = 0;
@ -172,23 +172,23 @@ sub process_update {
while(<IN>) { while(<IN>) {
if(m/^\s*(\d+)\s+(\S+)\s+(.*?)$/) { if(m/^\s*(\d+)\s+(\S+)\s+(.*?)$/) {
if($p eq trim($2)) { if($p eq trim($2)) {
push(@pid, $1); push(@pids, $1);
$pro++; $pro++;
next; next;
} }
if($p eq trim($3)) { if($p eq trim($3)) {
push(@pid, $1); push(@pids, $1);
$pro++; $pro++;
next; next;
} }
if(index($3, $p) != -1) { if(index($3, $p) != -1) {
push(@pid, $1); push(@pids, $1);
$pro++; $pro++;
next; next;
} }
} }
if(substr($p, 0, 15) eq substr($_, 6, 15)) { if(substr($p, 0, 15) eq substr($_, 6, 15)) {
push(@pid, $1); push(@pids, $1);
$pro++; $pro++;
next; next;
} }
@ -208,8 +208,8 @@ sub process_update {
} }
my $p_usage = 0; my $p_usage = 0;
foreach my $p (@pid) { foreach my $pid (@pids) {
if(open(IN, "/proc/$p/stat")) { if(open(IN, "/proc/$pid/stat")) {
my $utime = 0; my $utime = 0;
my $stime = 0; my $stime = 0;
my $v_nth = 0; my $v_nth = 0;
@ -219,11 +219,15 @@ sub process_update {
# since a process name can include spaces an 'split(' ', <IN>)' wouldn't work here, # since a process name can include spaces an 'split(' ', <IN>)' wouldn't work here,
# therefore we discard the first part of the process information (pid, comm and state). # therefore we discard the first part of the process information (pid, comm and state).
(undef, $rest) = <IN> =~ m/^(\d+\s\(.*?\)\s\S\s)(.*?)$/; (undef, $rest) = <IN> =~ m/^(\d+\s\(.*?\)\s\S\s)(.*?)$/;
(undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $utime, $stime, undef, undef, undef, undef, $v_nth, undef, undef, undef, $v_mem) = split(' ', $rest);
close(IN); close(IN);
$mem += ($v_mem *= 4096); if($rest) {
$nth += ($v_nth - 1); (undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $utime, $stime, undef, undef, undef, undef, $v_nth, undef, undef, undef, $v_mem) = split(' ', $rest);
$p_usage += $utime + $stime; $mem += ($v_mem *= 4096);
$nth += ($v_nth - 1);
$p_usage += $utime + $stime;
} else {
logger("$myself: WARNING: PID $pid ('$p') has vanished while accounting!");
}
} }
} }
$str = $e . "_cpu" . $n; $str = $e . "_cpu" . $n;
@ -233,8 +237,8 @@ sub process_update {
my $v_dsk = 0; my $v_dsk = 0;
my $v_net = 0; my $v_net = 0;
foreach my $p (@pid) { foreach my $pid (@pids) {
if(open(IN, "/proc/$p/io")) { if(open(IN, "/proc/$pid/io")) {
my $rchar = 0; my $rchar = 0;
my $wchar = 0; my $wchar = 0;
my $readb = 0; my $readb = 0;
@ -264,14 +268,14 @@ sub process_update {
my $v_vcs = 0; my $v_vcs = 0;
my $v_ics = 0; my $v_ics = 0;
foreach my $p (@pid) { foreach my $pid (@pids) {
if(opendir(DIR, "/proc/$p/fdinfo")) { if(opendir(DIR, "/proc/$pid/fdinfo")) {
my @files = grep { !/^[.]/ } readdir(DIR); my @files = grep { !/^[.]/ } readdir(DIR);
$nof += scalar(@files); $nof += scalar(@files);
closedir(DIR); closedir(DIR);
} }
if(open(IN, "/proc/$p/status")) { if(open(IN, "/proc/$pid/status")) {
while(<IN>) { while(<IN>) {
if(/^voluntary_ctxt_switches:\s+(\d+)$/) { if(/^voluntary_ctxt_switches:\s+(\d+)$/) {
$v_vcs += $1; $v_vcs += $1;