diff options
Diffstat (limited to 'cmds/statsd/src/metrics/DurationMetricProducer.cpp')
-rw-r--r-- | cmds/statsd/src/metrics/DurationMetricProducer.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/cmds/statsd/src/metrics/DurationMetricProducer.cpp b/cmds/statsd/src/metrics/DurationMetricProducer.cpp index 62237bc04642..35deffe5db97 100644 --- a/cmds/statsd/src/metrics/DurationMetricProducer.cpp +++ b/cmds/statsd/src/metrics/DurationMetricProducer.cpp @@ -68,17 +68,14 @@ DurationMetricProducer::DurationMetricProducer(const ConfigKey& key, const Durat const bool nesting, const sp<ConditionWizard>& wizard, const FieldMatcher& internalDimensions, - const int64_t startTimeNs) - : MetricProducer(metric.id(), key, startTimeNs, conditionIndex, wizard), + const int64_t timeBaseNs, const int64_t startTimeNs) + : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard), mAggregationType(metric.aggregation_type()), mStartIndex(startIndex), mStopIndex(stopIndex), mStopAllIndex(stopAllIndex), mNested(nesting), mContainANYPositionInInternalDimensions(false) { - // TODO: The following boiler plate code appears in all MetricProducers, but we can't abstract - // them in the base class, because the proto generated CountMetric, and DurationMetric are - // not related. Maybe we should add a template in the future?? if (metric.has_bucket()) { mBucketSizeNs = TimeUnitToBucketSizeInMillisGuardrailed(key.GetUid(), metric.bucket()) * 1000000; @@ -131,6 +128,9 @@ DurationMetricProducer::DurationMetricProducer(const ConfigKey& key, const Durat mMetric2ConditionLinks.begin()->conditionFields); } } + flushIfNeededLocked(startTimeNs); + // Adjust start for partial bucket + mCurrentBucketStartTimeNs = startTimeNs; VLOG("metric %lld created. bucket size %lld start_time: %lld", (long long)metric.id(), (long long)mBucketSizeNs, (long long)mTimeBaseNs); } @@ -434,8 +434,6 @@ void DurationMetricProducer::onConditionChangedLocked(const bool conditionMet, VLOG("Metric %lld onConditionChanged", (long long)mMetricId); mCondition = conditionMet; flushIfNeededLocked(eventTime); - // TODO: need to populate the condition change time from the event which triggers the condition - // change, instead of using current time. for (auto& whatIt : mCurrentSlicedDurationTrackerMap) { for (auto& pair : whatIt.second) { pair.second->onConditionChanged(conditionMet, eventTime); @@ -455,6 +453,7 @@ void DurationMetricProducer::clearPastBucketsLocked(const int64_t dumpTimeNs) { void DurationMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs, const bool include_current_partial_bucket, + const bool erase_data, std::set<string> *str_set, ProtoOutputStream* protoOutput) { if (include_current_partial_bucket) { @@ -543,7 +542,9 @@ void DurationMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs, } protoOutput->end(protoToken); - mPastBuckets.clear(); + if (erase_data) { + mPastBuckets.clear(); + } } void DurationMetricProducer::flushIfNeededLocked(const int64_t& eventTimeNs) { @@ -783,7 +784,7 @@ void DurationMetricProducer::onMatchedLogEventLocked(const size_t matcherIndex, if (whatIt != mCurrentSlicedDurationTrackerMap.end()) { for (const auto& condIt : whatIt->second) { const bool cond = dimensionKeysInCondition.find(condIt.first) != - dimensionKeysInCondition.end(); + dimensionKeysInCondition.end() && condition; handleStartEvent(MetricDimensionKey(dimensionInWhat, condIt.first), conditionKey, cond, event); dimensionKeysInCondition.erase(condIt.first); |