877b58118014fbc40851761f4da0707860d79bfc
[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 BENCHMARK(DwarfFindAddress, n) {
24   folly::BenchmarkSuspender suspender;
25   using namespace folly::symbolizer;
26   // NOTE: Using '/proc/self/exe' only works if the code for @dummy is
27   // statically linked into the binary.
28   ElfFile elf("/proc/self/exe");
29   Dwarf dwarf(&elf);
30   suspender.dismiss();
31   for (size_t i = 0; i < n; i++) {
32     Dwarf::LocationInfo info;
33     dwarf.findAddress(uintptr_t(&dummy), info);
34   }
35 }
36
37 int main(int argc, char* argv[]) {
38   gflags::ParseCommandLineFlags(&argc, &argv, true);
39   google::InitGoogleLogging(argv[0]);
40   folly::runBenchmarksOnFlag();
41   return 0;
42 }