blob: 5a26302b72b5b4cf65e6c04e9d1d10f868845377 [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;
Edgar Arriagafd214c12020-11-20 18:00:41 -080035 android::procinfo::ReadMapFile(
36 map_file, [&](const android::procinfo::MapInfo& mapinfo) { maps.emplace_back(mapinfo); });
Yabin Cui9581aea2018-05-10 17:19:12 -070037 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();