Update IO rate display to use NAN on error

This commit is contained in:
Benny Baumann
2020-09-07 11:53:58 +02:00
committed by cgzones
parent 47e2cefe02
commit 29ec115143
3 changed files with 13 additions and 6 deletions

View File

@ -17,6 +17,7 @@ in the source distribution for its full text.
#include <string.h>
#include <sys/syscall.h>
#include <time.h>
#include <math.h>
/* semi-global */
long long btime;
@ -237,9 +238,15 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
case IO_READ_RATE: Process_outputRate(str, buffer, n, lp->io_rate_read_bps, coloring); return;
case IO_WRITE_RATE: Process_outputRate(str, buffer, n, lp->io_rate_write_bps, coloring); return;
case IO_RATE: {
double totalRate = (lp->io_rate_read_bps != -1)
? (lp->io_rate_read_bps + lp->io_rate_write_bps)
: -1;
double totalRate = NAN;
if(!isnan(lp->io_rate_read_bps) && !isnan(lp->io_rate_write_bps))
totalRate = lp->io_rate_read_bps + lp->io_rate_write_bps;
else if(!isnan(lp->io_rate_read_bps))
totalRate = lp->io_rate_read_bps;
else if(!isnan(lp->io_rate_write_bps))
totalRate = lp->io_rate_write_bps;
else
totalRate = NAN;
Process_outputRate(str, buffer, n, totalRate, coloring); return;
}
#endif

View File

@ -331,8 +331,8 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
xSnprintf(filename, MAX_NAME, "%s/%s/io", dirname, name);
int fd = open(filename, O_RDONLY);
if (fd == -1) {
process->io_rate_read_bps = -1;
process->io_rate_write_bps = -1;
process->io_rate_read_bps = NAN;
process->io_rate_write_bps = NAN;
process->io_rchar = -1LL;
process->io_wchar = -1LL;
process->io_syscr = -1LL;