From ef5750765f3285916bf367b40d380b6916d30abe Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sat, 30 May 2020 00:00:00 -0500 Subject: [PATCH] top: help the '#define PRETEND48CPU' be more realistic An old PRETEND8CPUS #define was reintroduced & changed to PRETEND48CPU to better exercise the new '4' and '!' toggles. But, the implementation simply duplicated the /proc/stat summary line for each cpu. Therefore, every cpu showed the same graph/detail (depending upon 't'). This patch shows the actual individual cpu information (duplicated, of course, when total cpus are exceeded). Signed-off-by: Jim Warner --- top/top.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/top/top.c b/top/top.c index d619639b..537e7b0e 100644 --- a/top/top.c +++ b/top/top.c @@ -5576,28 +5576,38 @@ numa_nope: Msg_row += cpu_tics(Stat_reap->summary, N_txt(WORD_allcpus_txt), 1); } else { // display each cpu's states separately, screen height permitting... +#ifdef PRETEND48CPU + if (w->rc.combine_cpus) { + int j; + for (i = 0, j = 0; i < Cpu_cnt; i++) { + Stat_reap->cpus->stacks[j]->head[stat_ID].result.s_int = i; + Msg_row += cpu_unify(Stat_reap->cpus->stacks[j], (i+1 >= Cpu_cnt)); + if (++j >= Stat_reap->cpus->total) j = 0; + if (!isROOM(anyFLG, 1)) break; + } + } else { + int j; + for (i = 0, j = 0; i < Cpu_cnt; i++) { + snprintf(tmp, sizeof(tmp), N_fmt(WORD_eachcpu_fmt), i); + Msg_row += cpu_tics(Stat_reap->cpus->stacks[j], tmp, (i+1 >= Cpu_cnt)); + if (++j >= Stat_reap->cpus->total) j = 0; + if (!isROOM(anyFLG, 1)) break; + } + } +#else if (w->rc.combine_cpus) { for (i = 0; i < Cpu_cnt; i++) { -#ifdef PRETEND48CPU - Stat_reap->summary->head[stat_ID].result.s_int = i; - Msg_row += cpu_unify(Stat_reap->summary, (i+1 >= Cpu_cnt)); -#else Msg_row += cpu_unify(Stat_reap->cpus->stacks[i], (i+1 >= Cpu_cnt)); -#endif if (!isROOM(anyFLG, 1)) break; } } else { for (i = 0; i < Cpu_cnt; i++) { -#ifdef PRETEND48CPU - snprintf(tmp, sizeof(tmp), N_fmt(WORD_eachcpu_fmt), i); - Msg_row += cpu_tics(Stat_reap->summary, tmp, (i+1 >= Cpu_cnt)); -#else snprintf(tmp, sizeof(tmp), N_fmt(WORD_eachcpu_fmt), CPU_VAL(stat_ID, i)); Msg_row += cpu_tics(Stat_reap->cpus->stacks[i], tmp, (i+1 >= Cpu_cnt)); -#endif if (!isROOM(anyFLG, 1)) break; } } +#endif } } // end: View_STATES