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