Add EventMetricProducer
+ Started to use ProtoOutputStream in EventMetricProducer.
[TODO]: We need to auto-generate fieldIds for StatsLogReport, XXXMetricData, etc.
[TODO]: We need to add Enum type to liblog, otherwise we cannot reconstruct a proto containing
an enum
+ Some refactor in metric initialization code. There are still boiler plate code, because Metrics
are similar but with subtle differences.
Test: statsd_test
Change-Id: Id7e3212566249a8139b9680f04238c455d50c1b8
diff --git a/cmds/statsd/src/logd/LogEvent.cpp b/cmds/statsd/src/logd/LogEvent.cpp
index fb992c1..1a039f6 100644
--- a/cmds/statsd/src/logd/LogEvent.cpp
+++ b/cmds/statsd/src/logd/LogEvent.cpp
@@ -17,6 +17,7 @@
#include "logd/LogEvent.h"
#include <sstream>
+#include "stats_util.h"
namespace android {
namespace os {
@@ -24,6 +25,7 @@
using std::ostringstream;
using std::string;
+using android::util::ProtoOutputStream;
// We need to keep a copy of the android_log_event_list owned by this instance so that the char*
// for strings is not cleared before we can read them.
@@ -203,30 +205,24 @@
return result.str();
}
-void LogEvent::ToProto(EventMetricData* out) const {
- // TODO: Implement this when we have the ProtoOutputStream version.
-
- // set timestamp of the event.
- out->set_timestamp_nanos(mTimestampNs);
-
- // uint64_t token = proto->StartObject(EventMetricData.FIELD);
+void LogEvent::ToProto(ProtoOutputStream& proto) const {
+ long long atomToken = proto.start(TYPE_MESSAGE + mTagId);
const size_t N = mElements.size();
for (size_t i=0; i<N; i++) {
const int key = i + 1;
const android_log_list_element& elem = mElements[i];
if (elem.type == EVENT_TYPE_INT) {
- // proto->Write(key, elem.data.int32);
+ proto.write(TYPE_INT32 + key, elem.data.int32);
} else if (elem.type == EVENT_TYPE_LONG) {
- // proto->Write(key, elem.data.int64);
+ proto.write(TYPE_INT64 + key, (long long)elem.data.int64);
} else if (elem.type == EVENT_TYPE_FLOAT) {
- // proto->Write(key, elem.data.float32);
+ proto.write(TYPE_FLOAT + key, elem.data.float32);
} else if (elem.type == EVENT_TYPE_STRING) {
- // proto->Write(key, elem.data.string);
+ proto.write(TYPE_STRING + key, elem.data.string);
}
}
-
- //proto->EndObject(token);
+ proto.end(atomToken);
}
} // namespace statsd