Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 662b4691 authored by Tom Cherry's avatar Tom Cherry
Browse files

liblog: add benchmark tests for not-printed message

Add a BM_log_verbose_overhead test that measure the overhead of
writing a log message that will not be printed due to verbosity
levels.  This was optimized in R to not format the log messages before
checking if they will be logged.

Results with R:
BM_log_verbose_overhead_null_mean          159 ns     159 ns    100
BM_log_verbose_overhead_null_median        159 ns     159 ns    100
BM_log_verbose_overhead_null_stddev        0.568 ns   0.464 ns  100
Results with Q:
M_log_verbose_overhead_null_mean           601 ns     600 ns    100
BM_log_verbose_overhead_null_median        601 ns     600 ns    100
BM_log_verbose_overhead_null_stddev        2.40 ns    2.23 ns   100

This benchmark shows liblog's overhead when not printing a log message
to be nearly ~4x faster than with Q.

Test: run this benchmark
Change-Id: I09a60e61bf064330bf15a9d0a946acf16e777a6d
parent 3574c37f
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@
#include <unordered_set>
#include <unordered_set>


#include <android-base/file.h>
#include <android-base/file.h>
#include <android-base/properties.h>
#include <benchmark/benchmark.h>
#include <benchmark/benchmark.h>
#include <cutils/sockets.h>
#include <cutils/sockets.h>
#include <log/event_tag_map.h>
#include <log/event_tag_map.h>
@@ -1025,3 +1026,14 @@ static void BM_lookupEventTagNum_logd_existing(benchmark::State& state) {
  }
  }
}
}
BENCHMARK(BM_lookupEventTagNum_logd_existing);
BENCHMARK(BM_lookupEventTagNum_logd_existing);

static void BM_log_verbose_overhead(benchmark::State& state) {
  std::string test_log_tag = "liblog_verbose_tag";
  android::base::SetProperty("log.tag." + test_log_tag, "I");
  for (auto _ : state) {
    __android_log_print(ANDROID_LOG_VERBOSE, test_log_tag.c_str(), "%s test log message %d %d",
                        "test test", 123, 456);
  }
  android::base::SetProperty("log.tag." + test_log_tag, "");
}
BENCHMARK(BM_log_verbose_overhead);