Query callback and buffered tracing names (#135)
* Update include/rocprofiler/buffer_tracing.h - add query functions for kind name, and kind operation name - tweak iterate functions to not be specifically dedicated to names * Update include/rocprofiler/callback_tracing.h - add query functions for kind name, and kind operation name - tweak iterate functions to not be specifically dedicated to names * Update lib/rocprofiler/callback_tracing.cpp - implement rocprofiler_query_callback_tracing_kind_name - implement rocprofiler_query_callback_tracing_kind_name_buf - implement rocprofiler_query_callback_tracing_kind_operation_name - implement rocprofiler_query_callback_tracing_kind_operation_name_buf - implement rocprofiler_iterate_callback_tracing_kinds - implement rocprofiler_iterate_callback_tracing_kind_operations * Update lib/rocprofiler/buffer_tracing.cpp - implement rocprofiler_query_buffer_tracing_kind_name - implement rocprofiler_query_buffer_tracing_kind_name_buf - implement rocprofiler_query_buffer_tracing_kind_operation_name - implement rocprofiler_query_buffer_tracing_kind_operation_name_buf - implement rocprofiler_iterate_buffer_tracing_kinds - implement rocprofiler_iterate_buffer_tracing_kind_operations * Update lib/rocprofiler/tests/registration.cpp - use new implementation for getting callback/buffer tracing names * Update samples/api_buffered_tracing - use new implementation for getting callback/buffer tracing names * Update samples/api_callback_tracing - use new implementation for getting callback/buffer tracing names * Remove buffered query functions - *_buf variants of the rocprofiler_query_X_tracing_Y functions were removed since we currently have no names requiring these functions * Rename ROCPROFILER_STATUS_ERROR_DOMAIN_NOT_FOUND - "DOMAIN" changed to "KIND" since former is more specific tracing whereas kind is used more generically
Цей коміт міститься в:
1 джерело
de685246a7
коміт
87cc748c3d
10 files changed
+619
-232
No files matched your search
@@ -31,6 +31,7 @@
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
@@ -39,6 +40,7 @@
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
#include <typeinfo>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#define ROCPROFILER_CALL(ARG, MSG) \
|
||||
@@ -58,6 +60,7 @@ struct callback_data
|
||||
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;
|
||||
};
|
||||
@@ -68,48 +71,147 @@ struct agent_data
|
||||
std::vector<hsa_device_type_t> agents = {};
|
||||
};
|
||||
|
||||
void
|
||||
tool_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
rocprofiler_user_data_t*,
|
||||
void* client_data)
|
||||
using callback_kind_names_t = std::map<rocprofiler_service_callback_tracing_kind_t, const char*>;
|
||||
using callback_kind_operation_names_t =
|
||||
std::map<rocprofiler_service_callback_tracing_kind_t, std::map<uint32_t, const char*>>;
|
||||
|
||||
struct callback_name_info
|
||||
{
|
||||
using name_map_t = std::unordered_map<rocprofiler_service_callback_tracing_kind_t,
|
||||
std::unordered_map<uint32_t, const char*>>;
|
||||
callback_kind_names_t kind_names = {};
|
||||
callback_kind_operation_names_t operation_names = {};
|
||||
};
|
||||
|
||||
auto* cb_data = static_cast<callback_data*>(client_data);
|
||||
auto
|
||||
get_callback_tracing_names()
|
||||
{
|
||||
auto cb_name_info = callback_name_info{};
|
||||
//
|
||||
// callback for each kind operation
|
||||
//
|
||||
static auto tracing_kind_operation_cb =
|
||||
[](rocprofiler_service_callback_tracing_kind_t kindv, uint32_t operation, void* data_v) {
|
||||
auto* name_info_v = static_cast<callback_name_info*>(data_v);
|
||||
|
||||
static auto name_map = []() {
|
||||
auto outer_cb = [](rocprofiler_service_callback_tracing_kind_t kind_v,
|
||||
const char* /*kind_name*/,
|
||||
void* data_v) {
|
||||
auto inner_cb = [](rocprofiler_service_callback_tracing_kind_t kind,
|
||||
uint32_t operation,
|
||||
const char* operation_name,
|
||||
void* data) {
|
||||
auto& mdata = *static_cast<name_map_t*>(data);
|
||||
mdata[kind][operation] = operation_name;
|
||||
return 0;
|
||||
};
|
||||
|
||||
auto& mdata_v = *static_cast<name_map_t*>(data_v);
|
||||
mdata_v.emplace(kind_v, std::unordered_map<uint32_t, const char*>{});
|
||||
|
||||
rocprofiler_iterate_callback_tracing_kind_operation_names(kind_v, inner_cb, data_v);
|
||||
if(kindv == ROCPROFILER_SERVICE_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;
|
||||
};
|
||||
|
||||
auto tmp = name_map_t{};
|
||||
rocprofiler_iterate_callback_tracing_kind_names(outer_cb, static_cast<void*>(&tmp));
|
||||
//
|
||||
// callback for each callback kind (i.e. domain)
|
||||
//
|
||||
static auto tracing_kind_cb = [](rocprofiler_service_callback_tracing_kind_t kind, void* data) {
|
||||
// store the callback kind name
|
||||
auto* name_info_v = static_cast<callback_name_info*>(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;
|
||||
|
||||
EXPECT_EQ(tmp.size(), ROCPROFILER_SERVICE_CALLBACK_TRACING_LAST - 1);
|
||||
EXPECT_EQ(tmp.at(ROCPROFILER_SERVICE_CALLBACK_TRACING_HSA_API).size(),
|
||||
ROCPROFILER_HSA_API_ID_LAST);
|
||||
if(kind == ROCPROFILER_SERVICE_CALLBACK_TRACING_HSA_API)
|
||||
{
|
||||
ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_kind_operations(
|
||||
kind, tracing_kind_operation_cb, static_cast<void*>(data)),
|
||||
"iterating callback tracing kind operations");
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
return tmp;
|
||||
}();
|
||||
ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_kinds(tracing_kind_cb,
|
||||
static_cast<void*>(&cb_name_info)),
|
||||
"iterating callback tracing kinds");
|
||||
|
||||
return cb_name_info;
|
||||
}
|
||||
|
||||
using buffer_kind_names_t = std::map<rocprofiler_service_buffer_tracing_kind_t, const char*>;
|
||||
using buffer_kind_operation_names_t =
|
||||
std::map<rocprofiler_service_buffer_tracing_kind_t, std::map<uint32_t, const char*>>;
|
||||
|
||||
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_service_buffer_tracing_kind_t kindv, uint32_t operation, void* data_v) {
|
||||
auto* name_info_v = static_cast<buffer_name_info*>(data_v);
|
||||
|
||||
if(kindv == ROCPROFILER_SERVICE_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_service_buffer_tracing_kind_t kind, void* data) {
|
||||
// store the buffer kind name
|
||||
auto* name_info_v = static_cast<buffer_name_info*>(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_SERVICE_BUFFER_TRACING_HSA_API)
|
||||
{
|
||||
ROCPROFILER_CALL(rocprofiler_iterate_buffer_tracing_kind_operations(
|
||||
kind, tracing_kind_operation_cb, static_cast<void*>(data)),
|
||||
"iterating buffer tracing kind operations");
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_iterate_buffer_tracing_kinds(tracing_kind_cb,
|
||||
static_cast<void*>(&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,
|
||||
void* client_data)
|
||||
{
|
||||
auto* cb_data = static_cast<callback_data*>(client_data);
|
||||
auto get_timestamp = []() {
|
||||
return std::chrono::steady_clock::now().time_since_epoch().count();
|
||||
};
|
||||
|
||||
if(record.phase == ROCPROFILER_SERVICE_CALLBACK_PHASE_ENTER && cb_data->current_depth == 0)
|
||||
{
|
||||
user_data->value = get_timestamp();
|
||||
}
|
||||
|
||||
static auto name_map = get_callback_tracing_names();
|
||||
|
||||
EXPECT_EQ(name_map.kind_names.size(), ROCPROFILER_SERVICE_CALLBACK_TRACING_LAST);
|
||||
EXPECT_EQ(name_map.operation_names.at(ROCPROFILER_SERVICE_CALLBACK_TRACING_HSA_API).size(),
|
||||
ROCPROFILER_HSA_API_ID_LAST);
|
||||
|
||||
std::cout << "[" << __FILE__ << ":" << __LINE__ << "] "
|
||||
<< name_map[record.kind][record.operation] << "\n"
|
||||
<< name_map.operation_names[record.kind][record.operation] << "\n"
|
||||
<< std::flush;
|
||||
|
||||
cb_data->client_callback_count++;
|
||||
@@ -151,7 +253,7 @@ tool_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
return 0;
|
||||
};
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_operation_args(
|
||||
ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_kind_operation_args(
|
||||
record, info_data_cb, static_cast<void*>(&info_data_v)),
|
||||
"Failure iterating trace operation args");
|
||||
if(record.kind == ROCPROFILER_SERVICE_CALLBACK_TRACING_HSA_API &&
|
||||
@@ -159,7 +261,12 @@ tool_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
record.operation == ROCPROFILER_HSA_API_ID_hsa_shut_down))
|
||||
{
|
||||
EXPECT_GT(info_data_v.num_args, 0)
|
||||
<< name_map[record.kind][record.operation] << info_data_v.arg_ss.str();
|
||||
<< name_map.operation_names[record.kind][record.operation] << info_data_v.arg_ss.str();
|
||||
}
|
||||
|
||||
if(record.phase == ROCPROFILER_SERVICE_CALLBACK_PHASE_EXIT && cb_data->current_depth == 0)
|
||||
{
|
||||
cb_data->client_elapsed += (get_timestamp() - user_data->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,36 +278,13 @@ tool_tracing_buffered(rocprofiler_context_id_t context,
|
||||
void* buffer_data,
|
||||
uint64_t drop_count)
|
||||
{
|
||||
using name_map_t = std::unordered_map<rocprofiler_service_buffer_tracing_kind_t,
|
||||
std::unordered_map<uint32_t, const char*>>;
|
||||
|
||||
std::cout << __FUNCTION__ << "...\n" << std::endl;
|
||||
auto* cb_data = static_cast<callback_data*>(buffer_data);
|
||||
|
||||
static auto name_map = []() {
|
||||
auto tmp = name_map_t{};
|
||||
//
|
||||
static auto tracing_kind_names_cb = [](rocprofiler_service_buffer_tracing_kind_t kind,
|
||||
const char* /*kind_name*/,
|
||||
void* data) {
|
||||
auto tracing_operation_names_cb = [](rocprofiler_service_buffer_tracing_kind_t kindv,
|
||||
uint32_t operation,
|
||||
const char* operation_name,
|
||||
void* data_v) {
|
||||
(*static_cast<name_map_t*>(data_v))[kindv][operation] = operation_name;
|
||||
return 0;
|
||||
};
|
||||
static auto name_map = get_buffer_tracing_names();
|
||||
|
||||
rocprofiler_iterate_buffer_tracing_kind_operation_names(
|
||||
kind, tracing_operation_names_cb, data);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
rocprofiler_iterate_buffer_tracing_kind_names(tracing_kind_names_cb,
|
||||
static_cast<void*>(&tmp));
|
||||
return tmp;
|
||||
}();
|
||||
EXPECT_EQ(name_map.kind_names.size(), ROCPROFILER_SERVICE_BUFFER_TRACING_LAST);
|
||||
EXPECT_EQ(name_map.operation_names.at(ROCPROFILER_SERVICE_BUFFER_TRACING_HSA_API).size(),
|
||||
ROCPROFILER_HSA_API_ID_LAST);
|
||||
|
||||
auto v_records = std::vector<rocprofiler_buffer_tracing_hsa_api_record_t*>{};
|
||||
v_records.reserve(num_headers);
|
||||
@@ -230,9 +314,10 @@ tool_tracing_buffered(rocprofiler_context_id_t context,
|
||||
auto info = std::stringstream{};
|
||||
info << "tid=" << record->thread_id << ", context=" << context.handle
|
||||
<< ", buffer_id=" << buffer_id.handle << ", cid=" << record->correlation_id.internal
|
||||
<< ", kind=" << record->kind << ", operation=" << record->operation
|
||||
<< ", drop_count=" << drop_count << ", start=" << record->start_timestamp
|
||||
<< ", stop=" << record->end_timestamp;
|
||||
<< ", kind=" << name_map.kind_names.at(record->kind) << "(" << record->kind
|
||||
<< "), operation=" << name_map.operation_names.at(record->kind).at(record->operation)
|
||||
<< "(" << record->operation << "), drop_count=" << drop_count
|
||||
<< ", start=" << record->start_timestamp << ", stop=" << record->end_timestamp;
|
||||
|
||||
static int64_t last_corr_id = -1;
|
||||
auto corr_id = static_cast<int64_t>(record->correlation_id.internal);
|
||||
@@ -295,6 +380,7 @@ TEST(rocprofiler_lib, callback_registration_lambda_with_result)
|
||||
using hsa_iterate_agents_cb_t = hsa_status_t (*)(hsa_agent_t, void*);
|
||||
|
||||
auto cmd_line = rocprofiler::common::read_command_line(getpid());
|
||||
|
||||
ASSERT_FALSE(cmd_line.empty());
|
||||
|
||||
static init_func_t tool_init = [](rocprofiler_client_finalize_t fini_func,
|
||||
@@ -360,6 +446,10 @@ TEST(rocprofiler_lib, callback_registration_lambda_with_result)
|
||||
return &cfg_result;
|
||||
};
|
||||
|
||||
auto get_timestamp = []() {
|
||||
return std::chrono::steady_clock::now().time_since_epoch().count();
|
||||
};
|
||||
|
||||
auto ctx = rocprofiler_context_id_t{};
|
||||
EXPECT_NE(rocprofiler_create_context(&ctx), ROCPROFILER_STATUS_SUCCESS);
|
||||
EXPECT_EQ(rocprofiler_force_configure(rocp_init), ROCPROFILER_STATUS_SUCCESS);
|
||||
@@ -377,14 +467,26 @@ TEST(rocprofiler_lib, callback_registration_lambda_with_result)
|
||||
return status;
|
||||
};
|
||||
|
||||
auto _agent_data = agent_data{};
|
||||
hsa_init();
|
||||
hsa_status_t itr_status = hsa_iterate_agents(agent_cb, static_cast<void*>(&_agent_data));
|
||||
auto _agent_data = agent_data{};
|
||||
auto begin_ts = get_timestamp();
|
||||
hsa_status_t itr_status = hsa_iterate_agents(agent_cb, static_cast<void*>(&_agent_data));
|
||||
auto end_ts = get_timestamp();
|
||||
auto elapsed = (end_ts - begin_ts);
|
||||
|
||||
EXPECT_EQ(itr_status, HSA_STATUS_SUCCESS);
|
||||
EXPECT_GT(_agent_data.agent_count, 0);
|
||||
EXPECT_EQ(_agent_data.agent_count, _agent_data.agents.size());
|
||||
|
||||
#if !defined(__OPTIMIZE__) || (defined(CODECOV) && CODECOV > 0)
|
||||
EXPECT_GT(cb_data.client_elapsed, 0);
|
||||
EXPECT_GT(elapsed, 0);
|
||||
#else
|
||||
decltype(elapsed) elapsed_tolerance = 0.25 * elapsed;
|
||||
EXPECT_NEAR(elapsed, cb_data.client_elapsed, elapsed_tolerance)
|
||||
<< "it is possible this failed due to noise on the machine";
|
||||
#endif
|
||||
|
||||
ASSERT_NE(cb_data.client_id, nullptr);
|
||||
ASSERT_NE(cb_data.client_fini_func, nullptr);
|
||||
|
||||
|
||||
Reference in new issue
Заблокувати користувача