diff --git a/Android.bp b/Android.bp index 3f8a503..2731596 100644 --- a/Android.bp +++ b/Android.bp @@ -10,4 +10,12 @@ cc_binary { cflags: ["-Werror"], init_rc: ["lmkd.rc"], + + product_variables: { + debuggable: { + cflags: [ + "-DLMKD_TRACE_KILLS" + ], + }, + }, } diff --git a/lmkd.c b/lmkd.c index fb7cc00..c78461c 100644 --- a/lmkd.c +++ b/lmkd.c @@ -37,6 +37,25 @@ #include #include +/* + * Define LMKD_TRACE_KILLS to record lmkd kills in kernel traces + * to profile and correlate with OOM kills + */ +#ifdef LMKD_TRACE_KILLS + +#define ATRACE_TAG ATRACE_TAG_ALWAYS +#include + +#define TRACE_KILL_START(pid) ATRACE_INT(__FUNCTION__, pid); +#define TRACE_KILL_END() ATRACE_INT(__FUNCTION__, 0); + +#else /* LMKD_TRACE_KILLS */ + +#define TRACE_KILL_START(pid) +#define TRACE_KILL_END() + +#endif /* LMKD_TRACE_KILLS */ + #ifndef __unused #define __unused __attribute__((__unused__)) #endif @@ -638,6 +657,8 @@ static int kill_one_process(struct proc* procp, int min_score_adj, return -1; } + TRACE_KILL_START(pid); + r = kill(pid, SIGKILL); ALOGI( "Killing '%s' (%d), uid %d, adj %d\n" @@ -646,6 +667,8 @@ static int kill_one_process(struct proc* procp, int min_score_adj, level_name[level], min_score_adj); pid_remove(pid); + TRACE_KILL_END(); + if (r) { ALOGE("kill(%d): errno=%d", procp->pid, errno); return -1;