Add dimension query to counter collection sample (#918)
Co-authored-by: Benjamin Welton <ben@amd.com>
[ROCm/rocprofiler-sdk commit: f5753d3ae3]
This commit is contained in:
zatwierdzone przez
GitHub
rodzic
2662909daf
commit
81f97422fb
@@ -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<rocprofiler_record_dimension_info_t>
|
||||
counter_dimensions(rocprofiler_counter_id_t counter)
|
||||
{
|
||||
std::vector<rocprofiler_record_dimension_info_t> 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<rocprofiler_record_dimension_info_t>* vec =
|
||||
static_cast<std::vector<rocprofiler_record_dimension_info_t>*>(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<rocprofiler_record_counter_t*>(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 << "),";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user