Skip to content

Commit d91e00a

Browse files
committed
Reduce impact of tracing layer enabled with no tracers
- Added calls to check the existence of active tracers and callbacks before generating tracing such that the impact of tracing is reduced until enabled. Signed-off-by: Neil R. Spruit <[email protected]>
1 parent 2938500 commit d91e00a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

source/layers/tracing/tracing_imp.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2025 Intel Corporation
2+
* Copyright (C) 2020-2026 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -170,7 +170,7 @@ class APITracerCallbackDataImp {
170170
currentTracerArray = \
171171
(tracing_layer::tracer_array_t *) \
172172
tracing_layer::pGlobalAPITracerContextImp->getActiveTracersList(); \
173-
if (currentTracerArray) { \
173+
if (currentTracerArray && currentTracerArray->tracerArrayCount > 0) { \
174174
for (size_t i = 0; i < currentTracerArray->tracerArrayCount; i++) { \
175175
tracerType prologueCallbackPtr; \
176176
tracerType epilogue_callback_ptr; \
@@ -201,7 +201,7 @@ class APITracerCallbackDataImp {
201201
currentTracerArray = \
202202
(tracing_layer::tracer_array_t *) \
203203
tracing_layer::pGlobalAPITracerContextImp->getActiveTracersList(); \
204-
if (currentTracerArray) { \
204+
if (currentTracerArray && currentTracerArray->tracerArrayCount > 0) { \
205205
for (size_t i = 0; i < currentTracerArray->tracerArrayCount; i++){ \
206206
tracerType prologueCallbackPtr; \
207207
tracerType epilogue_callback_ptr; \
@@ -237,6 +237,15 @@ APITracerWrapperImp(TFunction_pointer zeApiPtr, TParams paramsStruct,
237237
TRet ret {};
238238
std::vector<APITracerCallbackStateImp<TTracer>> *callbacks_prologs =
239239
&prologCallbacks;
240+
std::vector<APITracerCallbackStateImp<TTracer>> *callbacksEpilogs =
241+
&epilogCallbacks;
242+
// Fast path: if no callbacks are registered, directly call the API
243+
if (callbacks_prologs->empty() && callbacksEpilogs->empty()) {
244+
ret = zeApiPtr(args...);
245+
tracing_layer::tracingInProgress = 0;
246+
tracing_layer::pGlobalAPITracerContextImp->releaseActivetracersList();
247+
return ret;
248+
}
240249

241250
std::vector<void *> ppTracerInstanceUserData;
242251
ppTracerInstanceUserData.resize(callbacks_prologs->size());
@@ -248,8 +257,6 @@ APITracerWrapperImp(TFunction_pointer zeApiPtr, TParams paramsStruct,
248257
&ppTracerInstanceUserData[i]);
249258
}
250259
ret = zeApiPtr(args...);
251-
std::vector<APITracerCallbackStateImp<TTracer>> *callbacksEpilogs =
252-
&epilogCallbacks;
253260
for (size_t i = 0; i < callbacksEpilogs->size(); i++) {
254261
if (callbacksEpilogs->at(i).current_api_callback != nullptr)
255262
callbacksEpilogs->at(i).current_api_callback(

0 commit comments

Comments
 (0)