]> granicus.if.org Git - procps-ng/commitdiff
top: added some elapsed running time 'ELAPSED' support
authorJim Warner <james.warner@comcast.net>
Sun, 27 Feb 2022 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@dropbear.xyz>
Mon, 28 Feb 2022 09:21:00 +0000 (20:21 +1100)
When the 'STARTED' field was added, in the message for
the commit referenced below, I explained why 'ELAPSED'
shouldn't be implemented though it might be preferred.

Well, after climbing out of my box to do a little more
thinking, I came up with the way to add that 'ELAPSED'
field while avoiding the possible performance penalty.

Just do not show what would change with every refresh!

If we do not show the seconds portion of a scaled tics
amount then the problem goes away. And this comes with
an additional benefit. The HH,MM (hours,minutes) style
then is readily compared with that system uptime shown
as HH:MM. The only difference is just the comma/colon.

[ assuming the top uptime/load average toggle was on ]

Reference(s):
. introduced 'start time' field
commit 7647e96b0a35d473fa9bc644ea6107487b3b0527

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

index d448d7ebf452c8cca1bb8d8e721fd3a90375f06d..ae33aa2e9147ab4b30cf0e38be4f9b5adabe8dea 100644 (file)
--- a/top/top.1
+++ b/top/top.1
@@ -746,6 +746,14 @@ included in the \*(MV (VIRT) amount.
 
 \*(XX.
 
+.TP 4
+\fBELAPSED \*(Em Elapsed Running Time\fR
+The length of time since a process was started.
+Thus, the most recently started task will display the smallest time interval.
+
+The value will be expressed as 'HH,MM' (hours,minutes) but is subject to
+additional scaling if the interval becomes too great to fit column width.
+
 .TP 4
 \fBENVIRON \*(Em Environment variables \fR
 Display all of the environment variables, if any, as seen by the
index 2fa8a6a7a56404eed256998eaea928fa4946e12b..4bdd54a5b956fd37be9214680ceb9a2f1f765991 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -1630,6 +1630,10 @@ end_justifies:
 } // end: scale_pcnt
 
 
+#define TICS_AS_FULL 0
+#define TICS_AS_SECS 1
+#define TICS_AS_MINS 2
+
         /*
          * Do some scaling stuff.
          * Format 'tics' to fit 'width', then justify it. */
@@ -1656,9 +1660,11 @@ static const char *scale_tics (TIC_t tics, int width, int justr, int abrv) {
    nt /= 100;                                   // total seconds
    nn  = nt % 60;                               // seconds past the minute
    nt /= 60;                                    // total minutes
-   if (!abrv && width >= snprintf(buf, sizeof(buf), "%lu:%02u.%02u", nt, nn, cc))
+   if (abrv < TICS_AS_SECS
+   && (width >= snprintf(buf, sizeof(buf), "%lu:%02u.%02u", nt, nn, cc)))
       goto end_justifies;
-   if (width >= snprintf(buf, sizeof(buf), "%lu:%02u", nt, nn))
+   if (abrv < TICS_AS_MINS
+   && (width >= snprintf(buf, sizeof(buf), "%lu:%02u", nt, nn)))
       goto end_justifies;
    nn  = nt % 60;                               // minutes past the hour
    nt /= 60;                                    // total hours
@@ -1777,8 +1783,9 @@ static struct {
    {     5,     -1,  A_right,  PIDS_AUTOGRP_ID     },  // s_int    EU_AGI
    {     4,     -1,  A_right,  PIDS_AUTOGRP_NICE   },  // s_int    EU_AGN
    {     7,     -1,  A_right,  PIDS_TICS_BEGAN     },  // ull_int  EU_TM3
-   {     6,     -1,  A_right,  PIDS_UTILIZATION    }   // real     EU_CUU
-#define eu_LAST  EU_CUU
+   {     6,     -1,  A_right,  PIDS_UTILIZATION    },  // real     EU_CUU
+   {     7,     -1,  A_right,  PIDS_TIME_ELAPSED   }   // real     EU_TM4
+#define eu_LAST  EU_TM4
 // xtra Fieldstab 'pseudo pflag' entries for the newlib interface . . . . . . .
 #define eu_CMDLINE     eu_LAST +1
 #define eu_TICS_ALL_C  eu_LAST +2
@@ -6242,12 +6249,16 @@ static const char *task_show (const WIN_t *q, int idx) {
          {  TIC_t t;
             if (CHKw(q, Show_CTIMES)) t = rSv(eu_TICS_ALL_C, ull_int);
             else t = rSv(i, ull_int);
-            cp = scale_tics(t, W, Jn, 0);
+            cp = scale_tics(t, W, Jn, TICS_AS_FULL);
          }
             break;
    /* ull_int, scale_tics (try seconds) */
          case EU_TM3:        // PIDS_TICS_BEGAN
-            cp = scale_tics(rSv(EU_TM3, ull_int), W, Jn, 1);
+            cp = scale_tics(rSv(EU_TM3, ull_int), W, Jn, TICS_AS_SECS);
+            break;
+   /* real, scale_tics (try minutes) */
+         case EU_TM4:        // PIDS_TIME_ELAPSED
+            cp = scale_tics(rSv(EU_TM4, real) * Hertz, W, Jn, TICS_AS_MINS);
             break;
    /* str, make_str (all AUTOX yes) */
          case EU_LXC:        // PIDS_LXCNAME
index d3ba4d8c7299b511fd5be6af096f975573a8c596..8a248a2e1719d306c4d038706f3de4f2133dd21e 100644 (file)
--- a/top/top.h
+++ b/top/top.h
@@ -202,7 +202,7 @@ enum pflag {
    EU_RSS, EU_PSS, EU_PZA, EU_PZF, EU_PZS, EU_USS,
    EU_IRB, EU_IRO, EU_IWB, EU_IWO,
    EU_AGI, EU_AGN,
-   EU_TM3, EU_CUU,
+   EU_TM3, EU_CUU, EU_TM4,
 #ifdef USE_X_COLHDR
    // not really pflags, used with tbl indexing
    EU_MAXPFLGS
index 7d496ac78c0350299860234c84f601f9a98b3df2..05669caf790dc867b1ab3841b6e84a8575cba48a 100644 (file)
@@ -356,6 +356,9 @@ static void build_two_nlstabs (void) {
 /* Translation Hint: maximum '%CUU' = 6 */
    Head_nlstab[EU_CUU] = _("%CUU");
    Desc_nlstab[EU_CUU] = _("CPU Utilization");
+/* Translation Hint: maximum 'ELAPSED' = 7 */
+   Head_nlstab[EU_TM4] = _("ELAPSED");
+   Desc_nlstab[EU_TM4] = _("Elapsed Running Time");
 }