Loading cmds/statsd/benchmark/filter_value_benchmark.cpp +6 −15 Original line number Diff line number Diff line Loading @@ -14,12 +14,14 @@ * limitations under the License. */ #include <vector> #include "benchmark/benchmark.h" #include "FieldValue.h" #include "HashableDimensionKey.h" #include "benchmark/benchmark.h" #include "logd/LogEvent.h" #include "stats_log_util.h" #include "metric_util.h" #include "stats_event.h" #include "stats_log_util.h" namespace android { namespace os { Loading @@ -34,24 +36,13 @@ static void createLogEventAndMatcher(LogEvent* event, FieldMatcher* field_matche std::vector<int> attributionUids = {100, 100}; std::vector<string> attributionTags = {"LOCATION", "LOCATION"}; writeAttribution(statsEvent, attributionUids, attributionTags); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); AStatsEvent_writeFloat(statsEvent, 3.2f); AStatsEvent_writeString(statsEvent, "LOCATION"); AStatsEvent_writeInt64(statsEvent, 990); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); event->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, event); field_matcher->set_field(1); auto child = field_matcher->add_child(); Loading cmds/statsd/benchmark/get_dimensions_for_condition_benchmark.cpp +6 −15 Original line number Diff line number Diff line Loading @@ -14,12 +14,14 @@ * limitations under the License. */ #include <vector> #include "benchmark/benchmark.h" #include "FieldValue.h" #include "HashableDimensionKey.h" #include "benchmark/benchmark.h" #include "logd/LogEvent.h" #include "stats_log_util.h" #include "metric_util.h" #include "stats_event.h" #include "stats_log_util.h" namespace android { namespace os { Loading @@ -34,24 +36,13 @@ static void createLogEventAndLink(LogEvent* event, Metric2Condition *link) { std::vector<int> attributionUids = {100, 100}; std::vector<string> attributionTags = {"LOCATION", "LOCATION"}; writeAttribution(statsEvent, attributionUids, attributionTags); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); AStatsEvent_writeFloat(statsEvent, 3.2f); AStatsEvent_writeString(statsEvent, "LOCATION"); AStatsEvent_writeInt64(statsEvent, 990); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); event->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, event); link->conditionId = 1; Loading cmds/statsd/benchmark/metric_util.cpp +27 −35 Original line number Diff line number Diff line Loading @@ -247,21 +247,37 @@ FieldMatcher CreateDimensions(const int atomId, const std::vector<int>& fields) return dimensions; } void writeAttribution(AStatsEvent* statsEvent, const vector<int>& attributionUids, const vector<string>& attributionTags) { vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); } void parseStatsEventToLogEvent(AStatsEvent* statsEvent, LogEvent* logEvent) { AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); } std::unique_ptr<LogEvent> CreateScreenStateChangedEvent( uint64_t timestampNs, const android::view::DisplayStateEnum state) { AStatsEvent* statsEvent = AStatsEvent_obtain(); AStatsEvent_setAtomId(statsEvent, util::SCREEN_STATE_CHANGED); AStatsEvent_overwriteTimestamp(statsEvent, timestampNs); AStatsEvent_writeInt32(statsEvent, state); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, logEvent.get()); return logEvent; } Loading @@ -272,24 +288,12 @@ std::unique_ptr<LogEvent> CreateScheduledJobStateChangedEvent( AStatsEvent_setAtomId(statsEvent, util::SCHEDULED_JOB_STATE_CHANGED); AStatsEvent_overwriteTimestamp(statsEvent, timestampNs); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); writeAttribution(statsEvent, attributionUids, attributionTags); AStatsEvent_writeString(statsEvent, jobName.c_str()); AStatsEvent_writeInt32(statsEvent, state); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, logEvent.get()); return logEvent; } Loading Loading @@ -319,24 +323,12 @@ std::unique_ptr<LogEvent> CreateSyncStateChangedEvent(uint64_t timestampNs, AStatsEvent_setAtomId(statsEvent, util::SYNC_STATE_CHANGED); AStatsEvent_overwriteTimestamp(statsEvent, timestampNs); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); writeAttribution(statsEvent, attributionUids, attributionTags); AStatsEvent_writeString(statsEvent, name.c_str()); AStatsEvent_writeInt32(statsEvent, state); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, logEvent.get()); return logEvent; } Loading cmds/statsd/benchmark/metric_util.h +6 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" #include "src/StatsLogProcessor.h" #include "src/logd/LogEvent.h" #include "stats_event.h" #include "statslog.h" namespace android { Loading Loading @@ -92,6 +93,11 @@ FieldMatcher CreateAttributionUidAndTagDimensions(const int atomId, FieldMatcher CreateAttributionUidDimensions(const int atomId, const std::vector<Position>& positions); void writeAttribution(AStatsEvent* statsEvent, const vector<int>& attributionUids, const vector<string>& attributionTags); void parseStatsEventToLogEvent(AStatsEvent* statsEvent, LogEvent* logEvent); // Create log event for screen state changed. std::unique_ptr<LogEvent> CreateScreenStateChangedEvent( uint64_t timestampNs, const android::view::DisplayStateEnum state); Loading cmds/statsd/tests/FieldValue_test.cpp +4 −28 Original line number Diff line number Diff line Loading @@ -41,22 +41,10 @@ void makeLogEvent(LogEvent* logEvent, const int32_t atomId, const int64_t timest AStatsEvent_setAtomId(statsEvent, atomId); AStatsEvent_overwriteTimestamp(statsEvent, timestamp); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); writeAttribution(statsEvent, attributionUids, attributionTags); AStatsEvent_writeString(statsEvent, name.c_str()); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, logEvent); } void makeLogEvent(LogEvent* logEvent, const int32_t atomId, const int64_t timestamp, Loading @@ -66,22 +54,10 @@ void makeLogEvent(LogEvent* logEvent, const int32_t atomId, const int64_t timest AStatsEvent_setAtomId(statsEvent, atomId); AStatsEvent_overwriteTimestamp(statsEvent, timestamp); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); writeAttribution(statsEvent, attributionUids, attributionTags); AStatsEvent_writeInt32(statsEvent, value); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, logEvent); } } // anonymous namespace Loading Loading
cmds/statsd/benchmark/filter_value_benchmark.cpp +6 −15 Original line number Diff line number Diff line Loading @@ -14,12 +14,14 @@ * limitations under the License. */ #include <vector> #include "benchmark/benchmark.h" #include "FieldValue.h" #include "HashableDimensionKey.h" #include "benchmark/benchmark.h" #include "logd/LogEvent.h" #include "stats_log_util.h" #include "metric_util.h" #include "stats_event.h" #include "stats_log_util.h" namespace android { namespace os { Loading @@ -34,24 +36,13 @@ static void createLogEventAndMatcher(LogEvent* event, FieldMatcher* field_matche std::vector<int> attributionUids = {100, 100}; std::vector<string> attributionTags = {"LOCATION", "LOCATION"}; writeAttribution(statsEvent, attributionUids, attributionTags); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); AStatsEvent_writeFloat(statsEvent, 3.2f); AStatsEvent_writeString(statsEvent, "LOCATION"); AStatsEvent_writeInt64(statsEvent, 990); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); event->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, event); field_matcher->set_field(1); auto child = field_matcher->add_child(); Loading
cmds/statsd/benchmark/get_dimensions_for_condition_benchmark.cpp +6 −15 Original line number Diff line number Diff line Loading @@ -14,12 +14,14 @@ * limitations under the License. */ #include <vector> #include "benchmark/benchmark.h" #include "FieldValue.h" #include "HashableDimensionKey.h" #include "benchmark/benchmark.h" #include "logd/LogEvent.h" #include "stats_log_util.h" #include "metric_util.h" #include "stats_event.h" #include "stats_log_util.h" namespace android { namespace os { Loading @@ -34,24 +36,13 @@ static void createLogEventAndLink(LogEvent* event, Metric2Condition *link) { std::vector<int> attributionUids = {100, 100}; std::vector<string> attributionTags = {"LOCATION", "LOCATION"}; writeAttribution(statsEvent, attributionUids, attributionTags); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); AStatsEvent_writeFloat(statsEvent, 3.2f); AStatsEvent_writeString(statsEvent, "LOCATION"); AStatsEvent_writeInt64(statsEvent, 990); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); event->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, event); link->conditionId = 1; Loading
cmds/statsd/benchmark/metric_util.cpp +27 −35 Original line number Diff line number Diff line Loading @@ -247,21 +247,37 @@ FieldMatcher CreateDimensions(const int atomId, const std::vector<int>& fields) return dimensions; } void writeAttribution(AStatsEvent* statsEvent, const vector<int>& attributionUids, const vector<string>& attributionTags) { vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); } void parseStatsEventToLogEvent(AStatsEvent* statsEvent, LogEvent* logEvent) { AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); } std::unique_ptr<LogEvent> CreateScreenStateChangedEvent( uint64_t timestampNs, const android::view::DisplayStateEnum state) { AStatsEvent* statsEvent = AStatsEvent_obtain(); AStatsEvent_setAtomId(statsEvent, util::SCREEN_STATE_CHANGED); AStatsEvent_overwriteTimestamp(statsEvent, timestampNs); AStatsEvent_writeInt32(statsEvent, state); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, logEvent.get()); return logEvent; } Loading @@ -272,24 +288,12 @@ std::unique_ptr<LogEvent> CreateScheduledJobStateChangedEvent( AStatsEvent_setAtomId(statsEvent, util::SCHEDULED_JOB_STATE_CHANGED); AStatsEvent_overwriteTimestamp(statsEvent, timestampNs); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); writeAttribution(statsEvent, attributionUids, attributionTags); AStatsEvent_writeString(statsEvent, jobName.c_str()); AStatsEvent_writeInt32(statsEvent, state); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, logEvent.get()); return logEvent; } Loading Loading @@ -319,24 +323,12 @@ std::unique_ptr<LogEvent> CreateSyncStateChangedEvent(uint64_t timestampNs, AStatsEvent_setAtomId(statsEvent, util::SYNC_STATE_CHANGED); AStatsEvent_overwriteTimestamp(statsEvent, timestampNs); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); writeAttribution(statsEvent, attributionUids, attributionTags); AStatsEvent_writeString(statsEvent, name.c_str()); AStatsEvent_writeInt32(statsEvent, state); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, logEvent.get()); return logEvent; } Loading
cmds/statsd/benchmark/metric_util.h +6 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" #include "src/StatsLogProcessor.h" #include "src/logd/LogEvent.h" #include "stats_event.h" #include "statslog.h" namespace android { Loading Loading @@ -92,6 +93,11 @@ FieldMatcher CreateAttributionUidAndTagDimensions(const int atomId, FieldMatcher CreateAttributionUidDimensions(const int atomId, const std::vector<Position>& positions); void writeAttribution(AStatsEvent* statsEvent, const vector<int>& attributionUids, const vector<string>& attributionTags); void parseStatsEventToLogEvent(AStatsEvent* statsEvent, LogEvent* logEvent); // Create log event for screen state changed. std::unique_ptr<LogEvent> CreateScreenStateChangedEvent( uint64_t timestampNs, const android::view::DisplayStateEnum state); Loading
cmds/statsd/tests/FieldValue_test.cpp +4 −28 Original line number Diff line number Diff line Loading @@ -41,22 +41,10 @@ void makeLogEvent(LogEvent* logEvent, const int32_t atomId, const int64_t timest AStatsEvent_setAtomId(statsEvent, atomId); AStatsEvent_overwriteTimestamp(statsEvent, timestamp); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); writeAttribution(statsEvent, attributionUids, attributionTags); AStatsEvent_writeString(statsEvent, name.c_str()); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, logEvent); } void makeLogEvent(LogEvent* logEvent, const int32_t atomId, const int64_t timestamp, Loading @@ -66,22 +54,10 @@ void makeLogEvent(LogEvent* logEvent, const int32_t atomId, const int64_t timest AStatsEvent_setAtomId(statsEvent, atomId); AStatsEvent_overwriteTimestamp(statsEvent, timestamp); vector<const char*> cTags(attributionTags.size()); for (int i = 0; i < cTags.size(); i++) { cTags[i] = attributionTags[i].c_str(); } AStatsEvent_writeAttributionChain(statsEvent, reinterpret_cast<const uint32_t*>(attributionUids.data()), cTags.data(), attributionUids.size()); writeAttribution(statsEvent, attributionUids, attributionTags); AStatsEvent_writeInt32(statsEvent, value); AStatsEvent_build(statsEvent); size_t size; uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); logEvent->parseBuffer(buf, size); AStatsEvent_release(statsEvent); parseStatsEventToLogEvent(statsEvent, logEvent); } } // anonymous namespace Loading