aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-11-23 01:18:02 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2023-11-23 01:18:02 +0100
commit28f41260935852eda6bd8ab1f26347c012ae0a53 (patch)
treecc285d997d959a15cc0cc8f87021faff58b4522b
parenta63b60bdd6fa26b867c80d44074118babbae7ffd (diff)
downloadbusybox-w32-28f41260935852eda6bd8ab1f26347c012ae0a53.tar.gz
busybox-w32-28f41260935852eda6bd8ab1f26347c012ae0a53.tar.bz2
busybox-w32-28f41260935852eda6bd8ab1f26347c012ae0a53.zip
top: improve large PID display in memory ('s') mode
Display VSZ[RW] fields in more compact form if PID is wider. function old new delta display_topmem_process_list 564 614 +50 ulltoa5_and_space - 14 +14 ulltoa6_and_space 14 - -14 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 1/0 up/down: 64/-14) Total: 50 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--procps/top.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/procps/top.c b/procps/top.c
index 6d25d9633..09d31c673 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -713,7 +713,10 @@ typedef struct { unsigned quot, rem; } bb_div_t;
713 ppu = ppubuf; 713 ppu = ppubuf;
714 if (n != 6+6+8) { 714 if (n != 6+6+8) {
715 /* Format PID PPID USER part into 6+6+8 chars: 715 /* Format PID PPID USER part into 6+6+8 chars:
716 * shrink PID/PPID if possible, then truncate USER 716 * shrink PID/PPID if possible, then truncate USER.
717 * Tested on Linux 5.18.0:
718 * sysctl kernel.pid_max=4194304 is the maximum allowed,
719 * so PID and PPID are 7 chars wide at most.
717 */ 720 */
718 char *p, *pp; 721 char *p, *pp;
719 if (*ppu == ' ') { 722 if (*ppu == ' ') {
@@ -857,11 +860,15 @@ static void display_topmem_header(int scr_width, int *lines_rem_p)
857 (*lines_rem_p) -= 3; 860 (*lines_rem_p) -= 3;
858} 861}
859 862
860static void ulltoa6_and_space(unsigned long long ul, char buf[6]) 863/* see http://en.wikipedia.org/wiki/Tera */
864static void ulltoa5_and_space(unsigned long long ul, char buf[6])
861{ 865{
862 /* see http://en.wikipedia.org/wiki/Tera */
863 smart_ulltoa5(ul, buf, " mgtpezy")[0] = ' '; 866 smart_ulltoa5(ul, buf, " mgtpezy")[0] = ' ';
864} 867}
868static void ulltoa4_and_space(unsigned long long ul, char buf[5])
869{
870 smart_ulltoa4(ul, buf, " mgtpezy")[0] = ' ';
871}
865 872
866static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width) 873static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width)
867{ 874{
@@ -887,16 +894,24 @@ static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width)
887 while (--lines_rem >= 0) { 894 while (--lines_rem >= 0) {
888 /* PID VSZ VSZRW RSS (SHR) DIRTY (SHR) COMMAND */ 895 /* PID VSZ VSZRW RSS (SHR) DIRTY (SHR) COMMAND */
889 int n = sprintf(line_buf, "%5u ", s->pid); 896 int n = sprintf(line_buf, "%5u ", s->pid);
890 ulltoa6_and_space(s->vsz , &line_buf[1*6]); 897 if (n > 7) {
891 if (n > 7 || (n == 7 && line_buf[6] != ' ')) 898 /* PID is 7 chars long (up to 4194304) */
892 /* PID and VSZ are clumped together, truncate PID */ 899 ulltoa4_and_space(s->vsz , &line_buf[8]);
893 line_buf[5] = '.'; 900 ulltoa4_and_space(s->vszrw, &line_buf[8+5]);
894 ulltoa6_and_space(s->vszrw , &line_buf[2*6]); 901 /* the next field (RSS) starts at 8+10 = 3*6 */
895 ulltoa6_and_space(s->rss , &line_buf[3*6]); 902 } else {
896 ulltoa6_and_space(s->rss_sh , &line_buf[4*6]); 903 if (n == 7) /* PID is 6 chars long */
897 ulltoa6_and_space(s->dirty , &line_buf[5*6]); 904 ulltoa4_and_space(s->vsz, &line_buf[7]);
898 ulltoa6_and_space(s->dirty_sh, &line_buf[6*6]); 905 /* the next field (VSZRW) starts at 7+5 = 2*6 */
899 ulltoa6_and_space(s->stack , &line_buf[7*6]); 906 else /* PID is 5 chars or less */
907 ulltoa5_and_space(s->vsz, &line_buf[6]);
908 ulltoa5_and_space(s->vszrw, &line_buf[2*6]);
909 }
910 ulltoa5_and_space(s->rss , &line_buf[3*6]);
911 ulltoa5_and_space(s->rss_sh , &line_buf[4*6]);
912 ulltoa5_and_space(s->dirty , &line_buf[5*6]);
913 ulltoa5_and_space(s->dirty_sh, &line_buf[6*6]);
914 ulltoa5_and_space(s->stack , &line_buf[7*6]);
900 line_buf[8*6] = '\0'; 915 line_buf[8*6] = '\0';
901 if (scr_width > (int)MIN_WIDTH) { 916 if (scr_width > (int)MIN_WIDTH) {
902 read_cmdline(&line_buf[8*6], scr_width - MIN_WIDTH, s->pid, s->comm); 917 read_cmdline(&line_buf[8*6], scr_width - MIN_WIDTH, s->pid, s->comm);