SDK: No bg thread if no clients use SDK (#123)

* SDK: No bg thread if no clients use SDK

* Update CHANGELOG

---------

Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
This commit is contained in:
Madsen, Jonathan
2025-02-06 08:34:56 -06:00
committed by GitHub
parent 90ae424c57
commit 0fbe6cc7b6
5 changed files with 73 additions and 26 deletions
+4 -2
View File
@@ -36,7 +36,8 @@ set_tests_properties(
PASS_REGULAR_EXPRESSION
"Test C tool \\(priority=0\\) is using rocprofiler-sdk v([0-9]+\\.[0-9]+\\.[0-9]+)"
FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")
"${ROCPROFILER_DEFAULT_FAIL_REGEX}|Internal thread for rocprofiler-sdk should not be created"
)
# this test uses ROCP_TOOL_LIBRARIES instead of LD_PRELOAD
add_test(NAME test-c-tool-rocp-tool-lib-execute COMMAND $<TARGET_FILE:transpose> 1)
@@ -59,4 +60,5 @@ set_tests_properties(
PASS_REGULAR_EXPRESSION
"Test C tool \\(priority=0\\) is using rocprofiler-sdk v([0-9]+\\.[0-9]+\\.[0-9]+)"
FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")
"${ROCPROFILER_DEFAULT_FAIL_REGEX}|Internal thread for rocprofiler-sdk should not be created"
)
+28
View File
@@ -34,6 +34,29 @@
#include <rocprofiler-sdk/registration.h>
#include <rocprofiler-sdk/rocprofiler.h>
#include <stdio.h>
#include <stdlib.h>
static void
thread_precreate(rocprofiler_runtime_library_t lib, void* tool_data)
{
uint32_t* priority = (uint32_t*) tool_data;
if(priority && *priority == 0)
{
fprintf(
stderr,
"Internal thread for rocprofiler-sdk should not be created when all tools return NULL "
"from rocprofiler_configure\n");
fflush(stderr);
abort();
}
(void) lib;
}
static uint32_t tool_priority = 0;
rocprofiler_tool_configure_result_t*
rocprofiler_configure(uint32_t version,
const char* runtime_version,
@@ -43,6 +66,8 @@ rocprofiler_configure(uint32_t version,
// set the client name
id->name = "Test C tool";
tool_priority = priority;
// compute major/minor/patch version info
uint32_t major = version / 10000;
uint32_t minor = (version % 10000) / 100;
@@ -57,6 +82,9 @@ rocprofiler_configure(uint32_t version,
patch,
runtime_version);
rocprofiler_at_internal_thread_create(
thread_precreate, NULL, ROCPROFILER_LIBRARY, &tool_priority);
// return pointer to configure data
return NULL;
}