From 8a94ed61119f8dcf7bcb98b84534e408d4eb7769 Mon Sep 17 00:00:00 2001
From: =?utf8?q?S=C3=A9bastien=20Bigaret?=
 <sebastien.bigaret@telecom-bretagne.eu>
Date: Sat, 11 Mar 2017 07:40:19 +0100
Subject: [PATCH] ps: add times & cputimes format specifiers: cumulative CPU
 time in seconds
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

These format specifiers are to time & cputime what etimes is to etime.

Signed-off-by: Sébastien Bigaret <sebastien.bigaret@telecom-bretagne.eu>
---
 man-po/fr.po | 12 ++++++++++++
 ps/output.c  |  8 ++++++++
 ps/ps.1      | 10 ++++++++++
 3 files changed, 30 insertions(+)

diff --git a/man-po/fr.po b/man-po/fr.po
index 258690a2..824ab801 100644
--- a/man-po/fr.po
+++ b/man-po/fr.po
@@ -4662,6 +4662,12 @@ msgstr "Le programme B<watch> a été écrit par Tony Rems E<lt>I<rembo@unisoft.
 #~ msgid "cumulative CPU time, \"[DD-]hh:mm:ss\" format.  (alias\n"
 #~ msgstr "Temps CPU cumulé, au format « [JJ-]HH:MM:SS » (alias\n"
 
+#~ msgid "cputimes\tTIME\tT{\n"
+#~ msgstr "cputimes\tTIME\tT{\n"
+
+#~ msgid "cumulative CPU time in seconds (alias\n"
+#~ msgstr "Temps CPU cumulé en secondes (alias\n"
+
 #~ msgid "B<time>).\n"
 #~ msgstr "B<time>).\n"
 
@@ -5537,6 +5543,12 @@ msgstr "Le programme B<watch> a été écrit par Tony Rems E<lt>I<rembo@unisoft.
 #~ msgid "cumulative CPU\\ time, \"[DD-]HH:MM:SS\" format.  (alias\n"
 #~ msgstr "Temps CPU cumulé, au format « [JJ-]HH:MM:SS » (alias\n"
 
+#~ msgid "times\tTIME\tT{\n"
+#~ msgstr "times\tTIME\tT{\n"
+
+#~ msgid "cumulative CPU\\ time in seconds  (alias\n"
+#~ msgstr "Temps CPU cumulé en secondes (alias\n"
+
 #~ msgid "B<cputime>).\n"
 #~ msgstr "B<cputime>).\n"
 
diff --git a/ps/output.c b/ps/output.c
index 21839389..1ae2f21c 100644
--- a/ps/output.c
+++ b/ps/output.c
@@ -568,6 +568,12 @@ static int pr_time(char *restrict const outbuf, const proc_t *restrict const pp)
   return c;
 }
 
+/* cumulative CPU time in seconds (not same as "etimes") */
+static int pr_times(char *restrict const outbuf, const proc_t *restrict const pp){
+  unsigned t = cook_time(pp);
+  return snprintf(outbuf, COLWID, "%u", t);
+}
+
 /* HP-UX puts this (I forget, vsz or vsize?) in kB and uses "sz" for pages.
  * Unix98 requires "vsz" to be kB.
  * Tru64 does both vsize and vsz like "1.23M"
@@ -1506,6 +1512,7 @@ static const format_struct format_array[] = {
 {"cpu",       "CPU",     pr_nop,      sr_nop,     3,   0,    BSD, AN|RIGHT}, /* FIXME ... HP-UX wants this as the CPU number for SMP? */
 {"cpuid",     "CPUID",   pr_psr,      sr_nop,     5,   0,    BSD, TO|RIGHT}, // OpenBSD: 8 wide!
 {"cputime",   "TIME",    pr_time,     sr_time,    8,   0,    DEC, ET|RIGHT}, /*time*/
+{"cputimes",  "TIME",    pr_times,    sr_time,    8,   0,    LNX, ET|RIGHT}, /*time*/
 {"ctid",      "CTID",    pr_nop,      sr_nop,     5,   0,    SUN, ET|RIGHT}, // resource contracts?
 {"cursig",    "CURSIG",  pr_nop,      sr_nop,     6,   0,    DEC, AN|RIGHT},
 {"cutime",    "-",       pr_nop,      sr_cutime,  1,   0,    LNX, AN|RIGHT},
@@ -1678,6 +1685,7 @@ static const format_struct format_array[] = {
 {"thcount",   "THCNT",   pr_nlwp,     sr_nlwp,    5,   0,    AIX, PO|RIGHT},
 {"tid",       "TID",     pr_tasks,    sr_tasks,   5,   0,    AIX, TO|PIDMAX|RIGHT},
 {"time",      "TIME",    pr_time,     sr_time,    8,   0,    U98, ET|RIGHT}, /*cputime*/ /* was 6 wide */
+{"times",     "TIME",    pr_times,    sr_time,    8,   0,    LNX, ET|RIGHT},
 {"timeout",   "TMOUT",   pr_nop,      sr_nop,     5,   0,    LNX, AN|RIGHT}, // 2.0.xx era
 {"tmout",     "TMOUT",   pr_nop,      sr_nop,     5,   0,    LNX, AN|RIGHT}, // 2.0.xx era
 {"tname",     "TTY",     pr_tty8,     sr_tty,     8,   0,    DEC, PO|LEFT},
diff --git a/ps/ps.1 b/ps/ps.1
index e239f942..df3ded0c 100644
--- a/ps/ps.1
+++ b/ps/ps.1
@@ -1192,6 +1192,11 @@ cumulative CPU time, "[DD\-]hh:mm:ss" format.  (alias
 .BR time ).
 T}
 
+cputimes	TIME	T{
+cumulative CPU time in seconds (alias
+.BR times ).
+T}
+
 drs	DRS	T{
 data resident set size, the amount of physical memory devoted to other than
 executable code.
@@ -1727,6 +1732,11 @@ cumulative CPU\ time, "[DD\-]HH:MM:SS" format.  (alias
 .BR cputime ).
 T}
 
+times	TIME	T{
+cumulative CPU\ time in seconds (alias
+.BR cputimes ).
+T}
+
 tname	TTY	T{
 controlling tty (terminal).  (alias
 .BR tt , \ tty ).
-- 
2.40.0