From 29ec1151436bd539dc659a394622cdd2d672f975 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 7 Sep 2020 11:53:58 +0200 Subject: [PATCH] Update IO rate display to use NAN on error --- Process.c | 2 +- linux/LinuxProcess.c | 13 ++++++++++--- linux/LinuxProcessList.c | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Process.c b/Process.c index 428e121f..839db8d7 100644 --- a/Process.c +++ b/Process.c @@ -219,7 +219,7 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c largeNumberColor = CRT_colors[PROCESS]; processMegabytesColor = CRT_colors[PROCESS]; } - if (rate == -1) { + if (isnan(rate)) { int len = snprintf(buffer, n, " no perm "); RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len); } else if (rate < ONE_K) { diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 9dd3b93d..ccdb9da8 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -17,6 +17,7 @@ in the source distribution for its full text. #include #include #include +#include /* 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 diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 8333da50..33248b50 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -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;