Skip to content

Commit bf55536

Browse files
committed
Check if xptiTraceEnabled only once on the hot paths
1 parent d782af3 commit bf55536

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

sycl/source/detail/graph/graph_impl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,9 @@ exec_graph_impl::enqueueNodeDirect(const sycl::context &Ctx,
742742
const bool xptiEnabled = xptiTraceEnabled();
743743
xpti_td *CmdTraceEvent = nullptr;
744744
uint64_t InstanceID = 0;
745-
auto StreamID = detail::getActiveXPTIStreamID();
745+
uint8_t StreamID;
746746
if (xptiEnabled) {
747+
StreamID = detail::getActiveXPTIStreamID();
747748
sycl::detail::CGExecKernel *CGExec =
748749
static_cast<sycl::detail::CGExecKernel *>(Node.MCommandGroup.get());
749750
sycl::detail::code_location CodeLoc(CGExec->MFileName.c_str(),

sycl/source/detail/queue_impl.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,12 @@ EventImplPtr queue_impl::submit_kernel_scheduler_bypass(
448448
#ifdef XPTI_ENABLE_INSTRUMENTATION
449449
xpti_td *CmdTraceEvent = nullptr;
450450
uint64_t InstanceID = 0;
451-
auto StreamID = detail::getActiveXPTIStreamID();
451+
uint8_t StreamID;
452452
// Only enable instrumentation if there are subscribes to the SYCL
453453
// stream
454-
const bool xptiEnabled = xptiCheckTraceEnabled(StreamID);
454+
const bool xptiEnabled = xptiTraceEnabled();
455455
if (xptiEnabled) {
456+
StreamID = detail::getActiveXPTIStreamID();
456457
std::tie(CmdTraceEvent, InstanceID) = emitKernelInstrumentationData(
457458
StreamID, KernelImplPtr, CodeLoc, IsTopCodeLoc,
458459
*KData.getDeviceKernelInfoPtr(), this, KData.getNDRDesc(),
@@ -843,8 +844,12 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {
843844
void *TelemetryEvent = nullptr;
844845
uint64_t IId;
845846
std::string Name;
846-
auto StreamID = detail::getActiveXPTIStreamID();
847-
TelemetryEvent = instrumentationProlog(CodeLoc, Name, StreamID, IId);
847+
uint8_t StreamID;
848+
const bool xptiEnabled = xptiTraceEnabled();
849+
if (xptiEnabled) {
850+
StreamID = detail::getActiveXPTIStreamID();
851+
TelemetryEvent = instrumentationProlog(CodeLoc, Name, StreamID, IId);
852+
}
848853
#endif
849854

850855
if (!MGraph.expired()) {
@@ -926,7 +931,9 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {
926931
#ifdef XPTI_ENABLE_INSTRUMENTATION
927932
// There is an early return in instrumentationEpilog() if no subscribers are
928933
// subscribing to queue.wait().
929-
instrumentationEpilog(TelemetryEvent, Name, StreamID, IId);
934+
if (xptiEnabled) {
935+
instrumentationEpilog(TelemetryEvent, Name, StreamID, IId);
936+
}
930937
#endif
931938
}
932939

0 commit comments

Comments
 (0)