summaryrefslogtreecommitdiffstats
path: root/healthd
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2015-07-23 09:22:50 -0700
committerSteve Kondik <steve@cyngn.com>2015-11-01 04:29:12 -0800
commit4f8d719dc4306c1daba79a5143217f056ace2427 (patch)
tree7b94fc3d0588e71425aeaa6a67a5e213b03e3a58 /healthd
parent67c96c8d5a59e071983270ddd54bad8d0d744d95 (diff)
downloadsystem_core-4f8d719dc4306c1daba79a5143217f056ace2427.zip
system_core-4f8d719dc4306c1daba79a5143217f056ace2427.tar.gz
system_core-4f8d719dc4306c1daba79a5143217f056ace2427.tar.bz2
healthd: logd: add timestamp to kernel logged battery messages
Aid monotonic to realtime logging synchronization correction in the Android ecosystem by providing a periodic notification. We now have the following messages in the kernel logs: - PM: suspend entry %Y-%m-%d %H:%M:%S.%09q UTC - PM: suspend exit %Y-%m-%d %H:%M:%S.%09q UTC - Suspended for %s.%03q seconds - healthd: battery l=100 ... %Y-%m-%d %H:%M:%S.%09q UTC Alter klogd to resynchronize on healthd messages as well. NB: Time using strftime format, %q is a reference to fractional second as introduced into log_time strptime method. Bug: 21868540 Change-Id: I854afc0a07dff9c7f26d2b2f68990e52bf90e300
Diffstat (limited to 'healthd')
-rw-r--r--healthd/BatteryMonitor.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp
index d611add..688348e 100644
--- a/healthd/BatteryMonitor.cpp
+++ b/healthd/BatteryMonitor.cpp
@@ -25,11 +25,13 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/types.h>
#include <unistd.h>
+
#include <batteryservice/BatteryService.h>
#include <cutils/klog.h>
#include <cutils/properties.h>
-#include <sys/types.h>
+#include <log/log_read.h>
#include <utils/Errors.h>
#include <utils/String8.h>
#include <utils/Vector.h>
@@ -352,11 +354,32 @@ bool BatteryMonitor::update(void) {
"dock-battery none");
}
- KLOG_WARNING(LOG_TAG, "%s %s chg=%s%s%s%s\n", dmesgline, dmesglinedock,
- props.chargerAcOnline ? "a" : "",
- props.chargerUsbOnline ? "u" : "",
- props.chargerWirelessOnline ? "w" : "",
- props.chargerDockAcOnline ? "d" : "");
+ size_t len = strlen(dmesgline);
+ snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s",
+ props.chargerAcOnline ? "a" : "",
+ props.chargerUsbOnline ? "u" : "",
+ props.chargerWirelessOnline ? "w" : "");
+
+ log_time realtime(CLOCK_REALTIME);
+ time_t t = realtime.tv_sec;
+ struct tm *tmp = gmtime(&t);
+ if (tmp) {
+ static const char fmt[] = " %Y-%m-%d %H:%M:%S.XXXXXXXXX UTC";
+ len = strlen(dmesgline);
+ if ((len < (sizeof(dmesgline) - sizeof(fmt) - 8)) // margin
+ && strftime(dmesgline + len, sizeof(dmesgline) - len,
+ fmt, tmp)) {
+ char *usec = strchr(dmesgline + len, 'X');
+ if (usec) {
+ len = usec - dmesgline;
+ snprintf(dmesgline + len, sizeof(dmesgline) - len,
+ "%09u", realtime.tv_nsec);
+ usec[9] = ' ';
+ }
+ }
+ }
+
+ KLOG_WARNING(LOG_TAG, "%s\n", dmesgline);
}
healthd_mode_ops->battery_update(&props);