blob: 360250495f35b76f8fa87948991cbf0002c081db [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>
Yabin Cui9581aea2018-05-10 17:19:12 -070026#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;
Edgar Arriagafd214c12020-11-20 18:00:41 -080034 android::procinfo::ReadMapFile(
35 map_file, [&](const android::procinfo::MapInfo& mapinfo) { maps.emplace_back(mapinfo); });
Yabin Cui9581aea2018-05-10 17:19:12 -070036 CHECK_EQ(maps.size(), 2043u);
37 }
38}
39BENCHMARK(BM_ReadMapFile);
40
41static void BM_unwindstack_FileMaps(benchmark::State& state) {
42 std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps";
43 for (auto _ : state) {
44 unwindstack::FileMaps maps(map_file);
45 maps.Parse();
46 CHECK_EQ(maps.Total(), 2043u);
47 }
48}
49BENCHMARK(BM_unwindstack_FileMaps);
50
51static void BM_unwindstack_BufferMaps(benchmark::State& state) {
52 std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps";
53 std::string content;
54 CHECK(android::base::ReadFileToString(map_file, &content));
55 for (auto _ : state) {
56 unwindstack::BufferMaps maps(content.c_str());
57 maps.Parse();
58 CHECK_EQ(maps.Total(), 2043u);
59 }
60}
61BENCHMARK(BM_unwindstack_BufferMaps);
62
Yabin Cui9581aea2018-05-10 17:19:12 -070063BENCHMARK_MAIN();