Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61421baf authored by Mark Salyzyn's avatar Mark Salyzyn
Browse files

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
parent a112e1c4
Loading
Loading
Loading
Loading
+2 −28
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@
#include <log/log.h>

#ifdef LMKD_LOG_STATS
#include <log/log_event_list.h>
#include <statslog.h>
#endif

@@ -76,18 +75,6 @@
#define ARRAY_SIZE(x)   (sizeof(x) / sizeof(*(x)))
#define EIGHT_MEGA (1 << 23)

#ifdef LMKD_LOG_STATS
#define MEMCG_PROCESS_MEMORY_STAT_PATH "/dev/memcg/apps/uid_%d/pid_%d/memory.stat"
/*
 * 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
#endif

/* default to old in-kernel interface if no memory pressure events */
static int use_inkernel_interface = 1;
static bool has_inkernel_module;
@@ -182,13 +169,6 @@ struct proc {
};

#ifdef LMKD_LOG_STATS
struct memory_stat {
   int64_t pgfault;
   int64_t pgmajfault;
   int64_t rss_in_bytes;
   int64_t cache_in_bytes;
   int64_t swap_in_bytes;
};
static bool enable_stats_log;
static android_log_context log_ctx;
#endif
@@ -1221,11 +1201,7 @@ int main(int argc __unused, char **argv __unused) {
        (unsigned long)property_get_int32("ro.lmk.kill_timeout_ms", 0);

#ifdef LMKD_LOG_STATS
    enable_stats_log = property_get_bool("ro.lmk.log_stats", false);

    if (enable_stats_log) {
        log_ctx = create_android_logger(kStatsEventTag);
    }
    statlog_init();
#endif

    // MCL_ONFAULT pins pages as they fault instead of loading
@@ -1245,9 +1221,7 @@ int main(int argc __unused, char **argv __unused) {
        mainloop();

#ifdef LMKD_LOG_STATS
    if (log_ctx) {
        android_log_destroy(&log_ctx);
    }
    statslog_destroy();
#endif

    ALOGI("exiting");
+43 −1
Original line number Diff line number Diff line
@@ -14,11 +14,50 @@
 *  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 @@ stats_write_lmk_kill_occurred(android_log_context ctx, int32_t code, int32_t uid
                              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_ */