fall back to .debug_info scan in fatal signal handler
[folly.git] / folly / experimental / symbolizer / test / DwarfBenchmark.cpp
1 /*
2  * Copyright 2016 Facebook, Inc.
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 <folly/Benchmark.h>
18 #include <folly/experimental/symbolizer/Dwarf.h>
19 #include <folly/portability/GFlags.h>
20
21 void dummy() {}
22
23 namespace {
24
25 using namespace folly::symbolizer;
26
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");
32   Dwarf dwarf(&elf);
33   suspender.dismiss();
34   for (size_t i = 0; i < n; i++) {
35     Dwarf::LocationInfo info;
36     dwarf.findAddress(uintptr_t(&dummy), info, mode);
37   }
38 }
39
40 } // namespace
41
42 BENCHMARK(DwarfFindAddressFast, n) {
43   run(folly::symbolizer::Dwarf::LocationInfoMode::FAST, n);
44 }
45
46 BENCHMARK(DwarfFindAddressFull, n) {
47   run(folly::symbolizer::Dwarf::LocationInfoMode::FULL, n);
48 }
49
50 int main(int argc, char* argv[]) {
51   gflags::ParseCommandLineFlags(&argc, &argv, true);
52   google::InitGoogleLogging(argv[0]);
53   folly::runBenchmarksOnFlag();
54   return 0;
55 }