DwarfBenchmark.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2016-present 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. #include <folly/Benchmark.h>
  17. #include <folly/experimental/symbolizer/Dwarf.h>
  18. #include <folly/portability/GFlags.h>
  19. void dummy() {}
  20. namespace {
  21. using namespace folly::symbolizer;
  22. void run(Dwarf::LocationInfoMode mode, size_t n) {
  23. folly::BenchmarkSuspender suspender;
  24. // NOTE: Using '/proc/self/exe' only works if the code for @dummy is
  25. // statically linked into the binary.
  26. ElfFile elf("/proc/self/exe");
  27. Dwarf dwarf(&elf);
  28. suspender.dismiss();
  29. for (size_t i = 0; i < n; i++) {
  30. Dwarf::LocationInfo info;
  31. dwarf.findAddress(uintptr_t(&dummy), info, mode);
  32. }
  33. }
  34. } // namespace
  35. BENCHMARK(DwarfFindAddressFast, n) {
  36. run(folly::symbolizer::Dwarf::LocationInfoMode::FAST, n);
  37. }
  38. BENCHMARK(DwarfFindAddressFull, n) {
  39. run(folly::symbolizer::Dwarf::LocationInfoMode::FULL, n);
  40. }
  41. int main(int argc, char* argv[]) {
  42. gflags::ParseCommandLineFlags(&argc, &argv, true);
  43. google::InitGoogleLogging(argv[0]);
  44. folly::runBenchmarksOnFlag();
  45. return 0;
  46. }