This shows the other fields in getrusage. I've chosen to only show the
ones actually maintained by Linux.
---
 toys/posix/time.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
From d7e80c0b1a6796959625628413215e9c273bf8dd Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Fri, 17 Nov 2017 12:10:36 -0800
Subject: [PATCH] Add "time -v".

This shows the other fields in getrusage. I've chosen to only show the
ones actually maintained by Linux.
---
 toys/posix/time.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/toys/posix/time.c b/toys/posix/time.c
index 2151826..18664c1 100644
--- a/toys/posix/time.c
+++ b/toys/posix/time.c
@@ -4,22 +4,24 @@
  *
  * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/time.html
 
-USE_TIME(NEWTOY(time, "<1^p", TOYFLAG_USR|TOYFLAG_BIN))
+USE_TIME(NEWTOY(time, "<1^pv", TOYFLAG_USR|TOYFLAG_BIN))
 
 config TIME
   bool "time"
   default y
   depends on TOYBOX_FLOAT
   help
-    usage: time [-p] COMMAND [ARGS...]
+    usage: time [-pv] COMMAND [ARGS...]
 
     Run command line and report real, user, and system time elapsed in seconds.
     (real = clock on the wall, user = cpu used by command's code,
     system = cpu used by OS on behalf of command.)
 
-    -p	posix mode (ignored)
+    -p	posix mode (default)
+    -v	verbose mode
 */
 
+#define FOR_time
 #include "toys.h"
 
 void time_main(void)
@@ -43,7 +45,20 @@ void time_main(void)
     r = (tv2.tv_sec-tv.tv_sec)+((tv2.tv_usec-tv.tv_usec)/1000000.0);
     u = ru.ru_utime.tv_sec+(ru.ru_utime.tv_usec/1000000.0);
     s = ru.ru_stime.tv_sec+(ru.ru_stime.tv_usec/1000000.0);
-    fprintf(stderr, "real %f\nuser %f\nsys %f\n", r, u, s);
+    if (toys.optflags&FLAG_v) {
+      fprintf(stderr, "Real time (s): %f\n"
+                      "System time (s): %f\n"
+                      "User time (s): %f\n"
+                      "Max RSS (KiB): %ld\n"
+                      "Major faults: %ld\n"
+                      "Minor faults: %ld\n"
+                      "File system inputs: %ld\n"
+                      "File system outputs: %ld\n"
+                      "Voluntary context switches: %ld\n"
+                      "Involuntary context switches: %ld\n", r, u, s,
+              ru.ru_maxrss, ru.ru_majflt, ru.ru_minflt, ru.ru_inblock,
+              ru.ru_oublock, ru.ru_nvcsw, ru.ru_nivcsw);
+    } else fprintf(stderr, "real %f\nuser %f\nsys %f\n", r, u, s);
     toys.exitval = WIFEXITED(stat) ? WEXITSTATUS(stat) : WTERMSIG(stat);
   }
 }
-- 
2.15.0.448.gf294e3d99a-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to