Only create ProtoOutputStream when onGetData() is called.
The exception is EventMetricProducer. Each EventMetricProducer will still have a ProtoOutputStream
Because LogEvent comes as a fixed 4K, it's more memory efficient to have an 8k ProtoOutputStream for
storing the events.
Also removed finish() api in MetricProducer, which was intended to use with Dropbox.
Test: statsd_test & dogfood app
Bug: 70393808
Change-Id: I2efe4ecc76a88060a9aa5eb49d1fa6ea60bc5da8
diff --git a/cmds/statsd/src/metrics/EventMetricProducer.h b/cmds/statsd/src/metrics/EventMetricProducer.h
index da3b3ca..75ccf47 100644
--- a/cmds/statsd/src/metrics/EventMetricProducer.h
+++ b/cmds/statsd/src/metrics/EventMetricProducer.h
@@ -40,8 +40,6 @@
virtual ~EventMetricProducer();
- void finish() override;
-
// TODO: Implement this later.
virtual void notifyAppUpgrade(const string& apk, const int uid, const int64_t version)
override{};
@@ -49,7 +47,7 @@
virtual void notifyAppRemoved(const string& apk, const int uid) override{};
protected:
- void startNewProtoOutputStreamLocked(long long timestamp);
+ void startNewProtoOutputStreamLocked();
private:
void onMatchedLogEventInternalLocked(
@@ -57,8 +55,8 @@
const std::map<std::string, HashableDimensionKey>& conditionKey, bool condition,
const LogEvent& event, bool scheduledPull) override;
- // TODO: Pass a timestamp as a parameter in onDumpReport.
- std::unique_ptr<std::vector<uint8_t>> onDumpReportLocked() override;
+ void onDumpReportLocked(const uint64_t dumpTimeNs,
+ android::util::ProtoOutputStream* protoOutput) override;
// Internal interface to handle condition change.
void onConditionChangedLocked(const bool conditionMet, const uint64_t eventTime) override;
@@ -70,6 +68,10 @@
size_t byteSizeLocked() const override;
const EventMetric mMetric;
+
+ // Maps to a EventMetricDataWrapper. Storing atom events in ProtoOutputStream
+ // is more space efficient than storing LogEvent.
+ std::unique_ptr<android::util::ProtoOutputStream> mProto;
};
} // namespace statsd