]> granicus.if.org Git - procps-ng/commit
top: refactor 'scale_tics' function for better scaling
authorJim Warner <james.warner@comcast.net>
Thu, 3 Mar 2022 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@dropbear.xyz>
Sun, 6 Mar 2022 03:52:34 +0000 (14:52 +1100)
commit71eb90c1b27ef039ccc90f6060406099df45eade
treed190ba4b6d47518056e12b09e931506e407597ff
parent9348d3b0085bd389749cc5619fdde4ec3fae5f11
top: refactor 'scale_tics' function for better scaling

This patch refactors the 'scale_tics' function to more
closely parallel uptime shown on the first line of the
summary area. The old logic has been preserved through
the header file's new  #define SCALE_FORMER provision.

However, the former logic was actually a big disaster.
These are some potential problems with that old logic:

1. With respect to our time fields top no longer deals
solely with cpu time. So, the old limits of '68 weeks'
could possibly be insufficient to reflect those times.

2. Given the widths of top's new time fields, the code
never got beyond scaling to hours. For example, with a
ridiculously large span of 19 years, the scaled result
would then be shown as '167832h'. We never reached the
days ('6993d') or even the weeks ('999w') equivalents.

3. Similarly, with that 'TIME+' field and a large tics
value, results would then appear as 'MMMMMM:SS' rather
than the more meaningful 'HH:MM:SS' or days and hours.

So henceforth we will adopt these scaling conventions:

  MMM:SS.hh ... minutes:seconds.hundredths
  MMM:SS ...... minutes:seconds
  HH,MM ....... hours,minutes
  D+H ......... days+hours (with 'd' & 'h' suffixes)
  D ........... days (with 'd' suffix)
  W+D ......... weeks+days (with 'w' & 'd' suffixes)
  W ........... weeks (with 'w' suffix)

Note that, unlike our former scaling logic, that 'MMM'
portion won't be allowed to grow unconditionally. It's
limited (arbitrarily?) to 360 total minutes (6 hours).
Additionally, the 'HH' guy will be limited to 96 hours
(4 days) while that 'D' limit was set at 14 (2 weeks).

Whenever a limit is hit, scaling will advance a level.

Reference(s):
. Feb, 2022 - added 'ELAPSED'
commit 9348d3b0085bd389749cc5619fdde4ec3fae5f11
. Feb, 2022 - added 'STARTED'
commit 7647e96b0a35d473fa9bc644ea6107487b3b0527

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c
top/top.h