libbacktrace: add benchmarks for Backtrace::Create, CreateNew.
Test: backtrace_benchmarks Change-Id: I80ba5adb31d446314060edd00149f09e14e6815e
This commit is contained in:
parent
3b094c169f
commit
b9670bb437
|
@ -230,5 +230,6 @@ cc_benchmark {
|
|||
shared_libs: [
|
||||
"libbacktrace",
|
||||
"libbase",
|
||||
"libunwindstack",
|
||||
],
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue