blob: eba4fd0d8030ab31ebafa7b9599a602240e78be5 [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>
Sandeep Patil60194582019-01-30 17:43:22 -080020#include <sys/types.h>
Yabin Cui9581aea2018-05-10 17:19:12 -070021
22#include <string>
23
24#include <android-base/file.h>
25#include <android-base/logging.h>
26#include <backtrace/BacktraceMap.h>
27#include <unwindstack/Maps.h>
28
29#include <benchmark/benchmark.h>
30
Yabin Cui9581aea2018-05-10 17:19:12 -070031static void BM_ReadMapFile(benchmark::State& state) {
32 std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps";
33 for (auto _ : state) {
Yabin Cui629a8622018-10-30 17:14:35 -070034 std::vector<android::procinfo::MapInfo> maps;
Sandeep Patil60194582019-01-30 17:43:22 -080035 android::procinfo::ReadMapFile(map_file, [&](uint64_t start, uint64_t end, uint16_t flags,
36 uint64_t pgoff, ino_t inode, const char* name) {
37 maps.emplace_back(start, end, flags, pgoff, inode, name);
38 });
Yabin Cui9581aea2018-05-10 17:19:12 -070039 CHECK_EQ(maps.size(), 2043u);
40 }
41}
42BENCHMARK(BM_ReadMapFile);
43
44static void BM_unwindstack_FileMaps(benchmark::State& state) {
45 std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps";
46 for (auto _ : state) {
47 unwindstack::FileMaps maps(map_file);
48 maps.Parse();
49 CHECK_EQ(maps.Total(), 2043u);
50 }
51}
52BENCHMARK(BM_unwindstack_FileMaps);
53
54static void BM_unwindstack_BufferMaps(benchmark::State& state) {
55 std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps";
56 std::string content;
57 CHECK(android::base::ReadFileToString(map_file, &content));
58 for (auto _ : state) {
59 unwindstack::BufferMaps maps(content.c_str());
60 maps.Parse();
61 CHECK_EQ(maps.Total(), 2043u);
62 }
63}
64BENCHMARK(BM_unwindstack_BufferMaps);
65
66static void BM_backtrace_BacktraceMap(benchmark::State& state) {
67 pid_t pid = getpid();
68 for (auto _ : state) {
69 BacktraceMap* map = BacktraceMap::Create(pid, true);
70 CHECK(map != nullptr);
71 delete map;
72 }
73}
74BENCHMARK(BM_backtrace_BacktraceMap);
75
76BENCHMARK_MAIN();