]> granicus.if.org Git - procps-ng/commitdiff
ps: plus for symmetry 'UTILIZATION_C' is newest format
authorJim Warner <james.warner@comcast.net>
Sun, 6 Mar 2022 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@dropbear.xyz>
Mon, 7 Mar 2022 09:29:06 +0000 (20:29 +1100)
This commit just compliments a change referenced below
by providing the value which includes reaped children.

[ as an aside, it looks like ps only includes reaped ]
[ children values under an obscure BSD or GNU option ]

[ so, this change is possibly of even more relevance ]

Reference(s):
. Mar, 2022 - added %CUU
commit 2ac72e2e801e015532b555ae0f2272c8ecef2c8b

Signed-off-by: Jim Warner <james.warner@comcast.net>
ps/common.h
ps/global.c
ps/output.c
ps/ps.1

index c60aa316a644c56a648da6968e0dd5959d0e3930..fde3932158c9b28f7bc010587b7b98d1c5fe7b30 100644 (file)
@@ -165,6 +165,7 @@ makEXT(TTY)
 makEXT(TTY_NAME)
 makEXT(TTY_NUMBER)
 makEXT(UTILIZATION)
+makEXT(UTILIZATION_C)
 makEXT(VM_DATA)
 makEXT(VM_RSS_LOCKED)
 makEXT(VM_RSS)
index 82ced68a210b0cca37765f3ea9f9a0f2497ff874..f973f47c140a5397c3d91b5983d05d01af3112d5 100644 (file)
@@ -146,6 +146,7 @@ makREL(TTY)
 makREL(TTY_NAME)
 makREL(TTY_NUMBER)
 makREL(UTILIZATION)
+makREL(UTILIZATION_C)
 makREL(VM_DATA)
 makREL(VM_RSS_LOCKED)
 makREL(VM_RSS)
index f37419e965c8a6bed43a386babb8a2dd4c8bb8fa..ba6d638b9dc29cbfe538c96f60b26d2a4cab4dbe 100644 (file)
@@ -1339,7 +1339,7 @@ setREL1(EXE)
   return max_rightward-rightward;
 }
 
-/* %cpu utilization over task lifetime */
+/* %cpu utilization over task lifetime, as ##.### format */
 static int pr_utilization(char *restrict const outbuf, const proc_t *restrict const pp){
 double cu;
 setREL1(UTILIZATION)
@@ -1350,6 +1350,17 @@ setREL1(UTILIZATION)
   return snprintf(outbuf, COLWID, "%#.3f", cu);
 }
 
+/* %cpu utilization (plus dead children) over task lifetime, as ##.### format */
+static int pr_utilization_c(char *restrict const outbuf, const proc_t *restrict const pp){
+double cu;
+setREL1(UTILIZATION_C)
+  cu = rSv(UTILIZATION_C, 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)
@@ -1635,6 +1646,7 @@ static const format_struct format_array[] = { /*
 {"cputime",   "TIME",    pr_time,          PIDS_TIME_ALL,            8,    DEC,  ET|RIGHT}, /*time*/
 {"cputimes",  "TIME",    pr_times,         PIDS_TIME_ALL,            8,    LNX,  ET|RIGHT}, /*time*/
 {"ctid",      "CTID",    pr_nop,           PIDS_noop,                5,    SUN,  ET|RIGHT}, // resource contracts?
+{"cuc",       "%CUC",    pr_utilization_c, PIDS_UTILIZATION_C,       6,    XXX,  AN|RIGHT},
 {"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},
diff --git a/ps/ps.1 b/ps/ps.1
index a6275fd379144b79c075b5afb2792479bad1b192..7c7aff46c01d7bc67e7526169fe0cdb4f35f7a6e 100644 (file)
--- a/ps/ps.1
+++ b/ps/ps.1
@@ -1211,12 +1211,23 @@ cumulative CPU time in seconds (alias
 .BR times ).
 T}
 
+cuc    %CUC    T{
+The CPU utilization of a process, including dead children, in an extended "##.###" format.
+(see also
+.BR %cpu ,
+.BR c ,
+.BR cp ,
+.BR cuu ,
+.BR pcpu ).
+T}
+
 cuu    %CUU    T{
 The CPU utilization of a process in an extended "##.###" format.
 (see also
 .BR %cpu ,
 .BR c ,
 .BR cp ,
+.BR cuc ,
 .BR pcpu ).
 T}