Hi,

After fussing with top(1)'s uptime display a bit I now think:

- An HH:MM:SS format uptime is useful in top(1).  It's also more
  visually consistent with the local timestamp printed on the line
  above it, so it is easier to read at a glance.

- The variable printing of "days" is annoying.  I would rather it
  just told me "0 days" if it had been less than one day.  It sucks
  when the information you want moves around or isn't shown at all.
  It's clever, sure, but I'd rather it be consistent.

This patch changes the uptime format string to "up D days HH:MM:SS".
The format string does not vary with the elapsed uptime.  There is no
inclusion/omission of the plural suffix depending on whether days is
equal to one.

For example, my machine has been up less than an hour.  Here's the
display in the -current top(1):

load averages:  0.24,  0.16,  0.11                        jetsam.local 15:30:15
50 processes: 49 idle, 1 on processor                                  up  0:22

And here's the display in my patched top(1):

load averages:  0.43,  0.24,  0.14                        jetsam.local 15:31:06
50 processes: 49 idle, 1 on processor                        up 0 days 00:22:25

I prefer the patched display.  Consistent formatting and more
information.

Maybe you like it too?  Try it out for a day or two.

Thoughts?

Index: display.c
===================================================================
RCS file: /cvs/src/usr.bin/top/display.c,v
retrieving revision 1.65
diff -u -p -r1.65 display.c
--- display.c   26 Aug 2020 16:21:28 -0000      1.65
+++ display.c   18 Sep 2020 20:53:36 -0000
@@ -212,7 +212,7 @@ static void
 format_uptime(char *buf, size_t buflen)
 {
        time_t uptime;
-       int days, hrs, mins;
+       int days, hrs, mins, secs;
        struct timespec boottime;
 
        /*
@@ -220,18 +220,14 @@ format_uptime(char *buf, size_t buflen)
         */
        if (clock_gettime(CLOCK_BOOTTIME, &boottime) != -1) {
                uptime = boottime.tv_sec;
-               uptime += 30;
                days = uptime / (3600 * 24);
                uptime %= (3600 * 24);
                hrs = uptime / 3600;
                uptime %= 3600;
                mins = uptime / 60;
-               if (days > 0)
-                       snprintf(buf, buflen, "up %d day%s, %2d:%02d",
-                           days, days > 1 ? "s" : "", hrs, mins);
-               else
-                       snprintf(buf, buflen, "up %2d:%02d",
-                           hrs, mins);
+               secs = uptime % 60;
+               snprintf(buf, buflen, "up %d days %02d:%02d:%02d",
+                   days, hrs, mins, secs);
        }
 }
 

Reply via email to