From b73a423cc2d3426f4820d519acb95adaac7d5444 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Mon, 9 Jan 2012 11:26:45 -0600 Subject: [PATCH] top: avoid %cpu distortions when toggling task/thread modes 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 | 10 ++++++---- top/top.h | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/top/top.c b/top/top.c index 0b065eda..ae059657 100644 --- 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); diff --git a/top/top.h b/top/top.h index c8d2fc83..2bd488f4 100644 --- a/top/top.h +++ b/top/top.h @@ -127,6 +127,10 @@ #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 ############################################ */