blob: b567fbf1c4fe297b874a2c2b57a5c218bcdd6b5b [file] [log] [blame]
Rajeev Kumarf0216a82018-01-24 14:40:36 -08001/*
2 * Copyright 2018 Google, Inc
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mark Salyzyn61421ba2018-02-01 09:54:32 -080017#ifndef _STATSLOG_H_
18#define _STATSLOG_H_
Rajeev Kumarf0216a82018-01-24 14:40:36 -080019
Mark Salyzyn61421ba2018-02-01 09:54:32 -080020#include <stdbool.h>
Rajeev Kumarf0216a82018-01-24 14:40:36 -080021#include <sys/cdefs.h>
Mark Salyzyn61421ba2018-02-01 09:54:32 -080022
23#include <cutils/properties.h>
24#include <log/log_event_list.h>
25
Rajeev Kumarf0216a82018-01-24 14:40:36 -080026__BEGIN_DECLS
27
Rajeev Kumar70450032018-01-31 17:54:56 -080028/*
Mark Salyzyn61421ba2018-02-01 09:54:32 -080029 * These are defined in
30 * http://cs/android/frameworks/base/cmds/statsd/src/atoms.proto
31 */
32#define LMK_KILL_OCCURRED 51
33#define LMK_STATE_CHANGED 54
34#define LMK_STATE_CHANGE_START 1
35#define LMK_STATE_CHANGE_STOP 2
36
37static inline void statslog_init() {
38 enable_stats_log = property_get_bool("ro.lmk.log_stats", false);
39
40 if (enable_stats_log) {
41 log_ctx = create_android_logger(kStatsEventTag);
42 }
43}
44
45static inline void statslog_destroy() {
46 if (log_ctx) {
47 android_log_destroy(&log_ctx);
48 }
49}
50
51struct memory_stat {
52 int64_t pgfault;
53 int64_t pgmajfault;
54 int64_t rss_in_bytes;
55 int64_t cache_in_bytes;
56 int64_t swap_in_bytes;
57};
58
59#define MEMCG_PROCESS_MEMORY_STAT_PATH "/dev/memcg/apps/uid_%u/pid_%u/memory.stat"
60
61/*
Rajeev Kumar70450032018-01-31 17:54:56 -080062 * The single event tag id for all stats logs.
63 * Keep this in sync with system/core/logcat/event.logtags
64 */
65const static int kStatsEventTag = 1937006964;
66
Rajeev Kumarf0216a82018-01-24 14:40:36 -080067/**
68 * Logs the change in LMKD state which is used as start/stop boundaries for logging
69 * LMK_KILL_OCCURRED event.
70 * Code: LMK_STATE_CHANGED = 54
71 */
72int
73stats_write_lmk_state_changed(android_log_context ctx, int32_t code, int32_t state);
74
75/**
76 * Logs the event when LMKD kills a process to reduce memory pressure.
77 * Code: LMK_KILL_OCCURRED = 51
78 */
79int
80stats_write_lmk_kill_occurred(android_log_context ctx, int32_t code, int32_t uid,
81 char const* process_name, int32_t oom_score, int64_t pgfault,
82 int64_t pgmajfault, int64_t rss_in_bytes, int64_t cache_in_bytes,
83 int64_t swap_in_bytes);
Mark Salyzyn61421ba2018-02-01 09:54:32 -080084
Rajeev Kumarf0216a82018-01-24 14:40:36 -080085__END_DECLS
Mark Salyzyn61421ba2018-02-01 09:54:32 -080086
87#endif /* _STATSLOG_H_ */