From a63e87996fd5a214ca7e7c511c713877d8d94300 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sat, 31 Mar 2018 10:15:04 +0200 Subject: [PATCH] pidstat: Report CPU usage for a process as the sum of all threads Commit 52977c4 introduced a new macro (SP_VALUE_100()) to limit CPU usage value displayed by pidstat to 100%. This was intended to be a workaround for some corner cases where inaccurate statistics could be provided by the kernel. Yet this macro also limits the value to 100% even when a process uses more than 100% of a core, e.g. when it starts several threads loading the system. This patch reverts commit 52977c4 and reports CPU usage for a process as the sum of CPU usage for all its threads. Signed-off-by: Sebastien GODARD --- common.h | 5 ----- pidstat.c | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/common.h b/common.h index 7fd2ca2..e9136fa 100644 --- a/common.h +++ b/common.h @@ -147,11 +147,6 @@ #define S_VALUE(m,n,p) (((double) ((n) - (m))) / (p) * 100) /* Define SP_VALUE() to normalize to % */ #define SP_VALUE(m,n,p) (((double) ((n) - (m))) / (p) * 100) -/* - * SP_VALUE_100() will not output value bigger than 100; this is needed for some - * corner cases, should be used with care. - */ -#define SP_VALUE_100(m,n,p) MINIMUM((((double) ((n) - (m))) / (p) * 100), 100.0) /* * Under very special circumstances, STDOUT may become unavailable. diff --git a/pidstat.c b/pidstat.c index 1c65d0f..d6e0435 100644 --- a/pidstat.c +++ b/pidstat.c @@ -1455,16 +1455,16 @@ int write_pid_task_all_stats(int prev, int curr, int dis, cprintf_pc(DISPLAY_UNIT(pidflag), 5, 7, 2, (pstc->utime - pstc->gtime) < (pstp->utime - pstp->gtime) ? 0.0 : - SP_VALUE_100(pstp->utime - pstp->gtime, + SP_VALUE(pstp->utime - pstp->gtime, pstc->utime - pstc->gtime, itv * HZ / 100), - SP_VALUE_100(pstp->stime, pstc->stime, itv * HZ / 100), - SP_VALUE_100(pstp->gtime, pstc->gtime, itv * HZ / 100), - SP_VALUE_100(pstp->wtime, pstc->wtime, itv * HZ / 100), + SP_VALUE(pstp->stime, pstc->stime, itv * HZ / 100), + SP_VALUE(pstp->gtime, pstc->gtime, itv * HZ / 100), + SP_VALUE(pstp->wtime, pstc->wtime, itv * HZ / 100), /* User time already includes guest time */ IRIX_MODE_OFF(pidflag) ? - SP_VALUE_100(pstp->utime + pstp->stime, + SP_VALUE(pstp->utime + pstp->stime, pstc->utime + pstc->stime, deltot_jiffies) : - SP_VALUE_100(pstp->utime + pstp->stime, + SP_VALUE(pstp->utime + pstp->stime, pstc->utime + pstc->stime, itv * HZ / 100)); cprintf_in(IS_INT, " %3d", "", pstc->processor); @@ -1666,16 +1666,16 @@ int write_pid_task_cpu_stats(int prev, int curr, int dis, int disp_avg, cprintf_pc(DISPLAY_UNIT(pidflag), 5, 7, 2, (pstc->utime - pstc->gtime) < (pstp->utime - pstp->gtime) ? 0.0 : - SP_VALUE_100(pstp->utime - pstp->gtime, + SP_VALUE(pstp->utime - pstp->gtime, pstc->utime - pstc->gtime, itv * HZ / 100), - SP_VALUE_100(pstp->stime, pstc->stime, itv * HZ / 100), - SP_VALUE_100(pstp->gtime, pstc->gtime, itv * HZ / 100), - SP_VALUE_100(pstp->wtime, pstc->wtime, itv * HZ / 100), + SP_VALUE(pstp->stime, pstc->stime, itv * HZ / 100), + SP_VALUE(pstp->gtime, pstc->gtime, itv * HZ / 100), + SP_VALUE(pstp->wtime, pstc->wtime, itv * HZ / 100), /* User time already includes guest time */ IRIX_MODE_OFF(pidflag) ? - SP_VALUE_100(pstp->utime + pstp->stime, + SP_VALUE(pstp->utime + pstp->stime, pstc->utime + pstc->stime, deltot_jiffies) : - SP_VALUE_100(pstp->utime + pstp->stime, + SP_VALUE(pstp->utime + pstp->stime, pstc->utime + pstc->stime, itv * HZ / 100)); if (!disp_avg) { -- 2.40.0