blob: 1e1d88ec142af8af79af8e5c8f1ec13d7deefef6 [file] [log] [blame]
Joe Onorato9fc9edf2017-10-15 20:08:52 -07001/*
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
25namespace android {
26namespace os {
27namespace statsd {
28
29static StatsdConfig build_fake_config();
30
31ConfigManager::ConfigManager() {
32}
33
34ConfigManager::~ConfigManager() {
35}
36
37void 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
45void ConfigManager::AddListener(const sp<ConfigListener>& listener) {
46 mListeners.push_back(listener);
47}
48
49void 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
63void 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
80void 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
102void 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
112void ConfigManager::update_saved_configs() {
113 // TODO: Implement me -- write to disk.
114}
115
116static StatsdConfig build_fake_config() {
117 // HACK: Hard code a test metric for counting screen on events...
118 StatsdConfig config;
Yangster-macd1815dc2017-11-13 21:43:15 -0800119 config.set_name("12345");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700120
Yao Chen5154a3792017-10-30 22:57:06 -0700121 int WAKE_LOCK_TAG_ID = 1111; // put a fake id here to make testing easier.
Yao Chen729093d2017-10-16 10:33:26 -0700122 int WAKE_LOCK_UID_KEY_ID = 1;
Yao Chen5154a3792017-10-30 22:57:06 -0700123 int WAKE_LOCK_NAME_KEY = 3;
124 int WAKE_LOCK_STATE_KEY = 4;
Yao Chen729093d2017-10-16 10:33:26 -0700125 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
Bookatzc1a050a2017-10-10 15:49:28 -0700134 int SCREEN_EVENT_TAG_ID = 29;
Yao Chen729093d2017-10-16 10:33:26 -0700135 int SCREEN_EVENT_STATE_KEY = 1;
136 int SCREEN_EVENT_ON_VALUE = 2;
137 int SCREEN_EVENT_OFF_VALUE = 1;
138
Bookatzc1a050a2017-10-10 15:49:28 -0700139 int UID_PROCESS_STATE_TAG_ID = 27;
Yao Chen729093d2017-10-16 10:33:26 -0700140 int UID_PROCESS_STATE_UID_KEY = 1;
141
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700142 int KERNEL_WAKELOCK_TAG_ID = 1004;
Chenjie Yub3dda412017-10-24 13:41:59 -0700143 int KERNEL_WAKELOCK_NAME_KEY = 4;
144
Yangster1d4d6862017-10-31 12:58:51 -0700145 int DEVICE_TEMPERATURE_TAG_ID = 33;
146 int DEVICE_TEMPERATURE_KEY = 1;
147
Yao Chen729093d2017-10-16 10:33:26 -0700148 // Count Screen ON events.
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700149 CountMetric* metric = config.add_count_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800150 metric->set_name("1");
Yao Chen729093d2017-10-16 10:33:26 -0700151 metric->set_what("SCREEN_TURNED_ON");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700152 metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
153
Bookatzd3606c72017-10-19 10:13:49 -0700154 // Anomaly threshold for screen-on count.
Yangster-macd1815dc2017-11-13 21:43:15 -0800155 Alert* alert = config.add_alerts();
156 alert->set_name("1");
Bookatzd3606c72017-10-19 10:13:49 -0700157 alert->set_number_of_buckets(6);
158 alert->set_trigger_if_sum_gt(10);
159 alert->set_refractory_period_secs(30);
160
Yao Chen729093d2017-10-16 10:33:26 -0700161 // Count process state changes, slice by uid.
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700162 metric = config.add_count_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800163 metric->set_name("2");
Yao Chen729093d2017-10-16 10:33:26 -0700164 metric->set_what("PROCESS_STATE_CHANGE");
165 metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
166 KeyMatcher* keyMatcher = metric->add_dimension();
167 keyMatcher->set_key(UID_PROCESS_STATE_UID_KEY);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700168
Yang Lu3eba6212017-10-25 19:54:45 -0700169 // Anomaly threshold for background count.
Yangster-macd1815dc2017-11-13 21:43:15 -0800170 alert = config.add_alerts();
171 alert->set_name("2");
Yang Lu3eba6212017-10-25 19:54:45 -0700172 alert->set_number_of_buckets(4);
173 alert->set_trigger_if_sum_gt(30);
174 alert->set_refractory_period_secs(20);
175
Yao Chen729093d2017-10-16 10:33:26 -0700176 // Count process state changes, slice by uid, while SCREEN_IS_OFF
177 metric = config.add_count_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800178 metric->set_name("3");
Yao Chen729093d2017-10-16 10:33:26 -0700179 metric->set_what("PROCESS_STATE_CHANGE");
180 metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
181 keyMatcher = metric->add_dimension();
182 keyMatcher->set_key(UID_PROCESS_STATE_UID_KEY);
183 metric->set_condition("SCREEN_IS_OFF");
184
Yao Chen5110bed2017-10-23 12:50:02 -0700185 // Count wake lock, slice by uid, while SCREEN_IS_ON and app in background
Yao Chen729093d2017-10-16 10:33:26 -0700186 metric = config.add_count_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800187 metric->set_name("4");
Yao Chen729093d2017-10-16 10:33:26 -0700188 metric->set_what("APP_GET_WL");
189 metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
190 keyMatcher = metric->add_dimension();
191 keyMatcher->set_key(WAKE_LOCK_UID_KEY_ID);
192 metric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
193 EventConditionLink* link = metric->add_links();
194 link->set_condition("APP_IS_BACKGROUND");
195 link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
196 link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
197
Yao Chen5154a3792017-10-30 22:57:06 -0700198 // Duration of an app holding any wl, while screen on and app in background, slice by uid
Yao Chen729093d2017-10-16 10:33:26 -0700199 DurationMetric* durationMetric = config.add_duration_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800200 durationMetric->set_name("5");
Yao Chen729093d2017-10-16 10:33:26 -0700201 durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
202 durationMetric->set_type(DurationMetric_AggregationType_DURATION_SUM);
203 keyMatcher = durationMetric->add_dimension();
204 keyMatcher->set_key(WAKE_LOCK_UID_KEY_ID);
Yao Chen967b2052017-11-07 16:36:43 -0800205 durationMetric->set_what("WL_HELD_PER_APP_PER_NAME");
Yao Chen729093d2017-10-16 10:33:26 -0700206 durationMetric->set_predicate("APP_IS_BACKGROUND_AND_SCREEN_ON");
207 link = durationMetric->add_links();
208 link->set_condition("APP_IS_BACKGROUND");
209 link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
210 link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
211
Yao Chen5154a3792017-10-30 22:57:06 -0700212 // max Duration of an app holding any wl, while screen on and app in background, slice by uid
213 durationMetric = config.add_duration_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800214 durationMetric->set_name("6");
Yao Chen5154a3792017-10-30 22:57:06 -0700215 durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
216 durationMetric->set_type(DurationMetric_AggregationType_DURATION_MAX_SPARSE);
217 keyMatcher = durationMetric->add_dimension();
218 keyMatcher->set_key(WAKE_LOCK_UID_KEY_ID);
Yao Chen967b2052017-11-07 16:36:43 -0800219 durationMetric->set_what("WL_HELD_PER_APP_PER_NAME");
Yao Chen5154a3792017-10-30 22:57:06 -0700220 durationMetric->set_predicate("APP_IS_BACKGROUND_AND_SCREEN_ON");
221 link = durationMetric->add_links();
222 link->set_condition("APP_IS_BACKGROUND");
223 link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
224 link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
225
226 // Duration of an app holding any wl, while screen on and app in background
227 durationMetric = config.add_duration_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800228 durationMetric->set_name("7");
Yao Chen5154a3792017-10-30 22:57:06 -0700229 durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
230 durationMetric->set_type(DurationMetric_AggregationType_DURATION_MAX_SPARSE);
Yao Chen967b2052017-11-07 16:36:43 -0800231 durationMetric->set_what("WL_HELD_PER_APP_PER_NAME");
Yao Chen5154a3792017-10-30 22:57:06 -0700232 durationMetric->set_predicate("APP_IS_BACKGROUND_AND_SCREEN_ON");
233 link = durationMetric->add_links();
234 link->set_condition("APP_IS_BACKGROUND");
235 link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
236 link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
237
238 // Duration of screen on time.
239 durationMetric = config.add_duration_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800240 durationMetric->set_name("8");
Yangster1d4d6862017-10-31 12:58:51 -0700241 durationMetric->mutable_bucket()->set_bucket_size_millis(10 * 1000L);
Yao Chen5154a3792017-10-30 22:57:06 -0700242 durationMetric->set_type(DurationMetric_AggregationType_DURATION_SUM);
243 durationMetric->set_what("SCREEN_IS_ON");
244
Chenjie Yub3dda412017-10-24 13:41:59 -0700245 // Value metric to count KERNEL_WAKELOCK when screen turned on
246 ValueMetric* valueMetric = config.add_value_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800247 valueMetric->set_name("6");
Chenjie Yub3dda412017-10-24 13:41:59 -0700248 valueMetric->set_what("KERNEL_WAKELOCK");
249 valueMetric->set_value_field(1);
250 valueMetric->set_condition("SCREEN_IS_ON");
251 keyMatcher = valueMetric->add_dimension();
252 keyMatcher->set_key(KERNEL_WAKELOCK_NAME_KEY);
253 // This is for testing easier. We should never set bucket size this small.
254 valueMetric->mutable_bucket()->set_bucket_size_millis(60 * 1000L);
255
Yao Chen5110bed2017-10-23 12:50:02 -0700256 // Add an EventMetric to log process state change events.
257 EventMetric* eventMetric = config.add_event_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800258 eventMetric->set_name("9");
Yao Chen5110bed2017-10-23 12:50:02 -0700259 eventMetric->set_what("SCREEN_TURNED_ON");
260
Yangster1d4d6862017-10-31 12:58:51 -0700261 // Add an GaugeMetric.
262 GaugeMetric* gaugeMetric = config.add_gauge_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800263 gaugeMetric->set_name("10");
Yangster1d4d6862017-10-31 12:58:51 -0700264 gaugeMetric->set_what("DEVICE_TEMPERATURE");
265 gaugeMetric->set_gauge_field(DEVICE_TEMPERATURE_KEY);
266 gaugeMetric->mutable_bucket()->set_bucket_size_millis(60 * 1000L);
267
Yao Chen729093d2017-10-16 10:33:26 -0700268 // Event matchers............
Yangster1d4d6862017-10-31 12:58:51 -0700269 LogEntryMatcher* temperatureEntryMatcher = config.add_log_entry_matcher();
270 temperatureEntryMatcher->set_name("DEVICE_TEMPERATURE");
271 temperatureEntryMatcher->mutable_simple_log_entry_matcher()->set_tag(
272 DEVICE_TEMPERATURE_TAG_ID);
273
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700274 LogEntryMatcher* eventMatcher = config.add_log_entry_matcher();
Yao Chen729093d2017-10-16 10:33:26 -0700275 eventMatcher->set_name("SCREEN_TURNED_ON");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700276 SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
Yao Chen729093d2017-10-16 10:33:26 -0700277 simpleLogEntryMatcher->set_tag(SCREEN_EVENT_TAG_ID);
278 KeyValueMatcher* keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
279 keyValueMatcher->mutable_key_matcher()->set_key(SCREEN_EVENT_STATE_KEY);
280 keyValueMatcher->set_eq_int(SCREEN_EVENT_ON_VALUE);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700281
282 eventMatcher = config.add_log_entry_matcher();
Yao Chen729093d2017-10-16 10:33:26 -0700283 eventMatcher->set_name("SCREEN_TURNED_OFF");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700284 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
Yao Chen729093d2017-10-16 10:33:26 -0700285 simpleLogEntryMatcher->set_tag(SCREEN_EVENT_TAG_ID);
286 keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
287 keyValueMatcher->mutable_key_matcher()->set_key(SCREEN_EVENT_STATE_KEY);
288 keyValueMatcher->set_eq_int(SCREEN_EVENT_OFF_VALUE);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700289
Yao Chen729093d2017-10-16 10:33:26 -0700290 eventMatcher = config.add_log_entry_matcher();
291 eventMatcher->set_name("PROCESS_STATE_CHANGE");
292 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
293 simpleLogEntryMatcher->set_tag(UID_PROCESS_STATE_TAG_ID);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700294
Yao Chen729093d2017-10-16 10:33:26 -0700295 eventMatcher = config.add_log_entry_matcher();
296 eventMatcher->set_name("APP_GOES_BACKGROUND");
297 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
298 simpleLogEntryMatcher->set_tag(APP_USAGE_ID);
299 keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
300 keyValueMatcher->mutable_key_matcher()->set_key(APP_USAGE_STATE_KEY);
301 keyValueMatcher->set_eq_int(APP_USAGE_BACKGROUND);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700302
Yao Chen729093d2017-10-16 10:33:26 -0700303 eventMatcher = config.add_log_entry_matcher();
304 eventMatcher->set_name("APP_GOES_FOREGROUND");
305 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
306 simpleLogEntryMatcher->set_tag(APP_USAGE_ID);
307 keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
308 keyValueMatcher->mutable_key_matcher()->set_key(APP_USAGE_STATE_KEY);
309 keyValueMatcher->set_eq_int(APP_USAGE_FOREGROUND);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700310
Yao Chen729093d2017-10-16 10:33:26 -0700311 eventMatcher = config.add_log_entry_matcher();
312 eventMatcher->set_name("APP_GET_WL");
313 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
314 simpleLogEntryMatcher->set_tag(WAKE_LOCK_TAG_ID);
315 keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
316 keyValueMatcher->mutable_key_matcher()->set_key(WAKE_LOCK_STATE_KEY);
317 keyValueMatcher->set_eq_int(WAKE_LOCK_ACQUIRE_VALUE);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700318
Yao Chen729093d2017-10-16 10:33:26 -0700319 eventMatcher = config.add_log_entry_matcher();
320 eventMatcher->set_name("APP_RELEASE_WL");
321 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
322 simpleLogEntryMatcher->set_tag(WAKE_LOCK_TAG_ID);
323 keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
324 keyValueMatcher->mutable_key_matcher()->set_key(WAKE_LOCK_STATE_KEY);
325 keyValueMatcher->set_eq_int(WAKE_LOCK_RELEASE_VALUE);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700326
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700327 // pulled events
328 eventMatcher = config.add_log_entry_matcher();
329 eventMatcher->set_name("KERNEL_WAKELOCK");
330 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
331 simpleLogEntryMatcher->set_tag(KERNEL_WAKELOCK_TAG_ID);
332
Yao Chen729093d2017-10-16 10:33:26 -0700333 // Conditions.............
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700334 Condition* condition = config.add_condition();
335 condition->set_name("SCREEN_IS_ON");
336 SimpleCondition* simpleCondition = condition->mutable_simple_condition();
Yao Chen729093d2017-10-16 10:33:26 -0700337 simpleCondition->set_start("SCREEN_TURNED_ON");
338 simpleCondition->set_stop("SCREEN_TURNED_OFF");
Yao Chen967b2052017-11-07 16:36:43 -0800339 simpleCondition->set_count_nesting(false);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700340
341 condition = config.add_condition();
342 condition->set_name("SCREEN_IS_OFF");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700343 simpleCondition = condition->mutable_simple_condition();
Yao Chen729093d2017-10-16 10:33:26 -0700344 simpleCondition->set_start("SCREEN_TURNED_OFF");
345 simpleCondition->set_stop("SCREEN_TURNED_ON");
Yao Chen967b2052017-11-07 16:36:43 -0800346 simpleCondition->set_count_nesting(false);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700347
348 condition = config.add_condition();
Yao Chen729093d2017-10-16 10:33:26 -0700349 condition->set_name("APP_IS_BACKGROUND");
350 simpleCondition = condition->mutable_simple_condition();
351 simpleCondition->set_start("APP_GOES_BACKGROUND");
352 simpleCondition->set_stop("APP_GOES_FOREGROUND");
Yao Chen5154a3792017-10-30 22:57:06 -0700353 KeyMatcher* condition_dimension1 = simpleCondition->add_dimension();
354 condition_dimension1->set_key(APP_USAGE_UID_KEY_ID);
Yao Chen967b2052017-11-07 16:36:43 -0800355 simpleCondition->set_count_nesting(false);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700356
357 condition = config.add_condition();
Yao Chen729093d2017-10-16 10:33:26 -0700358 condition->set_name("APP_IS_BACKGROUND_AND_SCREEN_ON");
359 Condition_Combination* combination_condition = condition->mutable_combination();
360 combination_condition->set_operation(LogicalOperation::AND);
361 combination_condition->add_condition("APP_IS_BACKGROUND");
362 combination_condition->add_condition("SCREEN_IS_ON");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700363
Yao Chen5154a3792017-10-30 22:57:06 -0700364 condition = config.add_condition();
Yao Chen967b2052017-11-07 16:36:43 -0800365 condition->set_name("WL_HELD_PER_APP_PER_NAME");
Yao Chen5154a3792017-10-30 22:57:06 -0700366 simpleCondition = condition->mutable_simple_condition();
367 simpleCondition->set_start("APP_GET_WL");
368 simpleCondition->set_stop("APP_RELEASE_WL");
369 KeyMatcher* condition_dimension = simpleCondition->add_dimension();
370 condition_dimension->set_key(WAKE_LOCK_UID_KEY_ID);
371 condition_dimension = simpleCondition->add_dimension();
372 condition_dimension->set_key(WAKE_LOCK_NAME_KEY);
Yao Chen967b2052017-11-07 16:36:43 -0800373 simpleCondition->set_count_nesting(true);
374
375 condition = config.add_condition();
376 condition->set_name("WL_HELD_PER_APP");
377 simpleCondition = condition->mutable_simple_condition();
378 simpleCondition->set_start("APP_GET_WL");
379 simpleCondition->set_stop("APP_RELEASE_WL");
380 simpleCondition->set_initial_value(SimpleCondition_InitialValue_FALSE);
381 condition_dimension = simpleCondition->add_dimension();
382 condition_dimension->set_key(WAKE_LOCK_UID_KEY_ID);
383 simpleCondition->set_count_nesting(true);
Yao Chen5154a3792017-10-30 22:57:06 -0700384
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700385 return config;
386}
387
388} // namespace statsd
389} // namespace os
390} // namespace android