1*e7c5e80fSMitch Phillips /* 2*e7c5e80fSMitch Phillips * Copyright (C) 2018 The Android Open Source Project 3*e7c5e80fSMitch Phillips * 4*e7c5e80fSMitch Phillips * Licensed under the Apache License, Version 2.0 (the "License"); 5*e7c5e80fSMitch Phillips * you may not use this file except in compliance with the License. 6*e7c5e80fSMitch Phillips * You may obtain a copy of the License at 7*e7c5e80fSMitch Phillips * 8*e7c5e80fSMitch Phillips * http://www.apache.org/licenses/LICENSE-2.0 9*e7c5e80fSMitch Phillips * 10*e7c5e80fSMitch Phillips * Unless required by applicable law or agreed to in writing, software 11*e7c5e80fSMitch Phillips * distributed under the License is distributed on an "AS IS" BASIS, 12*e7c5e80fSMitch Phillips * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*e7c5e80fSMitch Phillips * See the License for the specific language governing permissions and 14*e7c5e80fSMitch Phillips * limitations under the License. 15*e7c5e80fSMitch Phillips */ 16*e7c5e80fSMitch Phillips 17*e7c5e80fSMitch Phillips #include <procinfo/process_map.h> 18*e7c5e80fSMitch Phillips 19*e7c5e80fSMitch Phillips #include <string.h> 20*e7c5e80fSMitch Phillips #include <sys/types.h> 21*e7c5e80fSMitch Phillips 22*e7c5e80fSMitch Phillips #include <string> 23*e7c5e80fSMitch Phillips 24*e7c5e80fSMitch Phillips #include <android-base/file.h> 25*e7c5e80fSMitch Phillips #include <android-base/logging.h> 26*e7c5e80fSMitch Phillips #include <unwindstack/Maps.h> 27*e7c5e80fSMitch Phillips 28*e7c5e80fSMitch Phillips #include <benchmark/benchmark.h> 29*e7c5e80fSMitch Phillips BM_ReadMapFile(benchmark::State & state)30*e7c5e80fSMitch Phillipsstatic void BM_ReadMapFile(benchmark::State& state) { 31*e7c5e80fSMitch Phillips std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps"; 32*e7c5e80fSMitch Phillips for (auto _ : state) { 33*e7c5e80fSMitch Phillips std::vector<android::procinfo::MapInfo> maps; 34*e7c5e80fSMitch Phillips android::procinfo::ReadMapFile( 35*e7c5e80fSMitch Phillips map_file, [&](const android::procinfo::MapInfo& mapinfo) { maps.emplace_back(mapinfo); }); 36*e7c5e80fSMitch Phillips CHECK_EQ(maps.size(), 2043u); 37*e7c5e80fSMitch Phillips } 38*e7c5e80fSMitch Phillips } 39*e7c5e80fSMitch Phillips BENCHMARK(BM_ReadMapFile); 40*e7c5e80fSMitch Phillips BM_unwindstack_FileMaps(benchmark::State & state)41*e7c5e80fSMitch Phillipsstatic void BM_unwindstack_FileMaps(benchmark::State& state) { 42*e7c5e80fSMitch Phillips std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps"; 43*e7c5e80fSMitch Phillips for (auto _ : state) { 44*e7c5e80fSMitch Phillips unwindstack::FileMaps maps(map_file); 45*e7c5e80fSMitch Phillips maps.Parse(); 46*e7c5e80fSMitch Phillips CHECK_EQ(maps.Total(), 2043u); 47*e7c5e80fSMitch Phillips } 48*e7c5e80fSMitch Phillips } 49*e7c5e80fSMitch Phillips BENCHMARK(BM_unwindstack_FileMaps); 50*e7c5e80fSMitch Phillips BM_unwindstack_BufferMaps(benchmark::State & state)51*e7c5e80fSMitch Phillipsstatic void BM_unwindstack_BufferMaps(benchmark::State& state) { 52*e7c5e80fSMitch Phillips std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps"; 53*e7c5e80fSMitch Phillips std::string content; 54*e7c5e80fSMitch Phillips CHECK(android::base::ReadFileToString(map_file, &content)); 55*e7c5e80fSMitch Phillips for (auto _ : state) { 56*e7c5e80fSMitch Phillips unwindstack::BufferMaps maps(content.c_str()); 57*e7c5e80fSMitch Phillips maps.Parse(); 58*e7c5e80fSMitch Phillips CHECK_EQ(maps.Total(), 2043u); 59*e7c5e80fSMitch Phillips } 60*e7c5e80fSMitch Phillips } 61*e7c5e80fSMitch Phillips BENCHMARK(BM_unwindstack_BufferMaps); 62*e7c5e80fSMitch Phillips 63*e7c5e80fSMitch Phillips BENCHMARK_MAIN(); 64