top: added some elapsed running time 'ELAPSED' support
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>
This commit is contained in:
parent
a749414f16
commit
9348d3b008
@ -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
|
||||
|
23
top/top.c
23
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
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user