From 2ed818449f328ce0f8c6fcd6231a680cc28e1aa9 Mon Sep 17 00:00:00 2001 From: "Jonathan R. Madsen" Date: Wed, 28 Sep 2022 00:18:05 -0500 Subject: [PATCH] Support for libbfd (binary file descriptor) (#168) - provides addr2line information for sampling --- CMakeLists.txt | 9 ++++-- cmake/Packages.cmake | 11 +++++++ external/timemory | 2 +- source/lib/omnitrace/CMakeLists.txt | 1 + .../library/components/backtrace.cpp | 8 +++-- .../library/components/backtrace.hpp | 2 +- source/lib/omnitrace/library/sampling.cpp | 31 ++++++++++++++++--- 7 files changed, 52 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bc4dd2e31..b8f9193cbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,8 @@ set(CMAKE_INSTALL_MESSAGE mark_as_advanced(CMAKE_INSTALL_MESSAGE) omnitrace_add_option(OMNITRACE_USE_CLANG_TIDY "Enable clang-tidy" OFF) +omnitrace_add_option(OMNITRACE_USE_BFD + "Enable BFD support (map call-stack samples to LOC)" ON) omnitrace_add_option(OMNITRACE_USE_MPI "Enable MPI support" OFF) omnitrace_add_option(OMNITRACE_USE_HIP "Enable HIP support" ON) omnitrace_add_option(OMNITRACE_USE_PAPI "Enable HW counter support via PAPI" ON) @@ -133,8 +135,11 @@ omnitrace_add_option(OMNITRACE_USE_OMPT "Enable OpenMP tools support" ON) omnitrace_add_option(OMNITRACE_USE_PYTHON "Enable Python support" OFF) omnitrace_add_option(OMNITRACE_BUILD_DYNINST "Build dyninst from submodule" OFF) omnitrace_add_option(OMNITRACE_BUILD_LIBUNWIND "Build libunwind from submodule" ON) -omnitrace_add_option(OMNITRACE_BUILD_EXAMPLES "Enable building the examples" OFF) -omnitrace_add_option(OMNITRACE_BUILD_TESTING "Enable building the testing suite" OFF) +omnitrace_add_option(OMNITRACE_BUILD_EXAMPLES "Enable building the examples" OFF ADVANCED) +omnitrace_add_option(OMNITRACE_BUILD_TESTING "Enable building the testing suite" OFF + ADVANCED) +omnitrace_add_option(OMNITRACE_BUILD_DEBUG "Enable building with extensive debug symbols" + OFF ADVANCED) omnitrace_add_option(OMNITRACE_CUSTOM_DATA_SOURCE "Enable custom data source" OFF ADVANCED) omnitrace_add_option( diff --git a/cmake/Packages.cmake b/cmake/Packages.cmake index 8fabca747f..a6923851fd 100644 --- a/cmake/Packages.cmake +++ b/cmake/Packages.cmake @@ -23,6 +23,7 @@ omnitrace_add_interface_library(omnitrace-rocm-smi omnitrace_add_interface_library( omnitrace-rccl "Provides flags for ROCm Communication Collectives Library (RCCL)") omnitrace_add_interface_library(omnitrace-mpi "Provides MPI or MPI headers") +omnitrace_add_interface_library(omnitrace-bfd "Provides Binary File Descriptor (BFD)") omnitrace_add_interface_library(omnitrace-ptl "Enables PTL support (tasking)") omnitrace_add_interface_library(omnitrace-papi "Enable PAPI support") omnitrace_add_interface_library(omnitrace-ompt "Enable OMPT support") @@ -40,6 +41,7 @@ set(OMNITRACE_EXTENSION_LIBRARIES omnitrace::omnitrace-rocprofiler omnitrace::omnitrace-rocm-smi omnitrace::omnitrace-rccl + omnitrace::omnitrace-bfd omnitrace::omnitrace-mpi omnitrace::omnitrace-ptl omnitrace::omnitrace-ompt @@ -596,6 +598,9 @@ set(TIMEMORY_USE_OMPT set(TIMEMORY_USE_PAPI ${OMNITRACE_USE_PAPI} CACHE BOOL "Enable PAPI support in timemory" FORCE) +set(TIMEMORY_USE_BFD + ${OMNITRACE_USE_BFD} + CACHE BOOL "Enable BFD support in timemory" FORCE) set(TIMEMORY_USE_LIBUNWIND ON CACHE BOOL "Enable libunwind support in timemory") @@ -707,6 +712,12 @@ target_link_libraries( $ $) +target_link_libraries(omnitrace-bfd INTERFACE $) + +if(OMNITRACE_USE_BFD) + omnitrace_target_compile_definitions(omnitrace-bfd INTERFACE OMNITRACE_USE_BFD) +endif() + # ----------------------------------------------------------------------------------------# # # PTL (Parallel Tasking Library) submodule diff --git a/external/timemory b/external/timemory index 59ac91b591..f95f257a7f 160000 --- a/external/timemory +++ b/external/timemory @@ -1 +1 @@ -Subproject commit 59ac91b591468ec29a0a59fe79e4cf05b768e871 +Subproject commit f95f257a7f8e4979002a28d1c3094d4186243ecb diff --git a/source/lib/omnitrace/CMakeLists.txt b/source/lib/omnitrace/CMakeLists.txt index 492bf27053..8ac2cb909f 100644 --- a/source/lib/omnitrace/CMakeLists.txt +++ b/source/lib/omnitrace/CMakeLists.txt @@ -32,6 +32,7 @@ target_link_libraries( $ $ $ + $ $ $ $ diff --git a/source/lib/omnitrace/library/components/backtrace.cpp b/source/lib/omnitrace/library/components/backtrace.cpp index d55e2ba9c8..e8a6af6997 100644 --- a/source/lib/omnitrace/library/components/backtrace.cpp +++ b/source/lib/omnitrace/library/components/backtrace.cpp @@ -109,7 +109,7 @@ backtrace::description() return "Records backtrace data"; } -std::vector +std::vector backtrace::filter_and_patch(const std::vector& _data) { // check whether the call-stack entry should be used. -1 means break, 0 means continue @@ -143,14 +143,16 @@ backtrace::filter_and_patch(const std::vector& _data) return std::string{ _lbl }.replace(_pos, _dyninst.length(), ""); }; - auto _ret = std::vector{}; + auto _ret = std::vector{}; for(const auto& itr : _data) { auto _name = tim::demangle(_patch_label(itr.name)); auto _use = _use_label(_name); if(_use == -1) break; if(_use == 0) continue; - _ret.emplace_back(_name); + auto _v = itr; + _v.name = _name; + _ret.emplace_back(_v); } return _ret; diff --git a/source/lib/omnitrace/library/components/backtrace.hpp b/source/lib/omnitrace/library/components/backtrace.hpp index 0f18a8bc8e..03522a7bc3 100644 --- a/source/lib/omnitrace/library/components/backtrace.hpp +++ b/source/lib/omnitrace/library/components/backtrace.hpp @@ -70,7 +70,7 @@ struct backtrace backtrace& operator=(const backtrace&) = default; backtrace& operator=(backtrace&&) noexcept = default; - static std::vector filter_and_patch(const std::vector&); + static std::vector filter_and_patch(const std::vector&); static void start(); static void stop(); diff --git a/source/lib/omnitrace/library/sampling.cpp b/source/lib/omnitrace/library/sampling.cpp index 265ae7bed4..b27eaf5a82 100644 --- a/source/lib/omnitrace/library/sampling.cpp +++ b/source/lib/omnitrace/library/sampling.cpp @@ -606,6 +606,8 @@ post_process_perfetto(int64_t _tid, const bundle_t* _init, tracing::push_perfetto_ts(category::sampling{}, "samples [omnitrace]", _beg_ns, "begin_ns", _beg_ns); + auto _as_hex = [](auto _v) { return JOIN("", "0x", std::hex, _v); }; + for(const auto& itr : _data) { const auto* _bt_ts = itr->get(); @@ -617,13 +619,32 @@ post_process_perfetto(int64_t _tid, const bundle_t* _init, static std::set _static_strings{}; for(const auto& itr : backtrace::filter_and_patch(_bt_cs->get())) { - const auto* _name = _static_strings.emplace(itr).first->c_str(); + const auto* _name = _static_strings.emplace(itr.name).first->c_str(); uint64_t _beg = _last_ts; uint64_t _end = _bt_ts->get_timestamp(); if(!_thread_info->is_valid_lifetime({ _beg, _end })) continue; - tracing::push_perfetto_ts(category::sampling{}, _name, _beg, "begin_ns", - _beg); + tracing::push_perfetto_ts( + category::sampling{}, _name, _beg, [&](perfetto::EventContext ctx) { + tracing::add_perfetto_annotation(ctx, "begin_ns", _beg); + tracing::add_perfetto_annotation(ctx, "file", itr.location); + tracing::add_perfetto_annotation(ctx, "pc", _as_hex(itr.address)); + tracing::add_perfetto_annotation(ctx, "line_address", + _as_hex(itr.line_address)); + if(itr.lineinfo) + { + size_t _n = 0; + for(const auto& litr : itr.lineinfo.lines) + { + auto _label = JOIN('-', "lineinfo", _n++); + tracing::add_perfetto_annotation( + ctx, _label.c_str(), + JOIN('@', demangle(litr.name), + JOIN(':', litr.location, litr.line))); + } + } + }); + tracing::pop_perfetto_ts(category::sampling{}, _name, _end, "end_ns", _end); } @@ -687,7 +708,7 @@ post_process_timemory(int64_t _tid, const bundle_t* _init, // generate the instances of the tuple of components and start them for(const auto& itr : backtrace::filter_and_patch(_bt_data->get())) { - _tc.emplace_back(tim::string_view_t{ itr }); + _tc.emplace_back(tim::string_view_t{ itr.name }); _tc.back().push(_bt_time->get_tid()); _tc.back().start(); } @@ -761,7 +782,7 @@ post_process_timemory(int64_t _tid, const bundle_t* _init, // generate the instances of the tuple of components and start them for(const auto& itr : backtrace::filter_and_patch(_bt_data->get())) { - _tc.emplace_back(tim::string_view_t{ itr }); + _tc.emplace_back(tim::string_view_t{ itr.name }); _tc.back().push(_bt_time->get_tid()); _tc.back().start(); }