[Toybox] human_readable top header.

Rob Landley rob at landley.net
Thu May 16 17:08:52 PDT 2019


This commit from february says:

commit 706628b94e65cfa9e583d7a54d7cdd8de9f70c63
Author: Elliott Hughes <enh at google.com>
Date:   Wed Feb 13 15:10:29 2019 -0800

    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).

Except it doesn't. Linus Torvalds' first 386 in 1991 had 4 megs ram, meaning 4
digits, which would be shown as 4.0M losing precision already.

The problem is human_readable gives you 3 digits plus a unit, so instead of
devuan's kilobytes (yes, still, in the current release):

Tasks: 509 total,   2 running, 507 sleeping,   0 stopped,   0 zombie
%Cpu(s): 43.6 us,  9.4 sy,  0.1 ni, 44.8 id,  2.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 16340584 total,   616500 free, 14289944 used,  1434140 buff/cache
KiB Swap: 16679932 total, 13636264 free,  3043668 used.   775996 avail Mem

You get:

Tasks: 507 total,   4 running, 503 sleeping,   0 stopped,   0 zombie
  Mem:       16G total,       15G used,      681M free,       42M buffers
 Swap:       16G total,      2.9G used,       13G free,      1.2G cached
400%cpu  55%user   0%nice  42%sys 303%idle   0%iow   0%irq   0%sirq   0%host

There's a whole lot of empty space in that display, and when my laptop is
swap-thrashing  and Swap "used" is going down 4 megabytes/second (took me about
a week to do it to the new one, chrome is a memory hog _and_ won't show you more
than about 80 tabs/window), I can't even _see_ that on this display.

(Aside: a machine with >99 procesors would run out of space for the percentages.
Possibly at some point that should go back to 100% for the totals?)

Aesthetic issues are always hard. Possibly what I need to do is add a display
size field to human_readable so it knows how many digits of output to produce,
and when there's more than 3 don't decimalize, just do "12146M" and such.

Rob



More information about the Toybox mailing list