Skip to content

Commit ddf6e23

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 <neil.r.spruit@intel.com>
1 parent f096108 commit ddf6e23

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

source/layers/tracing/tracing_imp.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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)