From dc3c14720fb5702da67258067d89ddc51245c5d0 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Mon, 11 Sep 2017 13:29:59 -0700 Subject: [PATCH] liblog: clock_gettime, clock_getres and time benchmarks Add local BM_time_clock_gettime_*, BM_time_clock_getres_* and BM_time_time benchmarks. Relates to the bionic benchmarks of the same names, except adds CLOCK_MONOTONIC_RAW. Added here for developer convenience whenever updates to the liblog or logd code base need integration testing. ToDo: add liblog gTests that analyse the benchmark data to confirm that the specified integrated device has vdso access to all the pertinent clock sources. Add liblog local benchmarks and tests to measure the device clock drift of each possible liblog clock source to help evaluate device configuration. Test: liblog_benchmarks --benchmark_filter=BM_time* Bug: 63737556 Bug: 69423514 Change-Id: Ibafe0880d976ef2b3885765f71e0ba6c99d56f2a --- liblog/tests/liblog_benchmark.cpp | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/liblog/tests/liblog_benchmark.cpp b/liblog/tests/liblog_benchmark.cpp index 706a0f6ae..c2f3f837a 100644 --- a/liblog/tests/liblog_benchmark.cpp +++ b/liblog/tests/liblog_benchmark.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -107,6 +108,65 @@ static void BM_clock_overhead(benchmark::State& state) { } BENCHMARK(BM_clock_overhead); +static void do_clock_overhead(benchmark::State& state, clockid_t clk_id) { + timespec t; + while (state.KeepRunning()) { + clock_gettime(clk_id, &t); + } +} + +static void BM_time_clock_gettime_REALTIME(benchmark::State& state) { + do_clock_overhead(state, CLOCK_REALTIME); +} +BENCHMARK(BM_time_clock_gettime_REALTIME); + +static void BM_time_clock_gettime_MONOTONIC(benchmark::State& state) { + do_clock_overhead(state, CLOCK_MONOTONIC); +} +BENCHMARK(BM_time_clock_gettime_MONOTONIC); + +static void BM_time_clock_gettime_MONOTONIC_syscall(benchmark::State& state) { + timespec t; + while (state.KeepRunning()) { + syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &t); + } +} +BENCHMARK(BM_time_clock_gettime_MONOTONIC_syscall); + +static void BM_time_clock_gettime_MONOTONIC_RAW(benchmark::State& state) { + do_clock_overhead(state, CLOCK_MONOTONIC_RAW); +} +BENCHMARK(BM_time_clock_gettime_MONOTONIC_RAW); + +static void BM_time_clock_gettime_BOOTTIME(benchmark::State& state) { + do_clock_overhead(state, CLOCK_BOOTTIME); +} +BENCHMARK(BM_time_clock_gettime_BOOTTIME); + +static void BM_time_clock_getres_MONOTONIC(benchmark::State& state) { + timespec t; + while (state.KeepRunning()) { + clock_getres(CLOCK_MONOTONIC, &t); + } +} +BENCHMARK(BM_time_clock_getres_MONOTONIC); + +static void BM_time_clock_getres_MONOTONIC_syscall(benchmark::State& state) { + timespec t; + while (state.KeepRunning()) { + syscall(__NR_clock_getres, CLOCK_MONOTONIC, &t); + } +} +BENCHMARK(BM_time_clock_getres_MONOTONIC_syscall); + +static void BM_time_time(benchmark::State& state) { + while (state.KeepRunning()) { + time_t now; + now = time(&now); + } +} +BENCHMARK(BM_time_time); + /* * Measure the time it takes to submit the android logging data to pstore */