]> granicus.if.org Git - procps-ng/commitdiff
top: avoid %cpu distortions when toggling task/thread modes
authorJim Warner <james.warner@comcast.net>
Mon, 9 Jan 2012 17:26:45 +0000 (11:26 -0600)
committerCraig Small <csmall@enc.com.au>
Fri, 13 Jan 2012 13:04:46 +0000 (00:04 +1100)
This commit addresses a long standing buglet (debian #441166) which
surfaces when the display mode is switched between task and threads.

An extra procps refresh is now forced upon such a transition which
parallels the approach used at startup for the exact same reason.

Reference: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=441166

top/top.c
top/top.h

index 0b065eda10013490c8e6d679a39dc601467c28bf..ae0596571cfbecede295aff9dbd066a6bc2ef370 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -138,7 +138,7 @@ static int   Cap_can_goto = 0;
            The Stdout_buf is transparent to our code and regardless of whose
            buffer is used, stdout is flushed at frame end or if interactive. */
 static char  *Pseudo_screen;
-static int    Pseudo_row = -1;
+static int    Pseudo_row = PROC_XTRA;
 static size_t Pseudo_size;
 #ifndef OFF_STDIOLBF
         // less than stdout's normal buffer but with luck mostly '\n' anyway
@@ -2793,6 +2793,8 @@ static void keys_global (int ch) {
          if (!CHKw(w, View_STATES))
             show_msg(fmtmk(N_fmt(THREADS_show_fmt)
                , Thread_mode ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)));
+         // force an extra procs refresh to avoid %cpu distortions...
+         Pseudo_row = PROC_XTRA;
          break;
       case 'I':
          if (Cpu_tot > 1) {
@@ -3717,11 +3719,11 @@ static void frame_make (void) {
    if (Frames_paused) pause_pgm();
    if (Frames_resize) zap_fieldstab();
 
-   // whoa first time, gotta' prime the pump...
-   if (-1 == Pseudo_row) {
+   // whoa either first time or thread/task mode change, (re)prime the pump...
+   if (Pseudo_row == PROC_XTRA) {
       procs_refresh();
-      putp(Cap_clr_scr);
       usleep(LIB_USLEEP);
+      putp(Cap_clr_scr);
    } else
       putp(Batch ? "\n\n" : Cap_home);
 
index c8d2fc8300c89967079318168ad903726abf645e..2bd488f45fdf3e0298a18b492d1513edf34f0e04 100644 (file)
--- a/top/top.h
+++ b/top/top.h
 #define kbd_INS    '\x8a'
 #define kbd_DEL    '\x8b'
 
+        /* Special value in Pseudo_row to force an additional procs refresh
+           -- used at startup and for task/thread mode transitions */
+#define PROC_XTRA  -1
+
 
 /* #####  Enum's and Typedef's  ############################################ */