Yabin Cui | 9581aea | 2018-05-10 17:19:12 -0700 | [diff] [blame] | 1 | /* |
| 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 Patil | 6019458 | 2019-01-30 17:43:22 -0800 | [diff] [blame] | 20 | #include <sys/types.h> |
Yabin Cui | 9581aea | 2018-05-10 17:19:12 -0700 | [diff] [blame] | 21 | |
| 22 | #include <string> |
| 23 | |
| 24 | #include <android-base/file.h> |
| 25 | #include <android-base/logging.h> |
Yabin Cui | 9581aea | 2018-05-10 17:19:12 -0700 | [diff] [blame] | 26 | #include <unwindstack/Maps.h> |
| 27 | |
| 28 | #include <benchmark/benchmark.h> |
| 29 | |
Yabin Cui | 9581aea | 2018-05-10 17:19:12 -0700 | [diff] [blame] | 30 | static void BM_ReadMapFile(benchmark::State& state) { |
| 31 | std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps"; |
| 32 | for (auto _ : state) { |
Yabin Cui | 629a862 | 2018-10-30 17:14:35 -0700 | [diff] [blame] | 33 | std::vector<android::procinfo::MapInfo> maps; |
Edgar Arriaga | fd214c1 | 2020-11-20 18:00:41 -0800 | [diff] [blame] | 34 | android::procinfo::ReadMapFile( |
| 35 | map_file, [&](const android::procinfo::MapInfo& mapinfo) { maps.emplace_back(mapinfo); }); |
Yabin Cui | 9581aea | 2018-05-10 17:19:12 -0700 | [diff] [blame] | 36 | CHECK_EQ(maps.size(), 2043u); |
| 37 | } |
| 38 | } |
| 39 | BENCHMARK(BM_ReadMapFile); |
| 40 | |
| 41 | static 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 | } |
| 49 | BENCHMARK(BM_unwindstack_FileMaps); |
| 50 | |
| 51 | static 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 | } |
| 61 | BENCHMARK(BM_unwindstack_BufferMaps); |
| 62 | |
Yabin Cui | 9581aea | 2018-05-10 17:19:12 -0700 | [diff] [blame] | 63 | BENCHMARK_MAIN(); |