blob: 4a53e6673ca12cd57ade48a6765ea372f5cc139c [file] [log] [blame]
Yao Chen44cf27c2017-09-14 22:32:50 -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 */
Yangster-mac754e29e2018-05-02 12:23:17 -070016#define DEBUG false // STOPSHIP if true
Joe Onorato9fc9edf2017-10-15 20:08:52 -070017#include "Log.h"
Yao Chen44cf27c2017-09-14 22:32:50 -070018#include "MetricsManager.h"
Yao Chend10f7b12017-12-18 12:53:50 -080019#include "statslog.h"
Yao Chen93fe3a32017-11-02 13:52:59 -070020
Yao Chen44cf27c2017-09-14 22:32:50 -070021#include "CountMetricProducer.h"
Yao Chen93fe3a32017-11-02 13:52:59 -070022#include "condition/CombinationConditionTracker.h"
23#include "condition/SimpleConditionTracker.h"
Yao Chenb3561512017-11-21 18:07:17 -080024#include "guardrail/StatsdStats.h"
Yao Chen93fe3a32017-11-02 13:52:59 -070025#include "matchers/CombinationLogMatchingTracker.h"
26#include "matchers/SimpleLogMatchingTracker.h"
Yao Chencaf339d2017-10-06 16:01:10 -070027#include "metrics_manager_util.h"
28#include "stats_util.h"
Yangster-mac330af582018-02-08 15:24:38 -080029#include "stats_log_util.h"
Yao Chen44cf27c2017-09-14 22:32:50 -070030
Yao Chen93fe3a32017-11-02 13:52:59 -070031#include <log/logprint.h>
Bookatz6f197902018-02-05 12:30:14 -080032#include <private/android_filesystem_config.h>
David Chen16049572018-02-01 18:27:51 -080033#include <utils/SystemClock.h>
Yao Chen288c6002017-12-12 13:43:18 -080034
35using android::util::FIELD_COUNT_REPEATED;
David Chenfaa1af52018-03-30 15:14:04 -070036using android::util::FIELD_TYPE_INT32;
37using android::util::FIELD_TYPE_INT64;
Yao Chen288c6002017-12-12 13:43:18 -080038using android::util::FIELD_TYPE_MESSAGE;
Yangster-mac9def8e32018-04-17 13:55:51 -070039using android::util::FIELD_TYPE_STRING;
Yao Chen288c6002017-12-12 13:43:18 -080040using android::util::ProtoOutputStream;
41
Yao Chen44cf27c2017-09-14 22:32:50 -070042using std::make_unique;
43using std::set;
44using std::string;
Yao Chen44cf27c2017-09-14 22:32:50 -070045using std::unordered_map;
46using std::vector;
47
48namespace android {
49namespace os {
50namespace statsd {
51
Yao Chen288c6002017-12-12 13:43:18 -080052const int FIELD_ID_METRICS = 1;
David Chenfaa1af52018-03-30 15:14:04 -070053const int FIELD_ID_ANNOTATIONS = 7;
54const int FIELD_ID_ANNOTATIONS_INT64 = 1;
55const int FIELD_ID_ANNOTATIONS_INT32 = 2;
Yao Chen288c6002017-12-12 13:43:18 -080056
Yao Chend10f7b12017-12-18 12:53:50 -080057MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config,
Yangster-mac15f6bbc2018-04-08 11:52:26 -070058 const int64_t timeBaseNs, const int64_t currentTimeNs,
Yangster-mac932ecec2018-02-01 10:23:52 -080059 const sp<UidMap> &uidMap,
60 const sp<AlarmMonitor>& anomalyAlarmMonitor,
61 const sp<AlarmMonitor>& periodicAlarmMonitor)
Yangster-mac3fa5d7f2018-03-10 21:50:27 -080062 : mConfigKey(key), mUidMap(uidMap),
Yangster-macb142cc82018-03-30 15:22:08 -070063 mTtlNs(config.has_ttl_in_seconds() ? config.ttl_in_seconds() * NS_PER_SEC : -1),
64 mTtlEndNs(-1),
Yangster-mac15f6bbc2018-04-08 11:52:26 -070065 mLastReportTimeNs(timeBaseNs),
Yangster-mac3fa5d7f2018-03-10 21:50:27 -080066 mLastReportWallClockNs(getWallClockNs()) {
Yangster-macb142cc82018-03-30 15:22:08 -070067 // Init the ttl end timestamp.
Yangster-mac15f6bbc2018-04-08 11:52:26 -070068 refreshTtl(timeBaseNs);
Yangster-macb142cc82018-03-30 15:22:08 -070069
Yao Chenb3561512017-11-21 18:07:17 -080070 mConfigValid =
Yangster-mac932ecec2018-02-01 10:23:52 -080071 initStatsdConfig(key, config, *uidMap, anomalyAlarmMonitor, periodicAlarmMonitor,
Yangster-mac15f6bbc2018-04-08 11:52:26 -070072 timeBaseNs, currentTimeNs, mTagIds, mAllAtomMatchers,
Yangster-mac932ecec2018-02-01 10:23:52 -080073 mAllConditionTrackers, mAllMetricProducers, mAllAnomalyTrackers,
74 mAllPeriodicAlarmTrackers, mConditionToMetricMap, mTrackerToMetricMap,
75 mTrackerToConditionMap, mNoReportMetricIds);
Yao Chenb3561512017-11-21 18:07:17 -080076
Yao Chen147ce602017-12-22 14:35:34 -080077 if (config.allowed_log_source_size() == 0) {
David Chen8faaa012018-02-28 15:54:36 -080078 mConfigValid = false;
79 ALOGE("Log source whitelist is empty! This config won't get any data. Suggest adding at "
80 "least AID_SYSTEM and AID_STATSD to the allowed_log_source field.");
Yao Chend10f7b12017-12-18 12:53:50 -080081 } else {
Yao Chen147ce602017-12-22 14:35:34 -080082 for (const auto& source : config.allowed_log_source()) {
83 auto it = UidMap::sAidToUidMapping.find(source);
84 if (it != UidMap::sAidToUidMapping.end()) {
85 mAllowedUid.push_back(it->second);
86 } else {
87 mAllowedPkg.push_back(source);
88 }
89 }
Yao Chend10f7b12017-12-18 12:53:50 -080090
91 if (mAllowedUid.size() + mAllowedPkg.size() > StatsdStats::kMaxLogSourceCount) {
92 ALOGE("Too many log sources. This is likely to be an error in the config.");
93 mConfigValid = false;
94 } else {
95 initLogSourceWhiteList();
96 }
97 }
98
David Chenfaa1af52018-03-30 15:14:04 -070099 // Store the sub-configs used.
100 for (const auto& annotation : config.annotation()) {
101 mAnnotations.emplace_back(annotation.field_int64(), annotation.field_int32());
102 }
103
Yao Chenb3561512017-11-21 18:07:17 -0800104 // Guardrail. Reject the config if it's too big.
105 if (mAllMetricProducers.size() > StatsdStats::kMaxMetricCountPerConfig ||
106 mAllConditionTrackers.size() > StatsdStats::kMaxConditionCountPerConfig ||
Stefan Lafonb8c9aa82017-12-03 14:27:25 -0800107 mAllAtomMatchers.size() > StatsdStats::kMaxMatcherCountPerConfig) {
Yao Chenb3561512017-11-21 18:07:17 -0800108 ALOGE("This config is too big! Reject!");
109 mConfigValid = false;
110 }
Bookatz1476ef22018-02-13 12:26:01 -0800111 if (mAllAnomalyTrackers.size() > StatsdStats::kMaxAlertCountPerConfig) {
112 ALOGE("This config has too many alerts! Reject!");
113 mConfigValid = false;
114 }
Yao Chenf09569f2017-12-13 17:00:51 -0800115 // no matter whether this config is valid, log it in the stats.
David Chenfaa1af52018-03-30 15:14:04 -0700116 StatsdStats::getInstance().noteConfigReceived(
117 key, mAllMetricProducers.size(), mAllConditionTrackers.size(), mAllAtomMatchers.size(),
118 mAllAnomalyTrackers.size(), mAnnotations, mConfigValid);
Yao Chen44cf27c2017-09-14 22:32:50 -0700119}
120
121MetricsManager::~MetricsManager() {
Bookatzd3606c72017-10-19 10:13:49 -0700122 VLOG("~MetricsManager()");
Yao Chen44cf27c2017-09-14 22:32:50 -0700123}
124
Yao Chend10f7b12017-12-18 12:53:50 -0800125void MetricsManager::initLogSourceWhiteList() {
126 std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex);
127 mAllowedLogSources.clear();
128 mAllowedLogSources.insert(mAllowedUid.begin(), mAllowedUid.end());
129
130 for (const auto& pkg : mAllowedPkg) {
131 auto uids = mUidMap->getAppUid(pkg);
132 mAllowedLogSources.insert(uids.begin(), uids.end());
133 }
134 if (DEBUG) {
135 for (const auto& uid : mAllowedLogSources) {
136 VLOG("Allowed uid %d", uid);
137 }
138 }
139}
140
Yao Chencaf339d2017-10-06 16:01:10 -0700141bool MetricsManager::isConfigValid() const {
142 return mConfigValid;
143}
144
Yangster-macb142cc82018-03-30 15:22:08 -0700145void MetricsManager::notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid,
David Chen27785a82018-01-19 17:06:45 -0800146 const int64_t version) {
Yao Chend10f7b12017-12-18 12:53:50 -0800147 // check if we care this package
148 if (std::find(mAllowedPkg.begin(), mAllowedPkg.end(), apk) == mAllowedPkg.end()) {
149 return;
150 }
151 // We will re-initialize the whole list because we don't want to keep the multi mapping of
152 // UID<->pkg inside MetricsManager to reduce the memory usage.
153 initLogSourceWhiteList();
154}
155
Yangster-macb142cc82018-03-30 15:22:08 -0700156void MetricsManager::notifyAppRemoved(const int64_t& eventTimeNs, const string& apk,
David Chen27785a82018-01-19 17:06:45 -0800157 const int uid) {
Yao Chend10f7b12017-12-18 12:53:50 -0800158 // check if we care this package
159 if (std::find(mAllowedPkg.begin(), mAllowedPkg.end(), apk) == mAllowedPkg.end()) {
160 return;
161 }
162 // We will re-initialize the whole list because we don't want to keep the multi mapping of
163 // UID<->pkg inside MetricsManager to reduce the memory usage.
164 initLogSourceWhiteList();
165}
166
Yangster-macb142cc82018-03-30 15:22:08 -0700167void MetricsManager::onUidMapReceived(const int64_t& eventTimeNs) {
Yao Chend10f7b12017-12-18 12:53:50 -0800168 if (mAllowedPkg.size() == 0) {
169 return;
170 }
171 initLogSourceWhiteList();
172}
173
Yao Chen884c8c12018-01-26 10:36:25 -0800174void MetricsManager::dumpStates(FILE* out, bool verbose) {
175 fprintf(out, "ConfigKey %s, allowed source:", mConfigKey.ToString().c_str());
176 {
177 std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex);
178 for (const auto& source : mAllowedLogSources) {
179 fprintf(out, "%d ", source);
180 }
181 }
182 fprintf(out, "\n");
183 for (const auto& producer : mAllMetricProducers) {
184 producer->dumpStates(out, verbose);
185 }
186}
187
Yangster-macb142cc82018-03-30 15:22:08 -0700188void MetricsManager::dropData(const int64_t dropTimeNs) {
Yao Chen06dba5d2018-01-26 13:38:16 -0800189 for (const auto& producer : mAllMetricProducers) {
190 producer->dropData(dropTimeNs);
191 }
192}
193
Yangster-mace68f3a52018-04-04 00:01:43 -0700194void MetricsManager::onDumpReport(const int64_t dumpTimeStampNs,
195 const bool include_current_partial_bucket,
Yangster-mac9def8e32018-04-17 13:55:51 -0700196 std::set<string> *str_set,
Yangster-mace68f3a52018-04-04 00:01:43 -0700197 ProtoOutputStream* protoOutput) {
Yao Chen729093d2017-10-16 10:33:26 -0700198 VLOG("=========================Metric Reports Start==========================");
199 // one StatsLogReport per MetricProduer
Yangster-mac94e197c2018-01-02 16:03:03 -0800200 for (const auto& producer : mAllMetricProducers) {
201 if (mNoReportMetricIds.find(producer->getMetricId()) == mNoReportMetricIds.end()) {
Yangster-mac9def8e32018-04-17 13:55:51 -0700202 uint64_t token = protoOutput->start(
203 FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_METRICS);
204 producer->onDumpReport(dumpTimeStampNs, include_current_partial_bucket, str_set,
205 protoOutput);
Yangster-mac94e197c2018-01-02 16:03:03 -0800206 protoOutput->end(token);
Yangster-maca802d732018-04-24 07:50:38 -0700207 } else {
208 producer->clearPastBuckets(dumpTimeStampNs);
Yangster-mac94e197c2018-01-02 16:03:03 -0800209 }
Yao Chen729093d2017-10-16 10:33:26 -0700210 }
David Chenfaa1af52018-03-30 15:14:04 -0700211 for (const auto& annotation : mAnnotations) {
212 uint64_t token = protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED |
213 FIELD_ID_ANNOTATIONS);
214 protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_ANNOTATIONS_INT64,
215 (long long)annotation.first);
216 protoOutput->write(FIELD_TYPE_INT32 | FIELD_ID_ANNOTATIONS_INT32, annotation.second);
217 protoOutput->end(token);
218 }
Yangster-mac9def8e32018-04-17 13:55:51 -0700219
Yangster-mac330af582018-02-08 15:24:38 -0800220 mLastReportTimeNs = dumpTimeStampNs;
Yangster-mac3fa5d7f2018-03-10 21:50:27 -0800221 mLastReportWallClockNs = getWallClockNs();
Yao Chen729093d2017-10-16 10:33:26 -0700222 VLOG("=========================Metric Reports End==========================");
Yao Chen729093d2017-10-16 10:33:26 -0700223}
224
Yao Chen44cf27c2017-09-14 22:32:50 -0700225// Consume the stats log if it's interesting to this metric.
Joe Onoratoc4dfae52017-10-17 23:38:21 -0700226void MetricsManager::onLogEvent(const LogEvent& event) {
Yao Chencaf339d2017-10-06 16:01:10 -0700227 if (!mConfigValid) {
228 return;
229 }
230
David Chenb639d142018-02-14 17:29:54 -0800231 if (event.GetTagId() == android::util::APP_BREADCRUMB_REPORTED) {
232 // Check that app breadcrumb reported fields are valid.
233 // TODO: Find a way to make these checks easier to maintain.
David Chendaa9f3a2017-12-28 16:52:22 -0800234 status_t err = NO_ERROR;
Bookatzb223c4e2018-02-01 15:35:04 -0800235
236 // Uid is 3rd from last field and must match the caller's uid,
237 // unless that caller is statsd itself (statsd is allowed to spoof uids).
238 long appHookUid = event.GetLong(event.size()-2, &err);
David Chen77ef6712018-02-23 18:23:42 -0800239 if (err != NO_ERROR ) {
240 VLOG("APP_BREADCRUMB_REPORTED had error when parsing the uid");
241 return;
242 }
Bookatzb223c4e2018-02-01 15:35:04 -0800243 int32_t loggerUid = event.GetUid();
David Chen77ef6712018-02-23 18:23:42 -0800244 if (loggerUid != appHookUid && loggerUid != AID_STATSD) {
245 VLOG("APP_BREADCRUMB_REPORTED has invalid uid: claimed %ld but caller is %d",
246 appHookUid, loggerUid);
David Chendaa9f3a2017-12-28 16:52:22 -0800247 return;
248 }
Bookatzb223c4e2018-02-01 15:35:04 -0800249
David Chendaa9f3a2017-12-28 16:52:22 -0800250 // The state must be from 0,3. This part of code must be manually updated.
Bookatzb223c4e2018-02-01 15:35:04 -0800251 long appHookState = event.GetLong(event.size(), &err);
David Chen77ef6712018-02-23 18:23:42 -0800252 if (err != NO_ERROR ) {
253 VLOG("APP_BREADCRUMB_REPORTED had error when parsing the state field");
254 return;
255 } else if (appHookState < 0 || appHookState > 3) {
256 VLOG("APP_BREADCRUMB_REPORTED does not have valid state %ld", appHookState);
David Chendaa9f3a2017-12-28 16:52:22 -0800257 return;
258 }
Tej Singhbb8554a2018-01-26 11:59:14 -0800259 } else if (event.GetTagId() == android::util::DAVEY_OCCURRED) {
260 // Daveys can be logged from any app since they are logged in libs/hwui/JankTracker.cpp.
261 // Check that the davey duration is reasonable. Max length check is for privacy.
262 status_t err = NO_ERROR;
David Chen77ef6712018-02-23 18:23:42 -0800263
264 // Uid is the first field provided.
265 long jankUid = event.GetLong(1, &err);
266 if (err != NO_ERROR ) {
267 VLOG("Davey occurred had error when parsing the uid");
268 return;
269 }
270 int32_t loggerUid = event.GetUid();
271 if (loggerUid != jankUid && loggerUid != AID_STATSD) {
272 VLOG("DAVEY_OCCURRED has invalid uid: claimed %ld but caller is %d", jankUid,
273 loggerUid);
274 return;
275 }
276
Tej Singhbb8554a2018-01-26 11:59:14 -0800277 long duration = event.GetLong(event.size(), &err);
David Chen77ef6712018-02-23 18:23:42 -0800278 if (err != NO_ERROR ) {
279 VLOG("Davey occurred had error when parsing the duration");
280 return;
281 } else if (duration > 100000) {
Tej Singhbb8554a2018-01-26 11:59:14 -0800282 VLOG("Davey duration is unreasonably long: %ld", duration);
283 return;
284 }
285 } else {
286 std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex);
287 if (mAllowedLogSources.find(event.GetUid()) == mAllowedLogSources.end()) {
288 VLOG("log source %d not on the whitelist", event.GetUid());
289 return;
290 }
Yao Chend10f7b12017-12-18 12:53:50 -0800291 }
292
Joe Onoratoc4dfae52017-10-17 23:38:21 -0700293 int tagId = event.GetTagId();
Yangster-macb142cc82018-03-30 15:22:08 -0700294 int64_t eventTime = event.GetElapsedTimestampNs();
Yao Chen44cf27c2017-09-14 22:32:50 -0700295 if (mTagIds.find(tagId) == mTagIds.end()) {
296 // not interesting...
297 return;
298 }
Yao Chen44cf27c2017-09-14 22:32:50 -0700299
Stefan Lafonb8c9aa82017-12-03 14:27:25 -0800300 vector<MatchingState> matcherCache(mAllAtomMatchers.size(), MatchingState::kNotComputed);
Yao Chencaf339d2017-10-06 16:01:10 -0700301
Stefan Lafonb8c9aa82017-12-03 14:27:25 -0800302 for (auto& matcher : mAllAtomMatchers) {
303 matcher->onLogEvent(event, mAllAtomMatchers, matcherCache);
Yao Chen44cf27c2017-09-14 22:32:50 -0700304 }
305
Yao Chencaf339d2017-10-06 16:01:10 -0700306 // A bitmap to see which ConditionTracker needs to be re-evaluated.
307 vector<bool> conditionToBeEvaluated(mAllConditionTrackers.size(), false);
308
309 for (const auto& pair : mTrackerToConditionMap) {
310 if (matcherCache[pair.first] == MatchingState::kMatched) {
311 const auto& conditionList = pair.second;
312 for (const int conditionIndex : conditionList) {
313 conditionToBeEvaluated[conditionIndex] = true;
314 }
315 }
316 }
317
318 vector<ConditionState> conditionCache(mAllConditionTrackers.size(),
319 ConditionState::kNotEvaluated);
320 // A bitmap to track if a condition has changed value.
321 vector<bool> changedCache(mAllConditionTrackers.size(), false);
322 for (size_t i = 0; i < mAllConditionTrackers.size(); i++) {
323 if (conditionToBeEvaluated[i] == false) {
324 continue;
325 }
Yao Chencaf339d2017-10-06 16:01:10 -0700326 sp<ConditionTracker>& condition = mAllConditionTrackers[i];
327 condition->evaluateCondition(event, matcherCache, mAllConditionTrackers, conditionCache,
Yao Chen967b2052017-11-07 16:36:43 -0800328 changedCache);
Yao Chen729093d2017-10-16 10:33:26 -0700329 }
330
331 for (size_t i = 0; i < mAllConditionTrackers.size(); i++) {
Yao Chen967b2052017-11-07 16:36:43 -0800332 if (changedCache[i] == false) {
Yao Chen729093d2017-10-16 10:33:26 -0700333 continue;
334 }
335 auto pair = mConditionToMetricMap.find(i);
336 if (pair != mConditionToMetricMap.end()) {
337 auto& metricList = pair->second;
338 for (auto metricIndex : metricList) {
339 // metric cares about non sliced condition, and it's changed.
340 // Push the new condition to it directly.
Yao Chen967b2052017-11-07 16:36:43 -0800341 if (!mAllMetricProducers[metricIndex]->isConditionSliced()) {
Yao Chen5154a372017-10-30 22:57:06 -0700342 mAllMetricProducers[metricIndex]->onConditionChanged(conditionCache[i],
343 eventTime);
Yao Chen729093d2017-10-16 10:33:26 -0700344 // metric cares about sliced conditions, and it may have changed. Send
345 // notification, and the metric can query the sliced conditions that are
346 // interesting to it.
Yangsterf2bee6f2017-11-29 12:01:05 -0800347 } else {
Yao Chen427d3722018-03-22 15:21:52 -0700348 mAllMetricProducers[metricIndex]->onSlicedConditionMayChange(conditionCache[i],
349 eventTime);
Yao Chen44cf27c2017-09-14 22:32:50 -0700350 }
Yao Chencaf339d2017-10-06 16:01:10 -0700351 }
352 }
353 }
354
Stefan Lafonb8c9aa82017-12-03 14:27:25 -0800355 // For matched AtomMatchers, tell relevant metrics that a matched event has come.
356 for (size_t i = 0; i < mAllAtomMatchers.size(); i++) {
Yao Chencaf339d2017-10-06 16:01:10 -0700357 if (matcherCache[i] == MatchingState::kMatched) {
Yao Chenb3561512017-11-21 18:07:17 -0800358 StatsdStats::getInstance().noteMatcherMatched(mConfigKey,
Yangster-mac94e197c2018-01-02 16:03:03 -0800359 mAllAtomMatchers[i]->getId());
Yao Chencaf339d2017-10-06 16:01:10 -0700360 auto pair = mTrackerToMetricMap.find(i);
361 if (pair != mTrackerToMetricMap.end()) {
362 auto& metricList = pair->second;
363 for (const int metricIndex : metricList) {
Chenjie Yub3dda412017-10-24 13:41:59 -0700364 // pushed metrics are never scheduled pulls
Chenjie Yua7259ab2017-12-10 08:31:05 -0800365 mAllMetricProducers[metricIndex]->onMatchedLogEvent(i, event);
Yao Chencaf339d2017-10-06 16:01:10 -0700366 }
Yao Chen44cf27c2017-09-14 22:32:50 -0700367 }
368 }
369 }
370}
371
Yangster-mac932ecec2018-02-01 10:23:52 -0800372void MetricsManager::onAnomalyAlarmFired(
Yangster-macb142cc82018-03-30 15:22:08 -0700373 const int64_t& timestampNs,
Yangster-mac932ecec2018-02-01 10:23:52 -0800374 unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet) {
Yangster-mace2cd6d52017-11-09 20:38:30 -0800375 for (const auto& itr : mAllAnomalyTrackers) {
Yangster-mac932ecec2018-02-01 10:23:52 -0800376 itr->informAlarmsFired(timestampNs, alarmSet);
Yangster-mace2cd6d52017-11-09 20:38:30 -0800377 }
378}
379
Yangster-mac932ecec2018-02-01 10:23:52 -0800380void MetricsManager::onPeriodicAlarmFired(
Yangster-macb142cc82018-03-30 15:22:08 -0700381 const int64_t& timestampNs,
Yangster-mac932ecec2018-02-01 10:23:52 -0800382 unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet) {
383 for (const auto& itr : mAllPeriodicAlarmTrackers) {
384 itr->informAlarmsFired(timestampNs, alarmSet);
Yangster-mace2cd6d52017-11-09 20:38:30 -0800385 }
386}
387
yro69007c82017-10-26 20:42:57 -0700388// Returns the total byte size of all metrics managed by a single config source.
389size_t MetricsManager::byteSize() {
390 size_t totalSize = 0;
391 for (auto metricProducer : mAllMetricProducers) {
392 totalSize += metricProducer->byteSize();
393 }
394 return totalSize;
395}
396
Yao Chen44cf27c2017-09-14 22:32:50 -0700397} // namespace statsd
398} // namespace os
399} // namespace android