Add clear method to ProtoOutputStream so it is reusable by just
rewinding its internal pointer.
Bug: 72319159
Test: atest incidentd_test and atest statsd_test
Change-Id: Id046b987a7460d68300e5d4d46ae56aec1eba2d0
diff --git a/cmds/statsd/src/metrics/EventMetricProducer.cpp b/cmds/statsd/src/metrics/EventMetricProducer.cpp
index 0578e06..936a2ef1 100644
--- a/cmds/statsd/src/metrics/EventMetricProducer.cpp
+++ b/cmds/statsd/src/metrics/EventMetricProducer.cpp
@@ -59,9 +59,7 @@
metric.links().end());
mConditionSliced = true;
}
-
- startNewProtoOutputStreamLocked();
-
+ mProto = std::make_unique<ProtoOutputStream>();
VLOG("metric %lld created. bucket size %lld start_time: %lld", (long long)metric.id(),
(long long)mBucketSizeNs, (long long)mStartTimeNs);
}
@@ -70,10 +68,6 @@
VLOG("~EventMetricProducer() called");
}
-void EventMetricProducer::startNewProtoOutputStreamLocked() {
- mProto = std::make_unique<ProtoOutputStream>();
-}
-
void EventMetricProducer::onSlicedConditionMayChangeLocked(const uint64_t eventTime) {
}
@@ -113,7 +107,7 @@
protoOutput->write(FIELD_TYPE_MESSAGE | FIELD_ID_EVENT_METRICS,
reinterpret_cast<char*>(buffer.get()->data()), buffer.get()->size());
- startNewProtoOutputStreamLocked();
+ mProto->clear();
}
void EventMetricProducer::onConditionChangedLocked(const bool conditionMet,