diff options
Diffstat (limited to 'statsd/src/metrics/GaugeMetricProducer.cpp')
-rw-r--r-- | statsd/src/metrics/GaugeMetricProducer.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/statsd/src/metrics/GaugeMetricProducer.cpp b/statsd/src/metrics/GaugeMetricProducer.cpp index f82f04e4..979b3444 100644 --- a/statsd/src/metrics/GaugeMetricProducer.cpp +++ b/statsd/src/metrics/GaugeMetricProducer.cpp @@ -244,6 +244,7 @@ void GaugeMetricProducer::clearPastBucketsLocked(const int64_t dumpTimeNs) { flushIfNeededLocked(dumpTimeNs); mPastBuckets.clear(); mSkippedBuckets.clear(); + mTotalDataSize = 0; } void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs, @@ -261,13 +262,14 @@ void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs, protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_ID, (long long)mMetricId); protoOutput->write(FIELD_TYPE_BOOL | FIELD_ID_IS_ACTIVE, isActiveLocked()); - protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_ESTIMATED_MEMORY_BYTES, - (long long)byteSizeLocked()); if (mPastBuckets.empty() && mSkippedBuckets.empty()) { return; } + protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_ESTIMATED_MEMORY_BYTES, + (long long)byteSizeLocked()); + if (mDimensionGuardrailHit) { protoOutput->write(FIELD_TYPE_BOOL | FIELD_ID_DIMENSION_GUARDRAIL_HIT, mDimensionGuardrailHit); @@ -373,6 +375,7 @@ void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs, mPastBuckets.clear(); mSkippedBuckets.clear(); mDimensionGuardrailHit = false; + mTotalDataSize = 0; } } @@ -626,6 +629,7 @@ void GaugeMetricProducer::dropDataLocked(const int64_t dropTimeNs) { flushIfNeededLocked(dropTimeNs); StatsdStats::getInstance().noteBucketDropped(mMetricId); mPastBuckets.clear(); + mTotalDataSize = 0; } // When a new matched event comes in, we check if event falls into the current @@ -673,7 +677,11 @@ void GaugeMetricProducer::flushCurrentBucketLocked(const int64_t eventTimeNs, elapsedTimestampsNs.push_back(atom.mElapsedTimestampNs); } auto& bucketList = mPastBuckets[slice.first]; + const bool isFirstBucket = bucketList.empty(); bucketList.push_back(info); + mTotalDataSize += computeGaugeBucketSizeLocked(eventTimeNs >= fullBucketEndTimeNs, + /*dimKey=*/slice.first, isFirstBucket, + info.mAggregatedAtoms); VLOG("Gauge gauge metric %lld, dump key value: %s", (long long)mMetricId, slice.first.toString().c_str()); } @@ -685,6 +693,7 @@ void GaugeMetricProducer::flushCurrentBucketLocked(const int64_t eventTimeNs, buildDropEvent(eventTimeNs, BucketDropReason::BUCKET_TOO_SMALL)); } mSkippedBuckets.emplace_back(mCurrentSkippedBucket); + mTotalDataSize += computeSkippedBucketSizeLocked(mCurrentSkippedBucket); } // If we have anomaly trackers, we need to update the partial bucket values. @@ -708,7 +717,29 @@ void GaugeMetricProducer::flushCurrentBucketLocked(const int64_t eventTimeNs, mHasHitGuardrail = false; } +// Estimate for the size of a GaugeBucket. +size_t GaugeMetricProducer::computeGaugeBucketSizeLocked( + const bool isFullBucket, const MetricDimensionKey& dimKey, const bool isFirstBucket, + const std::unordered_map<AtomDimensionKey, std::vector<int64_t>>& aggregatedAtoms) const { + size_t bucketSize = + MetricProducer::computeBucketSizeLocked(isFullBucket, dimKey, isFirstBucket); + + // Gauge Atoms and timestamps + for (const auto& pair : aggregatedAtoms) { + bucketSize += getFieldValuesSizeV2(pair.first.getAtomFieldValues().getValues()); + bucketSize += sizeof(int64_t) * pair.second.size(); + } + + return bucketSize; +} + size_t GaugeMetricProducer::byteSizeLocked() const { + sp<ConfigMetadataProvider> configMetadataProvider = getConfigMetadataProvider(); + if (configMetadataProvider != nullptr && configMetadataProvider->useV2SoftMemoryCalculation()) { + return computeOverheadSizeLocked(!mPastBuckets.empty() || !mSkippedBuckets.empty(), + mDimensionGuardrailHit) + + mTotalDataSize; + } size_t totalSize = 0; for (const auto& pair : mPastBuckets) { for (const auto& bucket : pair.second) { |