Check to force tools to initialize the ctx id to zero. (#1135)

* Check to force tool to initialize the ctx id to zero.

* initialize rocprofiler_context_id_t with 0 in units tests

* changelog

---------

Co-authored-by: Gopesh Bhardwaj <gopesh.bhardwaj@amd.com>
This commit is contained in:
venkat1361
2024-10-22 07:39:25 -05:00
کامیت شده توسط GitHub
والد a92fa8f071
کامیت 3f91d90bbc
36فایلهای تغییر یافته به همراه66 افزوده شده و 61 حذف شده
@@ -84,7 +84,7 @@ rocprofiler_assign_callback_thread(rocprofiler_buffer_id_t buffer_id,
```cpp
{
// create a context
auto context_id = rocprofiler_context_id_t{};
auto context_id = rocprofiler_context_id_t{0};
rocprofiler_create_context(&context_id);
// create a buffer associated with the context
@@ -31,7 +31,7 @@ This guide explains how to setup dispatch and agent profiling along will describ
The setup for dispatch and agent profiling is similar (with only minor changes needed to adapt code from one to another). In tool_init, similar to tracing services, you need to create a context and a buffer to collect the output. Important Note: buffered_callback in rocprofiler_create_buffer is called when the buffer is full with a vector of collected counter samples, see the buffered callback section below for processing.
```CPP
rocprofiler_context_id_t ctx;
rocprofiler_context_id_t ctx{0};
rocprofiler_buffer_id_t buff;
ROCPROFILER_CALL(rocprofiler_create_context(&ctx), "context creation failed");
ROCPROFILER_CALL(rocprofiler_create_buffer(ctx,
@@ -92,7 +92,7 @@ tool_init(rocprofiler_client_finalize_t fini_func,
void* data_v)
{
// create a context
auto ctx = rocprofiler_context_id_t{};
auto ctx = rocprofiler_context_id_t{0};
rocprofiler_create_context(&ctx);
// ... associate services with context ...
@@ -178,7 +178,7 @@ tool_init(rocprofiler_client_finalize_t fini_func,
tool_data->finalizer = fini_func;
// create a context
auto ctx = rocprofiler_context_id_t{};
auto ctx = rocprofiler_context_id_t{0};
rocprofiler_create_context(&ctx);
// Save your contexts
@@ -68,6 +68,7 @@ typedef enum // NOLINT(performance-enum-size)
///< into active array failed)
ROCPROFILER_STATUS_ERROR_CONTEXT_CONFLICT, ///< Context operation failed due to a conflict with
///< another context
ROCPROFILER_STATUS_ERROR_CONTEXT_ID_NOT_ZERO, ///< Context ID is not initialized to zero
ROCPROFILER_STATUS_ERROR_BUFFER_BUSY, ///< buffer operation failed because it currently busy
///< handling another request (e.g. flushing)
ROCPROFILER_STATUS_ERROR_SERVICE_ALREADY_CONFIGURED, ///< service has already been configured
@@ -153,7 +153,7 @@ rocprofiler_is_finalized(int* status) ROCPROFILER_API ROCPROFILER_NONNULL(1);
*
* assert(*static_cast<int*>(tool_data) == 1234 && "tool_data is wrong");
*
* rocprofiler_context_id_t ctx;
* rocprofiler_context_id_t ctx{0};
* rocprofiler_create_context(&ctx);
*
* if(int valid_ctx = 0;
@@ -266,7 +266,7 @@ is_targeted_kernel(uint64_t _kern_id)
auto&
get_client_ctx()
{
static rocprofiler_context_id_t context_id;
static rocprofiler_context_id_t context_id{0};
return context_id;
}
@@ -1270,7 +1270,7 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
ROCPROFILER_CALL(rocprofiler_create_context(&get_client_ctx()), "create context failed");
auto code_obj_ctx = rocprofiler_context_id_t{};
auto code_obj_ctx = rocprofiler_context_id_t{0};
ROCPROFILER_CALL(rocprofiler_create_context(&code_obj_ctx), "failed to create context");
ROCPROFILER_CALL(
@@ -1294,7 +1294,7 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
nullptr),
"callback tracing service failed to configure");
auto pause_resume_ctx = rocprofiler_context_id_t{};
auto pause_resume_ctx = rocprofiler_context_id_t{0};
ROCPROFILER_CALL(rocprofiler_create_context(&pause_resume_ctx), "failed to create context");
ROCPROFILER_CALL(rocprofiler_configure_callback_tracing_service(
@@ -1465,7 +1465,7 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
if(tool::get_config().kernel_rename)
{
auto rename_ctx = rocprofiler_context_id_t{};
auto rename_ctx = rocprofiler_context_id_t{0};
auto marker_core_api_kinds = std::array<rocprofiler_tracing_operation_t, 3>{
ROCPROFILER_MARKER_CORE_API_ID_roctxMarkA,
ROCPROFILER_MARKER_CORE_API_ID_roctxRangePushA,
@@ -41,6 +41,7 @@ extern "C" {
rocprofiler_status_t
rocprofiler_create_context(rocprofiler_context_id_t* context_id)
{
if(context_id->handle != 0) return ROCPROFILER_STATUS_ERROR_CONTEXT_ID_NOT_ZERO;
// context already registered
if(rocprofiler::context::get_registered_context(*context_id))
return ROCPROFILER_STATUS_ERROR_CONTEXT_INVALID;
@@ -113,7 +113,7 @@ namespace
rocprofiler_context_id_t&
get_client_ctx()
{
static rocprofiler_context_id_t ctx;
static rocprofiler_context_id_t ctx{0};
return ctx;
}
@@ -131,7 +131,7 @@ dispatch_callback(rocprofiler_dispatch_counting_service_data_t,
rocprofiler_context_id_t&
get_client_ctx()
{
static rocprofiler_context_id_t ctx;
static rocprofiler_context_id_t ctx{0};
return ctx;
}
@@ -48,7 +48,7 @@ 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_context_id_t client_ctx = {0};
rocprofiler_buffer_id_t client_buffer = {};
rocprofiler_callback_thread_t client_thread = {};
uint64_t client_workflow_count = {};
@@ -344,7 +344,7 @@ TEST(pc_sampling, rocprofiler_configure_pc_sampling_service)
// We will create another context and try configuring pc sampling inside it,
// that is supposed to fail.
rocprofiler_context_id_t another_ctx;
rocprofiler_context_id_t another_ctx{0};
ROCPROFILER_CALL(rocprofiler_create_context(&another_ctx), "failed to create context");
rocprofiler_buffer_id_t another_buff;
ROCPROFILER_CALL(rocprofiler_create_buffer(another_ctx,
@@ -50,7 +50,7 @@ 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_context_id_t client_ctx = {0};
rocprofiler_buffer_id_t client_buffer = {};
rocprofiler_callback_thread_t client_thread = {};
uint64_t client_workflow_count = {};
@@ -46,7 +46,7 @@ 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_context_id_t client_ctx = {0};
rocprofiler_buffer_id_t client_buffer = {};
rocprofiler_callback_thread_t client_thread = {};
uint64_t client_workflow_count = {};
@@ -58,7 +58,7 @@ 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_context_id_t client_ctx = {0};
rocprofiler_buffer_id_t client_buffer = {};
rocprofiler_callback_thread_t client_thread = {};
uint64_t client_workflow_count = {};
@@ -55,6 +55,8 @@ ROCPROFILER_STATUS_STRING(ROCPROFILER_STATUS_ERROR_CONTEXT_INVALID,
ROCPROFILER_STATUS_STRING(ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_STARTED, "Context failed to start")
ROCPROFILER_STATUS_STRING(ROCPROFILER_STATUS_ERROR_CONTEXT_CONFLICT,
"Context has a conflict with another context")
ROCPROFILER_STATUS_STRING(ROCPROFILER_STATUS_ERROR_CONTEXT_ID_NOT_ZERO,
"Context ID should be initialized to zero")
ROCPROFILER_STATUS_STRING(
ROCPROFILER_STATUS_ERROR_BUFFER_BUSY,
"Buffer operation failed because it is currently busy handling another request")
@@ -56,7 +56,7 @@ 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_context_id_t client_ctx = {0};
rocprofiler_buffer_id_t client_buffer = {};
rocprofiler_callback_thread_t client_thread = {};
uint64_t client_workflow_count = {};
@@ -73,7 +73,7 @@ struct callback_data_ext
rocprofiler_client_id_t* client_id = nullptr;
rocprofiler_client_finalize_t client_fini_func = nullptr;
rocprofiler_context_id_t client_hsa_ctx = {};
rocprofiler_context_id_t client_hsa_ctx = {0};
rocprofiler_context_id_t client_hip_ctx = {};
rocprofiler_buffer_id_t client_buffer = {};
rocprofiler_callback_thread_t client_thread = {};
@@ -60,7 +60,7 @@ 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_context_id_t client_ctx = {0};
rocprofiler_buffer_id_t client_buffer = {};
rocprofiler_callback_thread_t client_thread = {};
uint64_t client_workflow_count = {};
@@ -472,7 +472,7 @@ TEST(rocprofiler_lib, buffered_external_correlation)
return &cfg_result;
};
auto ctx = rocprofiler_context_id_t{};
auto ctx = rocprofiler_context_id_t{0};
EXPECT_NE(rocprofiler_create_context(&ctx), ROCPROFILER_STATUS_SUCCESS);
EXPECT_EQ(rocprofiler_force_configure(rocp_init), ROCPROFILER_STATUS_SUCCESS);
EXPECT_NE(rocprofiler_create_context(&ctx), ROCPROFILER_STATUS_SUCCESS);
@@ -225,7 +225,7 @@ TEST(rocprofiler_lib, registration_lambda_no_result)
return nullptr;
};
auto ctx = rocprofiler_context_id_t{};
auto ctx = rocprofiler_context_id_t{0};
EXPECT_NE(rocprofiler_create_context(&ctx), ROCPROFILER_STATUS_SUCCESS);
EXPECT_EQ(rocprofiler_force_configure(rocp_init), ROCPROFILER_STATUS_SUCCESS);
EXPECT_NE(rocprofiler_create_context(&ctx), ROCPROFILER_STATUS_SUCCESS);
@@ -313,7 +313,7 @@ TEST(rocprofiler_lib, callback_registration_lambda_with_result)
return std::chrono::steady_clock::now().time_since_epoch().count();
};
auto ctx = rocprofiler_context_id_t{};
auto ctx = rocprofiler_context_id_t{0};
EXPECT_NE(rocprofiler_create_context(&ctx), ROCPROFILER_STATUS_SUCCESS);
EXPECT_EQ(rocprofiler_force_configure(rocp_init), ROCPROFILER_STATUS_SUCCESS);
EXPECT_NE(rocprofiler_create_context(&ctx), ROCPROFILER_STATUS_SUCCESS);
@@ -469,7 +469,7 @@ TEST(rocprofiler_lib, buffer_registration_lambda_with_result)
return &cfg_result;
};
auto ctx = rocprofiler_context_id_t{};
auto ctx = rocprofiler_context_id_t{0};
EXPECT_NE(rocprofiler_create_context(&ctx), ROCPROFILER_STATUS_SUCCESS);
EXPECT_EQ(rocprofiler_force_configure(rocp_init), ROCPROFILER_STATUS_SUCCESS);
EXPECT_NE(rocprofiler_create_context(&ctx), ROCPROFILER_STATUS_SUCCESS);
@@ -309,7 +309,7 @@ TEST(rocprofiler_lib, roctx_callback_tracing)
cb_data->client_workflow_count++;
cb_data->client_fini_func = fini_func;
auto pause_resume_ctx = rocprofiler_context_id_t{};
auto pause_resume_ctx = rocprofiler_context_id_t{0};
ROCPROFILER_CALL(rocprofiler_create_context(&pause_resume_ctx), "failed to create context");
ROCPROFILER_CALL(rocprofiler_create_context(&cb_data->client_ctx),
@@ -425,7 +425,7 @@ TEST(rocprofiler_lib, roctx_buffered_tracing)
cb_data->client_workflow_count++;
cb_data->client_fini_func = fini_func;
auto pause_resume_ctx = rocprofiler_context_id_t{};
auto pause_resume_ctx = rocprofiler_context_id_t{0};
ROCPROFILER_CALL(rocprofiler_create_context(&pause_resume_ctx), "failed to create context");
ROCPROFILER_CALL(rocprofiler_configure_callback_tracing_service(
@@ -134,7 +134,7 @@ TEST(thread_trace, configure_test)
registration::init_logging();
registration::set_init_status(-1);
context::push_client(1);
rocprofiler_context_id_t ctx;
rocprofiler_context_id_t ctx{0};
ROCPROFILER_CALL(rocprofiler_create_context(&ctx), "context creation failed");
std::vector<rocprofiler_att_parameter_t> params;
@@ -171,7 +171,7 @@ TEST(thread_trace, perfcounters_configure_test)
registration::init_logging();
registration::set_init_status(-1);
context::push_client(1);
rocprofiler_context_id_t ctx;
rocprofiler_context_id_t ctx{0};
ROCPROFILER_CALL(rocprofiler_create_context(&ctx), "context creation failed");
// Only GFX9 SQ Block counters are supported
@@ -299,7 +299,7 @@ TEST(thread_trace, agent_configure_test)
registration::init_logging();
registration::set_init_status(-1);
context::push_client(1);
rocprofiler_context_id_t ctx;
rocprofiler_context_id_t ctx{0};
ROCPROFILER_CALL(rocprofiler_create_context(&ctx), "context creation failed");
ROCPROFILER_CALL(rocprofiler_query_available_agents(ROCPROFILER_AGENT_INFO_VERSION_0,