Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 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 | |
| 17 | #include "config/ConfigManager.h" |
| 18 | |
| 19 | #include "stats_util.h" |
| 20 | |
| 21 | #include <vector> |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | |
| 25 | namespace android { |
| 26 | namespace os { |
| 27 | namespace statsd { |
| 28 | |
| 29 | static StatsdConfig build_fake_config(); |
| 30 | |
| 31 | ConfigManager::ConfigManager() { |
| 32 | } |
| 33 | |
| 34 | ConfigManager::~ConfigManager() { |
| 35 | } |
| 36 | |
| 37 | void ConfigManager::Startup() { |
| 38 | // TODO: Implement me -- read from storage and call onto all of the listeners. |
| 39 | // Instead, we'll just make a fake one. |
| 40 | |
| 41 | // this should be called from StatsService when it receives a statsd_config |
Yao Chen | 7ee9415 | 2017-11-17 09:44:40 -0800 | [diff] [blame^] | 42 | UpdateConfig(ConfigKey(1000, "fake"), build_fake_config()); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void ConfigManager::AddListener(const sp<ConfigListener>& listener) { |
| 46 | mListeners.push_back(listener); |
| 47 | } |
| 48 | |
| 49 | void ConfigManager::UpdateConfig(const ConfigKey& key, const StatsdConfig& config) { |
| 50 | // Add to map |
| 51 | mConfigs[key] = config; |
| 52 | // Why doesn't this work? mConfigs.insert({key, config}); |
| 53 | |
| 54 | // Save to disk |
| 55 | update_saved_configs(); |
| 56 | |
| 57 | // Tell everyone |
| 58 | for (auto& listener : mListeners) { |
| 59 | listener->OnConfigUpdated(key, config); |
| 60 | } |
| 61 | } |
| 62 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 63 | void ConfigManager::SetConfigReceiver(const ConfigKey& key, const string& pkg, const string& cls) { |
| 64 | mConfigReceivers[key] = pair<string, string>(pkg, cls); |
| 65 | } |
| 66 | |
| 67 | void ConfigManager::RemoveConfigReceiver(const ConfigKey& key) { |
| 68 | mConfigReceivers.erase(key); |
| 69 | } |
| 70 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 71 | void ConfigManager::RemoveConfig(const ConfigKey& key) { |
| 72 | unordered_map<ConfigKey, StatsdConfig>::iterator it = mConfigs.find(key); |
| 73 | if (it != mConfigs.end()) { |
| 74 | // Remove from map |
| 75 | mConfigs.erase(it); |
| 76 | |
| 77 | // Save to disk |
| 78 | update_saved_configs(); |
| 79 | |
| 80 | // Tell everyone |
| 81 | for (auto& listener : mListeners) { |
| 82 | listener->OnConfigRemoved(key); |
| 83 | } |
| 84 | } |
| 85 | // If we didn't find it, just quietly ignore it. |
| 86 | } |
| 87 | |
| 88 | void ConfigManager::RemoveConfigs(int uid) { |
| 89 | vector<ConfigKey> removed; |
| 90 | |
| 91 | for (auto it = mConfigs.begin(); it != mConfigs.end();) { |
| 92 | // Remove from map |
| 93 | if (it->first.GetUid() == uid) { |
| 94 | removed.push_back(it->first); |
| 95 | it = mConfigs.erase(it); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 96 | mConfigReceivers.erase(it->first); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 97 | } else { |
| 98 | it++; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // Remove separately so if they do anything in the callback they can't mess up our iteration. |
| 103 | for (auto& key : removed) { |
| 104 | // Tell everyone |
| 105 | for (auto& listener : mListeners) { |
| 106 | listener->OnConfigRemoved(key); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | void ConfigManager::Dump(FILE* out) { |
| 112 | fprintf(out, "CONFIGURATIONS (%d)\n", (int)mConfigs.size()); |
| 113 | fprintf(out, " uid name\n"); |
| 114 | for (unordered_map<ConfigKey, StatsdConfig>::const_iterator it = mConfigs.begin(); |
| 115 | it != mConfigs.end(); it++) { |
| 116 | fprintf(out, " %6d %s\n", it->first.GetUid(), it->first.GetName().c_str()); |
| 117 | // TODO: Print the contents of the config too. |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | void ConfigManager::update_saved_configs() { |
| 122 | // TODO: Implement me -- write to disk. |
| 123 | } |
| 124 | |
| 125 | static StatsdConfig build_fake_config() { |
| 126 | // HACK: Hard code a test metric for counting screen on events... |
| 127 | StatsdConfig config; |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 128 | config.set_name("12345"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 129 | |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 130 | int WAKE_LOCK_TAG_ID = 1111; // put a fake id here to make testing easier. |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 131 | int WAKE_LOCK_UID_KEY_ID = 1; |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 132 | int WAKE_LOCK_NAME_KEY = 3; |
| 133 | int WAKE_LOCK_STATE_KEY = 4; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 134 | int WAKE_LOCK_ACQUIRE_VALUE = 1; |
| 135 | int WAKE_LOCK_RELEASE_VALUE = 0; |
| 136 | |
| 137 | int APP_USAGE_ID = 12345; |
| 138 | int APP_USAGE_UID_KEY_ID = 1; |
| 139 | int APP_USAGE_STATE_KEY = 2; |
| 140 | int APP_USAGE_FOREGROUND = 1; |
| 141 | int APP_USAGE_BACKGROUND = 0; |
| 142 | |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 143 | int SCREEN_EVENT_TAG_ID = 29; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 144 | int SCREEN_EVENT_STATE_KEY = 1; |
| 145 | int SCREEN_EVENT_ON_VALUE = 2; |
| 146 | int SCREEN_EVENT_OFF_VALUE = 1; |
| 147 | |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 148 | int UID_PROCESS_STATE_TAG_ID = 27; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 149 | int UID_PROCESS_STATE_UID_KEY = 1; |
| 150 | |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 151 | int KERNEL_WAKELOCK_TAG_ID = 1004; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 152 | int KERNEL_WAKELOCK_NAME_KEY = 4; |
| 153 | |
Yangster | 1d4d686 | 2017-10-31 12:58:51 -0700 | [diff] [blame] | 154 | int DEVICE_TEMPERATURE_TAG_ID = 33; |
| 155 | int DEVICE_TEMPERATURE_KEY = 1; |
| 156 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 157 | // Count Screen ON events. |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 158 | CountMetric* metric = config.add_count_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 159 | metric->set_name("1"); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 160 | metric->set_what("SCREEN_TURNED_ON"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 161 | metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 162 | |
Bookatz | d3606c7 | 2017-10-19 10:13:49 -0700 | [diff] [blame] | 163 | // Anomaly threshold for screen-on count. |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 164 | Alert* alert = config.add_alerts(); |
| 165 | alert->set_name("1"); |
Bookatz | d3606c7 | 2017-10-19 10:13:49 -0700 | [diff] [blame] | 166 | alert->set_number_of_buckets(6); |
| 167 | alert->set_trigger_if_sum_gt(10); |
| 168 | alert->set_refractory_period_secs(30); |
| 169 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 170 | // Count process state changes, slice by uid. |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 171 | metric = config.add_count_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 172 | metric->set_name("2"); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 173 | metric->set_what("PROCESS_STATE_CHANGE"); |
| 174 | metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 175 | KeyMatcher* keyMatcher = metric->add_dimension(); |
| 176 | keyMatcher->set_key(UID_PROCESS_STATE_UID_KEY); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 177 | |
Yang Lu | 3eba621 | 2017-10-25 19:54:45 -0700 | [diff] [blame] | 178 | // Anomaly threshold for background count. |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 179 | alert = config.add_alerts(); |
| 180 | alert->set_name("2"); |
Yang Lu | 3eba621 | 2017-10-25 19:54:45 -0700 | [diff] [blame] | 181 | alert->set_number_of_buckets(4); |
| 182 | alert->set_trigger_if_sum_gt(30); |
| 183 | alert->set_refractory_period_secs(20); |
| 184 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 185 | // Count process state changes, slice by uid, while SCREEN_IS_OFF |
| 186 | metric = config.add_count_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 187 | metric->set_name("3"); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 188 | metric->set_what("PROCESS_STATE_CHANGE"); |
| 189 | metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 190 | keyMatcher = metric->add_dimension(); |
| 191 | keyMatcher->set_key(UID_PROCESS_STATE_UID_KEY); |
| 192 | metric->set_condition("SCREEN_IS_OFF"); |
| 193 | |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 194 | // Count wake lock, slice by uid, while SCREEN_IS_ON and app in background |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 195 | metric = config.add_count_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 196 | metric->set_name("4"); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 197 | metric->set_what("APP_GET_WL"); |
| 198 | metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 199 | keyMatcher = metric->add_dimension(); |
| 200 | keyMatcher->set_key(WAKE_LOCK_UID_KEY_ID); |
| 201 | metric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON"); |
| 202 | EventConditionLink* link = metric->add_links(); |
| 203 | link->set_condition("APP_IS_BACKGROUND"); |
| 204 | link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID); |
| 205 | link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID); |
| 206 | |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 207 | // Duration of an app holding any wl, while screen on and app in background, slice by uid |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 208 | DurationMetric* durationMetric = config.add_duration_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 209 | durationMetric->set_name("5"); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 210 | durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 211 | durationMetric->set_type(DurationMetric_AggregationType_DURATION_SUM); |
| 212 | keyMatcher = durationMetric->add_dimension(); |
| 213 | keyMatcher->set_key(WAKE_LOCK_UID_KEY_ID); |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 214 | durationMetric->set_what("WL_HELD_PER_APP_PER_NAME"); |
Yao Chen | 5c925ad | 2017-11-15 14:15:46 -0800 | [diff] [blame] | 215 | durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON"); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 216 | link = durationMetric->add_links(); |
| 217 | link->set_condition("APP_IS_BACKGROUND"); |
| 218 | link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID); |
| 219 | link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID); |
| 220 | |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 221 | // max Duration of an app holding any wl, while screen on and app in background, slice by uid |
| 222 | durationMetric = config.add_duration_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 223 | durationMetric->set_name("6"); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 224 | durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 225 | durationMetric->set_type(DurationMetric_AggregationType_DURATION_MAX_SPARSE); |
| 226 | keyMatcher = durationMetric->add_dimension(); |
| 227 | keyMatcher->set_key(WAKE_LOCK_UID_KEY_ID); |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 228 | durationMetric->set_what("WL_HELD_PER_APP_PER_NAME"); |
Yao Chen | 5c925ad | 2017-11-15 14:15:46 -0800 | [diff] [blame] | 229 | durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON"); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 230 | link = durationMetric->add_links(); |
| 231 | link->set_condition("APP_IS_BACKGROUND"); |
| 232 | link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID); |
| 233 | link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID); |
| 234 | |
| 235 | // Duration of an app holding any wl, while screen on and app in background |
| 236 | durationMetric = config.add_duration_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 237 | durationMetric->set_name("7"); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 238 | durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 239 | durationMetric->set_type(DurationMetric_AggregationType_DURATION_MAX_SPARSE); |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 240 | durationMetric->set_what("WL_HELD_PER_APP_PER_NAME"); |
Yao Chen | 5c925ad | 2017-11-15 14:15:46 -0800 | [diff] [blame] | 241 | durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON"); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 242 | link = durationMetric->add_links(); |
| 243 | link->set_condition("APP_IS_BACKGROUND"); |
| 244 | link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID); |
| 245 | link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID); |
| 246 | |
| 247 | // Duration of screen on time. |
| 248 | durationMetric = config.add_duration_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 249 | durationMetric->set_name("8"); |
Yangster | 1d4d686 | 2017-10-31 12:58:51 -0700 | [diff] [blame] | 250 | durationMetric->mutable_bucket()->set_bucket_size_millis(10 * 1000L); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 251 | durationMetric->set_type(DurationMetric_AggregationType_DURATION_SUM); |
| 252 | durationMetric->set_what("SCREEN_IS_ON"); |
| 253 | |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 254 | // Value metric to count KERNEL_WAKELOCK when screen turned on |
| 255 | ValueMetric* valueMetric = config.add_value_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 256 | valueMetric->set_name("6"); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 257 | valueMetric->set_what("KERNEL_WAKELOCK"); |
| 258 | valueMetric->set_value_field(1); |
| 259 | valueMetric->set_condition("SCREEN_IS_ON"); |
| 260 | keyMatcher = valueMetric->add_dimension(); |
| 261 | keyMatcher->set_key(KERNEL_WAKELOCK_NAME_KEY); |
| 262 | // This is for testing easier. We should never set bucket size this small. |
| 263 | valueMetric->mutable_bucket()->set_bucket_size_millis(60 * 1000L); |
| 264 | |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 265 | // Add an EventMetric to log process state change events. |
| 266 | EventMetric* eventMetric = config.add_event_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 267 | eventMetric->set_name("9"); |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 268 | eventMetric->set_what("SCREEN_TURNED_ON"); |
| 269 | |
Yangster | 1d4d686 | 2017-10-31 12:58:51 -0700 | [diff] [blame] | 270 | // Add an GaugeMetric. |
| 271 | GaugeMetric* gaugeMetric = config.add_gauge_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 272 | gaugeMetric->set_name("10"); |
Yangster | 1d4d686 | 2017-10-31 12:58:51 -0700 | [diff] [blame] | 273 | gaugeMetric->set_what("DEVICE_TEMPERATURE"); |
| 274 | gaugeMetric->set_gauge_field(DEVICE_TEMPERATURE_KEY); |
| 275 | gaugeMetric->mutable_bucket()->set_bucket_size_millis(60 * 1000L); |
| 276 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 277 | // Event matchers............ |
Yangster | 1d4d686 | 2017-10-31 12:58:51 -0700 | [diff] [blame] | 278 | LogEntryMatcher* temperatureEntryMatcher = config.add_log_entry_matcher(); |
| 279 | temperatureEntryMatcher->set_name("DEVICE_TEMPERATURE"); |
| 280 | temperatureEntryMatcher->mutable_simple_log_entry_matcher()->set_tag( |
| 281 | DEVICE_TEMPERATURE_TAG_ID); |
| 282 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 283 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 284 | eventMatcher->set_name("SCREEN_TURNED_ON"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 285 | SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 286 | simpleLogEntryMatcher->set_tag(SCREEN_EVENT_TAG_ID); |
| 287 | KeyValueMatcher* keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher(); |
| 288 | keyValueMatcher->mutable_key_matcher()->set_key(SCREEN_EVENT_STATE_KEY); |
| 289 | keyValueMatcher->set_eq_int(SCREEN_EVENT_ON_VALUE); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 290 | |
| 291 | eventMatcher = config.add_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 292 | eventMatcher->set_name("SCREEN_TURNED_OFF"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 293 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 294 | simpleLogEntryMatcher->set_tag(SCREEN_EVENT_TAG_ID); |
| 295 | keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher(); |
| 296 | keyValueMatcher->mutable_key_matcher()->set_key(SCREEN_EVENT_STATE_KEY); |
| 297 | keyValueMatcher->set_eq_int(SCREEN_EVENT_OFF_VALUE); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 298 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 299 | eventMatcher = config.add_log_entry_matcher(); |
| 300 | eventMatcher->set_name("PROCESS_STATE_CHANGE"); |
| 301 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
| 302 | simpleLogEntryMatcher->set_tag(UID_PROCESS_STATE_TAG_ID); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 303 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 304 | eventMatcher = config.add_log_entry_matcher(); |
| 305 | eventMatcher->set_name("APP_GOES_BACKGROUND"); |
| 306 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
| 307 | simpleLogEntryMatcher->set_tag(APP_USAGE_ID); |
| 308 | keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher(); |
| 309 | keyValueMatcher->mutable_key_matcher()->set_key(APP_USAGE_STATE_KEY); |
| 310 | keyValueMatcher->set_eq_int(APP_USAGE_BACKGROUND); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 311 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 312 | eventMatcher = config.add_log_entry_matcher(); |
| 313 | eventMatcher->set_name("APP_GOES_FOREGROUND"); |
| 314 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
| 315 | simpleLogEntryMatcher->set_tag(APP_USAGE_ID); |
| 316 | keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher(); |
| 317 | keyValueMatcher->mutable_key_matcher()->set_key(APP_USAGE_STATE_KEY); |
| 318 | keyValueMatcher->set_eq_int(APP_USAGE_FOREGROUND); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 319 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 320 | eventMatcher = config.add_log_entry_matcher(); |
| 321 | eventMatcher->set_name("APP_GET_WL"); |
| 322 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
| 323 | simpleLogEntryMatcher->set_tag(WAKE_LOCK_TAG_ID); |
| 324 | keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher(); |
| 325 | keyValueMatcher->mutable_key_matcher()->set_key(WAKE_LOCK_STATE_KEY); |
| 326 | keyValueMatcher->set_eq_int(WAKE_LOCK_ACQUIRE_VALUE); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 327 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 328 | eventMatcher = config.add_log_entry_matcher(); |
| 329 | eventMatcher->set_name("APP_RELEASE_WL"); |
| 330 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
| 331 | simpleLogEntryMatcher->set_tag(WAKE_LOCK_TAG_ID); |
| 332 | keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher(); |
| 333 | keyValueMatcher->mutable_key_matcher()->set_key(WAKE_LOCK_STATE_KEY); |
| 334 | keyValueMatcher->set_eq_int(WAKE_LOCK_RELEASE_VALUE); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 335 | |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 336 | // pulled events |
| 337 | eventMatcher = config.add_log_entry_matcher(); |
| 338 | eventMatcher->set_name("KERNEL_WAKELOCK"); |
| 339 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
| 340 | simpleLogEntryMatcher->set_tag(KERNEL_WAKELOCK_TAG_ID); |
| 341 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 342 | // Conditions............. |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 343 | Condition* condition = config.add_condition(); |
| 344 | condition->set_name("SCREEN_IS_ON"); |
| 345 | SimpleCondition* simpleCondition = condition->mutable_simple_condition(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 346 | simpleCondition->set_start("SCREEN_TURNED_ON"); |
| 347 | simpleCondition->set_stop("SCREEN_TURNED_OFF"); |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 348 | simpleCondition->set_count_nesting(false); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 349 | |
| 350 | condition = config.add_condition(); |
| 351 | condition->set_name("SCREEN_IS_OFF"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 352 | simpleCondition = condition->mutable_simple_condition(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 353 | simpleCondition->set_start("SCREEN_TURNED_OFF"); |
| 354 | simpleCondition->set_stop("SCREEN_TURNED_ON"); |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 355 | simpleCondition->set_count_nesting(false); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 356 | |
| 357 | condition = config.add_condition(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 358 | condition->set_name("APP_IS_BACKGROUND"); |
| 359 | simpleCondition = condition->mutable_simple_condition(); |
| 360 | simpleCondition->set_start("APP_GOES_BACKGROUND"); |
| 361 | simpleCondition->set_stop("APP_GOES_FOREGROUND"); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 362 | KeyMatcher* condition_dimension1 = simpleCondition->add_dimension(); |
| 363 | condition_dimension1->set_key(APP_USAGE_UID_KEY_ID); |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 364 | simpleCondition->set_count_nesting(false); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 365 | |
| 366 | condition = config.add_condition(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 367 | condition->set_name("APP_IS_BACKGROUND_AND_SCREEN_ON"); |
| 368 | Condition_Combination* combination_condition = condition->mutable_combination(); |
| 369 | combination_condition->set_operation(LogicalOperation::AND); |
| 370 | combination_condition->add_condition("APP_IS_BACKGROUND"); |
| 371 | combination_condition->add_condition("SCREEN_IS_ON"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 372 | |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 373 | condition = config.add_condition(); |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 374 | condition->set_name("WL_HELD_PER_APP_PER_NAME"); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 375 | simpleCondition = condition->mutable_simple_condition(); |
| 376 | simpleCondition->set_start("APP_GET_WL"); |
| 377 | simpleCondition->set_stop("APP_RELEASE_WL"); |
| 378 | KeyMatcher* condition_dimension = simpleCondition->add_dimension(); |
| 379 | condition_dimension->set_key(WAKE_LOCK_UID_KEY_ID); |
| 380 | condition_dimension = simpleCondition->add_dimension(); |
| 381 | condition_dimension->set_key(WAKE_LOCK_NAME_KEY); |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 382 | simpleCondition->set_count_nesting(true); |
| 383 | |
| 384 | condition = config.add_condition(); |
| 385 | condition->set_name("WL_HELD_PER_APP"); |
| 386 | simpleCondition = condition->mutable_simple_condition(); |
| 387 | simpleCondition->set_start("APP_GET_WL"); |
| 388 | simpleCondition->set_stop("APP_RELEASE_WL"); |
| 389 | simpleCondition->set_initial_value(SimpleCondition_InitialValue_FALSE); |
| 390 | condition_dimension = simpleCondition->add_dimension(); |
| 391 | condition_dimension->set_key(WAKE_LOCK_UID_KEY_ID); |
| 392 | simpleCondition->set_count_nesting(true); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 393 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 394 | return config; |
| 395 | } |
| 396 | |
| 397 | } // namespace statsd |
| 398 | } // namespace os |
| 399 | } // namespace android |