1*eb293b8fSAndroid Build Coastguard Worker /* 2*eb293b8fSAndroid Build Coastguard Worker * Copyright (C) 2020 The Android Open Source Project 3*eb293b8fSAndroid Build Coastguard Worker * 4*eb293b8fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*eb293b8fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*eb293b8fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*eb293b8fSAndroid Build Coastguard Worker * 8*eb293b8fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*eb293b8fSAndroid Build Coastguard Worker * 10*eb293b8fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*eb293b8fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*eb293b8fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*eb293b8fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*eb293b8fSAndroid Build Coastguard Worker * limitations under the License. 15*eb293b8fSAndroid Build Coastguard Worker */ 16*eb293b8fSAndroid Build Coastguard Worker 17*eb293b8fSAndroid Build Coastguard Worker #pragma once 18*eb293b8fSAndroid Build Coastguard Worker 19*eb293b8fSAndroid Build Coastguard Worker #include <benchmark/benchmark.h> 20*eb293b8fSAndroid Build Coastguard Worker #include <stdint.h> 21*eb293b8fSAndroid Build Coastguard Worker 22*eb293b8fSAndroid Build Coastguard Worker #include <string> 23*eb293b8fSAndroid Build Coastguard Worker 24*eb293b8fSAndroid Build Coastguard Worker std::string GetBenchmarkFilesDirectory(); 25*eb293b8fSAndroid Build Coastguard Worker 26*eb293b8fSAndroid Build Coastguard Worker std::string GetElfFile(); 27*eb293b8fSAndroid Build Coastguard Worker 28*eb293b8fSAndroid Build Coastguard Worker std::string GetSymbolSortedElfFile(); 29*eb293b8fSAndroid Build Coastguard Worker 30*eb293b8fSAndroid Build Coastguard Worker // GetLargeCompressedFrameElfFile and GetLargeEhFrameElfFile were added to provide larger 31*eb293b8fSAndroid Build Coastguard Worker // ELF files for more representative benchmarks. Theses ELF files will enable validation 32*eb293b8fSAndroid Build Coastguard Worker // of optimizations to the unwindstack::Elf. 33*eb293b8fSAndroid Build Coastguard Worker std::string GetLargeCompressedFrameElfFile(); 34*eb293b8fSAndroid Build Coastguard Worker 35*eb293b8fSAndroid Build Coastguard Worker std::string GetLargeEhFrameElfFile(); 36*eb293b8fSAndroid Build Coastguard Worker 37*eb293b8fSAndroid Build Coastguard Worker #if defined(__BIONIC__) 38*eb293b8fSAndroid Build Coastguard Worker 39*eb293b8fSAndroid Build Coastguard Worker #include <meminfo/procmeminfo.h> 40*eb293b8fSAndroid Build Coastguard Worker #include <procinfo/process_map.h> 41*eb293b8fSAndroid Build Coastguard Worker 42*eb293b8fSAndroid Build Coastguard Worker uint64_t GetRSSBytes(); 43*eb293b8fSAndroid Build Coastguard Worker 44*eb293b8fSAndroid Build Coastguard Worker #endif 45*eb293b8fSAndroid Build Coastguard Worker 46*eb293b8fSAndroid Build Coastguard Worker class MemoryTracker { 47*eb293b8fSAndroid Build Coastguard Worker public: 48*eb293b8fSAndroid Build Coastguard Worker void StartTrackingAllocations(); 49*eb293b8fSAndroid Build Coastguard Worker void StopTrackingAllocations(); 50*eb293b8fSAndroid Build Coastguard Worker void SetBenchmarkCounters(benchmark::State& state); 51*eb293b8fSAndroid Build Coastguard Worker 52*eb293b8fSAndroid Build Coastguard Worker private: 53*eb293b8fSAndroid Build Coastguard Worker #if defined(__BIONIC__) 54*eb293b8fSAndroid Build Coastguard Worker uint64_t total_rss_bytes_ = 0; 55*eb293b8fSAndroid Build Coastguard Worker uint64_t min_rss_bytes_ = std::numeric_limits<uint64_t>::max(); 56*eb293b8fSAndroid Build Coastguard Worker uint64_t max_rss_bytes_ = 0; 57*eb293b8fSAndroid Build Coastguard Worker uint64_t rss_bytes_before_; 58*eb293b8fSAndroid Build Coastguard Worker #endif 59*eb293b8fSAndroid Build Coastguard Worker uint64_t total_alloc_bytes_ = 0; 60*eb293b8fSAndroid Build Coastguard Worker uint64_t min_alloc_bytes_ = std::numeric_limits<uint64_t>::max(); 61*eb293b8fSAndroid Build Coastguard Worker uint64_t max_alloc_bytes_ = 0; 62*eb293b8fSAndroid Build Coastguard Worker uint64_t alloc_bytes_before_; 63*eb293b8fSAndroid Build Coastguard Worker }; 64