aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/ps.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-02-13 15:10:29 -0800
committerRob Landley <rob@landley.net>2019-02-13 20:58:05 -0600
commit706628b94e65cfa9e583d7a54d7cdd8de9f70c63 (patch)
tree151a04223e9280063778b13da432582894059224 /toys/posix/ps.c
parent8e7b298b17e53ac0f35f5e425f72836f729a10d6 (diff)
downloadtoybox-706628b94e65cfa9e583d7a54d7cdd8de9f70c63.tar.gz
top: use human_readable for the header lines too.
Even phones have enough RAM these days that KiB is not a reasonable unit. Traditional top always uses MiB instead of always using KiB, but we may as well just let human_readable pick a unit (that way if KiB is reasonable on your box, that's what you'll get). Before: Tasks: 967 total, 1 running, 581 sleeping, 0 stopped, 0 zombie Mem: 196734820k total,183891564k used, 12843256k free, 5805008k buffers Swap:199888892k total, 719104k used,199169788k free,130367280k cached After: Tasks: 965 total, 2 running, 577 sleeping, 0 stopped, 0 zombie Mem: 188G total, 175G used, 13G free, 5.5G buffers Swap: 191G total, 702M used, 190G free, 124G cached
Diffstat (limited to 'toys/posix/ps.c')
-rw-r--r--toys/posix/ps.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index ce13d4f6..926132c4 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -1544,6 +1544,8 @@ static void top_common(
// Display "top" header.
if (*toys.which->name == 't') {
struct ofields field;
+ char *hr0 = toybuf+sizeof(toybuf)-32, *hr1 = hr0-32, *hr2 = hr1-32,
+ *hr3 = hr2-32;
long long ll, up = 0;
long run[6];
int j;
@@ -1564,13 +1566,21 @@ static void top_common(
"\nBuffers:","\nCached:","\nSwapTotal:","\nSwapFree:"}[i]);
run[i] = pos ? atol(pos) : 0;
}
- sprintf(toybuf,
- "Mem:%10ldk total,%9ldk used,%9ldk free,%9ldk buffers",
- run[0], run[0]-run[1], run[1], run[2]);
+
+ human_readable(hr0, 1024*run[0], 0);
+ human_readable(hr1, 1024*(run[0]-run[1]), 0);
+ human_readable(hr2, 1024*run[1], 0);
+ human_readable(hr3, 1024*run[2], 0);
+ sprintf(toybuf, " Mem: %9s total, %9s used, %9s free, %9s buffers",
+ hr0, hr1, hr2, hr3);
lines = header_line(lines, 0);
- sprintf(toybuf,
- "Swap:%9ldk total,%9ldk used,%9ldk free,%9ldk cached",
- run[4], run[4]-run[5], run[5], run[3]);
+
+ human_readable(hr0, 1024*run[4], 0);
+ human_readable(hr1, 1024*(run[4]-run[5]), 0);
+ human_readable(hr2, 1024*run[5], 0);
+ human_readable(hr3, 1024*run[3], 0);
+ sprintf(toybuf, " Swap: %9s total, %9s used, %9s free, %9s cached",
+ hr0, hr1, hr2, hr3);
lines = header_line(lines, 0);
}