This commit allows to specify (statically) the number of CPU's (ncpu). This allows to show the cpu usage relative to 1 CPU. So, when 1 cpu is busy, 100% is shown. 2 cpu's busy: 200%, and so on. At this point, the configuration of ncpu is static.
When no number is given (the backward compatible option), then slstatus thinks it only has 1 cpu and no scaling is done, like it used to be. Signed-off-by: Kurt Van Dijck <dev.k...@vandijck-laurijssen.be> --- config.def.h | 6 ++++++ slstatus.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/config.def.h b/config.def.h index 6370008..f099bd1 100644 --- a/config.def.h +++ b/config.def.h @@ -3,6 +3,12 @@ /* interval between updates (in ms) */ static const int interval = 1000; +/* number of CPU's to scale CPU usage for + * ideally, this number is detected repeatedly in runtime + * since it may even change ... + */ +static int ncpu = 1; + /* text to show if no value can be retrieved */ static const char unknown_str[] = "n/a"; diff --git a/slstatus.c b/slstatus.c index cddc79a..ef79b03 100644 --- a/slstatus.c +++ b/slstatus.c @@ -197,7 +197,7 @@ cpu_perc(void) perc = 100 * ((b[0]+b[1]+b[2]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[5]+a[6])) / ((b[0]+b[1]+b[2]+b[3]+b[4]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6])); - return bprintf("%d", perc); + return bprintf("%d", (ncpu?:1)*perc); } static const char * @@ -221,7 +221,7 @@ cpu_iowait(void) perc = 100 * ((b[4]) - (a[4])) / ((b[0]+b[1]+b[2]+b[3]+b[4]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6])); - return bprintf("%d", perc); + return bprintf("%d", (ncpu?:1)*perc); } static const char * -- 1.8.5.rc3