@@ -30,6 +30,8 @@ constexpr int GMinVer = 1;
30
30
#ifdef XPTI_ENABLE_INSTRUMENTATION
31
31
static xpti_td *GCallEvent = nullptr ;
32
32
static xpti_td *GDebugEvent = nullptr ;
33
+ static uint8_t GCallStreamID = 0 ;
34
+ static uint8_t GDebugStreamID = 0 ;
33
35
#endif // XPTI_ENABLE_INSTRUMENTATION
34
36
35
37
enum class ZEApiKind {
@@ -43,9 +45,10 @@ void enableZeTracing() {
43
45
if (!xptiTraceEnabled ())
44
46
return ;
45
47
46
- xptiRegisterStream (ZE_CALL_STREAM_NAME);
48
+ // Initialize the required streams and stream ID for use
49
+ GCallStreamID = xptiRegisterStream (ZE_CALL_STREAM_NAME);
47
50
xptiInitialize (ZE_CALL_STREAM_NAME, GMajVer, GMinVer, GVerStr);
48
- xptiRegisterStream (ZE_DEBUG_STREAM_NAME);
51
+ GDebugStreamID = xptiRegisterStream (ZE_DEBUG_STREAM_NAME);
49
52
xptiInitialize (ZE_DEBUG_STREAM_NAME, GMajVer, GMinVer, GVerStr);
50
53
51
54
uint64_t Dummy;
@@ -84,39 +87,51 @@ void enableZeTracing() {
84
87
#define _ZE_API (call, domain, cb, params_type ) \
85
88
Prologue.domain .cb = [](params_type *Params, ze_result_t , void *, void **) { \
86
89
if (xptiTraceEnabled ()) { \
87
- uint8_t CallStreamID = xptiRegisterStream (ZE_CALL_STREAM_NAME); \
88
- uint8_t DebugStreamID = xptiRegisterStream (ZE_DEBUG_STREAM_NAME); \
89
- CallCorrelationID = xptiGetUniqueId (); \
90
- DebugCorrelationID = xptiGetUniqueId (); \
91
90
const char *FuncName = #call; \
92
- xptiNotifySubscribers ( \
93
- CallStreamID, (uint16_t )xpti::trace_point_type_t ::function_begin, \
94
- GCallEvent, nullptr , CallCorrelationID, FuncName); \
95
- uint32_t FuncID = static_cast <uint32_t >(ZEApiKind::call); \
96
- xpti::function_with_args_t Payload{FuncID, FuncName, Params, nullptr , \
97
- nullptr }; \
98
- xptiNotifySubscribers ( \
99
- DebugStreamID, \
100
- (uint16_t )xpti::trace_point_type_t ::function_with_args_begin, \
101
- GDebugEvent, nullptr , DebugCorrelationID, &Payload); \
91
+ if (xptiCheckTraceEnabled ( \
92
+ GCallStreamID, \
93
+ (uint16_t )xpti::trace_point_type_t ::function_begin)) { \
94
+ CallCorrelationID = xptiGetUniqueId (); \
95
+ xptiNotifySubscribers ( \
96
+ GCallStreamID, (uint16_t )xpti::trace_point_type_t ::function_begin, \
97
+ GCallEvent, nullptr , CallCorrelationID, FuncName); \
98
+ } \
99
+ if (xptiCheckTraceEnabled ( \
100
+ GDebugStreamID, \
101
+ (uint16_t )xpti::trace_point_type_t ::function_with_args_begin)) { \
102
+ DebugCorrelationID = xptiGetUniqueId (); \
103
+ uint32_t FuncID = static_cast <uint32_t >(ZEApiKind::call); \
104
+ xpti::function_with_args_t Payload{FuncID, FuncName, Params, nullptr , \
105
+ nullptr }; \
106
+ xptiNotifySubscribers ( \
107
+ GDebugStreamID, \
108
+ (uint16_t )xpti::trace_point_type_t ::function_with_args_begin, \
109
+ GDebugEvent, nullptr , DebugCorrelationID, &Payload); \
110
+ } \
102
111
} \
103
112
}; \
104
113
Epilogue.domain .cb = [](params_type *Params, ze_result_t Result, void *, \
105
114
void **) { \
106
115
if (xptiTraceEnabled ()) { \
107
- uint8_t CallStreamID = xptiRegisterStream (ZE_CALL_STREAM_NAME); \
108
- uint8_t DebugStreamID = xptiRegisterStream (ZE_DEBUG_STREAM_NAME); \
109
116
const char *FuncName = #call; \
110
- xptiNotifySubscribers (CallStreamID, \
111
- (uint16_t )xpti::trace_point_type_t ::function_end, \
112
- GCallEvent, nullptr , CallCorrelationID, FuncName); \
113
- uint32_t FuncID = static_cast <uint32_t >(ZEApiKind::call); \
114
- xpti::function_with_args_t Payload{FuncID, FuncName, Params, &Result, \
115
- nullptr }; \
116
- xptiNotifySubscribers ( \
117
- DebugStreamID, \
118
- (uint16_t )xpti::trace_point_type_t ::function_with_args_end, \
119
- GDebugEvent, nullptr , DebugCorrelationID, &Payload); \
117
+ if (xptiCheckTraceEnabled ( \
118
+ GCallStreamID, \
119
+ (uint16_t )xpti::trace_point_type_t ::function_end)) { \
120
+ xptiNotifySubscribers ( \
121
+ GCallStreamID, (uint16_t )xpti::trace_point_type_t ::function_end, \
122
+ GCallEvent, nullptr , CallCorrelationID, FuncName); \
123
+ } \
124
+ if (xptiCheckTraceEnabled ( \
125
+ GDebugStreamID, \
126
+ (uint16_t )xpti::trace_point_type_t ::function_with_args_end)) { \
127
+ uint32_t FuncID = static_cast <uint32_t >(ZEApiKind::call); \
128
+ xpti::function_with_args_t Payload{FuncID, FuncName, Params, &Result, \
129
+ nullptr }; \
130
+ xptiNotifySubscribers ( \
131
+ GDebugStreamID, \
132
+ (uint16_t )xpti::trace_point_type_t ::function_with_args_end, \
133
+ GDebugEvent, nullptr , DebugCorrelationID, &Payload); \
134
+ } \
120
135
} \
121
136
};
122
137
0 commit comments