aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2022-05-10 14:04:34 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2022-05-10 14:04:34 +0200
commit1099a27696cd733041db97f99da4e22ecd2424e5 (patch)
tree047fe089e7ba4de474a232e1e18474d4e520c103
parent69f82e305b34aa35994b87f7ca6528abfbd73520 (diff)
downloadbusybox-w32-1099a27696cd733041db97f99da4e22ecd2424e5.tar.gz
busybox-w32-1099a27696cd733041db97f99da4e22ecd2424e5.tar.bz2
busybox-w32-1099a27696cd733041db97f99da4e22ecd2424e5.zip
top: code shrink
function old new delta display_process_list 1186 1168 -18 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--procps/top.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/procps/top.c b/procps/top.c
index 5141feef1..744f20e9b 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -690,7 +690,7 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
690 s = top + G_scroll_ofs; 690 s = top + G_scroll_ofs;
691 while (--lines_rem >= 0) { 691 while (--lines_rem >= 0) {
692 int n; 692 int n;
693 char *pp; 693 char *ppu;
694 char ppubuf[sizeof(int)*3 * 2 + 12]; 694 char ppubuf[sizeof(int)*3 * 2 + 12];
695 char vsz_str_buf[8]; 695 char vsz_str_buf[8];
696 unsigned col; 696 unsigned col;
@@ -703,37 +703,35 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
703 smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy"); 703 smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy");
704 /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ 704 /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */
705 n = sprintf(ppubuf, "%5u %5u %-8.8s", s->pid, s->ppid, get_cached_username(s->uid)); 705 n = sprintf(ppubuf, "%5u %5u %-8.8s", s->pid, s->ppid, get_cached_username(s->uid));
706 ppu = ppubuf;
706 if (n != 6+6+8) { 707 if (n != 6+6+8) {
707 /* Format PID PPID USER part into 6+6+8 chars: 708 /* Format PID PPID USER part into 6+6+8 chars:
708 * shrink PID/PPID if possible, then truncate USER 709 * shrink PID/PPID if possible, then truncate USER
709 */ 710 */
710 char *p; 711 char *p, *pp;
711 pp = ppubuf; 712 if (*ppu == ' ') {
712 if (*pp == ' ') {
713 do { 713 do {
714 pp++, n--; 714 ppu++, n--;
715 if (n == 6+6+8) 715 if (n == 6+6+8)
716 goto shortened; 716 goto shortened;
717 } while (*pp == ' '); 717 } while (*ppu == ' ');
718 overlapping_strcpy(ppubuf, pp); /* shrink PID */
719 } 718 }
720 pp = p = skip_non_whitespace(ppubuf) + 1; 719 pp = p = skip_non_whitespace(ppu) + 1;
721 if (*p == ' ') { 720 if (*p == ' ') {
722 do 721 do
723 p++, n--; 722 p++, n--;
724 while (n != 6+6+8 && *p == ' '); 723 while (n != 6+6+8 && *p == ' ');
725 overlapping_strcpy(pp, p); /* shrink PPID */ 724 overlapping_strcpy(pp, p); /* shrink PPID */
726 } 725 }
727 ppubuf[6+6+8] = '\0'; /* truncate USER */ 726 ppu[6+6+8] = '\0'; /* truncate USER */
728 } 727 }
729 pp = ppubuf;
730 shortened: 728 shortened:
731 col = snprintf(line_buf, scr_width, 729 col = snprintf(line_buf, scr_width,
732 "\n" "%s %s %.5s" FMT 730 "\n" "%s %s %.5s" FMT
733 IF_FEATURE_TOP_SMP_PROCESS(" %3d") 731 IF_FEATURE_TOP_SMP_PROCESS(" %3d")
734 IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) 732 IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT)
735 " ", 733 " ",
736 pp, 734 ppu,
737 s->state, vsz_str_buf, 735 s->state, vsz_str_buf,
738 SHOW_STAT(pmem) 736 SHOW_STAT(pmem)
739 IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) 737 IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu)