2 * Copyright 2016-present Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <folly/Benchmark.h>
18 #include <folly/experimental/symbolizer/Dwarf.h>
19 #include <folly/portability/GFlags.h>
25 using namespace folly::symbolizer;
27 void run(Dwarf::LocationInfoMode mode, size_t n) {
28 folly::BenchmarkSuspender suspender;
29 // NOTE: Using '/proc/self/exe' only works if the code for @dummy is
30 // statically linked into the binary.
31 ElfFile elf("/proc/self/exe");
34 for (size_t i = 0; i < n; i++) {
35 Dwarf::LocationInfo info;
36 dwarf.findAddress(uintptr_t(&dummy), info, mode);
42 BENCHMARK(DwarfFindAddressFast, n) {
43 run(folly::symbolizer::Dwarf::LocationInfoMode::FAST, n);
46 BENCHMARK(DwarfFindAddressFull, n) {
47 run(folly::symbolizer::Dwarf::LocationInfoMode::FULL, n);
50 int main(int argc, char* argv[]) {
51 gflags::ParseCommandLineFlags(&argc, &argv, true);
52 google::InitGoogleLogging(argv[0]);
53 folly::runBenchmarksOnFlag();