top: code shrink
function old new delta display_process_list 1191 1186 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
294881d2e9
commit
69f82e305b
25
procps/top.c
25
procps/top.c
@ -608,8 +608,6 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
|
|||||||
BITS_PER_INT = sizeof(int) * 8
|
BITS_PER_INT = sizeof(int) * 8
|
||||||
};
|
};
|
||||||
|
|
||||||
char ppubuf[sizeof(int)*3 * 2 + 12];
|
|
||||||
int n;
|
|
||||||
top_status_t *s;
|
top_status_t *s;
|
||||||
unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */
|
unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */
|
||||||
/* xxx_shift and xxx_scale variables allow us to replace
|
/* xxx_shift and xxx_scale variables allow us to replace
|
||||||
@ -691,6 +689,9 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
|
|||||||
lines_rem = ntop - G_scroll_ofs;
|
lines_rem = ntop - G_scroll_ofs;
|
||||||
s = top + G_scroll_ofs;
|
s = top + G_scroll_ofs;
|
||||||
while (--lines_rem >= 0) {
|
while (--lines_rem >= 0) {
|
||||||
|
int n;
|
||||||
|
char *pp;
|
||||||
|
char ppubuf[sizeof(int)*3 * 2 + 12];
|
||||||
char vsz_str_buf[8];
|
char vsz_str_buf[8];
|
||||||
unsigned col;
|
unsigned col;
|
||||||
|
|
||||||
@ -706,14 +707,15 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
|
|||||||
/* Format PID PPID USER part into 6+6+8 chars:
|
/* Format PID PPID USER part into 6+6+8 chars:
|
||||||
* shrink PID/PPID if possible, then truncate USER
|
* shrink PID/PPID if possible, then truncate USER
|
||||||
*/
|
*/
|
||||||
char *pp, *p = ppubuf;
|
char *p;
|
||||||
if (*p == ' ') {
|
pp = ppubuf;
|
||||||
do
|
if (*pp == ' ') {
|
||||||
p++, n--;
|
do {
|
||||||
while (n != 6+6+8 && *p == ' ');
|
pp++, n--;
|
||||||
overlapping_strcpy(ppubuf, p); /* shrink PID */
|
if (n == 6+6+8)
|
||||||
if (n == 6+6+8)
|
goto shortened;
|
||||||
goto shortened;
|
} while (*pp == ' ');
|
||||||
|
overlapping_strcpy(ppubuf, pp); /* shrink PID */
|
||||||
}
|
}
|
||||||
pp = p = skip_non_whitespace(ppubuf) + 1;
|
pp = p = skip_non_whitespace(ppubuf) + 1;
|
||||||
if (*p == ' ') {
|
if (*p == ' ') {
|
||||||
@ -724,13 +726,14 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
|
|||||||
}
|
}
|
||||||
ppubuf[6+6+8] = '\0'; /* truncate USER */
|
ppubuf[6+6+8] = '\0'; /* truncate USER */
|
||||||
}
|
}
|
||||||
|
pp = ppubuf;
|
||||||
shortened:
|
shortened:
|
||||||
col = snprintf(line_buf, scr_width,
|
col = snprintf(line_buf, scr_width,
|
||||||
"\n" "%s %s %.5s" FMT
|
"\n" "%s %s %.5s" FMT
|
||||||
IF_FEATURE_TOP_SMP_PROCESS(" %3d")
|
IF_FEATURE_TOP_SMP_PROCESS(" %3d")
|
||||||
IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT)
|
IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT)
|
||||||
" ",
|
" ",
|
||||||
ppubuf,
|
pp,
|
||||||
s->state, vsz_str_buf,
|
s->state, vsz_str_buf,
|
||||||
SHOW_STAT(pmem)
|
SHOW_STAT(pmem)
|
||||||
IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu)
|
IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu)
|
||||||
|
Loading…
Reference in New Issue
Block a user