dumpstate: add key timestamps to power dump

This change adds two key timestamps to the power stats section of
dumpstate_board.txt: the time at which the device was booted and the
current time immediately prior to capturing the power stats.  It also
refactors the lines of code for dumping power stats into a
self-contained function to improve code maintainability.

Currently, because the process of generating a bugreport takes several
minutes, there is significant uncertainty about the temporal
relationship between the bugreport timestamp and the time at which the
power stats were captured.  Also, boot time is reverse-engineered -
again, with an unhelpful degree of uncertainty - by combining the
bugreport timestamp with uptime.  Generating these two timestamps
immediately prior to capturing live power stats will allow
identification of the onset times of key subsystem-related power issues
with much more precision than is currently possible.

Bug: 143312304
Test: Built userdebug and user builds, installed and tested by
generating a bugreport and verifying the new content was present.

Change-Id: I49d3234de27205bdfcfae3662500d2d3b77c2e33
diff --git a/dumpstate/DumpstateDevice.cpp b/dumpstate/DumpstateDevice.cpp
index 2cf2fc1..38d89ea 100755
--- a/dumpstate/DumpstateDevice.cpp
+++ b/dumpstate/DumpstateDevice.cpp
@@ -363,6 +363,15 @@
     }
 }
 
+static void DumpPower(int fd) {
+    RunCommandToFd(fd, "Power Stats Times", {"/vendor/bin/sh", "-c",
+                   "echo -n \"Boot: \" && /vendor/bin/uptime -s &&"
+                   "echo -n \"Now: \" && date"});
+    DumpFileToFd(fd, "Sleep Stats", "/sys/power/system_sleep/stats");
+    DumpFileToFd(fd, "Power Management Stats", "/sys/power/rpmh_stats/master_stats");
+    DumpFileToFd(fd, "WLAN Power Stats", "/sys/kernel/wlan/power_stats");
+}
+
 // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow.
 Return<void> DumpstateDevice::dumpstateBoard(const hidl_handle& handle) {
     // Exit when dump is completed since this is a lazy HAL.
@@ -393,9 +402,9 @@
     DumpUFS(fd);
 
     DumpFileToFd(fd, "INTERRUPTS", "/proc/interrupts");
-    DumpFileToFd(fd, "Sleep Stats", "/sys/power/system_sleep/stats");
-    DumpFileToFd(fd, "Power Management Stats", "/sys/power/rpmh_stats/master_stats");
-    DumpFileToFd(fd, "WLAN Power Stats", "/sys/kernel/wlan/power_stats");
+
+    DumpPower(fd);
+
     DumpFileToFd(fd, "LL-Stats", "/d/wlan0/ll_stats");
     DumpFileToFd(fd, "WLAN Connect Info", "/d/wlan0/connect_info");
     DumpFileToFd(fd, "WLAN Offload Info", "/d/wlan0/offload_info");