summaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorDenys Vlasenko2023-02-13 15:04:11 +0100
committerDenys Vlasenko2023-02-13 15:05:19 +0100
commit669c40ed8ebf480c95ce36135104e474e361a7e6 (patch)
tree1b2d30afb35c0e6afa1d68132d9a7e5a13841cac /procps
parent93ae7464e6e460f25b73e4ffefd2d9a6499eae30 (diff)
downloadbusybox-669c40ed8ebf480c95ce36135104e474e361a7e6.zip
busybox-669c40ed8ebf480c95ce36135104e474e361a7e6.tar.gz
top: stop using div() from libc, compilers now do it better
function old new delta div 23 - -23 display_process_list 1237 1178 -59 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-82) Total: -82 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps')
-rw-r--r--procps/top.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/procps/top.c b/procps/top.c
index ff77542..6d25d96 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -619,17 +619,15 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
unsigned busy_jifs;
#endif
- /* what info of the processes is shown */
- printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width,
- " PID PPID USER STAT VSZ %VSZ"
- IF_FEATURE_TOP_SMP_PROCESS(" CPU")
- IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU")
- " COMMAND");
- lines_rem--;
-
#if ENABLE_FEATURE_TOP_DECIMALS
# define UPSCALE 1000
-# define CALC_STAT(name, val) div_t name = div((val), 10)
+typedef struct { unsigned quot, rem; } bb_div_t;
+/* Used to have "div_t name = div((val), 10)" here
+ * (IOW: intended to use libc-compatible way to divide and use
+ * both result and remainder, but musl does not inline div()...)
+ * Oh well. Modern compilers detect "N/d, N%d" idiom by themselves:
+ */
+# define CALC_STAT(name, val) bb_div_t name = { (val) / 10, (val) % 10 }
# define SHOW_STAT(name) name.quot, '0'+name.rem
# define FMT "%3u.%c"
#else
@@ -638,6 +636,15 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
# define SHOW_STAT(name) name
# define FMT "%4u%%"
#endif
+
+ /* what info of the processes is shown */
+ printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width,
+ " PID PPID USER STAT VSZ %VSZ"
+ IF_FEATURE_TOP_SMP_PROCESS(" CPU")
+ IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU")
+ " COMMAND");
+ lines_rem--;
+
/*
* %VSZ = s->vsz/MemTotal
*/