Adds aidl definitions and their implementations for binder transfer of
statsd entries to clients. This change only includes changes on statds
side and does not include java library for clients to import. Java
library will be a separate change as it requires system api review.
Test: statsd, statsd_test
Change-Id: I306c6e9687801668cc0145b12d38406bfe634775
diff --git a/cmds/statsd/src/StatsLogProcessor.cpp b/cmds/statsd/src/StatsLogProcessor.cpp
index e7825cf..68f48a4 100644
--- a/cmds/statsd/src/StatsLogProcessor.cpp
+++ b/cmds/statsd/src/StatsLogProcessor.cpp
@@ -33,8 +33,9 @@
namespace os {
namespace statsd {
-StatsLogProcessor::StatsLogProcessor(const sp<UidMap>& uidMap)
- : m_dropbox_writer("all-logs"), mUidMap(uidMap) {
+StatsLogProcessor::StatsLogProcessor(const sp<UidMap>& uidMap,
+ const std::function<void(const vector<uint8_t>&)>& pushLog)
+ : m_dropbox_writer("all-logs"), mUidMap(uidMap), mPushLog(pushLog) {
}
StatsLogProcessor::~StatsLogProcessor() {
@@ -91,6 +92,41 @@
}
}
+void StatsLogProcessor::addEventMetricData(const EventMetricData& eventMetricData) {
+ // TODO: Replace this code when MetricsManager.onDumpReport() is ready to
+ // get a list of byte arrays.
+ flushIfNecessary(eventMetricData);
+ const int numBytes = eventMetricData.ByteSize();
+ char buffer[numBytes];
+ eventMetricData.SerializeToArray(&buffer[0], numBytes);
+ string bufferString(buffer, numBytes);
+ mEvents.push_back(bufferString);
+ mBufferSize += eventMetricData.ByteSize();
+}
+
+void StatsLogProcessor::flushIfNecessary(const EventMetricData& eventMetricData) {
+ if (eventMetricData.ByteSize() + mBufferSize > kMaxSerializedBytes) {
+ flush();
+ }
+}
+
+void StatsLogProcessor::flush() {
+ StatsLogReport logReport;
+ for (string eventBuffer : mEvents) {
+ EventMetricData eventFromBuffer;
+ eventFromBuffer.ParseFromString(eventBuffer);
+ EventMetricData* newEntry = logReport.mutable_event_metrics()->add_data();
+ newEntry->CopyFrom(eventFromBuffer);
+ }
+
+ const int numBytes = logReport.ByteSize();
+ vector<uint8_t> logReportBuffer(numBytes);
+ logReport.SerializeToArray(&logReportBuffer[0], numBytes);
+ mPushLog(logReportBuffer);
+ mEvents.clear();
+ mBufferSize = 0;
+}
+
} // namespace statsd
} // namespace os
} // namespace android