top: make sort field for 's' mode less confusing

function                                             old     new   delta
display_topmem_process_list                          542     565     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2015-10-14 22:29:52 +02:00
parent 926d801fa5
commit 4ad702c0a7

View File

@ -829,10 +829,17 @@ static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width)
#define HDR_STR " PID VSZ VSZRW RSS (SHR) DIRTY (SHR) STACK" #define HDR_STR " PID VSZ VSZRW RSS (SHR) DIRTY (SHR) STACK"
#define MIN_WIDTH sizeof(HDR_STR) #define MIN_WIDTH sizeof(HDR_STR)
const topmem_status_t *s = topmem + G_scroll_ofs; const topmem_status_t *s = topmem + G_scroll_ofs;
char *cp, ch;
display_topmem_header(scr_width, &lines_rem); display_topmem_header(scr_width, &lines_rem);
strcpy(line_buf, HDR_STR " COMMAND"); strcpy(line_buf, HDR_STR " COMMAND");
line_buf[11 + sort_field * 6] = "^_"[inverted]; /* Mark the ^FIELD^ we sort by */
cp = &line_buf[5 + sort_field * 6];
ch = "^_"[inverted];
cp[6] = ch;
do *cp++ = ch; while (*cp == ' ');
printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf); printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf);
lines_rem--; lines_rem--;
@ -1172,10 +1179,8 @@ int top_main(int argc UNUSED_PARAM, char **argv)
ntop = 0; ntop = 0;
while ((p = procps_scan(p, scan_mask)) != NULL) { while ((p = procps_scan(p, scan_mask)) != NULL) {
int n; int n;
#if ENABLE_FEATURE_TOPMEM
if (scan_mask != TOPMEM_MASK) IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) {
#endif
{
n = ntop; n = ntop;
top = xrealloc_vector(top, 6, ntop++); top = xrealloc_vector(top, 6, ntop++);
top[n].pid = p->pid; top[n].pid = p->pid;
@ -1215,7 +1220,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
break; break;
} }
if (scan_mask != TOPMEM_MASK) { IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) {
#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
if (!prev_hist_count) { if (!prev_hist_count) {
do_stats(); do_stats();
@ -1229,17 +1234,13 @@ int top_main(int argc UNUSED_PARAM, char **argv)
#else #else
qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0])); qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0]));
#endif #endif
display_process_list(G.lines, col);
} }
#if ENABLE_FEATURE_TOPMEM #if ENABLE_FEATURE_TOPMEM
else { /* TOPMEM */ else { /* TOPMEM */
qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort); qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort);
}
#endif
if (scan_mask != TOPMEM_MASK)
display_process_list(G.lines, col);
#if ENABLE_FEATURE_TOPMEM
else
display_topmem_process_list(G.lines, col); display_topmem_process_list(G.lines, col);
}
#endif #endif
clearmems(); clearmems();
if (iterations >= 0 && !--iterations) if (iterations >= 0 && !--iterations)
@ -1248,7 +1249,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
sleep(interval); sleep(interval);
#else #else
scan_mask = handle_input(scan_mask, interval); scan_mask = handle_input(scan_mask, interval);
#endif /* FEATURE_USE_TERMIOS */ #endif
} /* end of "while (not Q)" */ } /* end of "while (not Q)" */
bb_putchar('\n'); bb_putchar('\n');