Added benchmark for LogEvent header & body parsing
- version with header re-parsing
Bug: 266520742
Test: statsd_test
Test: CtsStatsdHostTestCases
Ignore-AOSP-First: Android U feature
Change-Id: I6e1634bd0eff40da5cc6b194888beca2c2a08ade
diff --git a/statsd/benchmark/log_event_benchmark.cpp b/statsd/benchmark/log_event_benchmark.cpp
index 057e00b..6eb250c 100644
--- a/statsd/benchmark/log_event_benchmark.cpp
+++ b/statsd/benchmark/log_event_benchmark.cpp
@@ -45,6 +45,21 @@
}
BENCHMARK(BM_LogEventCreation);
+static void BM_LogEventCreationWithPrefetch(benchmark::State& state) {
+ uint8_t msg[LOGGER_ENTRY_MAX_PAYLOAD];
+ size_t size = createAndParseStatsEvent(msg);
+ while (state.KeepRunning()) {
+ LogEvent event(/*uid=*/1000, /*pid=*/1001);
+
+ // explicitly parse header first
+ benchmark::DoNotOptimize(event.parseBuffer(msg, size, /*fetchHeaderOnly*/ true));
+
+ // re-parse header & body
+ benchmark::DoNotOptimize(event.parseBuffer(msg, size, /*fetchHeaderOnly*/ false));
+ }
+}
+BENCHMARK(BM_LogEventCreationWithPrefetch);
+
} // namespace statsd
} // namespace os
} // namespace android