top: squashed catch-up of new scalable 'STARTED' field

[ the original newlib commit message(s) appear below ]
[ but 'cpu utilization' was not implemented to avoid ]
[ any library modifications and thus version impact! ]

--------------------------------- newlib patch #1 ---
top: added fields for 'start time' & 'cpu utilization'

This patch will exploit some new library capabilities.

[ one will raise eyebrows, the other likely will not ]

A new 'STARTED' field was added which shows the time a
process started after system boot. As such the largest
interval represents the most recently started process.

This is the field that will likely be questioned since
it's somewhat counterintuitive. But were we to instead
use TIME_ELAPSED, the value will change with every top
refresh. This will defeat any PUFF macro optimization.

The new '%CUU' field will probably be better received.
It represents the cpu usage over the life of the task.
When a process was showing high %CPU usage, this field
can be used to determine if it's an anomaly or normal.

[ and as with %CPU, %CUU shows a '?' when running in ]
[ a namespace when /proc was mounted with subset=pid ]

---------------------------------- newlib patch #2 ---
top: tweaked the recently introduced 'STARTED' support

When the 'STARTED' field was added, the width was made
the same as the 'TIME+' field. Thus, a full time could
be shown (which then included hundredths of a second).

That kind of granularity is totally unnecessary. After
all, this column is potentially confusing enough since
it is so counterintuitive. So, this commit will reduce
the width of the field with some help from scale_tics.

Henceforth it will not include those ol' centiseconds.

[ along the way let's expand the man document with a ]
[ a remainder about content representation & scaling ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2022-03-11 00:00:00 -06:00 committed by Craig Small
parent dd57e856d8
commit ed8dbd05e7
3 changed files with 22 additions and 4 deletions

View File

@ -328,6 +328,7 @@ static int SCB_NAME(TME) (const proc_t **P, const proc_t **Q) {
}
return SORT_eq;
}
SCB_NUM1(TM3, start_time)
SCB_NUM1(TPG, tpgid)
SCB_NUMx(TTY, tty)
SCB_NUMx(UED, euid)
@ -1704,18 +1705,27 @@ end_justifies:
/*
* Make and then justify a percentage, with decreasing precision. */
static const char *scale_pcnt (float num, int width, int justr) {
static const char *scale_pcnt (float num, int width, int justr, int xtra) {
static char buf[SMLBUFSIZ];
buf[0] = '\0';
if (Rc.zero_suppress && 0 >= num)
goto end_justifies;
if (xtra) {
if (width >= snprintf(buf, sizeof(buf), "%#.3f", num))
goto end_justifies;
if (width >= snprintf(buf, sizeof(buf), "%#.2f", num))
goto end_justifies;
goto carry_on;
}
#ifdef BOOST_PERCNT
if (width >= snprintf(buf, sizeof(buf), "%#.3f", num))
goto end_justifies;
if (width >= snprintf(buf, sizeof(buf), "%#.2f", num))
goto end_justifies;
(void)xtra;
#endif
carry_on:
if (width >= snprintf(buf, sizeof(buf), "%#.1f", num))
goto end_justifies;
if (width >= snprintf(buf, sizeof(buf), "%*.0f", width, num))
@ -1961,6 +1971,7 @@ static FLD_t Fieldstab[] = {
{ 6, SK_Kb, A_right, SF(RZS), L_status },
{ -1, -1, A_left, SF(CGN), L_CGROUP },
{ 0, -1, A_right, SF(NMA), L_stat },
{ 7, -1, A_right, SF(TM3), L_stat },
#undef SF
#undef A_left
#undef A_right
@ -6418,7 +6429,7 @@ static const char *task_show (const WIN_t *q, const int idx) {
if (u > 100.0 * p->nlwp) u = 100.0 * p->nlwp;
#endif
if (u > Cpu_pmax) u = Cpu_pmax;
cp = scale_pcnt(u, W, Jn);
cp = scale_pcnt(u, W, Jn, 0);
}
break;
case EU_DAT:
@ -6455,7 +6466,7 @@ static const char *task_show (const WIN_t *q, const int idx) {
cp = make_str(p->lxcname, W, Js, EU_LXC);
break;
case EU_MEM:
cp = scale_pcnt((float)pages2K(p->resident) * 100 / kb_main_total, W, Jn);
cp = scale_pcnt((float)pages2K(p->resident) * 100 / kb_main_total, W, Jn, 0);
break;
case EU_NCE:
cp = make_num(p->nice, W, Jn, AUTOX_NO, 1);
@ -6540,6 +6551,9 @@ static const char *task_show (const WIN_t *q, const int idx) {
cp = scale_tics(t, W, Jn, TICS_AS_SECS);
}
break;
case EU_TM3:
cp = scale_tics(p->start_time, W, Jn, TICS_AS_MINS);
break;
case EU_TPG:
cp = make_num(p->tpgid, W, Jn, AUTOX_NO, 0);
break;

View File

@ -220,6 +220,7 @@ enum pflag {
EU_RZA, EU_RZF, EU_RZL, EU_RZS,
EU_CGN,
EU_NMA,
EU_TM3,
#ifdef USE_X_COLHDR
// not really pflags, used with tbl indexing
EU_MAXPFLGS
@ -747,7 +748,7 @@ typedef struct WIN_t {
//atic inline const char *make_str_utf8 (const char *str, int width, int justr, int col);
//atic const char *scale_mem (int target, float num, int width, int justr);
//atic const char *scale_num (float num, int width, int justr);
//atic const char *scale_pcnt (float num, int width, int justr);
//atic const char *scale_pcnt (float num, int width, int justr, int xtra);
//atic const char *scale_tics (TIC_t tics, int width, int justr, int target);
/*------ Fields Management support -------------------------------------*/
/*atic FLD_t Fieldstab[] = { ... } */

View File

@ -305,6 +305,9 @@ static void build_two_nlstabs (void) {
/* Translation Hint: maximum 'NU' = 2 */
Head_nlstab[EU_NMA] = _("NU");
Desc_nlstab[EU_NMA] = _("Last Used NUMA node");
/* Translation Hint: maximum 'STARTED' = 7 */
Head_nlstab[EU_TM3] = _("STARTED");
Desc_nlstab[EU_TM3] = _("Start Time from boot");
}