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> 20 #include <sys/types.h> 21 22 #include <string> 23 24 #include <android-base/file.h> 25 #include <android-base/logging.h> 26 #include <unwindstack/Maps.h> 27 28 #include <benchmark/benchmark.h> 29 BM_ReadMapFile(benchmark::State & state)30static void BM_ReadMapFile(benchmark::State& state) { 31 std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps"; 32 for (auto _ : state) { 33 std::vector<android::procinfo::MapInfo> maps; 34 android::procinfo::ReadMapFile( 35 map_file, [&](const android::procinfo::MapInfo& mapinfo) { maps.emplace_back(mapinfo); }); 36 CHECK_EQ(maps.size(), 2043u); 37 } 38 } 39 BENCHMARK(BM_ReadMapFile); 40 BM_unwindstack_FileMaps(benchmark::State & state)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 } 49 BENCHMARK(BM_unwindstack_FileMaps); 50 BM_unwindstack_BufferMaps(benchmark::State & state)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 } 61 BENCHMARK(BM_unwindstack_BufferMaps); 62 63 BENCHMARK_MAIN(); 64