diff --git a/samples/counter_collection/callback_client.cpp b/samples/counter_collection/callback_client.cpp index 28382e4203..2c3ea18db4 100644 --- a/samples/counter_collection/callback_client.cpp +++ b/samples/counter_collection/callback_client.cpp @@ -155,13 +155,14 @@ dispatch_callback(rocprofiler_queue_id_t /*queue_id*/, // Look for the counters contained in counters_to_collect in gpu_counters for(auto& counter : gpu_counters) { - const char* name; - size_t size; - ROCPROFILER_CALL(rocprofiler_query_counter_name(counter, &name, &size), - "Could not query name"); - if(counters_to_collect.count(std::string(name)) > 0) + rocprofiler_counter_info_v0_t version; + ROCPROFILER_CALL( + rocprofiler_query_counter_info( + counter, ROCPROFILER_COUNTER_INFO_VERSION_0, static_cast(&version)), + "Could not query info"); + if(counters_to_collect.count(std::string(version.name)) > 0) { - std::clog << "Counter: " << counter.handle << " " << name << "\n"; + std::clog << "Counter: " << counter.handle << " " << version.name << "\n"; collect_counters.push_back(counter); } } diff --git a/samples/counter_collection/client.cpp b/samples/counter_collection/client.cpp index df69c8ec89..24ec2edebc 100644 --- a/samples/counter_collection/client.cpp +++ b/samples/counter_collection/client.cpp @@ -178,13 +178,14 @@ dispatch_callback(rocprofiler_queue_id_t /*queue_id*/, // Look for the counters contained in counters_to_collect in gpu_counters for(auto& counter : gpu_counters) { - const char* name; - size_t size; - ROCPROFILER_CALL(rocprofiler_query_counter_name(counter, &name, &size), - "Could not query name"); - if(counters_to_collect.count(std::string(name)) > 0) + rocprofiler_counter_info_v0_t version; + ROCPROFILER_CALL( + rocprofiler_query_counter_info( + counter, ROCPROFILER_COUNTER_INFO_VERSION_0, static_cast(&version)), + "Could not query info for counter"); + if(counters_to_collect.count(std::string(version.name)) > 0) { - std::clog << "Counter: " << counter.handle << " " << name << "\n"; + std::clog << "Counter: " << counter.handle << " " << version.name << "\n"; collect_counters.push_back(counter); } } diff --git a/samples/counter_collection/print_functional_counters.cpp b/samples/counter_collection/print_functional_counters.cpp index 7e1190ba2b..244177f304 100644 --- a/samples/counter_collection/print_functional_counters.cpp +++ b/samples/counter_collection/print_functional_counters.cpp @@ -229,11 +229,13 @@ dispatch_callback(rocprofiler_queue_id_t /*queue_id*/, for(auto& found_counter : counters_needed) { - const char* name; - size_t name_size; - ROCPROFILER_CALL(rocprofiler_query_counter_name(found_counter, &name, &name_size), - "Could not query name"); - cap.expected_counter_names.emplace(found_counter.handle, std::string(name)); + rocprofiler_counter_info_v0_t version; + + ROCPROFILER_CALL(rocprofiler_query_counter_info(found_counter, + ROCPROFILER_COUNTER_INFO_VERSION_0, + static_cast(&version)), + "Could not query counter_id"); + cap.expected_counter_names.emplace(found_counter.handle, std::string(version.name)); size_t expected = 0; ROCPROFILER_CALL( rocprofiler_query_counter_instance_count(agent->id, found_counter, &expected), diff --git a/source/include/rocprofiler-sdk/counters.h b/source/include/rocprofiler-sdk/counters.h index 47871cdb49..76afc2cc85 100644 --- a/source/include/rocprofiler-sdk/counters.h +++ b/source/include/rocprofiler-sdk/counters.h @@ -97,19 +97,21 @@ rocprofiler_iterate_counter_dimensions(rocprofiler_counter_id_t id, void* user_data); /** - * @brief Query Counter name. Name is a pointer controlled by rocprofiler and - * should not be free'd or modified. + * @brief Query Counter info such as name or description. * - * @param [in] counter_id counter for which to get its name. - * @param [out] name returns a pointer to the name of the counter - * @param [out] size returns the size of the name returned + * @param [in] counter_id counter to get info for + * @param [in] version Version of struct in info, see @ref rocprofiler_counter_info_version_id_t for + * available types + * @param [out] info rocprofiler_counter_info_{version}_t struct to write info to. * @return ::rocprofiler_status_t * @retval ROCPROFILER_STATUS_SUCCESS if counter found * @retval ROCPROFILER_STATUS_ERROR_COUNTER_NOT_FOUND if counter not found + * @retval ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI Version is not supported */ rocprofiler_status_t ROCPROFILER_API -rocprofiler_query_counter_name(rocprofiler_counter_id_t counter_id, const char** name, size_t* size) - ROCPROFILER_NONNULL(2, 3); +rocprofiler_query_counter_info(rocprofiler_counter_id_t counter_id, + rocprofiler_counter_info_version_id_t version, + void* info) ROCPROFILER_NONNULL(3); /** * @brief This call returns the number of instances specific counter contains. diff --git a/source/include/rocprofiler-sdk/fwd.h b/source/include/rocprofiler-sdk/fwd.h index d5637feddf..e85266f522 100644 --- a/source/include/rocprofiler-sdk/fwd.h +++ b/source/include/rocprofiler-sdk/fwd.h @@ -260,6 +260,26 @@ typedef enum ROCPROFILER_TABLE_LAST = ROCPROFILER_MARKER_NAME_TABLE, } rocprofiler_intercept_table_t; +/** + * @brief Enumeration for specifying the data type contained within the union. + */ +typedef enum +{ + ROCPROFILER_UNION_TYPE_NONE = 0, ///< No union type + ROCPROFILER_UNION_TYPE_STRING, ///< String Type set + ROCPROFILER_UNION_TYPE_INT, ///< Integer Type Set + ROCPROFILER_UNION_TYPE_LAST, +} rocprofiler_union_type_t; + +/** + * @brief Enumeration for specifying the counter info struct version you want. + */ +typedef enum +{ + ROCPROFILER_COUNTER_INFO_VERSION_NONE, + ROCPROFILER_COUNTER_INFO_VERSION_0, ///< @see rocprofiler_counter_info_v0_t + ROCPROFILER_COUNTER_INFO_VERSION_LAST, +} rocprofiler_counter_info_version_id_t; //--------------------------------------------------------------------------------------// // // ALIASES @@ -500,6 +520,18 @@ typedef struct rocprofiler_correlation_id_t corr_id; } rocprofiler_record_counter_t; +/** + * @brief Counter info struct version 0 + */ +typedef struct +{ + const char* name; ///< Name of the counter + const char* description; ///< Description of the counter + bool is_derived; ///< If this counter is a derrived counter + const char* block; ///< Block of the counter (non-derrived only) + const char* expression; ///< Counter expression (derrived counters only) +} rocprofiler_counter_info_v0_t; + /** * @brief ROCProfiler SPM Record. * diff --git a/source/lib/rocprofiler-sdk-tool/tool.cpp b/source/lib/rocprofiler-sdk-tool/tool.cpp index e679c93f46..5c60b7f368 100644 --- a/source/lib/rocprofiler-sdk-tool/tool.cpp +++ b/source/lib/rocprofiler-sdk-tool/tool.cpp @@ -576,11 +576,15 @@ buffered_tracing_callback(rocprofiler_context_id_t /*context*/, auto* profiler_record = static_cast(header->payload); rocprofiler_tool_kernel_properties_t kernel_properties = GetKernelProperties(profiler_record->corr_id.internal); - rocprofiler_counter_id_t counter_id; - const char* counter_name; - size_t size, pos; + rocprofiler_counter_id_t counter_id; + size_t pos; + rocprofiler_counter_info_v0_t version; + rocprofiler_query_record_counter_id(profiler_record->id, &counter_id); - rocprofiler_query_counter_name(counter_id, &counter_name, &size); + + rocprofiler_query_counter_info( + counter_id, ROCPROFILER_COUNTER_INFO_VERSION_0, static_cast(&version)); + rocprofiler_query_record_dimension_position(profiler_record->id, 0, &pos); auto counter_collection_ss = std::stringstream{}; @@ -599,7 +603,7 @@ buffered_tracing_callback(rocprofiler_context_id_t /*context*/, kernel_properties.scratch_size, kernel_properties.arch_vgpr_count, kernel_properties.sgpr_count, - fmt::format("{}[{}]", counter_name, pos), + fmt::format("{}[{}]", version.name, pos), profiler_record->counter_value); get_counter_collection_file() << counter_collection_ss.str(); @@ -639,18 +643,16 @@ get_agent_profile(const rocprofiler_agent_t* agent) auto* vec = static_cast(user_data); for(size_t i = 0; i < num_counters; i++) { - const char* name = nullptr; - size_t len = 0; + rocprofiler_counter_info_v0_t version; - ROCPROFILER_CALL(rocprofiler_query_counter_name( - counters[i], &name, &len), - "Could not query name"); + ROCPROFILER_CALL(rocprofiler_query_counter_info( + counters[i], + ROCPROFILER_COUNTER_INFO_VERSION_0, + static_cast(&version)), + "Could not query counter_id"); - if(name && len > 0) - { - if(tool::get_config().counters.count(name) > 0) - vec->emplace_back(counters[i]); - } + if(tool::get_config().counters.count(version.name) > 0) + vec->emplace_back(counters[i]); } return ROCPROFILER_STATUS_SUCCESS; }, diff --git a/source/lib/rocprofiler-sdk/counters.cpp b/source/lib/rocprofiler-sdk/counters.cpp index b0e0fbc602..854582e78a 100644 --- a/source/lib/rocprofiler-sdk/counters.cpp +++ b/source/lib/rocprofiler-sdk/counters.cpp @@ -40,22 +40,35 @@ extern "C" { /** - * @brief Query Counter name. + * @brief Query Counter info such as name or description. * - * @param [in] counter_id - * @param [out] name if nullptr, size will be returned - * @param [out] size + * @param [in] counter_id counter to get info for + * @param [in] version Version of struct in info, see @ref rocprofiler_counter_info_version_id_t for + * available types + * @param [out] info rocprofiler_counter_info_{version}_t struct to write info to. * @return ::rocprofiler_status_t + * @retval ROCPROFILER_STATUS_SUCCESS if counter found + * @retval ROCPROFILER_STATUS_ERROR_COUNTER_NOT_FOUND if counter not found + * @retval ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI Version is not supported */ -rocprofiler_status_t -rocprofiler_query_counter_name(rocprofiler_counter_id_t counter_id, const char** name, size_t* size) +rocprofiler_status_t ROCPROFILER_API +rocprofiler_query_counter_info(rocprofiler_counter_id_t counter_id, + rocprofiler_counter_info_version_id_t version, + void* info) { + if(version != ROCPROFILER_COUNTER_INFO_VERSION_0) + return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI; const auto& id_map = *CHECK_NOTNULL(rocprofiler::counters::getMetricIdMap()); + auto& out_struct = *static_cast(info); + if(const auto* metric_ptr = rocprofiler::common::get_val(id_map, counter_id.handle)) { - *name = metric_ptr->name().c_str(); - *size = metric_ptr->name().size(); + out_struct.name = metric_ptr->name().c_str(); + out_struct.description = metric_ptr->description().c_str(); + out_struct.is_derived = !metric_ptr->expression().empty(); + out_struct.block = metric_ptr->block().c_str(); + out_struct.expression = metric_ptr->expression().c_str(); return ROCPROFILER_STATUS_SUCCESS; } diff --git a/source/lib/rocprofiler-sdk/counters/tests/metrics_test.cpp b/source/lib/rocprofiler-sdk/counters/tests/metrics_test.cpp index d6259492a6..4b842bb5d5 100644 --- a/source/lib/rocprofiler-sdk/counters/tests/metrics_test.cpp +++ b/source/lib/rocprofiler-sdk/counters/tests/metrics_test.cpp @@ -183,11 +183,16 @@ TEST(metrics, check_public_api_query) const auto* id_map = counters::getMetricIdMap(); for(const auto& [id, metric] : *id_map) { - const char* name = nullptr; - size_t size = 0; - ASSERT_EQ(rocprofiler_query_counter_name({.handle = id}, &name, &size), - ROCPROFILER_STATUS_SUCCESS); - EXPECT_EQ(std::string(name), metric.name()); - EXPECT_EQ(size, metric.name().size()); + rocprofiler_counter_info_v0_t version; + + ASSERT_EQ( + rocprofiler_query_counter_info( + {.handle = id}, ROCPROFILER_COUNTER_INFO_VERSION_0, static_cast(&version)), + ROCPROFILER_STATUS_SUCCESS); + EXPECT_EQ(version.name, metric.name().c_str()); + EXPECT_EQ(version.block, metric.block().c_str()); + EXPECT_EQ(version.expression, metric.expression().c_str()); + EXPECT_EQ(version.is_derived, !metric.expression().empty()); + EXPECT_EQ(version.description, metric.description().c_str()); } } \ No newline at end of file diff --git a/tests/tools/json-tool.cpp b/tests/tools/json-tool.cpp index 883677aac9..0c04ffd79c 100644 --- a/tests/tools/json-tool.cpp +++ b/tests/tools/json-tool.cpp @@ -460,11 +460,14 @@ dispatch_callback(rocprofiler_queue_id_t, /*queue_id*/ // Look for the counters contained in counters_to_collect in gpu_counters for(auto& counter : gpu_counters) { - const char* name; - size_t size; - ROCPROFILER_CALL(rocprofiler_query_counter_name(counter, &name, &size), - "Could not query name"); - if(counters_to_collect.count(std::string(name)) > 0) + rocprofiler_counter_info_v0_t version; + + ROCPROFILER_CALL( + rocprofiler_query_counter_info( + counter, ROCPROFILER_COUNTER_INFO_VERSION_0, static_cast(&version)), + "Could not query counter_id"); + + if(counters_to_collect.count(std::string(version.name)) > 0) { collect_counters.push_back(counter); }