]> granicus.if.org Git - procps-ng/commitdiff
top: help the '#define PRETEND48CPU' be more realistic
authorJim Warner <james.warner@comcast.net>
Sat, 30 May 2020 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Thu, 4 Jun 2020 10:19:03 +0000 (20:19 +1000)
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 <james.warner@comcast.net>
top/top.c

index d619639b2a917d0a7750f49b948a06331f84d9f2..537e7b0e159687e4e577b7416412dabcbfc68072 100644 (file)
--- 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...
-         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));
+         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++) {
                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