ps: exploit the library addition for 'cpu utilization'

This just parallels the top program by adding that new
library PIDS_UTILIZATION item to the ps repertoire. It
should be noted, however, that the new %CUU field is a
little redundant. I mean, ps already has 4 such fields
implemented identified as: '%cpu', 'c', 'cp' & 'pcpu'.

Oh well, at least the newest one offers a little value
added in the form of extra precision. We'll follow the
top lead and display results in the form of: '##.###'.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2022-03-04 00:00:00 -06:00 committed by Craig Small
parent 9c0e8e9429
commit 2ac72e2e80
4 changed files with 23 additions and 0 deletions

View File

@ -159,6 +159,7 @@ makEXT(TICS_BEGAN)
makEXT(TTY)
makEXT(TTY_NAME)
makEXT(TTY_NUMBER)
makEXT(UTILIZATION)
makEXT(VM_DATA)
makEXT(VM_RSS_LOCKED)
makEXT(VM_RSS)

View File

@ -145,6 +145,7 @@ makREL(TICS_BEGAN)
makREL(TTY)
makREL(TTY_NAME)
makREL(TTY_NUMBER)
makREL(UTILIZATION)
makREL(VM_DATA)
makREL(VM_RSS_LOCKED)
makREL(VM_RSS)

View File

@ -1339,6 +1339,17 @@ setREL1(EXE)
return max_rightward-rightward;
}
/* %cpu utilization over task lifetime */
static int pr_utilization(char *restrict const outbuf, const proc_t *restrict const pp){
double cu;
setREL1(UTILIZATION)
cu = rSv(UTILIZATION, real, pp);
/* this check is really just for us (the ps program) since we will be very
short lived and the library might reflect 100% or even more utilization */
if (cu > 99.0) cu = 99.999;
return snprintf(outbuf, COLWID, "%#.3f", cu);
}
/************************* Systemd stuff ********************************/
static int pr_sd_unit(char *restrict const outbuf, const proc_t *restrict const pp){
setREL1(SD_UNIT)
@ -1626,6 +1637,7 @@ static const format_struct format_array[] = { /*
{"ctid", "CTID", pr_nop, PIDS_noop, 5, SUN, ET|RIGHT}, // resource contracts?
{"cursig", "CURSIG", pr_nop, PIDS_noop, 6, DEC, AN|RIGHT},
{"cutime", "-", pr_nop, PIDS_TICS_USER_C, 1, LNX, AN|RIGHT},
{"cuu", "%CUU", pr_utilization, PIDS_UTILIZATION, 6, XXX, AN|RIGHT},
{"cwd", "CWD", pr_nop, PIDS_noop, 3, LNX, AN|LEFT},
{"drs", "DRS", pr_drs, PIDS_VSIZE_PGS, 5, LNX, PO|RIGHT},
{"dsiz", "DSIZ", pr_dsiz, PIDS_VSIZE_PGS, 4, LNX, PO|RIGHT},

View File

@ -1211,6 +1211,15 @@ cumulative CPU time in seconds (alias
.BR times ).
T}
cuu %CUU T{
The CPU utilization of a process in an extended "##.###" format.
(see also
.BR %cpu ,
.BR c ,
.BR cp ,
.BR pcpu ).
T}
drs DRS T{
data resident set size, the amount of physical memory devoted to other than
executable code.