diff --git a/samples/counter_collection/client.cpp b/samples/counter_collection/client.cpp index b83da4fa..aa4b5b38 100644 --- a/samples/counter_collection/client.cpp +++ b/samples/counter_collection/client.cpp @@ -74,6 +74,32 @@ get_buffer() return buf; } +/** + * For a given counter, query the dimensions that it has. Typically you will + * want to call this function once to get the dimensions and cache them. + */ +std::vector +counter_dimensions(rocprofiler_counter_id_t counter) +{ + std::vector dims; + rocprofiler_available_dimensions_cb_t cb = + [](rocprofiler_counter_id_t, + const rocprofiler_record_dimension_info_t* dim_info, + size_t num_dims, + void* user_data) { + std::vector* vec = + static_cast*>(user_data); + for(size_t i = 0; i < num_dims; i++) + { + vec->push_back(dim_info[i]); + } + return ROCPROFILER_STATUS_SUCCESS; + }; + ROCPROFILER_CALL(rocprofiler_iterate_counter_dimensions(counter, cb, &dims), + "Could not iterate counter dimensions"); + return dims; +} + /** * buffered_callback (set in rocprofiler_create_buffer in tool_init) is called when the * buffer is full (or when the buffer is flushed). The callback is responsible for processing @@ -90,9 +116,6 @@ buffered_callback(rocprofiler_context_id_t, void* user_data, uint64_t) { - static int enter_count = 0; - enter_count++; - if(enter_count % 100 != 0) return; std::stringstream ss; // Iterate through the returned records for(size_t i = 0; i < num_headers; ++i) @@ -113,8 +136,20 @@ buffered_callback(rocprofiler_context_id_t, { // Print the returned counter data. auto* record = static_cast(header->payload); - ss << " (Dispatch_Id: " << record->dispatch_id << " Id: " << record->id - << " Value [D]: " << record->counter_value << "),"; + rocprofiler_counter_id_t counter_id = {.handle = 0}; + + rocprofiler_query_record_counter_id(record->id, &counter_id); + + ss << " (Dispatch_Id: " << record->dispatch_id << " Counter_Id: " << counter_id.handle + << " Record_Id: " << record->id << " Dimensions: ["; + + for(auto& dim : counter_dimensions(counter_id)) + { + size_t pos = 0; + rocprofiler_query_record_dimension_position(record->id, dim.id, &pos); + ss << "{" << dim.name << ": " << pos << "},"; + } + ss << "] Value [D]: " << record->counter_value << "),"; } } diff --git a/source/lib/rocprofiler-sdk/counters/tests/dimension.cpp b/source/lib/rocprofiler-sdk/counters/tests/dimension.cpp index 1a690a55..a064b3ac 100644 --- a/source/lib/rocprofiler-sdk/counters/tests/dimension.cpp +++ b/source/lib/rocprofiler-sdk/counters/tests/dimension.cpp @@ -128,6 +128,12 @@ TEST(dimension, set_get) check_dim_pos(test_id, dim, i * 5); set_dim_in_rec(test_id, dim, i * 3); check_dim_pos(test_id, dim, i * 3); + for(size_t j = 1; j < 64; j++) + { + test_id = 0; + set_dim_in_rec(test_id, dim, j); + check_dim_pos(test_id, dim, j); + } } test_counter.handle = 123;