]> 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:16:21 +0000 (20:16 +1000)
The previous PRETEND8CPUS #define was recently 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 5c10618318846c28a73c0587b54944c63f7a3d8a..d66c07804f6955157260c51f14f2694690e151d4 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -96,6 +96,9 @@ static CPU_t      *Cpu_tics;
 static int         Cpu_faux_tot;
 static float       Cpu_pmax;
 static const char *Cpu_States_fmts;
+#ifdef PRETEND48CPU
+static int         Cpu_true_tot;
+#endif
 
         /* Specific process id monitoring support */
 static pid_t Monpids [MONPIDMAX+1] = { 0 };
@@ -2553,7 +2556,9 @@ static void cpus_refresh (void) {
    for (i = 0; i < sumSLOT; i++) {
       CPU_t *cpu_ptr = &Cpu_tics[i];           // avoid gcc subscript bloat
 #ifdef PRETEND48CPU
-      bp = buf;
+      int j;
+      if (i == 0) j = 0; else ++j;
+      if (j >= Cpu_true_tot) { bp = buf; j = 0; }
 #endif
       bp = 1 + strchr(bp, '\n');
       // remember from last time around
@@ -3650,6 +3655,7 @@ static void before (char *me) {
    // establish cpu particulars
    cpuinfo();
 #ifdef PRETEND48CPU
+   Cpu_true_tot = smp_num_cpus;
    smp_num_cpus = 48;
 #endif
    Cpu_States_fmts = N_unq(STATE_lin2x4_fmt);
@@ -5975,7 +5981,11 @@ static void summary_show (void) {
             // display the node summary, then the associated cpus (if room)
             snprintf(tmp, sizeof(tmp), N_fmt(NUMA_nodenam_fmt), Numa_node_sel);
             Msg_row += cpu_tics(&Cpu_tics[1 + smp_num_cpus + Numa_node_sel], tmp, 1);
+#ifdef PRETEND48CPU
+            for (i = 0; i < Cpu_true_tot; i++) {
+#else
             for (i = 0; i < Cpu_faux_tot; i++) {
+#endif
                if (Numa_node_sel == Cpu_tics[i].node) {
                   if (!isROOM(anyFLG, 1)) break;
                   snprintf(tmp, sizeof(tmp), N_fmt(WORD_eachcpu_fmt), Cpu_tics[i].id);