diff options
Diffstat (limited to 'cmds/statsd/src/metrics/MetricsManager.cpp')
-rw-r--r-- | cmds/statsd/src/metrics/MetricsManager.cpp | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/cmds/statsd/src/metrics/MetricsManager.cpp b/cmds/statsd/src/metrics/MetricsManager.cpp index 4fac0e1a141b..4244d5bed23b 100644 --- a/cmds/statsd/src/metrics/MetricsManager.cpp +++ b/cmds/statsd/src/metrics/MetricsManager.cpp @@ -56,10 +56,12 @@ const int FIELD_ID_ANNOTATIONS_INT32 = 2; MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseNs, const int64_t currentTimeNs, - const sp<UidMap> &uidMap, + const sp<UidMap>& uidMap, + const sp<StatsPullerManager>& pullerManager, const sp<AlarmMonitor>& anomalyAlarmMonitor, const sp<AlarmMonitor>& periodicAlarmMonitor) - : mConfigKey(key), mUidMap(uidMap), + : mConfigKey(key), + mUidMap(uidMap), mTtlNs(config.has_ttl_in_seconds() ? config.ttl_in_seconds() * NS_PER_SEC : -1), mTtlEndNs(-1), mLastReportTimeNs(currentTimeNs), @@ -67,12 +69,12 @@ MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config, // Init the ttl end timestamp. refreshTtl(timeBaseNs); - mConfigValid = - initStatsdConfig(key, config, *uidMap, anomalyAlarmMonitor, periodicAlarmMonitor, - timeBaseNs, currentTimeNs, mTagIds, mAllAtomMatchers, - mAllConditionTrackers, mAllMetricProducers, mAllAnomalyTrackers, - mAllPeriodicAlarmTrackers, mConditionToMetricMap, mTrackerToMetricMap, - mTrackerToConditionMap, mNoReportMetricIds); + mConfigValid = initStatsdConfig( + key, config, *uidMap, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor, + timeBaseNs, currentTimeNs, mTagIds, mAllAtomMatchers, mAllConditionTrackers, + mAllMetricProducers, mAllAnomalyTrackers, mAllPeriodicAlarmTrackers, + mConditionToMetricMap, mTrackerToMetricMap, mTrackerToConditionMap, + mActivationAtomTrackerToMetricMap, mMetricIndexesWithActivation, mNoReportMetricIds); mHashStringsInReport = config.hash_strings_in_metric_report(); @@ -195,6 +197,7 @@ void MetricsManager::dropData(const int64_t dropTimeNs) { void MetricsManager::onDumpReport(const int64_t dumpTimeStampNs, const bool include_current_partial_bucket, + const bool erase_data, std::set<string> *str_set, ProtoOutputStream* protoOutput) { VLOG("=========================Metric Reports Start=========================="); @@ -204,11 +207,11 @@ void MetricsManager::onDumpReport(const int64_t dumpTimeStampNs, uint64_t token = protoOutput->start( FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_METRICS); if (mHashStringsInReport) { - producer->onDumpReport(dumpTimeStampNs, include_current_partial_bucket, str_set, - protoOutput); + producer->onDumpReport(dumpTimeStampNs, include_current_partial_bucket, erase_data, + str_set, protoOutput); } else { - producer->onDumpReport(dumpTimeStampNs, include_current_partial_bucket, nullptr, - protoOutput); + producer->onDumpReport(dumpTimeStampNs, include_current_partial_bucket, erase_data, + nullptr, protoOutput); } protoOutput->end(token); } else { @@ -237,7 +240,6 @@ void MetricsManager::onLogEvent(const LogEvent& event) { if (event.GetTagId() == android::util::APP_BREADCRUMB_REPORTED) { // Check that app breadcrumb reported fields are valid. - // TODO: Find a way to make these checks easier to maintain. status_t err = NO_ERROR; // Uid is 3rd from last field and must match the caller's uid, @@ -298,7 +300,12 @@ void MetricsManager::onLogEvent(const LogEvent& event) { } int tagId = event.GetTagId(); - int64_t eventTime = event.GetElapsedTimestampNs(); + int64_t eventTimeNs = event.GetElapsedTimestampNs(); + + for (int metric : mMetricIndexesWithActivation) { + mAllMetricProducers[metric]->flushIfExpire(eventTimeNs); + } + if (mTagIds.find(tagId) == mTagIds.end()) { // not interesting... return; @@ -310,6 +317,14 @@ void MetricsManager::onLogEvent(const LogEvent& event) { matcher->onLogEvent(event, mAllAtomMatchers, matcherCache); } + for (const auto& it : mActivationAtomTrackerToMetricMap) { + if (matcherCache[it.first] == MatchingState::kMatched) { + for (int metricIndex : it.second) { + mAllMetricProducers[metricIndex]->activate(it.first, eventTimeNs); + } + } + } + // A bitmap to see which ConditionTracker needs to be re-evaluated. vector<bool> conditionToBeEvaluated(mAllConditionTrackers.size(), false); @@ -347,13 +362,13 @@ void MetricsManager::onLogEvent(const LogEvent& event) { // Push the new condition to it directly. if (!mAllMetricProducers[metricIndex]->isConditionSliced()) { mAllMetricProducers[metricIndex]->onConditionChanged(conditionCache[i], - eventTime); + eventTimeNs); // metric cares about sliced conditions, and it may have changed. Send // notification, and the metric can query the sliced conditions that are // interesting to it. } else { mAllMetricProducers[metricIndex]->onSlicedConditionMayChange(conditionCache[i], - eventTime); + eventTimeNs); } } } |