top: do not use previous colleced data wheh "h" toggles threads display
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 11 Aug 2019 14:17:11 +0000 (16:17 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 11 Aug 2019 14:17:11 +0000 (16:17 +0200)
This prevents first update from showing incorrect CPU usage data

function                                             old     new   delta
handle_input                                         620     643     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
procps/top.c

index 8fe53324f53d6b1fc66fb54fad4fecff2a8d619f..5c41e8e10a8b2b29e80167602db69ea8ad8e72db 100644 (file)
@@ -979,6 +979,9 @@ static unsigned handle_input(unsigned scan_mask, duration_t interval)
                IF_FEATURE_TOPMEM(&& scan_mask != TOPMEM_MASK)
                ) {
                        scan_mask ^= PSSCAN_TASKS;
+                       free(prev_hist);
+                       prev_hist = NULL;
+                       prev_hist_count = 0;
                        continue;
                }
 # endif
@@ -1000,10 +1003,10 @@ static unsigned handle_input(unsigned scan_mask, duration_t interval)
 #  if ENABLE_FEATURE_TOPMEM
                if (c == 's') {
                        scan_mask = TOPMEM_MASK;
+                       sort_field = (sort_field + 1) % NUM_SORT_FIELD;
                        free(prev_hist);
                        prev_hist = NULL;
                        prev_hist_count = 0;
-                       sort_field = (sort_field + 1) % NUM_SORT_FIELD;
                        continue;
                }
 #  endif