Skip to content

Commit

Permalink
Merge pull request #2230 from pbalcer/check-xpti-enabled
Browse files Browse the repository at this point in the history
don't call xpti if there are no subscribers
  • Loading branch information
pbalcer authored Oct 31, 2024
2 parents 8c0cc4c + 9d1d3ac commit 6ade245
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ if(UR_ENABLE_TRACING)

if (UR_BUILD_XPTI_LIBS)
# fetch xpti proxy library for the tracing layer
FetchContentSparse_Declare(xpti https://github.com/intel/llvm.git "sycl-nightly/20230703" "xpti")
FetchContentSparse_Declare(xpti https://github.com/intel/llvm.git "nightly-2024-10-22" "xpti")
FetchContent_MakeAvailable(xpti)

# set -fPIC for xpti since we are linking it with a shared library
Expand All @@ -149,7 +149,7 @@ if(UR_ENABLE_TRACING)
set(XPTI_DIR ${xpti_SOURCE_DIR})
set(XPTI_ENABLE_TESTS OFF CACHE INTERNAL "Turn off xptifw tests")

FetchContentSparse_Declare(xptifw https://github.com/intel/llvm.git "sycl-nightly/20230703" "xptifw")
FetchContentSparse_Declare(xptifw https://github.com/intel/llvm.git "nightly-2024-10-22" "xptifw")

FetchContent_MakeAvailable(xptifw)

Expand Down
3 changes: 1 addition & 2 deletions examples/collector/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ XPTI_CALLBACK_API void xptiTraceInit(unsigned int major_version,
return;
}
if (std::string_view(stream_name) != UR_STREAM_NAME) {
std::cout << "Invalid stream name: " << stream_name << ". Expected "
<< UR_STREAM_NAME << ". Aborting." << std::endl;
// we expect ur.call, but this can also be xpti.framework.
return;
}

Expand Down
11 changes: 11 additions & 0 deletions source/loader/layers/tracing/ur_tracing_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "xpti/xpti_data_types.h"
#include "xpti/xpti_trace_framework.h"
#include <atomic>
#include <cstdint>
#include <optional>
#include <sstream>

Expand Down Expand Up @@ -59,6 +60,12 @@ void context_t::notify(uint16_t trace_type, uint32_t id, const char *name,
}

uint64_t context_t::notify_begin(uint32_t id, const char *name, void *args) {
// we use UINT64_MAX as a special value that means "tracing disabled",
// so that we don't have to repeat this check in notify_end.
if (!xptiCheckTraceEnabled(call_stream_id)) {
return UINT64_MAX;
}

if (auto loc = codelocData.get_codeloc()) {
xpti::payload_t payload =
xpti::payload_t(loc->functionName, loc->sourceFile, loc->lineNumber,
Expand All @@ -77,6 +84,10 @@ uint64_t context_t::notify_begin(uint32_t id, const char *name, void *args) {

void context_t::notify_end(uint32_t id, const char *name, void *args,
ur_result_t *resultp, uint64_t instance) {
if (instance == UINT64_MAX) { // tracing disabled
return;
}

notify((uint16_t)xpti::trace_point_type_t::function_with_args_end, id, name,
args, resultp, instance);
}
Expand Down
3 changes: 1 addition & 2 deletions test/layers/tracing/test_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ XPTI_CALLBACK_API void xptiTraceInit(unsigned int major_version,
return;
}
if (std::string_view(stream_name) != UR_STREAM_NAME) {
std::cout << "Invalid stream name: " << stream_name << ". Expected "
<< UR_STREAM_NAME << ". Aborting." << std::endl;
// we expect ur.call, but this can also be xpti.framework.
return;
}

Expand Down

0 comments on commit 6ade245

Please sign in to comment.