lmkd: move sundry pieces to statslog.h

Pragma once is not part of the standard, and is actually a gnu
C++ addition. Android coding standard requires the #ifndef header
wrappers. Moved things that belong in statslog.h from the lmkd files.

SideEffects: None
Test: lmkd_unit_tests
Bug: 33808187
Bug: 72838192
Change-Id: I9686b1a0791ee2b723d05b91905eda0bb64a1156
diff --git a/lmkd/statslog.h b/lmkd/statslog.h
index 6a27030..b567fbf 100644
--- a/lmkd/statslog.h
+++ b/lmkd/statslog.h
@@ -14,12 +14,51 @@
  *  limitations under the License.
  */
 
-#pragma once
+#ifndef _STATSLOG_H_
+#define _STATSLOG_H_
 
+#include <stdbool.h>
 #include <sys/cdefs.h>
+
+#include <cutils/properties.h>
+#include <log/log_event_list.h>
+
 __BEGIN_DECLS
 
 /*
+ * These are defined in
+ * http://cs/android/frameworks/base/cmds/statsd/src/atoms.proto
+ */
+#define LMK_KILL_OCCURRED 51
+#define LMK_STATE_CHANGED 54
+#define LMK_STATE_CHANGE_START 1
+#define LMK_STATE_CHANGE_STOP 2
+
+static inline void statslog_init() {
+    enable_stats_log = property_get_bool("ro.lmk.log_stats", false);
+
+    if (enable_stats_log) {
+        log_ctx = create_android_logger(kStatsEventTag);
+    }
+}
+
+static inline void statslog_destroy() {
+    if (log_ctx) {
+        android_log_destroy(&log_ctx);
+    }
+}
+
+struct memory_stat {
+    int64_t pgfault;
+    int64_t pgmajfault;
+    int64_t rss_in_bytes;
+    int64_t cache_in_bytes;
+    int64_t swap_in_bytes;
+};
+
+#define MEMCG_PROCESS_MEMORY_STAT_PATH "/dev/memcg/apps/uid_%u/pid_%u/memory.stat"
+
+/*
  * The single event tag id for all stats logs.
  * Keep this in sync with system/core/logcat/event.logtags
  */
@@ -42,4 +81,7 @@
                               char const* process_name, int32_t oom_score, int64_t pgfault,
                               int64_t pgmajfault, int64_t rss_in_bytes, int64_t cache_in_bytes,
                               int64_t swap_in_bytes);
+
 __END_DECLS
+
+#endif /* _STATSLOG_H_ */