Enhance bootstat_summary to accept a list of events.

If provided with arguments, the script will summarize only the named
events.  If no arguments are provided, the script summarizes all
available events, just as before.

BUG=None
TEST=run the command with and without arguments

Change-Id: I21fdcced548d5a1d63c62b8e40f3817342319c46
Reviewed-on: https://gerrit.chromium.org/gerrit/48821
Reviewed-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Richard Barnette <jrbarnette@chromium.org>
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
diff --git a/bootstat_summary b/bootstat_summary
index e22c6b6..05c1672 100755
--- a/bootstat_summary
+++ b/bootstat_summary
@@ -15,6 +15,7 @@
     #  $1 = time since boot
     #  $2 = idle time since boot (normalized for NCPU)
     #  $3 = event name
+    # input lines are sorted by $1
     uptime = $1 ; idle = $2
     cum_util = (200 * (uptime - idle) / uptime + 1) / 2
     delta = uptime - prev
@@ -24,11 +25,22 @@
   }
 '
 
+# If there are no arguments on the command line, summarize all the
+# events.  If there are arguments, summarize only the named events.
+# Error checking is deliberately minimal, to keep this script simple.
+if [ $# -eq 0 ]; then
+  EVENTS="$(ls /tmp/uptime-*)"
+else
+  for EV in "$@"; do
+    EVENTS="$EVENTS /tmp/uptime-$EV"
+  done
+fi
+
 # Pipeline explained:
-#  1st awk program: extract raw time data, and perform some simple
-#    conversions.
-#  sort: sort the data by the uptime timestamp.
+#  1st awk program: print times as milliseconds and normalize idle time
+#     by NCPU.
+#  sort: sort the events by the uptime timestamp.
 #  sed: remove '/tmp/uptime-' from the event name.
 #  2nd awk program:  produce the summarized output
-awk '{print 1000*$1, 1000*$2/'$NCPU', FILENAME}' /tmp/uptime-* |
+awk '{print 1000*$1, 1000*$2/'$NCPU', FILENAME}' $EVENTS |
   sort -k 1n | sed 's=[^ ]*uptime-==' | awk "$SUMMARIZE_TIME"