diff --git a/sycl/source/detail/event_impl.cpp b/sycl/source/detail/event_impl.cpp index 6bcc03a2c99ec..37d2a9672a6f3 100644 --- a/sycl/source/detail/event_impl.cpp +++ b/sycl/source/detail/event_impl.cpp @@ -220,10 +220,11 @@ void event_impl::setSubmittedQueue(std::weak_ptr SubmittedQueue) { MSubmittedQueue = std::move(SubmittedQueue); } -void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID, +#ifdef XPTI_ENABLE_INSTRUMENTATION +void *event_impl::instrumentationProlog(std::string &Name, + xpti::stream_id_t StreamID, uint64_t &IId) const { void *TraceEvent = nullptr; -#ifdef XPTI_ENABLE_INSTRUMENTATION constexpr uint16_t NotificationTraceType = xpti::trace_wait_begin; if (!xptiCheckTraceEnabled(StreamID, NotificationTraceType)) return TraceEvent; @@ -258,14 +259,13 @@ void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID, xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, WaitEvent, IId, static_cast(Name.c_str())); TraceEvent = (void *)WaitEvent; -#endif return TraceEvent; } void event_impl::instrumentationEpilog(void *TelemetryEvent, const std::string &Name, - int32_t StreamID, uint64_t IId) const { -#ifdef XPTI_ENABLE_INSTRUMENTATION + xpti::stream_id_t StreamID, + uint64_t IId) const { constexpr uint16_t NotificationTraceType = xpti::trace_wait_end; if (!(xptiCheckTraceEnabled(StreamID, NotificationTraceType) && TelemetryEvent)) @@ -275,8 +275,8 @@ void event_impl::instrumentationEpilog(void *TelemetryEvent, (xpti::trace_event_data_t *)TelemetryEvent; xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, TraceEvent, IId, static_cast(Name.c_str())); -#endif } +#endif // XPTI_ENABLE_INSTRUMENTATION void event_impl::wait(bool *Success) { if (MState == HES_Discarded) @@ -293,7 +293,7 @@ void event_impl::wait(bool *Success) { void *TelemetryEvent = nullptr; uint64_t IId = 0; std::string Name; - int32_t StreamID = xptiRegisterStream(SYCL_STREAM_NAME); + xpti::stream_id_t StreamID = xptiRegisterStream(SYCL_STREAM_NAME); TelemetryEvent = instrumentationProlog(Name, StreamID, IId); #endif diff --git a/sycl/source/detail/event_impl.hpp b/sycl/source/detail/event_impl.hpp index 21ba80f61775c..758f216ce96db 100644 --- a/sycl/source/detail/event_impl.hpp +++ b/sycl/source/detail/event_impl.hpp @@ -372,11 +372,13 @@ class event_impl { protected: // When instrumentation is enabled emits trace event for event wait begin and // returns the telemetry event generated for the wait - void *instrumentationProlog(std::string &Name, int32_t StreamID, +#ifdef XPTI_ENABLE_INSTRUMENTATION + void *instrumentationProlog(std::string &Name, xpti::stream_id_t StreamID, uint64_t &instance_id) const; // Uses events generated by the Prolog and emits event wait done event void instrumentationEpilog(void *TelementryEvent, const std::string &Name, - int32_t StreamID, uint64_t IId) const; + xpti::stream_id_t StreamID, uint64_t IId) const; +#endif void checkProfilingPreconditions() const; std::atomic MEvent = nullptr; diff --git a/sycl/source/detail/graph/graph_impl.cpp b/sycl/source/detail/graph/graph_impl.cpp index 5928cec31f784..62dc1f577ca68 100644 --- a/sycl/source/detail/graph/graph_impl.cpp +++ b/sycl/source/detail/graph/graph_impl.cpp @@ -744,7 +744,7 @@ ur_exp_command_buffer_sync_point_t exec_graph_impl::enqueueNodeDirect( #ifdef XPTI_ENABLE_INSTRUMENTATION const bool xptiEnabled = xptiTraceEnabled(); - int32_t StreamID = xpti::invalid_id<>; + auto StreamID = xpti::invalid_id; xpti_td *CmdTraceEvent = nullptr; uint64_t InstanceID = 0; if (xptiEnabled) { diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index c2a66f485d634..e7b163ddd62e6 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -503,15 +503,12 @@ event queue_impl::submitMemOpHelper(const std::vector &DepEvents, return submitWithHandler(DepEvents, CallerNeedsEvent, HandlerFunc); } +#ifdef XPTI_ENABLE_INSTRUMENTATION void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc, - std::string &Name, int32_t StreamID, + std::string &Name, + xpti::stream_id_t StreamID, uint64_t &IId) { void *TraceEvent = nullptr; - (void)CodeLoc; - (void)Name; - (void)StreamID; - (void)IId; -#ifdef XPTI_ENABLE_INSTRUMENTATION constexpr uint16_t NotificationTraceType = xpti::trace_wait_begin; if (!xptiCheckTraceEnabled(StreamID, NotificationTraceType)) return TraceEvent; @@ -556,17 +553,12 @@ void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc, static_cast(Name.c_str())); TraceEvent = (void *)WaitEvent; } -#endif return TraceEvent; } void queue_impl::instrumentationEpilog(void *TelemetryEvent, std::string &Name, - int32_t StreamID, uint64_t IId) { - (void)TelemetryEvent; - (void)Name; - (void)StreamID; - (void)IId; -#ifdef XPTI_ENABLE_INSTRUMENTATION + xpti::stream_id_t StreamID, + uint64_t IId) { constexpr uint16_t NotificationTraceType = xpti::trace_wait_end; if (!(xptiCheckTraceEnabled(StreamID, NotificationTraceType) && TelemetryEvent)) @@ -576,9 +568,10 @@ void queue_impl::instrumentationEpilog(void *TelemetryEvent, std::string &Name, (xpti::trace_event_data_t *)TelemetryEvent; xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, TraceEvent, IId, static_cast(Name.c_str())); -#endif } +#endif // XPTI_ENABLE_INSTRUMENTATION + void queue_impl::wait(const detail::code_location &CodeLoc) { (void)CodeLoc; #ifdef XPTI_ENABLE_INSTRUMENTATION @@ -586,7 +579,7 @@ void queue_impl::wait(const detail::code_location &CodeLoc) { void *TelemetryEvent = nullptr; uint64_t IId; std::string Name; - int32_t StreamID = xpti::invalid_id<>; + auto StreamID = xpti::invalid_id; if (xptiEnabled) { StreamID = xptiRegisterStream(SYCL_STREAM_NAME); TelemetryEvent = instrumentationProlog(CodeLoc, Name, StreamID, IId); diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index b3e7eb4bbe17f..e39cf23d74dbd 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -950,14 +950,16 @@ class queue_impl : public std::enable_shared_from_this { MemMngrFuncT MemMngrFunc, MemMngrArgTs &&...MemOpArgs); +#ifdef XPTI_ENABLE_INSTRUMENTATION // When instrumentation is enabled emits trace event for wait begin and // returns the telemetry event generated for the wait void *instrumentationProlog(const detail::code_location &CodeLoc, - std::string &Name, int32_t StreamID, + std::string &Name, xpti::stream_id_t StreamID, uint64_t &iid); // Uses events generated by the Prolog and emits wait done event void instrumentationEpilog(void *TelementryEvent, std::string &Name, - int32_t StreamID, uint64_t IId); + xpti::stream_id_t StreamID, uint64_t IId); +#endif // We need to emit a queue_create notification when a queue object is created void constructorNotification(); diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index d26ccba7895aa..7d6029d4e1c0d 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -90,7 +90,7 @@ static bool CurrentCodeLocationValid() { (FunctionName && FunctionName[0] != '\0'); } -void emitInstrumentationGeneral(uint32_t StreamID, uint64_t InstanceID, +void emitInstrumentationGeneral(xpti::stream_id_t StreamID, uint64_t InstanceID, xpti_td *TraceEvent, uint16_t Type, const void *Addr) { if (!(xptiCheckTraceEnabled(StreamID, Type) && TraceEvent)) @@ -2105,7 +2105,8 @@ void instrumentationFillCommonData(const std::string &KernelName, #ifdef XPTI_ENABLE_INSTRUMENTATION std::pair emitKernelInstrumentationData( - int32_t StreamID, const std::shared_ptr &SyclKernel, + xpti::stream_id_t StreamID, + const std::shared_ptr &SyclKernel, const detail::code_location &CodeLoc, bool IsTopCodeLoc, const std::string_view SyclKernelName, KernelNameBasedCacheT *KernelNameBasedCachePtr, queue_impl *Queue, diff --git a/sycl/source/detail/scheduler/commands.hpp b/sycl/source/detail/scheduler/commands.hpp index 5093f57fac45d..f23f1d3c4728b 100644 --- a/sycl/source/detail/scheduler/commands.hpp +++ b/sycl/source/detail/scheduler/commands.hpp @@ -23,6 +23,10 @@ #include #include +#ifdef XPTI_ENABLE_INSTRUMENTATION +#include +#endif + namespace sycl { inline namespace _V1 { @@ -33,7 +37,7 @@ class node_impl; namespace detail { #ifdef XPTI_ENABLE_INSTRUMENTATION -void emitInstrumentationGeneral(uint32_t StreamID, uint64_t InstanceID, +void emitInstrumentationGeneral(xpti::stream_id_t StreamID, uint64_t InstanceID, xpti_td *TraceEvent, uint16_t Type, const void *Addr); #endif @@ -347,10 +351,12 @@ class Command { /// The event for node_create and task_begin. void *MTraceEvent = nullptr; +#ifdef XPTI_ENABLE_INSTRUMENTATION /// The stream under which the traces are emitted. /// /// Stream ids are positive integers and we set it to an invalid value. - int32_t MStreamID = -1; + xpti::stream_id_t MStreamID = xpti::invalid_id; +#endif /// Reserved for storing the object address such as SPIR-V or memory object /// address. void *MAddress = nullptr; @@ -686,7 +692,8 @@ class ExecCGCommand : public Command { // Very close to ExecCGCommand::emitInstrumentationData content. #ifdef XPTI_ENABLE_INSTRUMENTATION std::pair emitKernelInstrumentationData( - int32_t StreamID, const std::shared_ptr &SyclKernel, + xpti::stream_id_t StreamID, + const std::shared_ptr &SyclKernel, const detail::code_location &CodeLoc, bool IsTopCodeLoc, std::string_view SyclKernelName, KernelNameBasedCacheT *KernelNameBasedCachePtr, queue_impl *Queue, diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 1e729b2100eb6..b23ea75eacb24 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -580,7 +580,7 @@ event handler::finalize() { #endif auto EnqueueKernel = [&]() { #ifdef XPTI_ENABLE_INSTRUMENTATION - int32_t StreamID = xpti::invalid_id<>; + auto StreamID = xpti::invalid_id; xpti_td *CmdTraceEvent = nullptr; uint64_t InstanceID = 0; if (xptiEnabled) { diff --git a/sycl/unittests/scheduler/CMakeLists.txt b/sycl/unittests/scheduler/CMakeLists.txt index afc0e185eb7c0..7e181f64931d0 100644 --- a/sycl/unittests/scheduler/CMakeLists.txt +++ b/sycl/unittests/scheduler/CMakeLists.txt @@ -23,3 +23,8 @@ add_sycl_unittest(SchedulerTests OBJECT HostTaskAndBarrier.cpp BarrierDependencies.cpp ) + +if (SYCL_ENABLE_XPTI_TRACING) + target_compile_definitions(SchedulerTests + PRIVATE XPTI_ENABLE_INSTRUMENTATION XPTI_STATIC_LIBRARY) +endif() diff --git a/xpti/include/xpti/xpti_data_types.h b/xpti/include/xpti/xpti_data_types.h index fe469390b7464..41d6775cd3802 100644 --- a/xpti/include/xpti/xpti_data_types.h +++ b/xpti/include/xpti/xpti_data_types.h @@ -318,9 +318,7 @@ struct uid_t { return p1 == rhs.p1 && p2 == rhs.p2; } }; -} // namespace xpti -namespace xpti { template constexpr T invalid_id = std::numeric_limits::max(); constexpr uint64_t invalid_uid = 0; @@ -352,6 +350,8 @@ enum class payload_flag_t { HashAvailable = 2 << 16 }; +using stream_id_t = uint8_t; + // // Helper macros for creating new tracepoint and // event types diff --git a/xpti/include/xpti/xpti_trace_framework.h b/xpti/include/xpti/xpti_trace_framework.h index a9d206933798a..2ac5494d79960 100644 --- a/xpti/include/xpti/xpti_trace_framework.h +++ b/xpti/include/xpti/xpti_trace_framework.h @@ -476,7 +476,7 @@ XPTI_EXPORT_API uint64_t xptiRegisterPayload(xpti::payload_t *payload); /// @param stream_name The stream name that needs to be registered. /// @return The stream ID. If the stream has already been registered, the /// previously generated stream ID is returned. -XPTI_EXPORT_API uint8_t xptiRegisterStream(const char *stream_name); +XPTI_EXPORT_API xpti::stream_id_t xptiRegisterStream(const char *stream_name); /// @brief Unregister a stream by its name /// @details Unregistering a stream will invalidate the stream ID associated @@ -755,7 +755,7 @@ XPTI_EXPORT_API xpti::result_t xptiDeleteTracepoint(xpti_tracepoint_t *tp); /// 3. XPTI_RESULT_UNDELETE when the registration is for a callback /// that had been previously unregistered. XPTI_EXPORT_API xpti::result_t -xptiRegisterCallback(uint8_t stream_id, uint16_t trace_type, +xptiRegisterCallback(xpti::stream_id_t stream_id, uint16_t trace_type, xpti::tracepoint_callback_api_t cb); /// @brief Unregisters a previously registered callback for a trace point type @@ -776,7 +776,7 @@ xptiRegisterCallback(uint8_t stream_id, uint16_t trace_type, /// 3. XPTI_RESULT_NOTFOUND if the callback has not been previously /// registered. XPTI_EXPORT_API xpti::result_t -xptiUnregisterCallback(uint8_t stream_id, uint16_t trace_type, +xptiUnregisterCallback(xpti::stream_id_t stream_id, uint16_t trace_type, xpti::tracepoint_callback_api_t cb); /// @brief Notifies all registered subscribers that an event has occurred @@ -810,7 +810,7 @@ xptiUnregisterCallback(uint8_t stream_id, uint16_t trace_type, /// function_begin and function_end, the per_instance_user_data value /// must be populated to not get this return value. XPTI_EXPORT_API xpti::result_t -xptiNotifySubscribers(uint8_t stream_id, uint16_t trace_type, +xptiNotifySubscribers(xpti::stream_id_t stream_id, uint16_t trace_type, xpti::trace_event_data_t *parent, xpti::trace_event_data_t *object, uint64_t instance, const void *per_instance_user_data); @@ -860,7 +860,8 @@ XPTI_EXPORT_API bool xptiTraceEnabled(); /// @param stream Stream ID /// @param ttype The trace type within the stream /// @return bool that indicates whether it is enabled or not -XPTI_EXPORT_API bool xptiCheckTraceEnabled(uint16_t stream, uint16_t ttype = 0); +XPTI_EXPORT_API bool xptiCheckTraceEnabled(xpti::stream_id_t stream, + uint16_t ttype = 0); /// @brief Resets internal state /// @details This method is currently ONLY used by the tests and is NOT @@ -936,7 +937,7 @@ xptiRegisterTracepointScope(const char *funcName, const char *fileName, /// @details This function is used to get the default stream ID that is /// currently set in the tracing framework. /// @return The default stream ID. -XPTI_EXPORT_API uint8_t xptiGetDefaultStreamID(); +XPTI_EXPORT_API xpti::stream_id_t xptiGetDefaultStreamID(); /// @brief Sets the default stream ID. /// @details This function is used to set the default stream ID in the tracing @@ -945,7 +946,8 @@ XPTI_EXPORT_API uint8_t xptiGetDefaultStreamID(); /// /// @param defaultStreamID The stream ID to be set as default. /// @return Result of the operation, success or failure. -XPTI_EXPORT_API xpti::result_t xptiSetDefaultStreamID(uint8_t defaultStreamID); +XPTI_EXPORT_API xpti::result_t +xptiSetDefaultStreamID(xpti::stream_id_t defaultStreamID); /// @brief Retrieves the default event type. /// @details This function is used to get the default event type that is @@ -1042,7 +1044,8 @@ typedef xpti::result_t (*xpti_add_metadata_t)(xpti::trace_event_data_t *, const char *, xpti::object_id_t); typedef xpti::metadata_t *(*xpti_query_metadata_t)(xpti::trace_event_data_t *); typedef bool (*xpti_trace_enabled_t)(); -typedef bool (*xpti_check_trace_enabled_t)(uint16_t stream, uint16_t ttype); +typedef bool (*xpti_check_trace_enabled_t)(xpti::stream_id_t stream, + uint16_t ttype); typedef void (*xpti_force_set_trace_enabled_t)(bool); typedef void (*xpti_release_event_t)(xpti::trace_event_data_t *); typedef void (*xpti_enable_tracepoint_scope_notification_t)(bool); @@ -1056,8 +1059,8 @@ typedef const xpti_tracepoint_t *(*xpti_register_tracepoint_scope_t)( typedef xpti::result_t (*xpti_set_trace_point_scope_data_t)( xpti_tracepoint_t *); typedef void (*xpti_unset_trace_point_scope_data_t)(); -typedef uint8_t (*xpti_get_default_stream_id_t)(); -typedef xpti::result_t (*xpti_set_default_stream_id_t)(uint8_t); +typedef xpti::stream_id_t (*xpti_get_default_stream_id_t)(); +typedef xpti::result_t (*xpti_set_default_stream_id_t)(xpti::stream_id_t); typedef xpti::trace_event_type_t (*xpti_get_default_event_type_t)(); typedef xpti::result_t (*xpti_set_default_event_type_t)( xpti::trace_event_type_t); diff --git a/xpti/include/xpti/xpti_trace_framework.hpp b/xpti/include/xpti/xpti_trace_framework.hpp index 3e7145bbaf823..db676c5627f31 100644 --- a/xpti/include/xpti/xpti_trace_framework.hpp +++ b/xpti/include/xpti/xpti_trace_framework.hpp @@ -1124,7 +1124,7 @@ class tracepoint_scope_t { /// /// @return The stream ID. /// - uint8_t streamId() { return MStreamId; } + stream_id_t streamId() { return MStreamId; } /// @brief Sets the stream for the tracepoint scoped notification /// @@ -1152,7 +1152,7 @@ class tracepoint_scope_t { /// with. /// @return tracepoint_scope_t& A reference to the tracepoint scope /// - tracepoint_scope_t &stream(uint8_t streamId) { + tracepoint_scope_t &stream(stream_id_t streamId) { // If tracing is not enabled, don't do anything if (xptiTraceEnabled()) { MStreamId = streamId; @@ -1355,7 +1355,7 @@ class tracepoint_scope_t { /// from self notification uint64_t MScopedCorrelationId = 0; /// Stores the ID of the stream - uint8_t MStreamId = 0; + stream_id_t MStreamId = 0; /// Stores the ID of the default stream use for self notification; the /// system sets the default stream ID at the start of the program uint8_t MDefaultStreamId = 0; @@ -1397,7 +1397,7 @@ class notify_scope_t { /// @param UserData The user data. /// @param traceType The type of the trace event. Defaults to function_begin. /// - notify_scope_t(uint8_t streamId, xpti::trace_event_data_t *traceEvent, + notify_scope_t(stream_id_t streamId, xpti::trace_event_data_t *traceEvent, const char *UserData, uint16_t traceType = (uint16_t) xpti::trace_point_type_t::function_begin) diff --git a/xpti/src/xpti_proxy.cpp b/xpti/src/xpti_proxy.cpp index a735ecb283977..6400b6824c1a2 100644 --- a/xpti/src/xpti_proxy.cpp +++ b/xpti/src/xpti_proxy.cpp @@ -454,7 +454,7 @@ XPTI_EXPORT_API const xpti::payload_t *xptiQueryPayloadByUID(uint64_t uid) { } XPTI_EXPORT_API xpti::result_t -xptiRegisterCallback(uint8_t stream_id, uint16_t trace_type, +xptiRegisterCallback(xpti::stream_id_t stream_id, uint16_t trace_type, xpti::tracepoint_callback_api_t cb) { if (xpti::ProxyLoader::instance().noErrors()) { auto f = @@ -467,7 +467,7 @@ xptiRegisterCallback(uint8_t stream_id, uint16_t trace_type, } XPTI_EXPORT_API xpti::result_t -xptiUnregisterCallback(uint8_t stream_id, uint16_t trace_type, +xptiUnregisterCallback(xpti::stream_id_t stream_id, uint16_t trace_type, xpti::tracepoint_callback_api_t cb) { if (xpti::ProxyLoader::instance().noErrors()) { auto f = @@ -480,7 +480,7 @@ xptiUnregisterCallback(uint8_t stream_id, uint16_t trace_type, } XPTI_EXPORT_API xpti::result_t -xptiNotifySubscribers(uint8_t stream_id, uint16_t trace_type, +xptiNotifySubscribers(xpti::stream_id_t stream_id, uint16_t trace_type, xpti::trace_event_data_t *parent, xpti::trace_event_data_t *object, uint64_t instance, const void *user_data) { @@ -505,7 +505,8 @@ XPTI_EXPORT_API bool xptiTraceEnabled() { return false; } -XPTI_EXPORT_API bool xptiCheckTraceEnabled(uint16_t stream, uint16_t ttype) { +XPTI_EXPORT_API bool xptiCheckTraceEnabled(xpti::stream_id_t stream, + uint16_t ttype) { if (xpti::ProxyLoader::instance().noErrors()) { auto f = xpti::ProxyLoader::instance().functionByIndex(XPTI_CHECK_TRACE_ENABLED); @@ -681,7 +682,7 @@ xptiRegisterTracepointScope(const char *FuncName, const char *FileName, return nullptr; } -XPTI_EXPORT_API uint8_t xptiGetDefaultStreamID() { +XPTI_EXPORT_API xpti::stream_id_t xptiGetDefaultStreamID() { if (xpti::ProxyLoader::instance().noErrors()) { auto f = xpti::ProxyLoader::instance().functionByIndex( XPTI_GET_DEFAULT_STREAM_ID); @@ -689,10 +690,11 @@ XPTI_EXPORT_API uint8_t xptiGetDefaultStreamID() { return (*(xpti_get_default_stream_id_t)f)(); } } - return xpti::invalid_id; + return xpti::invalid_id; } -XPTI_EXPORT_API xpti::result_t xptiSetDefaultStreamID(uint8_t stream_id) { +XPTI_EXPORT_API xpti::result_t +xptiSetDefaultStreamID(xpti::stream_id_t stream_id) { if (xpti::ProxyLoader::instance().noErrors()) { auto f = xpti::ProxyLoader::instance().functionByIndex( XPTI_SET_DEFAULT_STREAM_ID); diff --git a/xptifw/src/xpti_trace_framework.cpp b/xptifw/src/xpti_trace_framework.cpp index 264ad2122ecc4..14c79728dff6b 100644 --- a/xptifw/src/xpti_trace_framework.cpp +++ b/xptifw/src/xpti_trace_framework.cpp @@ -1489,10 +1489,10 @@ class Notifications { /// @typedef stream_cb_t /// @brief Maps a stream ID to its corresponding callbacks for different /// trace types - /// @details This unordered map uses a uint16_t as the key for the stream - /// ID, and cb_t to map the stream to registered callbacks for each trace - /// type - using stream_cb_t = emhash7::HashMap; + /// @details This unordered map uses the xpti::strem_id_t as the key for the + /// stream ID, and cb_t to map the stream to registered callbacks for each + /// trace type + using stream_cb_t = emhash7::HashMap; /// @typedef statistics_t /// @brief Keeps track of statistics, typically counts, associated with @@ -1512,11 +1512,11 @@ class Notifications { /// @typedef stream_flags_t /// @brief Maps a stream ID to its corresponding trace flags for different /// trace point types. - /// @details This unordered map uses a uint8_t as the key for trace type, - /// and trace_flags_t to map the trace type to their boolean that indiciates - /// whether a callback has been registered for this trace type in the given - /// stream. - using stream_flags_t = emhash7::HashMap; + /// @details This unordered map uses the xpti::stream_id_t as the key for + /// trace type, and trace_flags_t to map the trace type to their boolean that + /// indiciates whether a callback has been registered for this trace type in + /// the given stream. + using stream_flags_t = emhash7::HashMap; /// @brief Registers a callback function for a specific trace type and stream /// ID. @@ -1545,7 +1545,8 @@ class Notifications { /// previously unregistered and is now re-enabled. /// - xpti::result_t registerCallback(uint8_t StreamID, uint16_t TraceType, + xpti::result_t registerCallback(xpti::stream_id_t StreamID, + uint16_t TraceType, xpti::tracepoint_callback_api_t cbFunc) { if (!cbFunc) return xpti::result_t::XPTI_RESULT_INVALIDARG; @@ -1630,7 +1631,8 @@ class Notifications { /// `xpti::result_t::XPTI_RESULT_NOTFOUND` if the callback is not /// found for the specified trace type and stream ID. - xpti::result_t unregisterCallback(uint8_t StreamID, uint16_t TraceType, + xpti::result_t unregisterCallback(xpti::stream_id_t StreamID, + uint16_t TraceType, xpti::tracepoint_callback_api_t cbFunc) { if (!cbFunc) return xpti::result_t::XPTI_RESULT_INVALIDARG; @@ -1688,7 +1690,7 @@ class Notifications { /// modifying the callbacks and stream flags. If the implementation evolves to /// use reader-writer locks, a reader lock should be used where appropriate. - xpti::result_t unregisterStream(uint8_t StreamID) { + xpti::result_t unregisterStream(xpti::stream_id_t StreamID) { // If there are no callbacks registered for the requested stream ID, we // return not found; use reader lock here if the implementation moves to // reader-writer locks. @@ -1726,7 +1728,7 @@ class Notifications { /// @return Returns true if the trace type ihas subscribers in the stream; /// otherwise, returns false. - bool checkSubscribed(uint16_t StreamID, uint16_t TraceType) { + bool checkSubscribed(xpti::stream_id_t StreamID, uint16_t TraceType) { if (StreamID == 0) return false; @@ -1791,7 +1793,8 @@ class Notifications { /// function also updates the event occurrence count in a thread-safe /// manner. - xpti::result_t notifySubscribers(uint16_t StreamID, uint16_t TraceType, + xpti::result_t notifySubscribers(xpti::stream_id_t StreamID, + uint16_t TraceType, xpti::trace_event_data_t *Parent, xpti::trace_event_data_t *Object, uint64_t InstanceNo, const void *UserData) { @@ -2374,17 +2377,20 @@ class Framework { return g_tls_temp_scope_data; } - xpti::result_t registerCallback(uint8_t StreamID, uint16_t TraceType, + xpti::result_t registerCallback(xpti::stream_id_t StreamID, + uint16_t TraceType, xpti::tracepoint_callback_api_t cbFunc) { return MNotifier.registerCallback(StreamID, TraceType, cbFunc); } - xpti::result_t unregisterCallback(uint8_t StreamID, uint16_t TraceType, + xpti::result_t unregisterCallback(xpti::stream_id_t StreamID, + uint16_t TraceType, xpti::tracepoint_callback_api_t cbFunc) { return MNotifier.unregisterCallback(StreamID, TraceType, cbFunc); } - xpti::result_t notifySubscribers(uint8_t StreamID, uint16_t TraceType, + xpti::result_t notifySubscribers(xpti::stream_id_t StreamID, + uint16_t TraceType, xpti::trace_event_data_t *Parent, xpti::trace_event_data_t *Object, uint64_t InstanceNo, const void *UserData) { @@ -3270,7 +3276,7 @@ xptiQueryPayload(xpti::trace_event_data_t *LookupObject) { /// efficient and do not introduce significant performance overhead. XPTI_EXPORT_API xpti::result_t -xptiRegisterCallback(uint8_t StreamID, uint16_t TraceType, +xptiRegisterCallback(xpti::stream_id_t StreamID, uint16_t TraceType, xpti::tracepoint_callback_api_t cbFunc) { return xpti::Framework::instance().registerCallback(StreamID, TraceType, cbFunc); @@ -3298,7 +3304,7 @@ xptiRegisterCallback(uint8_t StreamID, uint16_t TraceType, /// error code indicating the reason for failure. XPTI_EXPORT_API xpti::result_t -xptiUnregisterCallback(uint8_t StreamID, uint16_t TraceType, +xptiUnregisterCallback(xpti::stream_id_t StreamID, uint16_t TraceType, xpti::tracepoint_callback_api_t cbFunc) { return xpti::Framework::instance().unregisterCallback(StreamID, TraceType, cbFunc); @@ -3335,7 +3341,7 @@ xptiUnregisterCallback(uint8_t StreamID, uint16_t TraceType, /// relevant subscribers, or an error code indicating the reason for failure. XPTI_EXPORT_API xpti::result_t -xptiNotifySubscribers(uint8_t StreamID, uint16_t TraceType, +xptiNotifySubscribers(xpti::stream_id_t StreamID, uint16_t TraceType, xpti::trace_event_data_t *Parent, xpti::trace_event_data_t *Object, uint64_t InstanceNo, const void *TemporalUserData) { @@ -3376,7 +3382,8 @@ XPTI_EXPORT_API bool xptiTraceEnabled() { /// specified stream and trace type. Returns `true` if tracing is enabled, and /// `false` otherwise. -XPTI_EXPORT_API bool xptiCheckTraceEnabled(uint16_t stream, uint16_t ttype) { +XPTI_EXPORT_API bool xptiCheckTraceEnabled(xpti::stream_id_t stream, + uint16_t ttype) { return xpti::Framework::instance().checkTraceEnabled(stream, ttype); } @@ -3591,7 +3598,7 @@ XPTI_EXPORT_API bool xptiCheckTracepointScopeNotification() { /// /// @return The default stream ID as an 8-bit unsigned integer. -XPTI_EXPORT_API uint8_t xptiGetDefaultStreamID() { +XPTI_EXPORT_API xpti::stream_id_t xptiGetDefaultStreamID() { return xpti::g_default_stream_id; } @@ -3606,7 +3613,8 @@ XPTI_EXPORT_API uint8_t xptiGetDefaultStreamID() { /// @return xpti::result_t Returns XPTI_RESULT_SUCCESS on success, or an /// appropriate error code on failure. -XPTI_EXPORT_API xpti::result_t xptiSetDefaultStreamID(uint8_t DefaultStreamId) { +XPTI_EXPORT_API xpti::result_t +xptiSetDefaultStreamID(xpti::stream_id_t DefaultStreamId) { if ((int8_t)DefaultStreamId < 0) return xpti::result_t::XPTI_RESULT_INVALIDARG;