libbacktrace: add benchmarks for Backtrace::Create, CreateNew.

Test: backtrace_benchmarks
Change-Id: I80ba5adb31d446314060edd00149f09e14e6815e
This commit is contained in:
Josh Gao 2017-10-25 15:12:24 -07:00
parent 3b094c169f
commit b9670bb437
2 changed files with 24 additions and 0 deletions

View File

@ -230,5 +230,6 @@ cc_benchmark {
shared_libs: [
"libbacktrace",
"libbase",
"libunwindstack",
],
}

View File

@ -32,6 +32,7 @@
#include <backtrace/Backtrace.h>
#include <backtrace/BacktraceMap.h>
#include <unwindstack/Memory.h>
// Definitions of prctl arguments to set a vma name in Android kernels.
#define ANDROID_PR_SET_VMA 0x53564d41
@ -153,4 +154,26 @@ static void BM_create_map_new(benchmark::State& state) {
}
BENCHMARK(BM_create_map_new);
using BacktraceCreateFn = decltype(Backtrace::Create);
static void CreateBacktrace(benchmark::State& state, BacktraceMap* map, BacktraceCreateFn fn) {
while (state.KeepRunning()) {
std::unique_ptr<Backtrace> backtrace(fn(getpid(), gettid(), map));
backtrace->Unwind(0);
}
}
static void BM_create_backtrace(benchmark::State& state) {
std::unique_ptr<BacktraceMap> backtrace_map(BacktraceMap::Create(getpid()));
CreateBacktrace(state, backtrace_map.get(), Backtrace::Create);
}
BENCHMARK(BM_create_backtrace);
static void BM_create_backtrace_new(benchmark::State& state) {
std::unique_ptr<BacktraceMap> backtrace_map(BacktraceMap::CreateNew(getpid()));
CreateBacktrace(state, backtrace_map.get(), Backtrace::CreateNew);
}
BENCHMARK(BM_create_backtrace_new);
BENCHMARK_MAIN();