From 666e76deac6f70295d9e2b60238f6ccfa9a33e13 Mon Sep 17 00:00:00 2001 From: Milan Radosavljevic Date: Tue, 16 Dec 2025 08:32:18 +0100 Subject: [PATCH] [rocprofiler-systems] Add cached demangler and replace old demangle (#2135) * Add cached demangler and replace old * Add unit tests * Applied suggestions from code review * Applied suggestions from code review --- .../source/bin/rocprof-sys-avail/avail.hpp | 3 +- .../source/bin/rocprof-sys-avail/common.hpp | 1 - .../component_categories.hpp | 3 +- .../bin/rocprof-sys-avail/get_categories.hpp | 3 +- .../bin/rocprof-sys-instrument/details.cpp | 6 +- .../function_signature.cpp | 4 +- .../rocprof-sys-instrument/internal_libs.cpp | 3 +- .../rocprof-sys-instrument.cpp | 5 +- .../source/lib/binary/symbol.cpp | 12 +- .../source/lib/core/CMakeLists.txt | 10 +- .../source/lib/core/common.hpp | 10 +- .../source/lib/core/demangler.hpp | 144 ++++++++++++++++ .../source/lib/core/tests/CMakeLists.txt | 30 ++++ .../source/lib/core/tests/demangler_test.cpp | 155 ++++++++++++++++++ .../core/trace_cache/perfetto_processor.cpp | 3 +- .../lib/core/trace_cache/rocpd_processor.cpp | 6 +- .../lib/rocprof-sys/library/causal/data.cpp | 25 +-- .../rocprof-sys/library/causal/experiment.cpp | 15 +- .../library/components/backtrace.cpp | 3 +- .../library/components/category_region.hpp | 7 +- .../rocprof-sys/library/components/mpip.hpp | 7 +- .../rocprof-sys/library/rocprofiler-sdk.cpp | 39 +++-- .../library/rocprofiler-sdk/counters.cpp | 5 +- .../lib/rocprof-sys/library/sampling.cpp | 24 ++- .../lib/rocprof-sys/library/tracing.hpp | 6 +- .../source/tests/CMakeLists.txt | 2 +- .../source/tests/dummy.cpp | 3 - 27 files changed, 450 insertions(+), 84 deletions(-) create mode 100644 projects/rocprofiler-systems/source/lib/core/demangler.hpp create mode 100644 projects/rocprofiler-systems/source/lib/core/tests/CMakeLists.txt create mode 100644 projects/rocprofiler-systems/source/lib/core/tests/demangler_test.cpp delete mode 100644 projects/rocprofiler-systems/source/tests/dummy.cpp diff --git a/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/avail.hpp b/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/avail.hpp index 4c43f60fe0..da6d710220 100644 --- a/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/avail.hpp +++ b/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/avail.hpp @@ -22,6 +22,7 @@ #pragma once +#include "core/demangler.hpp" #include "defines.hpp" #include @@ -273,7 +274,7 @@ TIMEMORY_CEREAL_SAVE_FUNCTION_NAME(SettingsTextArchive& ar, const NameValuePair< } else { - ar.setNextType(tim::demangle().c_str()); + ar.setNextType(rocprofsys::utility::demangle().c_str()); } ar(t.value); } diff --git a/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/common.hpp b/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/common.hpp index e78598d5e9..07793f6651 100644 --- a/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/common.hpp +++ b/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/common.hpp @@ -45,7 +45,6 @@ namespace regex_const = ::std::regex_constants; // NOLINT namespace comp = ::tim::component; // NOLINT using settings = ::tim::settings; // NOLINT -using tim::demangle; // NOLINT using tim::type_list; // NOLINT //--------------------------------------------------------------------------------------// diff --git a/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/component_categories.hpp b/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/component_categories.hpp index d5285bc1d0..2f825c3797 100644 --- a/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/component_categories.hpp +++ b/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/component_categories.hpp @@ -23,6 +23,7 @@ #pragma once #include "common.hpp" +#include "core/demangler.hpp" #include "defines.hpp" #include @@ -51,7 +52,7 @@ struct component_categories (void) _cleanup; // unused but set if sizeof...(Tp) == 0 TIMEMORY_FOLD_EXPRESSION(_v.emplace(TIMEMORY_JOIN( - "::", "component", _cleanup(tim::try_demangle(), "tim::")))); + "::", "component", _cleanup(rocprofsys::utility::demangle(), "tim::")))); } void operator()(std::set& _v) const diff --git a/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/get_categories.hpp b/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/get_categories.hpp index d02bd2b1e1..cb05609379 100644 --- a/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/get_categories.hpp +++ b/projects/rocprofiler-systems/source/bin/rocprof-sys-avail/get_categories.hpp @@ -23,6 +23,7 @@ #pragma once #include "common.hpp" +#include "core/demangler.hpp" #include #include @@ -43,7 +44,7 @@ get_categories(type_list) }; (void) _cleanup; // unused but set if sizeof...(Tp) == 0 - auto _vec = str_vec_t{ _cleanup(demangle(), "tim::")... }; + auto _vec = str_vec_t{ _cleanup(rocprofsys::utility::demangle(), "tim::")... }; std::sort(_vec.begin(), _vec.end(), [](const auto& lhs, const auto& rhs) { // prioritize project category auto lpos = lhs.find("project::"); diff --git a/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/details.cpp b/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/details.cpp index 5da3bd4ba1..fa16b0d90a 100644 --- a/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/details.cpp +++ b/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/details.cpp @@ -29,6 +29,8 @@ #include #include +#include "core/demangler.hpp" + #include #include #include @@ -893,7 +895,8 @@ process_modules(const std::vector& _app_modules) for(auto* fitr : symtab_data.functions.at(itr)) { - symtab_data.typed_func_names[tim::demangle(fitr->getName())] = fitr; + symtab_data.typed_func_names[rocprofsys::utility::demangle(fitr->getName())] = + fitr; symtab_data.symbols.emplace(fitr, std::vector{}); if(!fitr->getSymbols(symtab_data.symbols.at(fitr))) continue; @@ -906,7 +909,6 @@ process_modules(const std::vector& _app_modules) } } } - _pr.stop(); _wc.stop(); verbprintf(0, "Processing %zu modules... Done (%.3f %s, %.3f %s)\n", diff --git a/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/function_signature.cpp b/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/function_signature.cpp index ed28118549..1840879765 100644 --- a/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/function_signature.cpp +++ b/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/function_signature.cpp @@ -22,6 +22,8 @@ #include "function_signature.hpp" +#include "core/demangler.hpp" + function_signature::function_signature(std::string_view _ret, std::string_view _name, std::string_view _file, location_t _row, location_t _col, bool _loop, bool _info_beg, @@ -32,7 +34,7 @@ function_signature::function_signature(std::string_view _ret, std::string_view _ , m_row(std::move(_row)) , m_col(std::move(_col)) , m_return(_ret) -, m_name(tim::demangle(_name.data())) +, m_name(rocprofsys::utility::demangle(_name.data())) , m_file(_file) { if(m_file.find('/') != std::string_view::npos) diff --git a/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/internal_libs.cpp b/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/internal_libs.cpp index 3ed1ec9725..54a9b4e4e6 100644 --- a/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/internal_libs.cpp +++ b/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/internal_libs.cpp @@ -27,6 +27,7 @@ #include "binary/scope_filter.hpp" #include "binary/symbol.hpp" #include "common/defines.h" +#include "core/demangler.hpp" #include "core/utility.hpp" #include "fwd.hpp" #include "log.hpp" @@ -491,7 +492,7 @@ get_internal_libs_data_impl() for(const auto& fitr : _funcs) { auto _fname = fitr->getName(); - auto _dname = tim::demangle(_fname); + auto _dname = rocprofsys::utility::demangle(_fname); _data[itr.first][_mpath].emplace(_fname); _data[itr.first][_mpath].emplace(_dname); diff --git a/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/rocprof-sys-instrument.cpp b/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/rocprof-sys-instrument.cpp index 717d657324..58c5f44c4e 100644 --- a/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/rocprof-sys-instrument.cpp +++ b/projects/rocprofiler-systems/source/bin/rocprof-sys-instrument/rocprof-sys-instrument.cpp @@ -24,6 +24,7 @@ #include "common/defines.h" #include "common/join.hpp" #include "common/path.hpp" +#include "core/demangler.hpp" #include "dl/dl.hpp" #include "fwd.hpp" #include "internal_libs.hpp" @@ -1451,8 +1452,8 @@ main(int argc, char** argv) dynamic_cast(addr_space) != nullptr) { errprintf(-1, "address space statisfied dynamic_cast<%s> and dynamic_cast<%s>.\n", - tim::demangle().c_str(), - tim::demangle().c_str()); + rocprofsys::utility::demangle().c_str(), + rocprofsys::utility::demangle().c_str()); } auto _rewrite = (dynamic_cast(addr_space) != nullptr && diff --git a/projects/rocprofiler-systems/source/lib/binary/symbol.cpp b/projects/rocprofiler-systems/source/lib/binary/symbol.cpp index 1fb7f0ae1c..0cb41900be 100644 --- a/projects/rocprofiler-systems/source/lib/binary/symbol.cpp +++ b/projects/rocprofiler-systems/source/lib/binary/symbol.cpp @@ -41,6 +41,7 @@ #include #include "core/binary/fwd.hpp" +#include "core/demangler.hpp" #include "core/timemory.hpp" #include "core/utility.hpp" #include "dwarf_entry.hpp" @@ -116,7 +117,8 @@ symbol::operator()(const std::vector& _filters) const using sf = scope_filter; // apply filters to the main symbol - return (sf::satisfies_filter(_filters, sf::FUNCTION_FILTER, demangle(func)) && + return (sf::satisfies_filter(_filters, sf::FUNCTION_FILTER, + rocprofsys::utility::demangle(func)) && (sf::satisfies_filter(_filters, sf::SOURCE_FILTER, file) || sf::satisfies_filter(_filters, sf::SOURCE_FILTER, join(':', file, line)))); } @@ -283,7 +285,8 @@ symbol::get_inline_symbols(const std::vector& _filters) const for(const auto& itr : inlines) { - if(sf::satisfies_filter(_filters, sf::FUNCTION_FILTER, demangle(itr.func)) && + if(sf::satisfies_filter(_filters, sf::FUNCTION_FILTER, + rocprofsys::utility::demangle(itr.func)) && (sf::satisfies_filter(_filters, sf::SOURCE_FILTER, itr.file) || sf::satisfies_filter(_filters, sf::SOURCE_FILTER, join(':', itr.file, itr.line)))) @@ -316,7 +319,8 @@ symbol::get_debug_line_info(const std::vector& _filters) const auto _data = Tp{}; - if(sf::satisfies_filter(_filters, sf::FUNCTION_FILTER, demangle(func))) + if(sf::satisfies_filter(_filters, sf::FUNCTION_FILTER, + rocprofsys::utility::demangle(func))) { for(const auto& itr : dwarf_info) { @@ -361,7 +365,7 @@ symbol::serialize(ArchiveT& ar, const unsigned int) make_nvp("line", line), make_nvp("func", func), make_nvp("file", file), make_nvp("inlines", inlines), make_nvp("dwarf_info", dwarf_info)); if constexpr(concepts::is_output_archive::value) - ar(cereal::make_nvp("dfunc", demangle(func))); + ar(cereal::make_nvp("dfunc", rocprofsys::utility::demangle(func))); } template void diff --git a/projects/rocprofiler-systems/source/lib/core/CMakeLists.txt b/projects/rocprofiler-systems/source/lib/core/CMakeLists.txt index 6657f59c39..694a098d56 100644 --- a/projects/rocprofiler-systems/source/lib/core/CMakeLists.txt +++ b/projects/rocprofiler-systems/source/lib/core/CMakeLists.txt @@ -48,8 +48,6 @@ set(core_sources ${CMAKE_CURRENT_LIST_DIR}/state.cpp ${CMAKE_CURRENT_LIST_DIR}/timemory.cpp ${CMAKE_CURRENT_LIST_DIR}/utility.cpp - ${CMAKE_CURRENT_LIST_DIR}/agent_manager.cpp - ${CMAKE_CURRENT_LIST_DIR}/node_info.cpp ) set(core_headers @@ -66,6 +64,7 @@ set(core_headers ${CMAKE_CURRENT_LIST_DIR}/constraint.hpp ${CMAKE_CURRENT_LIST_DIR}/cpu.hpp ${CMAKE_CURRENT_LIST_DIR}/debug.hpp + ${CMAKE_CURRENT_LIST_DIR}/demangler.hpp ${CMAKE_CURRENT_LIST_DIR}/dynamic_library.hpp ${CMAKE_CURRENT_LIST_DIR}/exception.hpp ${CMAKE_CURRENT_LIST_DIR}/gpu.hpp @@ -81,9 +80,6 @@ set(core_headers ${CMAKE_CURRENT_LIST_DIR}/state.hpp ${CMAKE_CURRENT_LIST_DIR}/timemory.hpp ${CMAKE_CURRENT_LIST_DIR}/utility.hpp - ${CMAKE_CURRENT_LIST_DIR}/agent.hpp - ${CMAKE_CURRENT_LIST_DIR}/agent_manager.hpp - ${CMAKE_CURRENT_LIST_DIR}/node_info.hpp ) add_library(rocprofiler-systems-core-library STATIC) @@ -141,3 +137,7 @@ set_target_properties( rocprofiler-systems-core-library PROPERTIES OUTPUT_NAME ${BINARY_NAME_PREFIX}-core ) + +if(ROCPROFSYS_BUILD_TESTING) + add_subdirectory(tests) +endif() diff --git a/projects/rocprofiler-systems/source/lib/core/common.hpp b/projects/rocprofiler-systems/source/lib/core/common.hpp index 232a467a91..9759328bc1 100644 --- a/projects/rocprofiler-systems/source/lib/core/common.hpp +++ b/projects/rocprofiler-systems/source/lib/core/common.hpp @@ -115,12 +115,10 @@ namespace policy = ::tim::policy; // NOLINT namespace trait = ::tim::trait; // NOLINT namespace cereal = ::tim::cereal; // NOLINT -using ::tim::auto_lock_t; // NOLINT -using ::tim::demangle; // NOLINT -using ::tim::get_env; // NOLINT -using ::tim::set_env; // NOLINT -using ::tim::try_demangle; // NOLINT -using ::tim::type_mutex; // NOLINT +using ::tim::auto_lock_t; // NOLINT +using ::tim::get_env; // NOLINT +using ::tim::set_env; // NOLINT +using ::tim::type_mutex; // NOLINT struct construct_on_thread { diff --git a/projects/rocprofiler-systems/source/lib/core/demangler.hpp b/projects/rocprofiler-systems/source/lib/core/demangler.hpp new file mode 100644 index 0000000000..196d6dd36d --- /dev/null +++ b/projects/rocprofiler-systems/source/lib/core/demangler.hpp @@ -0,0 +1,144 @@ +// MIT License +// +// Copyright (c) 2022-2025 Advanced Micro Devices, Inc. All Rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace rocprofsys +{ +namespace utility +{ + +struct cxa_demangle_wrapper_impl +{ + static char* demangle(const char* _mangled_name, char* _output_buffer, + size_t* _length, int* _status) + { + return abi::__cxa_demangle(_mangled_name, _output_buffer, _length, _status); + } +}; + +template +struct demangler +{ + template + std::string demangle() + { + return demangle(typeid(Tp).name()); + } + + std::string demangle(std::string_view _mangled_name) + { + if(_mangled_name.empty()) return {}; + + const auto result = try_get_from_cache(_mangled_name); + if(result._found) + { + return result._cache_it->second; + } + + // Possible improvement: Limit the cache size to avoid memory bloat + return demangle_and_cache(_mangled_name); + } + +private: + std::shared_mutex m_mutex; + std::map> m_cache; + using cache_iterator = typename decltype(m_cache)::iterator; + + struct cache_result + { + bool _found; + cache_iterator _cache_it; + }; + + static std::string demangle_impl(const char* _mangled_name) + { + int _status = 0; + std::unique_ptr _demangled( + DemanglerTp::demangle(_mangled_name, nullptr, nullptr, &_status), &std::free); + + if(_status != 0 || !_demangled) return std::string{ _mangled_name }; + + return std::string{ _demangled.get() }; + } + + cache_result try_get_from_cache(std::string_view _mangled_name) + { + std::shared_lock _read_lock{ m_mutex }; + + auto _it = m_cache.find(_mangled_name); + if(_it != m_cache.end()) + { + return { true, _it }; + } + + return { false, m_cache.end() }; + } + + std::string demangle_and_cache(std::string_view _mangled_name) + { + std::unique_lock _write_lock{ m_mutex }; + + auto _it = m_cache.find(_mangled_name); + if(_it != m_cache.end()) + { + return _it->second; + } + + auto _result = demangle_impl(_mangled_name.data()); + m_cache.emplace(_mangled_name, _result); + return _result; + } +}; + +inline demangler<>& +get_demangler() +{ + static demangler g_demangler; + return g_demangler; +} + +template +inline std::string +demangle() +{ + return get_demangler().demangle(); +} + +inline std::string +demangle(std::string_view name) +{ + return get_demangler().demangle(name); +} + +} // namespace utility +} // namespace rocprofsys diff --git a/projects/rocprofiler-systems/source/lib/core/tests/CMakeLists.txt b/projects/rocprofiler-systems/source/lib/core/tests/CMakeLists.txt new file mode 100644 index 0000000000..c6f746c3c6 --- /dev/null +++ b/projects/rocprofiler-systems/source/lib/core/tests/CMakeLists.txt @@ -0,0 +1,30 @@ +# MIT License +# +# Copyright (c) 2025 Advanced Micro Devices, Inc. All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +add_library(demangler-tests OBJECT demangler_test.cpp) + +target_link_libraries( + demangler-tests + PRIVATE rocprofiler-systems-googletest-library rocprofiler-systems-core-library +) + +target_include_directories(demangler-tests PRIVATE ${PROJECT_SOURCE_DIR}/source/lib) diff --git a/projects/rocprofiler-systems/source/lib/core/tests/demangler_test.cpp b/projects/rocprofiler-systems/source/lib/core/tests/demangler_test.cpp new file mode 100644 index 0000000000..69d4e1e65b --- /dev/null +++ b/projects/rocprofiler-systems/source/lib/core/tests/demangler_test.cpp @@ -0,0 +1,155 @@ +// MIT License +// +// Copyright (c) 2025 Advanced Micro Devices, Inc. All Rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include "gtest/gtest.h" + +#include "core/demangler.hpp" + +#include +#include + +struct mock_demangler_impl +{ + static inline int call_count = 0; + + static char* demangle(const char* _mangled_name, char*, size_t*, int* _status) + { + ++call_count; + + if(std::string(_mangled_name).find("FAIL") != std::string::npos) + { + *_status = -1; + return nullptr; + } + + std::string result = "demangled_" + std::string(_mangled_name); + char* output = static_cast(std::malloc(result.size() + 1)); + memcpy(output, result.c_str(), result.size() + 1); + *_status = 0; + return output; + } +}; + +class demangler_test : public ::testing::Test +{ +protected: + void SetUp() override { mock_demangler_impl::call_count = 0; } +}; + +TEST_F(demangler_test, successful_demangle) +{ + rocprofsys::utility::demangler demangler; + std::string result = demangler.demangle("mangled"); + + EXPECT_EQ(result, "demangled_mangled"); + EXPECT_EQ(mock_demangler_impl::call_count, 1); +} + +TEST_F(demangler_test, failed_demangle_returns_original) +{ + rocprofsys::utility::demangler demangler; + std::string result = demangler.demangle("mangled_FAIL"); + + EXPECT_EQ(result, "mangled_FAIL"); + EXPECT_EQ(mock_demangler_impl::call_count, 1); +} + +TEST_F(demangler_test, empty_string_returns_empty) +{ + rocprofsys::utility::demangler demangler; + std::string result = demangler.demangle(""); + + EXPECT_TRUE(result.empty()); + EXPECT_EQ(mock_demangler_impl::call_count, 0); +} + +TEST_F(demangler_test, caching_prevents_redundant_calls) +{ + rocprofsys::utility::demangler demangler; + + std::string first = demangler.demangle("mangled"); + std::string second = demangler.demangle("mangled"); + std::string third = demangler.demangle("mangled"); + + EXPECT_EQ(first, "demangled_mangled"); + EXPECT_EQ(first, second); + EXPECT_EQ(second, third); + EXPECT_EQ(mock_demangler_impl::call_count, 1); +} + +TEST_F(demangler_test, different_inputs_cached_separately) +{ + rocprofsys::utility::demangler demangler; + + std::string result1 = demangler.demangle("mangled1"); + std::string result2 = demangler.demangle("mangled2"); + std::string result1_again = demangler.demangle("mangled1"); + + EXPECT_EQ(result1, "demangled_mangled1"); + EXPECT_EQ(result2, "demangled_mangled2"); + EXPECT_EQ(result1, result1_again); + EXPECT_EQ(mock_demangler_impl::call_count, 2); +} + +TEST_F(demangler_test, string_view_interface) +{ + rocprofsys::utility::demangler demangler; + std::string str = "mangled"; + std::string_view sv{ str }; + + std::string result = demangler.demangle(sv); + + EXPECT_EQ(result, "demangled_mangled"); + EXPECT_EQ(mock_demangler_impl::call_count, 1); +} + +TEST_F(demangler_test, template_demangle_interface) +{ + rocprofsys::utility::demangler demangler; + std::string result = demangler.demangle(); + + EXPECT_NE(result.find("demangled_"), std::string::npos); + EXPECT_FALSE(result.empty()); +} + +TEST_F(demangler_test, cache_handles_failed_demangle) +{ + rocprofsys::utility::demangler demangler; + + std::string first = demangler.demangle("FAIL"); + std::string second = demangler.demangle("FAIL"); + + EXPECT_EQ(first, "FAIL"); + EXPECT_EQ(first, second); + EXPECT_EQ(mock_demangler_impl::call_count, 1); +} + +TEST_F(demangler_test, multiple_instances_independent_caches) +{ + rocprofsys::utility::demangler demangler1; + rocprofsys::utility::demangler demangler2; + + demangler1.demangle("mangled"); + demangler2.demangle("mangled"); + + EXPECT_EQ(mock_demangler_impl::call_count, 2); +} diff --git a/projects/rocprofiler-systems/source/lib/core/trace_cache/perfetto_processor.cpp b/projects/rocprofiler-systems/source/lib/core/trace_cache/perfetto_processor.cpp index dec39b14bd..dc7ab7d804 100644 --- a/projects/rocprofiler-systems/source/lib/core/trace_cache/perfetto_processor.cpp +++ b/projects/rocprofiler-systems/source/lib/core/trace_cache/perfetto_processor.cpp @@ -25,6 +25,7 @@ #include "core/agent_manager.hpp" #include "core/categories.hpp" #include "core/common_types.hpp" +#include "core/demangler.hpp" #include "core/gpu_metrics.hpp" #include "core/utility.hpp" #include "library/tracing.hpp" @@ -474,7 +475,7 @@ perfetto_processor_t::handle([[maybe_unused]] const kernel_dispatch_sample& _kds throw std::runtime_error("Kernel symbol is missing for kernel dispatch"); } - auto kernel_name = tim::demangle(kernel_symbol->kernel_name); + auto kernel_name = rocprofsys::utility::demangle(kernel_symbol->kernel_name); const auto _track = tracing::get_perfetto_track(category::rocm_kernel_dispatch{}, _track_desc, diff --git a/projects/rocprofiler-systems/source/lib/core/trace_cache/rocpd_processor.cpp b/projects/rocprofiler-systems/source/lib/core/trace_cache/rocpd_processor.cpp index d7c0cc4cf1..7042b3783c 100644 --- a/projects/rocprofiler-systems/source/lib/core/trace_cache/rocpd_processor.cpp +++ b/projects/rocprofiler-systems/source/lib/core/trace_cache/rocpd_processor.cpp @@ -25,6 +25,7 @@ #include "core/common_types.hpp" #include "core/config.hpp" #include "core/debug.hpp" +#include "core/demangler.hpp" #include "core/gpu_metrics.hpp" #include "core/node_info.hpp" #include "core/rocpd/data_processor.hpp" @@ -39,7 +40,6 @@ #include #include #include -#include #if ROCPROFSYS_USE_ROCM > 0 # include "library/rocprofiler-sdk/fwd.hpp" @@ -91,7 +91,7 @@ rocpd_processor_t::handle([[maybe_unused]] const kernel_dispatch_sample& _kds) } auto region_name_primary_key = m_data_processor->insert_string( - tim::demangle(kernel_symbol->kernel_name).c_str()); + rocprofsys::utility::demangle(kernel_symbol->kernel_name).c_str()); auto stack_id = _kds.correlation_id_internal; auto parent_stack_id = _kds.correlation_id_ancestor; @@ -698,7 +698,7 @@ rocpd_processor_t::post_process_metadata() auto _kernel_symbols_list = m_metadata->get_kernel_symbol_list(); for(const auto& kernel_symbol : _kernel_symbols_list) { - auto kernel_name = tim::demangle(kernel_symbol.kernel_name); + auto kernel_name = rocprofsys::utility::demangle(kernel_symbol.kernel_name); m_data_processor->insert_kernel_symbol( kernel_symbol.kernel_id, n_info.id, process_info.pid, kernel_symbol.code_object_id, kernel_symbol.kernel_name, kernel_name.c_str(), diff --git a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/causal/data.cpp b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/causal/data.cpp index 3f2a23168c..929bc1693a 100644 --- a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/causal/data.cpp +++ b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/causal/data.cpp @@ -30,6 +30,7 @@ #include "core/config.hpp" #include "core/containers/c_array.hpp" #include "core/debug.hpp" +#include "core/demangler.hpp" #include "core/state.hpp" #include "core/utility.hpp" #include "library/causal/delay.hpp" @@ -399,7 +400,8 @@ save_line_info_impl(std::ostream& _ofs, _ofs << " " << as_hex(_addr_off) << " [" << as_hex(_addr) << "] :: " << itr.file; if(itr.line > 0) _ofs << ":" << itr.line; - if(!itr.func.empty()) _ofs << " [" << tim::demangle(itr.func) << "]"; + if(!itr.func.empty()) + _ofs << " [" << rocprofsys::utility::demangle(itr.func) << "]"; _ofs << "\n"; if(std::get<0>(_info)) @@ -408,7 +410,7 @@ save_line_info_impl(std::ostream& _ofs, { _ofs << " " << ditr.file << ":" << ditr.line; if(!ditr.func.empty()) - _ofs << " [" << tim::demangle(ditr.func) << "]"; + _ofs << " [" << rocprofsys::utility::demangle(ditr.func) << "]"; _ofs << "\n"; } } @@ -608,14 +610,16 @@ perform_experiment_impl(std::shared_ptr> _started) // NOLINT << " :: " << std::setw(5) << std::boolalpha << _is_eligible << " :: " << as_hex(itr.first) << " " << _linfo->location << ":" << _linfo->lineno << " [" - << demangle(_linfo->name) << "]\n"; + << rocprofsys::utility::demangle(_linfo->name) + << "]\n"; for(const auto& iitr : _linfo->lineinfo.lines) { - _sample << " " << std::setw(8) << itr.second - << " :: " << std::setw(5) << std::boolalpha - << _is_eligible << " :: " << as_hex(itr.first) - << " " << iitr.location << ":" << iitr.line - << " [" << demangle(iitr.name) << "]\n"; + _sample + << " " << std::setw(8) << itr.second + << " :: " << std::setw(5) << std::boolalpha + << _is_eligible << " :: " << as_hex(itr.first) << " " + << iitr.location << ":" << iitr.line << " [" + << rocprofsys::utility::demangle(iitr.name) << "]\n"; } } } @@ -839,8 +843,9 @@ sample_selection(size_t _nitr, size_t _wait_ns) as_hex(_lookup_addr).c_str(), as_hex(_addr).c_str(), as_hex(_sym_addr).c_str(), (_location.empty()) ? "" : _location.data(), - demangle(itr.func).c_str(), itr.file.c_str(), itr.line, - itr.address.as_string().c_str(), itr.address.size()); + rocprofsys::utility::demangle(itr.func).c_str(), + itr.file.c_str(), itr.line, itr.address.as_string().c_str(), + itr.address.size()); } } } diff --git a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/causal/experiment.cpp b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/causal/experiment.cpp index 437d3c545c..51869e7aa3 100644 --- a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/causal/experiment.cpp +++ b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/causal/experiment.cpp @@ -27,6 +27,7 @@ #include "common/defines.h" #include "core/config.hpp" #include "core/debug.hpp" +#include "core/demangler.hpp" #include "core/state.hpp" #include "library/causal/components/backtrace.hpp" #include "library/causal/components/progress_point.hpp" @@ -127,7 +128,7 @@ experiment::sample::serialize(ArchiveT& ar, const unsigned) if constexpr(concepts::is_output_archive::value) { - ar(cereal::make_nvp("dfunc", demangle(name)), + ar(cereal::make_nvp("dfunc", rocprofsys::utility::demangle(name)), cereal::make_nvp("dwarf_info", std::vector{})); } ar(cereal::make_nvp("inlines", inlines)); @@ -140,7 +141,7 @@ std::string experiment::sample::get_identifier() const { return (lineno > 0 && !location.empty()) ? join(":", location, lineno) - : demangle(name); + : rocprofsys::utility::demangle(name); } template @@ -391,7 +392,7 @@ experiment::as_string() const } return _v; }; - auto _func = _patch(demangle(selection.symbol.func)); + auto _func = _patch(rocprofsys::utility::demangle(selection.symbol.func)); _ss << "['" << _func << "']"; return _ss.str(); @@ -620,7 +621,7 @@ experiment::save_experiments(std::string _fname_base, const filename_config_t& _ as_hex(_line_info.address).c_str(), _line_info.file.c_str(), _line_info.line, _line_info.func.c_str()); - ofs << "experiment\tselected=" << demangle(_name) + ofs << "experiment\tselected=" << rocprofsys::utility::demangle(_name) << "\tspeedup=" << std::setprecision(2) << static_cast(itr.virtual_speedup / 100.0) << "\tduration=" << itr.duration << "\tselected-samples=" << itr.selected @@ -637,7 +638,8 @@ experiment::save_experiments(std::string _fname_base, const filename_config_t& _ if(pitr.second.is_throughput_point() && pitr.second.get_delta() != 0) { ofs << "throughput-point\tname=" - << tim::demangle(tim::get_hash_identifier(pitr.first)) + << rocprofsys::utility::demangle( + tim::get_hash_identifier(pitr.first)) << "\tdelta=" << pitr.second.get_delta() << "\n"; if(get_causal_end_to_end()) break; } @@ -646,7 +648,8 @@ experiment::save_experiments(std::string _fname_base, const filename_config_t& _ if(get_causal_end_to_end()) continue; auto _delta = std::max(pitr.second.get_latency_delta(), 1); ofs << "latency-point\tname=" - << tim::demangle(tim::get_hash_identifier(pitr.first)) + << rocprofsys::utility::demangle( + tim::get_hash_identifier(pitr.first)) << "\tarrivals=" << pitr.second.get_arrival() << "\tdepartures=" << pitr.second.get_departure() << "\tdifference=" << _delta << "\n"; diff --git a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/backtrace.cpp b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/backtrace.cpp index 30718886ca..99514dd88d 100644 --- a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/backtrace.cpp +++ b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/backtrace.cpp @@ -24,6 +24,7 @@ #include "core/components/fwd.hpp" #include "core/config.hpp" #include "core/debug.hpp" +#include "core/demangler.hpp" #include "core/perfetto.hpp" #include "core/state.hpp" #include "library/components/ensure_storage.hpp" @@ -150,7 +151,7 @@ backtrace::filter_and_patch(const std::vector& _data) _ret.reserve(_data.size()); for(const auto& itr : _data) { - auto _name = tim::demangle(_patch_label(itr.name)); + auto _name = rocprofsys::utility::demangle(_patch_label(itr.name)); auto _use = _use_label(_name); if(_use == -1) break; if(_use == 0) continue; diff --git a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/category_region.hpp b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/category_region.hpp index 99f6e460d0..5c0e2a09a1 100644 --- a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/category_region.hpp +++ b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/category_region.hpp @@ -24,6 +24,7 @@ #include "core/config.hpp" #include "core/defines.hpp" +#include "core/demangler.hpp" #include "core/state.hpp" #include "core/timemory.hpp" #include "core/trace_cache/cache_manager.hpp" @@ -403,7 +404,8 @@ category_region::audit(const gotcha_data_t& _data, audit::incoming, { int64_t _n = 0; ROCPROFSYS_FOLD_EXPRESSION(tracing::add_perfetto_annotation( - ctx, tim::try_demangle>(), _args, _n++)); + ctx, rocprofsys::utility::demangle>(), + _args, _n++)); } }); } @@ -431,7 +433,8 @@ category_region::audit(std::string_view _name, audit::incoming, { int64_t _n = 0; ROCPROFSYS_FOLD_EXPRESSION(tracing::add_perfetto_annotation( - ctx, tim::try_demangle>(), _args, _n++)); + ctx, rocprofsys::utility::demangle>(), + _args, _n++)); } }); } diff --git a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/mpip.hpp b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/mpip.hpp index 1c5e359914..95df51ba42 100644 --- a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/mpip.hpp +++ b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/components/mpip.hpp @@ -22,6 +22,7 @@ #pragma once +#include "core/demangler.hpp" #include "core/timemory.hpp" #include @@ -184,7 +185,8 @@ rocprofsys::component::activate_mpip() static std::string _label = []() { std::stringstream ss; - ss << "rocprofsys-mpip-" << demangle() << "-" << demangle(); + ss << "rocprofsys-mpip-" << rocprofsys::utility::demangle() << "-" + << rocprofsys::utility::demangle(); return ss.str(); }(); ROCPROFSYS_BASIC_DEBUG_F("Adding cleanup for %s", _label.c_str()); @@ -208,7 +210,8 @@ rocprofsys::component::deactivate_mpip(uint64_t id) { static std::string _label = []() { std::stringstream ss; - ss << "rocprofsys-mpip-" << demangle() << "-" << demangle(); + ss << "rocprofsys-mpip-" << rocprofsys::utility::demangle() << "-" + << rocprofsys::utility::demangle(); return ss.str(); }(); ROCPROFSYS_BASIC_DEBUG_F("Removing cleanup for %s", _label.c_str()); diff --git a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk.cpp b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk.cpp index d4bd5a5dbb..1e4569fe6d 100644 --- a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk.cpp +++ b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk.cpp @@ -28,6 +28,7 @@ #include "core/config.hpp" #include "core/containers/stable_vector.hpp" #include "core/debug.hpp" +#include "core/demangler.hpp" #include "core/gpu.hpp" #include "core/perfetto.hpp" #include "core/state.hpp" @@ -335,8 +336,9 @@ iterate_args_callback(rocprofiler_callback_tracing_kind_t /*kind*/, int32_t /*op { auto* _data = static_cast(data); if(arg_type && arg_name && arg_value_str) - _data->emplace_back( - argument_info{ arg_number, demangle(arg_type), arg_name, arg_value_str }); + _data->emplace_back(argument_info{ arg_number, + rocprofsys::utility::demangle(arg_type), + arg_name, arg_value_str }); return 0; } @@ -388,8 +390,8 @@ get_backtrace(std::optional>& _bt_data (_linfo && _linfo.line > 0) ? join("", _linfo.line) : ((itr.lineno == 0) ? std::string{ "?" } : join("", itr.lineno)); - auto _entry = join("", demangle(*_func), " @ ", - join(':', ::basename(_loc->c_str()), _line)); + auto _entry = join("", rocprofsys::utility::demangle(*_func), " @ ", + join(':', ::basename(_loc->c_str()), _line)); backtrace[join("", "frame#", _bt_cnt++)] = _entry; } } @@ -771,7 +773,7 @@ tool_tracing_callback_stop( : ((itr.lineno == 0) ? std::string{ "?" } : join("", itr.lineno)); auto _entry = - join("", demangle(*_func), " @ ", + join("", rocprofsys::utility::demangle(*_func), " @ ", join(':', ::basename(_loc->c_str()), _line)); if(_bt_cnt < 10) { @@ -1139,12 +1141,13 @@ ompt_tracing_callback_stop( (_linfo && !_linfo.location.empty()) ? &_linfo.location : ((itr.location.empty()) ? &_unk : &itr.location); - auto _line = (_linfo && _linfo.line > 0) - ? join("", _linfo.line) - : ((itr.lineno == 0) ? std::string{ "?" } - : join("", itr.lineno)); - auto _entry = join("", demangle(*_func), " @ ", - join(':', ::basename(_loc->c_str()), _line)); + auto _line = (_linfo && _linfo.line > 0) + ? join("", _linfo.line) + : ((itr.lineno == 0) ? std::string{ "?" } + : join("", itr.lineno)); + auto _entry = + join("", rocprofsys::utility::demangle(*_func), " @ ", + join(':', ::basename(_loc->c_str()), _line)); if(_bt_cnt < 10) { // Prepend zero for better ordering in UI. Only one zero @@ -1570,13 +1573,13 @@ tool_tracing_buffered(rocprofiler_context_id_t /*context*/, const auto* _kern_sym_data = get_kernel_symbol_info(record->dispatch_info.kernel_id); - auto _name = tim::demangle(_kern_sym_data->kernel_name); - auto _stack_id = record->correlation_id.internal; - auto _beg_ns = record->start_timestamp; - auto _end_ns = record->end_timestamp; - auto _agent_id = record->dispatch_info.agent_id; - auto _queue_id = record->dispatch_info.queue_id; - const auto* _agent = tool_data->get_gpu_tool_agent(_agent_id); + auto _name = rocprofsys::utility::demangle(_kern_sym_data->kernel_name); + auto _stack_id = record->correlation_id.internal; + auto _beg_ns = record->start_timestamp; + auto _end_ns = record->end_timestamp; + auto _agent_id = record->dispatch_info.agent_id; + auto _queue_id = record->dispatch_info.queue_id; + const auto* _agent = tool_data->get_gpu_tool_agent(_agent_id); uint64_t _stream_id = get_stream_id(record).handle; if(_stream_id == 0) diff --git a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk/counters.cpp b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk/counters.cpp index 0dbceb94cc..2c9c93947a 100644 --- a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk/counters.cpp +++ b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk/counters.cpp @@ -22,6 +22,7 @@ #include "library/rocprofiler-sdk/counters.hpp" #include "core/agent_manager.hpp" +#include "core/demangler.hpp" #include "core/trace_cache/cache_manager.hpp" #include "core/trace_cache/metadata_registry.hpp" #include "library/rocprofiler-sdk/fwd.hpp" @@ -94,7 +95,9 @@ counter_event::operator()(const client_data* tool_data, ::perfetto::CounterTrack const auto* _kern_sym_data = tool_data->get_kernel_symbol_info(_dispatch_info.kernel_id); - auto _bundle = counter_bundle_t{ tim::demangle(_kern_sym_data->kernel_name), _scope }; + auto _bundle = + counter_bundle_t{ rocprofsys::utility::demangle(_kern_sym_data->kernel_name), + _scope }; _bundle.push(_dispatch_info.queue_id.handle) .start() diff --git a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/sampling.cpp b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/sampling.cpp index 8b98777b7e..1499ccec10 100644 --- a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/sampling.cpp +++ b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/sampling.cpp @@ -25,6 +25,7 @@ #include "core/components/fwd.hpp" #include "core/config.hpp" #include "core/debug.hpp" +#include "core/demangler.hpp" #include "core/locking.hpp" #include "core/node_info.hpp" #include "core/perf.hpp" @@ -172,7 +173,7 @@ generate_call_stack_json(const tim::unwind::processed_entry& stack_entry) { nlohmann::json call_stack; - call_stack["name"] = std::string(demangle(stack_entry.name)); + call_stack["name"] = std::string(rocprofsys::utility::demangle(stack_entry.name)); call_stack["pc"] = as_hex(stack_entry.address); call_stack["file"] = std::string(stack_entry.location); @@ -184,7 +185,7 @@ generate_line_info_json(const tim::unwind::processed_entry& line_info_entry) { nlohmann::json line_info; line_info["line_address"] = as_hex(line_info_entry.line_address); - line_info["name"] = std::string(demangle(line_info_entry.name)); + line_info["name"] = std::string(rocprofsys::utility::demangle(line_info_entry.name)); if(line_info_entry.lineinfo && !line_info_entry.lineinfo.lines.empty()) { @@ -193,7 +194,7 @@ generate_line_info_json(const tim::unwind::processed_entry& line_info_entry) for(const auto& line : _lines) { nlohmann::json inlined; - inlined["name"] = std::string(demangle(line.name)); + inlined["name"] = std::string(rocprofsys::utility::demangle(line.name)); inlined["location"] = std::string(line.location); inlined["line"] = std::to_string(line.line); line_info["inlined"] = inlined; @@ -311,7 +312,7 @@ cache_sampling_data(int64_t _tid, const std::vector& _timer for(const auto& iitr : itr.m_stack) { - auto _name = std::string(demangle(iitr.name)); + auto _name = std::string(rocprofsys::utility::demangle(iitr.name)); auto _track_name = get_track_name(*_thread_info); auto _call_stack = generate_call_stack_json(iitr); auto _line_info = generate_line_info_json(iitr); @@ -343,7 +344,7 @@ cache_sampling_data(int64_t _tid, const std::vector& _timer for(const auto& iitr : itr.m_stack) { - auto _name = std::string(demangle(iitr.name)); + auto _name = std::string(rocprofsys::utility::demangle(iitr.name)); auto _track_name = get_track_name(*_thread_info); auto _call_stack = generate_call_stack_json(iitr); auto _line_info = generate_line_info_json(iitr); @@ -1384,7 +1385,8 @@ post_process_perfetto(int64_t _tid, const std::vector& _tim for(const auto& iitr : itr.m_stack) { const auto* _name = - static_strings.emplace(demangle(iitr.name)).first->c_str(); + static_strings.emplace(rocprofsys::utility::demangle(iitr.name)) + .first->c_str(); tracing::push_perfetto_track( category::overflow_sampling{}, _name, _track, _beg, [&](::perfetto::EventContext ctx) { @@ -1405,7 +1407,8 @@ post_process_perfetto(int64_t _tid, const std::vector& _tim auto _label = JOIN('-', "lineinfo", _n++); tracing::add_perfetto_annotation( ctx, _label.c_str(), - JOIN('@', demangle(line.name), + JOIN('@', + rocprofsys::utility::demangle(line.name), JOIN(':', line.location, line.line))); } } @@ -1496,7 +1499,9 @@ post_process_perfetto(int64_t _tid, const std::vector& _tim for(const auto& line : _lines) { const auto* _name = - static_strings.emplace(demangle(line.name)).first->c_str(); + static_strings + .emplace(rocprofsys::utility::demangle(line.name)) + .first->c_str(); auto _info = JOIN(':', line.location, line.line); tracing::push_perfetto_track( category::timer_sampling{}, _name, _track, _beg, @@ -1542,7 +1547,8 @@ post_process_perfetto(int64_t _tid, const std::vector& _tim auto _label = JOIN('-', "lineinfo", _n++); tracing::add_perfetto_annotation( ctx, _label.c_str(), - JOIN('@', demangle(line.name), + JOIN('@', + rocprofsys::utility::demangle(line.name), JOIN(':', line.location, line.line))); } } diff --git a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/tracing.hpp b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/tracing.hpp index 324c959a66..ce768040d6 100644 --- a/projects/rocprofiler-systems/source/lib/rocprof-sys/library/tracing.hpp +++ b/projects/rocprofiler-systems/source/lib/rocprof-sys/library/tracing.hpp @@ -28,6 +28,7 @@ #include "core/config.hpp" #include "core/debug.hpp" #include "core/defines.hpp" +#include "core/demangler.hpp" #include "core/perfetto.hpp" #include "core/state.hpp" #include "core/timemory.hpp" @@ -181,8 +182,9 @@ get_perfetto_track(CategoryT, FuncT&& _desc_generator, Args&&... _args) ::perfetto::TrackEvent::SetTrackDescriptor(_track, _desc); ROCPROFSYS_VERBOSE_F(4, "[%s] Created %s(%zu) with description: \"%s\"\n", - trait::name::value, demangle().c_str(), - _uuid, _name.c_str()); + trait::name::value, + rocprofsys::utility::demangle().c_str(), _uuid, + _name.c_str()); _track_uuids.emplace(_uuid, _name); } diff --git a/projects/rocprofiler-systems/source/tests/CMakeLists.txt b/projects/rocprofiler-systems/source/tests/CMakeLists.txt index 9b6e56d4fc..40cf7a1924 100644 --- a/projects/rocprofiler-systems/source/tests/CMakeLists.txt +++ b/projects/rocprofiler-systems/source/tests/CMakeLists.txt @@ -22,9 +22,9 @@ add_executable( rocprof-sys-unit-tests - dummy.cpp $ $ + $ ) target_link_libraries( diff --git a/projects/rocprofiler-systems/source/tests/dummy.cpp b/projects/rocprofiler-systems/source/tests/dummy.cpp deleted file mode 100644 index 510c7ab81c..0000000000 --- a/projects/rocprofiler-systems/source/tests/dummy.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -TEST(first, test) { ASSERT_TRUE(true); }