| Rajeev Kumar | f0216a8 | 2018-01-24 14:40:36 -0800 | [diff] [blame] | 1 | /* | 
 | 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 Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 17 | #ifndef _STATSLOG_H_ | 
 | 18 | #define _STATSLOG_H_ | 
| Rajeev Kumar | f0216a8 | 2018-01-24 14:40:36 -0800 | [diff] [blame] | 19 |  | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 20 | #include <stdbool.h> | 
| Rajeev Kumar | f0216a8 | 2018-01-24 14:40:36 -0800 | [diff] [blame] | 21 | #include <sys/cdefs.h> | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 22 |  | 
 | 23 | #include <cutils/properties.h> | 
 | 24 | #include <log/log_event_list.h> | 
 | 25 |  | 
| Rajeev Kumar | f0216a8 | 2018-01-24 14:40:36 -0800 | [diff] [blame] | 26 | __BEGIN_DECLS | 
 | 27 |  | 
| Rajeev Kumar | 7045003 | 2018-01-31 17:54:56 -0800 | [diff] [blame] | 28 | /* | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 29 |  * 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 |  | 
 | 37 | static 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 |  | 
 | 45 | static inline void statslog_destroy() { | 
 | 46 |     if (log_ctx) { | 
 | 47 |         android_log_destroy(&log_ctx); | 
 | 48 |     } | 
 | 49 | } | 
 | 50 |  | 
 | 51 | struct 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 Kumar | 7045003 | 2018-01-31 17:54:56 -0800 | [diff] [blame] | 62 |  * The single event tag id for all stats logs. | 
 | 63 |  * Keep this in sync with system/core/logcat/event.logtags | 
 | 64 |  */ | 
 | 65 | const static int kStatsEventTag = 1937006964; | 
 | 66 |  | 
| Rajeev Kumar | f0216a8 | 2018-01-24 14:40:36 -0800 | [diff] [blame] | 67 | /** | 
 | 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 |  */ | 
 | 72 | int | 
 | 73 | stats_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 |  */ | 
 | 79 | int | 
 | 80 | stats_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 Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 84 |  | 
| Rajeev Kumar | f0216a8 | 2018-01-24 14:40:36 -0800 | [diff] [blame] | 85 | __END_DECLS | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 86 |  | 
 | 87 | #endif /* _STATSLOG_H_ */ |