| 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 |  | 
| Rajeev Kumar | 1c669f7 | 2018-03-09 15:20:56 -0800 | [diff] [blame] | 20 | #include <assert.h> | 
| Yao Chen | 389aee1 | 2018-05-02 11:19:27 -0700 | [diff] [blame] | 21 | #include <stats_event_list.h> | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 22 | #include <stdbool.h> | 
| Rajeev Kumar | f0216a8 | 2018-01-24 14:40:36 -0800 | [diff] [blame] | 23 | #include <sys/cdefs.h> | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 24 |  | 
|  | 25 | #include <cutils/properties.h> | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 26 |  | 
| Rajeev Kumar | f0216a8 | 2018-01-24 14:40:36 -0800 | [diff] [blame] | 27 | __BEGIN_DECLS | 
|  | 28 |  | 
| Rajeev Kumar | 7045003 | 2018-01-31 17:54:56 -0800 | [diff] [blame] | 29 | /* | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 30 | * These are defined in | 
|  | 31 | * http://cs/android/frameworks/base/cmds/statsd/src/atoms.proto | 
|  | 32 | */ | 
|  | 33 | #define LMK_KILL_OCCURRED 51 | 
|  | 34 | #define LMK_STATE_CHANGED 54 | 
|  | 35 | #define LMK_STATE_CHANGE_START 1 | 
|  | 36 | #define LMK_STATE_CHANGE_STOP 2 | 
|  | 37 |  | 
| Rajeev Kumar | 1c669f7 | 2018-03-09 15:20:56 -0800 | [diff] [blame] | 38 | /* | 
|  | 39 | * The single event tag id for all stats logs. | 
|  | 40 | * Keep this in sync with system/core/logcat/event.logtags | 
|  | 41 | */ | 
|  | 42 | const static int kStatsEventTag = 1937006964; | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 43 |  | 
| Rajeev Kumar | 1c669f7 | 2018-03-09 15:20:56 -0800 | [diff] [blame] | 44 | static inline void statslog_init(android_log_context* log_ctx, bool* enable_stats_log) { | 
|  | 45 | assert(log_ctx != NULL); | 
|  | 46 | assert(enable_stats_log != NULL); | 
|  | 47 | *enable_stats_log = property_get_bool("ro.lmk.log_stats", false); | 
|  | 48 |  | 
|  | 49 | if (*enable_stats_log) { | 
|  | 50 | *log_ctx = create_android_logger(kStatsEventTag); | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 51 | } | 
|  | 52 | } | 
|  | 53 |  | 
| Rajeev Kumar | 1c669f7 | 2018-03-09 15:20:56 -0800 | [diff] [blame] | 54 | static inline void statslog_destroy(android_log_context* log_ctx) { | 
|  | 55 | assert(log_ctx != NULL); | 
|  | 56 | if (*log_ctx) { | 
|  | 57 | android_log_destroy(log_ctx); | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 58 | } | 
|  | 59 | } | 
|  | 60 |  | 
|  | 61 | struct memory_stat { | 
|  | 62 | int64_t pgfault; | 
|  | 63 | int64_t pgmajfault; | 
|  | 64 | int64_t rss_in_bytes; | 
|  | 65 | int64_t cache_in_bytes; | 
|  | 66 | int64_t swap_in_bytes; | 
|  | 67 | }; | 
|  | 68 |  | 
|  | 69 | #define MEMCG_PROCESS_MEMORY_STAT_PATH "/dev/memcg/apps/uid_%u/pid_%u/memory.stat" | 
|  | 70 |  | 
| Rajeev Kumar | f0216a8 | 2018-01-24 14:40:36 -0800 | [diff] [blame] | 71 | /** | 
|  | 72 | * Logs the change in LMKD state which is used as start/stop boundaries for logging | 
|  | 73 | * LMK_KILL_OCCURRED event. | 
|  | 74 | * Code: LMK_STATE_CHANGED = 54 | 
|  | 75 | */ | 
|  | 76 | int | 
|  | 77 | stats_write_lmk_state_changed(android_log_context ctx, int32_t code, int32_t state); | 
|  | 78 |  | 
|  | 79 | /** | 
|  | 80 | * Logs the event when LMKD kills a process to reduce memory pressure. | 
|  | 81 | * Code: LMK_KILL_OCCURRED = 51 | 
|  | 82 | */ | 
|  | 83 | int | 
|  | 84 | stats_write_lmk_kill_occurred(android_log_context ctx, int32_t code, int32_t uid, | 
|  | 85 | char const* process_name, int32_t oom_score, int64_t pgfault, | 
|  | 86 | int64_t pgmajfault, int64_t rss_in_bytes, int64_t cache_in_bytes, | 
|  | 87 | int64_t swap_in_bytes); | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 88 |  | 
| Rajeev Kumar | f0216a8 | 2018-01-24 14:40:36 -0800 | [diff] [blame] | 89 | __END_DECLS | 
| Mark Salyzyn | 61421ba | 2018-02-01 09:54:32 -0800 | [diff] [blame] | 90 |  | 
|  | 91 | #endif /* _STATSLOG_H_ */ |