1 /*
2  * Copyright (C) 2020 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 #pragma once
18 
19 #include <benchmark/benchmark.h>
20 #include <stdint.h>
21 
22 #include <string>
23 
24 std::string GetBenchmarkFilesDirectory();
25 
26 std::string GetElfFile();
27 
28 std::string GetSymbolSortedElfFile();
29 
30 // GetLargeCompressedFrameElfFile and GetLargeEhFrameElfFile were added to provide larger
31 // ELF files for more representative benchmarks. Theses ELF files will enable validation
32 // of optimizations to the unwindstack::Elf.
33 std::string GetLargeCompressedFrameElfFile();
34 
35 std::string GetLargeEhFrameElfFile();
36 
37 #if defined(__BIONIC__)
38 
39 #include <meminfo/procmeminfo.h>
40 #include <procinfo/process_map.h>
41 
42 uint64_t GetRSSBytes();
43 
44 #endif
45 
46 class MemoryTracker {
47  public:
48   void StartTrackingAllocations();
49   void StopTrackingAllocations();
50   void SetBenchmarkCounters(benchmark::State& state);
51 
52  private:
53 #if defined(__BIONIC__)
54   uint64_t total_rss_bytes_ = 0;
55   uint64_t min_rss_bytes_ = std::numeric_limits<uint64_t>::max();
56   uint64_t max_rss_bytes_ = 0;
57   uint64_t rss_bytes_before_;
58 #endif
59   uint64_t total_alloc_bytes_ = 0;
60   uint64_t min_alloc_bytes_ = std::numeric_limits<uint64_t>::max();
61   uint64_t max_alloc_bytes_ = 0;
62   uint64_t alloc_bytes_before_;
63 };
64