blob: 04995d4cbb8308cb5cea6b761b312233f341d092 [file] [log] [blame]
Yabin Cui9581aea2018-05-10 17:19:12 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <procinfo/process_map.h>
18
19#include <string.h>
20
21#include <string>
22
23#include <android-base/file.h>
24#include <android-base/logging.h>
25#include <backtrace/BacktraceMap.h>
26#include <unwindstack/Maps.h>
27
28#include <benchmark/benchmark.h>
29
Yabin Cui9581aea2018-05-10 17:19:12 -070030static void BM_ReadMapFile(benchmark::State& state) {
31 std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps";
32 for (auto _ : state) {
Yabin Cui629a8622018-10-30 17:14:35 -070033 std::vector<android::procinfo::MapInfo> maps;
Yabin Cui9581aea2018-05-10 17:19:12 -070034 android::procinfo::ReadMapFile(
35 map_file, [&](uint64_t start, uint64_t end, uint16_t flags, uint64_t pgoff,
36 const char* name) { maps.emplace_back(start, end, flags, pgoff, name); });
37 CHECK_EQ(maps.size(), 2043u);
38 }
39}
40BENCHMARK(BM_ReadMapFile);
41
42static void BM_unwindstack_FileMaps(benchmark::State& state) {
43 std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps";
44 for (auto _ : state) {
45 unwindstack::FileMaps maps(map_file);
46 maps.Parse();
47 CHECK_EQ(maps.Total(), 2043u);
48 }
49}
50BENCHMARK(BM_unwindstack_FileMaps);
51
52static void BM_unwindstack_BufferMaps(benchmark::State& state) {
53 std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps";
54 std::string content;
55 CHECK(android::base::ReadFileToString(map_file, &content));
56 for (auto _ : state) {
57 unwindstack::BufferMaps maps(content.c_str());
58 maps.Parse();
59 CHECK_EQ(maps.Total(), 2043u);
60 }
61}
62BENCHMARK(BM_unwindstack_BufferMaps);
63
64static void BM_backtrace_BacktraceMap(benchmark::State& state) {
65 pid_t pid = getpid();
66 for (auto _ : state) {
67 BacktraceMap* map = BacktraceMap::Create(pid, true);
68 CHECK(map != nullptr);
69 delete map;
70 }
71}
72BENCHMARK(BM_backtrace_BacktraceMap);
73
74BENCHMARK_MAIN();