From 0b37d01f72685cc957706ef6c3a93fdc4ef5bc93 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 22 Nov 2016 13:08:59 -0800 Subject: [PATCH] liblog: event_tag_map benchmark Tested on Hikey, all services stopped, shell only access, CPUs not locked. $ /data/nativetest64/liblog-benchmarks/liblog-benchmarks BM_lookupEvent* iterations ns/op Precharge: start Precharge: stop 231 BM_lookupEventTag 10000000 153 BM_lookupEventTag_NOT 20000000 139 BM_lookupEventFormat 10000000 153 Test: run benchmarks Bug: 31456426 Change-Id: Ice3ffa0b061d9a6b917718b2d9aedcc2348b7005 --- liblog/tests/liblog_benchmark.cpp | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/liblog/tests/liblog_benchmark.cpp b/liblog/tests/liblog_benchmark.cpp index 44045c34b..5420f684d 100644 --- a/liblog/tests/liblog_benchmark.cpp +++ b/liblog/tests/liblog_benchmark.cpp @@ -20,7 +20,10 @@ #include #include +#include + #include +#include #include #include "benchmark.h" @@ -689,3 +692,96 @@ static void BM_security(int iters) { StopBenchmarkTiming(); } BENCHMARK(BM_security); + +// Keep maps around for multiple iterations +static std::unordered_set set; +static const EventTagMap* map; + +static bool prechargeEventMap() { + if (map) return true; + + fprintf(stderr, "Precharge: start\n"); + + map = android_openEventTagMap(NULL); + for (uint32_t tag = 1; tag < USHRT_MAX; ++tag) { + size_t len; + if (android_lookupEventTag_len(map, &len, tag) == NULL) continue; + set.insert(tag); + } + + fprintf(stderr, "Precharge: stop %zu\n", set.size()); + + return true; +} + +/* + * Measure the time it takes for android_lookupEventTag_len + */ +static void BM_lookupEventTag(int iters) { + + prechargeEventMap(); + + std::unordered_set::const_iterator it = set.begin(); + + StartBenchmarkTiming(); + + for (int i = 0; i < iters; ++i) { + size_t len; + android_lookupEventTag_len(map, &len, (*it)); + ++it; + if (it == set.end()) it = set.begin(); + } + + StopBenchmarkTiming(); +} +BENCHMARK(BM_lookupEventTag); + +/* + * Measure the time it takes for android_lookupEventTag_len + */ +static uint32_t notTag = 1; + +static void BM_lookupEventTag_NOT(int iters) { + + prechargeEventMap(); + + while (set.find(notTag) != set.end()) { + ++notTag; + if (notTag >= USHRT_MAX) notTag = 1; + } + + StartBenchmarkTiming(); + + for (int i = 0; i < iters; ++i) { + size_t len; + android_lookupEventTag_len(map, &len, notTag); + } + + StopBenchmarkTiming(); + + ++notTag; + if (notTag >= USHRT_MAX) notTag = 1; +} +BENCHMARK(BM_lookupEventTag_NOT); + +/* + * Measure the time it takes for android_lookupEventFormat_len + */ +static void BM_lookupEventFormat(int iters) { + + prechargeEventMap(); + + std::unordered_set::const_iterator it = set.begin(); + + StartBenchmarkTiming(); + + for (int i = 0; i < iters; ++i) { + size_t len; + android_lookupEventFormat_len(map, &len, (*it)); + ++it; + if (it == set.end()) it = set.begin(); + } + + StopBenchmarkTiming(); +} +BENCHMARK(BM_lookupEventFormat);