aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2022-05-10 13:51:09 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2022-05-10 13:51:09 +0200
commit69f82e305b34aa35994b87f7ca6528abfbd73520 (patch)
tree52191a87bd77a48cdd3d7685750106cdea407bc7
parent294881d2e9ab014f918fba63c01a629906508515 (diff)
downloadbusybox-w32-69f82e305b34aa35994b87f7ca6528abfbd73520.tar.gz
busybox-w32-69f82e305b34aa35994b87f7ca6528abfbd73520.tar.bz2
busybox-w32-69f82e305b34aa35994b87f7ca6528abfbd73520.zip
top: code shrink
function old new delta display_process_list 1191 1186 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--procps/top.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/procps/top.c b/procps/top.c
index 15222f570..5141feef1 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -608,8 +608,6 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
608 BITS_PER_INT = sizeof(int) * 8 608 BITS_PER_INT = sizeof(int) * 8
609 }; 609 };
610 610
611 char ppubuf[sizeof(int)*3 * 2 + 12];
612 int n;
613 top_status_t *s; 611 top_status_t *s;
614 unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */ 612 unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */
615 /* xxx_shift and xxx_scale variables allow us to replace 613 /* 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)
691 lines_rem = ntop - G_scroll_ofs; 689 lines_rem = ntop - G_scroll_ofs;
692 s = top + G_scroll_ofs; 690 s = top + G_scroll_ofs;
693 while (--lines_rem >= 0) { 691 while (--lines_rem >= 0) {
692 int n;
693 char *pp;
694 char ppubuf[sizeof(int)*3 * 2 + 12];
694 char vsz_str_buf[8]; 695 char vsz_str_buf[8];
695 unsigned col; 696 unsigned col;
696 697
@@ -706,14 +707,15 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
706 /* Format PID PPID USER part into 6+6+8 chars: 707 /* Format PID PPID USER part into 6+6+8 chars:
707 * shrink PID/PPID if possible, then truncate USER 708 * shrink PID/PPID if possible, then truncate USER
708 */ 709 */
709 char *pp, *p = ppubuf; 710 char *p;
710 if (*p == ' ') { 711 pp = ppubuf;
711 do 712 if (*pp == ' ') {
712 p++, n--; 713 do {
713 while (n != 6+6+8 && *p == ' '); 714 pp++, n--;
714 overlapping_strcpy(ppubuf, p); /* shrink PID */ 715 if (n == 6+6+8)
715 if (n == 6+6+8) 716 goto shortened;
716 goto shortened; 717 } while (*pp == ' ');
718 overlapping_strcpy(ppubuf, pp); /* shrink PID */
717 } 719 }
718 pp = p = skip_non_whitespace(ppubuf) + 1; 720 pp = p = skip_non_whitespace(ppubuf) + 1;
719 if (*p == ' ') { 721 if (*p == ' ') {
@@ -724,13 +726,14 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
724 } 726 }
725 ppubuf[6+6+8] = '\0'; /* truncate USER */ 727 ppubuf[6+6+8] = '\0'; /* truncate USER */
726 } 728 }
729 pp = ppubuf;
727 shortened: 730 shortened:
728 col = snprintf(line_buf, scr_width, 731 col = snprintf(line_buf, scr_width,
729 "\n" "%s %s %.5s" FMT 732 "\n" "%s %s %.5s" FMT
730 IF_FEATURE_TOP_SMP_PROCESS(" %3d") 733 IF_FEATURE_TOP_SMP_PROCESS(" %3d")
731 IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) 734 IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT)
732 " ", 735 " ",
733 ppubuf, 736 pp,
734 s->state, vsz_str_buf, 737 s->state, vsz_str_buf,
735 SHOW_STAT(pmem) 738 SHOW_STAT(pmem)
736 IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) 739 IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu)