Fix the stats log in lmkd
am: 389aee1117
Change-Id: I533b09089280681a9c41a3597c62ec621a870839
diff --git a/lmkd/Android.bp b/lmkd/Android.bp
index c7cc41b..1369b8b 100644
--- a/lmkd/Android.bp
+++ b/lmkd/Android.bp
@@ -8,6 +8,7 @@
],
static_libs: [
"libstatslogc",
+ "libstatssocket",
],
local_include_dirs: ["include"],
cflags: ["-Werror", "-DLMKD_TRACE_KILLS"],
@@ -31,6 +32,7 @@
shared_libs: [
"liblog",
],
+ static_libs: ["libstatssocket",],
}
cc_library_static {
diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c
index 63a9bc6..bd4aa7e 100644
--- a/lmkd/lmkd.c
+++ b/lmkd/lmkd.c
@@ -39,7 +39,7 @@
#include <log/log.h>
#ifdef LMKD_LOG_STATS
-#include <statslog.h>
+#include "statslog.h"
#endif
/*
diff --git a/lmkd/statslog.c b/lmkd/statslog.c
index db7a76a..66d1164 100644
--- a/lmkd/statslog.c
+++ b/lmkd/statslog.c
@@ -16,8 +16,16 @@
#include <assert.h>
#include <errno.h>
-#include <log/log_event_list.h>
#include <log/log_id.h>
+#include <stats_event_list.h>
+#include <time.h>
+
+static int64_t getElapsedRealTimeNs() {
+ struct timespec t;
+ t.tv_sec = t.tv_nsec = 0;
+ clock_gettime(CLOCK_BOOTTIME, &t);
+ return (int64_t)t.tv_sec * 1000000000LL + t.tv_nsec;
+}
/**
* Logs the change in LMKD state which is used as start/stop boundaries for logging
@@ -32,6 +40,12 @@
return ret;
}
+ reset_log_context(ctx);
+
+ if ((ret = android_log_write_int64(ctx, getElapsedRealTimeNs())) < 0) {
+ return ret;
+ }
+
if ((ret = android_log_write_int32(ctx, code)) < 0) {
return ret;
}
@@ -39,7 +53,8 @@
if ((ret = android_log_write_int32(ctx, state)) < 0) {
return ret;
}
- return ret;
+
+ return write_to_logger(ctx, LOG_ID_STATS);
}
/**
@@ -56,6 +71,11 @@
if (!ctx) {
return ret;
}
+ reset_log_context(ctx);
+
+ if ((ret = android_log_write_int64(ctx, getElapsedRealTimeNs())) < 0) {
+ return ret;
+ }
if ((ret = android_log_write_int32(ctx, code)) < 0) {
return ret;
@@ -93,8 +113,5 @@
return ret;
}
- if ((ret = android_log_write_list(ctx, LOG_ID_STATS)) < 0) {
- return ret;
- }
- return ret;
+ return write_to_logger(ctx, LOG_ID_STATS);
}
diff --git a/lmkd/statslog.h b/lmkd/statslog.h
index 4cde840..edebb19 100644
--- a/lmkd/statslog.h
+++ b/lmkd/statslog.h
@@ -18,11 +18,11 @@
#define _STATSLOG_H_
#include <assert.h>
+#include <stats_event_list.h>
#include <stdbool.h>
#include <sys/cdefs.h>
#include <cutils/properties.h>
-#include <log/log_event_list.h>
__BEGIN_DECLS