diff --git a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/buffer_tracing.h b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/buffer_tracing.h index ab91a49adf..75e4976ee5 100644 --- a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/buffer_tracing.h +++ b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/buffer_tracing.h @@ -76,7 +76,7 @@ typedef struct rocprofiler_thread_id_t thread_id; ///< id for thread generating this record uint64_t marker_id; ///< rocprofiler_marker_id_t // const char* message; // (Need Review?) -} rocprofiler_buffer_tracing_marker_record_t; +} rocprofiler_buffer_tracing_marker_api_record_t; /** * @brief ROCProfiler Buffer Memory Copy Tracer Record. diff --git a/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt b/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt index e7437611b9..f57e1e3aa0 100644 --- a/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt +++ b/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt @@ -3,13 +3,14 @@ # rocprofiler_activate_clang_tidy() -set(common_sources config.cpp environment.cpp demangle.cpp static_object.cpp utility.cpp - xml.cpp) +set(common_sources config.cpp environment.cpp demangle.cpp logging.cpp static_object.cpp + utility.cpp xml.cpp) set(common_headers config.hpp defines.hpp environment.hpp demangle.hpp + logging.hpp mpl.hpp scope_destructor.hpp static_object.hpp diff --git a/projects/rocprofiler-sdk/source/lib/common/logging.cpp b/projects/rocprofiler-sdk/source/lib/common/logging.cpp new file mode 100644 index 0000000000..56d37349e7 --- /dev/null +++ b/projects/rocprofiler-sdk/source/lib/common/logging.cpp @@ -0,0 +1,86 @@ +// MIT License +// +// Copyright (c) 2023 Advanced Micro Devices, Inc. +// +// 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 "lib/common/logging.hpp" +#include "lib/common/environment.hpp" + +#include +#include + +#include +#include +#include + +namespace rocprofiler +{ +namespace common +{ +void +init_logging(std::string_view env_var) +{ + static auto _once = std::once_flag{}; + std::call_once(_once, [env_var]() { + auto get_argv0 = []() { + auto ifs = std::ifstream{"/proc/self/cmdline"}; + auto sarg = std::string{}; + while(ifs && !ifs.eof()) + { + ifs >> sarg; + if(!sarg.empty()) break; + } + return sarg; + }; + + static auto argv0 = get_argv0(); + google::InitGoogleLogging(argv0.c_str()); + auto loglvl = common::get_env(env_var, "error"); + for(auto& itr : loglvl) + itr = tolower(itr); + // default to warning + auto loglvl_v = google::WARNING; + if(loglvl.find_first_not_of("0123456789") == std::string::npos) + { + loglvl_v = std::stoul(loglvl); + } + else + { + const auto opts = + std::unordered_map{{"info", google::INFO}, + {"warning", google::WARNING}, + {"error", google::ERROR}, + {"fatal", google::FATAL}}; + if(opts.find(loglvl) == opts.end()) + throw std::runtime_error{ + fmt::format("invalid specifier for ROCPROFILER_LOG_LEVEL: {}. Supported: info, " + "warning, error, fatal", + loglvl)}; + else + loglvl_v = opts.at(loglvl); + } + + FLAGS_minloglevel = loglvl_v; + FLAGS_stderrthreshold = loglvl_v; + LOG(INFO) << "logging initialized"; + }); +} +} // namespace common +} // namespace rocprofiler diff --git a/projects/rocprofiler-sdk/source/lib/common/logging.hpp b/projects/rocprofiler-sdk/source/lib/common/logging.hpp new file mode 100644 index 0000000000..7e0cdce99a --- /dev/null +++ b/projects/rocprofiler-sdk/source/lib/common/logging.hpp @@ -0,0 +1,34 @@ +// MIT License +// +// Copyright (c) 2023 Advanced Micro Devices, Inc. +// +// 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 + +namespace rocprofiler +{ +namespace common +{ +void +init_logging(std::string_view env_var); +} +} // namespace rocprofiler diff --git a/projects/rocprofiler-sdk/source/lib/common/utility.hpp b/projects/rocprofiler-sdk/source/lib/common/utility.hpp index 9dac80a7f2..3a67942b56 100644 --- a/projects/rocprofiler-sdk/source/lib/common/utility.hpp +++ b/projects/rocprofiler-sdk/source/lib/common/utility.hpp @@ -210,66 +210,5 @@ private: data_type m_data = {}; functor_type m_destroy_func = {}; }; - -/** - * Limits the number of active items to those set in capacity. - * If capacity is reached, will block until another caller - * removes active capacity. - */ -class active_capacity_gate -{ -public: - active_capacity_gate(size_t capacity); - - void add_active(size_t size); - void remove_active(size_t size); - -private: - size_t _count{0}; - size_t _capacity{0}; - size_t _waiters{0}; - std::mutex _m; - std::condition_variable _cv; -}; - -inline active_capacity_gate::active_capacity_gate(size_t capacity) -: _capacity(capacity) -{} - -inline void -active_capacity_gate::add_active(size_t size) -{ - if(size >= _capacity) - { - throw std::runtime_error("Size exceeds gate capacity"); - } - - std::unique_lock lock(_m); - if(_count + size < _capacity) - { - _count += size; - return; - } - _waiters++; - _cv.wait(lock, [&]() { return _count + size < _capacity; }); - _waiters--; - _count += size; -} - -inline void -active_capacity_gate::remove_active(size_t size) -{ - std::unique_lock lock(_m); - if(_count > size) - _count -= size; - else - _count = 0; - - if(_waiters > 0) - { - _cv.notify_all(); - } -} - } // namespace common } // namespace rocprofiler diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/xml/basic_counters.xml b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/xml/basic_counters.xml index c75e39462b..7d6dbd87d0 100755 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/xml/basic_counters.xml +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/xml/basic_counters.xml @@ -772,3 +772,6 @@ + + + diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/xml/derived_counters.xml b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/xml/derived_counters.xml index d88099f707..80dee30ddc 100755 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/xml/derived_counters.xml +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/xml/derived_counters.xml @@ -498,6 +498,9 @@ + + + @@ -519,6 +522,7 @@ #Navi31 + diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hsa/async_copy.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hsa/async_copy.cpp index 212f965213..6714c4dc52 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hsa/async_copy.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hsa/async_copy.cpp @@ -103,8 +103,6 @@ convert_hsa_handle(Up _hsa_object) bool async_copy_handler(hsa_signal_value_t signal_value, void* arg) { - LOG(ERROR) << "[" << __FUNCTION__ << "] invoked with signal value " << signal_value; - static auto sysclock_period = []() -> uint64_t { constexpr auto nanosec = 1000000000UL; uint64_t sysclock_hz = 0; @@ -123,9 +121,6 @@ async_copy_handler(hsa_signal_value_t signal_value, void* arg) copy_time.start *= sysclock_period; copy_time.end *= sysclock_period; - LOG(ERROR) << "[" << __FUNCTION__ << "] start=" << copy_time.start << ", end=" << copy_time.end - << ", delta=" << (copy_time.end - copy_time.start) << ", period=" << sysclock_period; - // if we encounter this in CI, it will cause test to fail ROCP_CI_LOG_IF(ERROR, copy_time_status == HSA_STATUS_SUCCESS && copy_time.end < copy_time.start) << "hsa_amd_profiling_get_async_copy_time for returned async times where the end time (" @@ -204,8 +199,6 @@ async_copy_handler(hsa_signal_value_t signal_value, void* arg) delete _data; } - LOG(ERROR) << "[" << __FUNCTION__ << "] completed (signal value " << signal_value << ")"; - return (signal_value > 0); } @@ -257,8 +250,6 @@ async_copy_impl(Args... args) constexpr auto N = sizeof...(Args); - LOG(ERROR) << "[" << __FUNCTION__ << "] started..."; - auto&& _tied_args = std::tie(args...); auto ctxs = context::get_active_contexts(context_filter); @@ -415,8 +406,6 @@ async_copy_impl(Args... args) _data->orig_signal = _completion_signal; _completion_signal = _data->rocp_signal; - auto _dtor = common::scope_destructor{[]() { LOG(ERROR) << "[async_copy_impl] ... returned"; }}; - return invoke(get_next_dispatch(), std::move(_tied_args), std::make_index_sequence{}); } diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/registration.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/registration.cpp index ac5a869ad4..c0de2dc14e 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/registration.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/registration.cpp @@ -22,6 +22,7 @@ #include "lib/rocprofiler-sdk/registration.hpp" #include "lib/common/environment.hpp" +#include "lib/common/logging.hpp" #include "lib/common/static_object.hpp" #include "lib/rocprofiler-sdk/agent.hpp" #include "lib/rocprofiler-sdk/context/context.hpp" @@ -36,6 +37,7 @@ #include #include #include +#include #include #include @@ -45,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -477,25 +480,12 @@ invoke_client_finalizer(rocprofiler_client_id_t client_id) void init_logging() { - static auto _once = std::once_flag{}; - std::call_once(_once, []() { - auto get_argv0 = []() { - auto ifs = std::ifstream{"/proc/self/cmdline"}; - auto sarg = std::string{}; - while(ifs && !ifs.eof()) - { - ifs >> sarg; - if(!sarg.empty()) break; - } - return sarg; - }; - - static auto argv0 = get_argv0(); - google::InitGoogleLogging(argv0.c_str()); - LOG(INFO) << "logging initialized"; - }); + common::init_logging("ROCPROFILER_LOG_LEVEL"); } +// ensure that logging is always initialized when library is loaded +bool init_logging_at_load = (init_logging(), true); + uint32_t get_client_offset() { @@ -619,6 +609,7 @@ rocprofiler_force_configure(rocprofiler_configure_func_t configure_func) // let's just make sure that the forced configure function is a nullptr if(forced_config) return ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED; + setenv("ROCPROFILER_REGISTER_FORCE_LOAD", "1", 1); forced_config = configure_func; rocprofiler::registration::initialize(); @@ -632,6 +623,12 @@ rocprofiler_set_api_table(const char* name, void** tables, uint64_t num_tables) { + // implementation has a call once + rocprofiler::registration::init_logging(); + + LOG(ERROR) << __FUNCTION__ << "(\"" << name << "\", " << lib_version << ", " << lib_instance + << ", ..., " << num_tables << ")"; + static auto _once = std::once_flag{}; std::call_once(_once, rocprofiler::registration::initialize); diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/tests/common.hpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/tests/common.hpp new file mode 100644 index 0000000000..ae4c44f4ea --- /dev/null +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/tests/common.hpp @@ -0,0 +1,192 @@ +// MIT License +// +// Copyright (c) 2023 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 "lib/common/defines.hpp" + +#include + +#include +#include +#include +#include +#include + +#define ROCPROFILER_CALL(ARG, MSG) \ + { \ + auto _status = (ARG); \ + EXPECT_EQ(_status, ROCPROFILER_STATUS_SUCCESS) << MSG << " :: " << #ARG; \ + } + +namespace +{ +struct callback_data +{ + rocprofiler_client_id_t* client_id = nullptr; + rocprofiler_client_finalize_t client_fini_func = nullptr; + rocprofiler_context_id_t client_ctx = {}; + rocprofiler_buffer_id_t client_buffer = {}; + rocprofiler_callback_thread_t client_thread = {}; + uint64_t client_workflow_count = {}; + uint64_t client_callback_count = {}; + uint64_t client_elapsed = {}; + int64_t current_depth = 0; + int64_t max_depth = 0; +}; + +struct agent_data +{ + uint64_t agent_count = 0; + std::vector agents = {}; +}; + +using callback_kind_names_t = std::map; +using callback_kind_operation_names_t = + std::map>; + +struct callback_name_info +{ + callback_kind_names_t kind_names = {}; + callback_kind_operation_names_t operation_names = {}; +}; + +inline auto +get_callback_tracing_names() +{ + static const auto supported_kinds = std::unordered_set{ + ROCPROFILER_CALLBACK_TRACING_HSA_API}; + + auto cb_name_info = callback_name_info{}; + // + // callback for each kind operation + // + static auto tracing_kind_operation_cb = + [](rocprofiler_callback_tracing_kind_t kindv, uint32_t operation, void* data_v) { + auto* name_info_v = static_cast(data_v); + + if(supported_kinds.count(kindv) > 0) + { + const char* name = nullptr; + ROCPROFILER_CALL(rocprofiler_query_callback_tracing_kind_operation_name( + kindv, operation, &name, nullptr), + "query callback tracing kind operation name"); + EXPECT_TRUE(name != nullptr) << "kind=" << kindv << ", operation=" << operation; + if(name) name_info_v->operation_names[kindv][operation] = name; + } + return 0; + }; + + // + // callback for each callback kind (i.e. domain) + // + static auto tracing_kind_cb = [](rocprofiler_callback_tracing_kind_t kind, void* data) { + // store the callback kind name + auto* name_info_v = static_cast(data); + const char* name = nullptr; + ROCPROFILER_CALL(rocprofiler_query_callback_tracing_kind_name(kind, &name, nullptr), + "query callback tracing kind operation name"); + EXPECT_TRUE(name != nullptr) << "kind=" << kind; + if(name) name_info_v->kind_names[kind] = name; + + if(supported_kinds.count(kind) > 0) + { + ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_kind_operations( + kind, tracing_kind_operation_cb, static_cast(data)), + "iterating callback tracing kind operations"); + } + return 0; + }; + + ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_kinds(tracing_kind_cb, + static_cast(&cb_name_info)), + "iterating callback tracing kinds"); + + return cb_name_info; +} + +using buffer_kind_names_t = std::map; +using buffer_kind_operation_names_t = + std::map>; + +struct buffer_name_info +{ + buffer_kind_names_t kind_names = {}; + buffer_kind_operation_names_t operation_names = {}; +}; + +inline buffer_name_info +get_buffer_tracing_names() +{ + static const auto supported_kinds = + std::unordered_set{ROCPROFILER_BUFFER_TRACING_HSA_API}; + + auto cb_name_info = buffer_name_info{}; + // + // callback for each kind operation + // + static auto tracing_kind_operation_cb = + [](rocprofiler_buffer_tracing_kind_t kindv, uint32_t operation, void* data_v) { + auto* name_info_v = static_cast(data_v); + + if(supported_kinds.count(kindv) > 0) + { + const char* name = nullptr; + ROCPROFILER_CALL(rocprofiler_query_buffer_tracing_kind_operation_name( + kindv, operation, &name, nullptr), + "query buffer tracing kind operation name"); + EXPECT_TRUE(name != nullptr) << "kind=" << kindv << ", operation=" << operation; + if(name) name_info_v->operation_names[kindv][operation] = name; + } + return 0; + }; + + // + // callback for each buffer kind (i.e. domain) + // + static auto tracing_kind_cb = [](rocprofiler_buffer_tracing_kind_t kind, void* data) { + // store the buffer kind name + auto* name_info_v = static_cast(data); + const char* name = nullptr; + ROCPROFILER_CALL(rocprofiler_query_buffer_tracing_kind_name(kind, &name, nullptr), + "query buffer tracing kind operation name"); + EXPECT_TRUE(name != nullptr) << "kind=" << kind; + if(name) name_info_v->kind_names[kind] = name; + + if(supported_kinds.count(kind) > 0) + { + ROCPROFILER_CALL(rocprofiler_iterate_buffer_tracing_kind_operations( + kind, tracing_kind_operation_cb, static_cast(data)), + "iterating buffer tracing kind operations"); + } + return 0; + }; + + ROCPROFILER_CALL(rocprofiler_iterate_buffer_tracing_kinds(tracing_kind_cb, + static_cast(&cb_name_info)), + "iterating buffer tracing kinds"); + + return cb_name_info; +} +} // namespace diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/tests/registration.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/tests/registration.cpp index fbb4a463f6..77b7c61a6f 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/tests/registration.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/tests/registration.cpp @@ -28,6 +28,7 @@ #include "lib/common/filesystem.hpp" #include "lib/common/units.hpp" #include "lib/common/utility.hpp" +#include "lib/rocprofiler-sdk/tests/common.hpp" #include @@ -45,152 +46,8 @@ #include #include -#define ROCPROFILER_CALL(ARG, MSG) \ - { \ - auto _status = (ARG); \ - EXPECT_EQ(_status, ROCPROFILER_STATUS_SUCCESS) << MSG << " :: " << #ARG; \ - } - namespace { -struct callback_data -{ - rocprofiler_client_id_t* client_id = nullptr; - rocprofiler_client_finalize_t client_fini_func = nullptr; - rocprofiler_context_id_t client_ctx = {}; - rocprofiler_buffer_id_t client_buffer = {}; - rocprofiler_callback_thread_t client_thread = {}; - uint64_t client_workflow_count = {}; - uint64_t client_callback_count = {}; - uint64_t client_elapsed = {}; - int64_t current_depth = 0; - int64_t max_depth = 0; -}; - -struct agent_data -{ - uint64_t agent_count = 0; - std::vector agents = {}; -}; - -using callback_kind_names_t = std::map; -using callback_kind_operation_names_t = - std::map>; - -struct callback_name_info -{ - callback_kind_names_t kind_names = {}; - callback_kind_operation_names_t operation_names = {}; -}; - -auto -get_callback_tracing_names() -{ - auto cb_name_info = callback_name_info{}; - // - // callback for each kind operation - // - static auto tracing_kind_operation_cb = - [](rocprofiler_callback_tracing_kind_t kindv, uint32_t operation, void* data_v) { - auto* name_info_v = static_cast(data_v); - - if(kindv == ROCPROFILER_CALLBACK_TRACING_HSA_API) - { - const char* name = nullptr; - ROCPROFILER_CALL(rocprofiler_query_callback_tracing_kind_operation_name( - kindv, operation, &name, nullptr), - "query callback tracing kind operation name"); - if(name) name_info_v->operation_names[kindv][operation] = name; - } - return 0; - }; - - // - // callback for each callback kind (i.e. domain) - // - static auto tracing_kind_cb = [](rocprofiler_callback_tracing_kind_t kind, void* data) { - // store the callback kind name - auto* name_info_v = static_cast(data); - const char* name = nullptr; - ROCPROFILER_CALL(rocprofiler_query_callback_tracing_kind_name(kind, &name, nullptr), - "query callback tracing kind operation name"); - if(name) name_info_v->kind_names[kind] = name; - - if(kind == ROCPROFILER_CALLBACK_TRACING_HSA_API) - { - ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_kind_operations( - kind, tracing_kind_operation_cb, static_cast(data)), - "iterating callback tracing kind operations"); - } - return 0; - }; - - ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_kinds(tracing_kind_cb, - static_cast(&cb_name_info)), - "iterating callback tracing kinds"); - - return cb_name_info; -} - -using buffer_kind_names_t = std::map; -using buffer_kind_operation_names_t = - std::map>; - -struct buffer_name_info -{ - buffer_kind_names_t kind_names = {}; - buffer_kind_operation_names_t operation_names = {}; -}; - -buffer_name_info -get_buffer_tracing_names() -{ - auto cb_name_info = buffer_name_info{}; - // - // callback for each kind operation - // - static auto tracing_kind_operation_cb = - [](rocprofiler_buffer_tracing_kind_t kindv, uint32_t operation, void* data_v) { - auto* name_info_v = static_cast(data_v); - - if(kindv == ROCPROFILER_BUFFER_TRACING_HSA_API) - { - const char* name = nullptr; - ROCPROFILER_CALL(rocprofiler_query_buffer_tracing_kind_operation_name( - kindv, operation, &name, nullptr), - "query buffer tracing kind operation name"); - if(name) name_info_v->operation_names[kindv][operation] = name; - } - return 0; - }; - - // - // callback for each buffer kind (i.e. domain) - // - static auto tracing_kind_cb = [](rocprofiler_buffer_tracing_kind_t kind, void* data) { - // store the buffer kind name - auto* name_info_v = static_cast(data); - const char* name = nullptr; - ROCPROFILER_CALL(rocprofiler_query_buffer_tracing_kind_name(kind, &name, nullptr), - "query buffer tracing kind operation name"); - if(name) name_info_v->kind_names[kind] = name; - - if(kind == ROCPROFILER_BUFFER_TRACING_HSA_API) - { - ROCPROFILER_CALL(rocprofiler_iterate_buffer_tracing_kind_operations( - kind, tracing_kind_operation_cb, static_cast(data)), - "iterating buffer tracing kind operations"); - } - return 0; - }; - - ROCPROFILER_CALL(rocprofiler_iterate_buffer_tracing_kinds(tracing_kind_cb, - static_cast(&cb_name_info)), - "iterating buffer tracing kinds"); - - return cb_name_info; -} - void tool_tracing_callback(rocprofiler_callback_tracing_record_t record, rocprofiler_user_data_t* user_data, @@ -566,6 +423,8 @@ TEST(rocprofiler_lib, buffer_registration_lambda_with_result) static fini_func_t tool_fini = [](void* client_data) -> void { auto* cb_data = static_cast(client_data); + ROCPROFILER_CALL(rocprofiler_flush_buffer(cb_data->client_buffer), + "rocprofiler context stop failed"); ROCPROFILER_CALL(rocprofiler_stop_context(cb_data->client_ctx), "rocprofiler context stop failed"); diff --git a/projects/rocprofiler-sdk/tests/common/serialization.hpp b/projects/rocprofiler-sdk/tests/common/serialization.hpp index 0f0ede1cee..fa5ce521a1 100644 --- a/projects/rocprofiler-sdk/tests/common/serialization.hpp +++ b/projects/rocprofiler-sdk/tests/common/serialization.hpp @@ -120,8 +120,6 @@ save(ArchiveT& ar, rocprofiler_callback_tracing_code_object_load_data_t data) SAVE_DATA_FIELD(code_object_id); SAVE_DATA_FIELD(rocp_agent); SAVE_DATA_FIELD(hsa_agent); - SAVE_DATA_FIELD(rocp_agent); - SAVE_DATA_FIELD(hsa_agent); SAVE_DATA_CSTR(uri); SAVE_DATA_FIELD(load_base); SAVE_DATA_FIELD(load_size); @@ -210,7 +208,7 @@ save(ArchiveT& ar, rocprofiler_buffer_tracing_hip_api_record_t data) template void -save(ArchiveT& ar, rocprofiler_buffer_tracing_marker_record_t data) +save(ArchiveT& ar, rocprofiler_buffer_tracing_marker_api_record_t data) { save_buffer_tracing_api_record(ar, data); }