am bc193c53: healthd: logd: add timestamp to kernel logged battery messages
* commit 'bc193c53ecc740d0ac3de976c6654b90a24669b6': healthd: logd: add timestamp to kernel logged battery messages
This commit is contained in:
commit
b2205bc721
2 changed files with 39 additions and 5 deletions
|
|
@ -24,11 +24,13 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <batteryservice/BatteryService.h>
|
#include <batteryservice/BatteryService.h>
|
||||||
#include <cutils/klog.h>
|
#include <cutils/klog.h>
|
||||||
#include <cutils/properties.h>
|
#include <cutils/properties.h>
|
||||||
#include <sys/types.h>
|
#include <log/log_read.h>
|
||||||
#include <utils/Errors.h>
|
#include <utils/Errors.h>
|
||||||
#include <utils/String8.h>
|
#include <utils/String8.h>
|
||||||
#include <utils/Vector.h>
|
#include <utils/Vector.h>
|
||||||
|
|
@ -275,10 +277,32 @@ bool BatteryMonitor::update(void) {
|
||||||
"battery none");
|
"battery none");
|
||||||
}
|
}
|
||||||
|
|
||||||
KLOG_WARNING(LOG_TAG, "%s chg=%s%s%s\n", dmesgline,
|
size_t len = strlen(dmesgline);
|
||||||
props.chargerAcOnline ? "a" : "",
|
snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s",
|
||||||
props.chargerUsbOnline ? "u" : "",
|
props.chargerAcOnline ? "a" : "",
|
||||||
props.chargerWirelessOnline ? "w" : "");
|
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);
|
healthd_mode_ops->battery_update(&props);
|
||||||
|
|
|
||||||
|
|
@ -256,6 +256,7 @@ void LogKlog::sniffTime(log_time &now, const char **buf, bool reverse) {
|
||||||
if ((cp = now.strptime(*buf, "[ %s.%q]"))) {
|
if ((cp = now.strptime(*buf, "[ %s.%q]"))) {
|
||||||
static const char suspend[] = "PM: suspend entry ";
|
static const char suspend[] = "PM: suspend entry ";
|
||||||
static const char resume[] = "PM: suspend exit ";
|
static const char resume[] = "PM: suspend exit ";
|
||||||
|
static const char healthd[] = "healthd: battery ";
|
||||||
static const char suspended[] = "Suspended for ";
|
static const char suspended[] = "Suspended for ";
|
||||||
|
|
||||||
if (isspace(*cp)) {
|
if (isspace(*cp)) {
|
||||||
|
|
@ -265,6 +266,15 @@ void LogKlog::sniffTime(log_time &now, const char **buf, bool reverse) {
|
||||||
calculateCorrection(now, cp + sizeof(suspend) - 1);
|
calculateCorrection(now, cp + sizeof(suspend) - 1);
|
||||||
} else if (!strncmp(cp, resume, sizeof(resume) - 1)) {
|
} else if (!strncmp(cp, resume, sizeof(resume) - 1)) {
|
||||||
calculateCorrection(now, cp + sizeof(resume) - 1);
|
calculateCorrection(now, cp + sizeof(resume) - 1);
|
||||||
|
} else if (!strncmp(cp, healthd, sizeof(healthd) - 1)) {
|
||||||
|
// look for " 2???-??-?? ??:??:??.????????? ???"
|
||||||
|
const char *tp;
|
||||||
|
for (tp = cp + sizeof(healthd) - 1; *tp && (*tp != '\n'); ++tp) {
|
||||||
|
if ((tp[0] == ' ') && (tp[1] == '2') && (tp[5] == '-')) {
|
||||||
|
calculateCorrection(now, tp + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (!strncmp(cp, suspended, sizeof(suspended) - 1)) {
|
} else if (!strncmp(cp, suspended, sizeof(suspended) - 1)) {
|
||||||
log_time real;
|
log_time real;
|
||||||
char *endp;
|
char *endp;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue