diff --git a/sycl/source/detail/pi.cpp b/sycl/source/detail/pi.cpp index a372f676b7016..48648aaf0640e 100644 --- a/sycl/source/detail/pi.cpp +++ b/sycl/source/detail/pi.cpp @@ -435,6 +435,8 @@ static void initializePlugins(std::vector &Plugins) { } #ifdef XPTI_ENABLE_INSTRUMENTATION + GlobalHandler::instance().getXPTIRegistry().initializeFrameworkOnce(); + if (!(xptiTraceEnabled() && !XPTIInitDone)) return; // Not sure this is the best place to initialize the framework; SYCL runtime diff --git a/sycl/source/detail/xpti_registry.hpp b/sycl/source/detail/xpti_registry.hpp index cd721bedd4a7a..f82a000b1378b 100644 --- a/sycl/source/detail/xpti_registry.hpp +++ b/sycl/source/detail/xpti_registry.hpp @@ -8,6 +8,7 @@ #pragma once +#include #include #include @@ -31,6 +32,12 @@ inline constexpr const char *SYCL_PIDEBUGCALL_STREAM_NAME = "sycl.pi.debug"; class XPTIRegistry { public: + void initializeFrameworkOnce() { +#ifdef XPTI_ENABLE_INSTRUMENTATION + std::call_once(MInitialized, [] { xptiFrameworkInitialize(); }); +#endif + } + /// Notifies XPTI subscribers about new stream. /// /// \param StreamName is a name of newly initialized stream. @@ -50,11 +57,13 @@ class XPTIRegistry { for (const auto &StreamName : MActiveStreams) { xptiFinalize(StreamName.c_str()); } + xptiFrameworkFinalize(); #endif // XPTI_ENABLE_INSTRUMENTATION } private: std::unordered_set MActiveStreams; + std::once_flag MInitialized; }; } // namespace detail } // namespace sycl diff --git a/xpti/include/xpti/xpti_trace_framework.h b/xpti/include/xpti/xpti_trace_framework.h index 82465daf37e03..d45c47fc47f14 100644 --- a/xpti/include/xpti/xpti_trace_framework.h +++ b/xpti/include/xpti/xpti_trace_framework.h @@ -35,6 +35,20 @@ extern "C" { +/// @brief Initializes XPTI framework. +/// @details Initialize XPTI framework resources. Each user of XPTI must call +/// this function prior to any other XPTI API call. It is framework's +/// responsibility to ensure that resources are initialized once. Each call to +/// this function must have corresponding call to xptiFrameworkFinalize() to +/// ensure resources are freed. +XPTI_EXPORT_API void xptiFrameworkInitialize(); + +/// @brief Deinitializes XPTI framework. +/// @details Call to this function decrements framework's internal reference +/// counter. Once its value is equal to zero, XPTI framework can release +/// resources and unload subscribers. +XPTI_EXPORT_API void xptiFrameworkFinalize(); + /// @brief Initialization function that is called when a new stream is generated /// @details When a runtime or application that uses XPTI instrumentation API /// starts to generate a new stream, a call to xptiInitialize() must be made to @@ -414,6 +428,8 @@ XPTI_EXPORT_API void xptiReset(); /// The proxy/stub library does not implement this function. XPTI_EXPORT_API void xptiForceSetTraceEnabled(bool yesOrNo); +typedef xpti::result_t (*xpti_framework_initialize_t)(); +typedef xpti::result_t (*xpti_framework_finalize_t)(); typedef xpti::result_t (*xpti_initialize_t)(const char *, uint32_t, uint32_t, const char *); typedef void (*xpti_finalize_t)(const char *); diff --git a/xpti/include/xpti/xpti_trace_framework.hpp b/xpti/include/xpti/xpti_trace_framework.hpp index 6e464d32290c9..a86d024a32aac 100644 --- a/xpti/include/xpti/xpti_trace_framework.hpp +++ b/xpti/include/xpti/xpti_trace_framework.hpp @@ -7,6 +7,7 @@ // #pragma once +#include #include #include #include @@ -273,6 +274,20 @@ class PlatformHelper { return false; } }; + +/// This is an implementation of a SpinLock synchronization primitive, that has +/// trivial constructor and destructor. +class SpinLock { +public: + void lock() { + while (MLock.test_and_set(std::memory_order_acquire)) + std::this_thread::yield(); + } + void unlock() { MLock.clear(std::memory_order_release); } + +private: + std::atomic_flag MLock = ATOMIC_FLAG_INIT; +}; } // namespace utils namespace framework { diff --git a/xpti/src/xpti_proxy.cpp b/xpti/src/xpti_proxy.cpp index 8e1439cd24bd5..6fe78c274e2a4 100644 --- a/xpti/src/xpti_proxy.cpp +++ b/xpti/src/xpti_proxy.cpp @@ -7,12 +7,15 @@ // #include "xpti/xpti_trace_framework.hpp" +#include #include #include #include #include enum functions_t { + XPTI_FRAMEWORK_INITIALIZE, + XPTI_FRAMEWORK_FINALIZE, XPTI_INITIALIZE, XPTI_FINALIZE, XPTI_GET_UNIQUE_ID, @@ -42,6 +45,8 @@ enum functions_t { namespace xpti { class ProxyLoader { std::unordered_map m_function_names = { + {XPTI_FRAMEWORK_INITIALIZE, "xptiFrameworkInitialize"}, + {XPTI_FRAMEWORK_FINALIZE, "xptiFrameworkFinalize"}, {XPTI_INITIALIZE, "xptiInitialize"}, {XPTI_FINALIZE, "xptiFinalize"}, {XPTI_GET_UNIQUE_ID, "xptiGetUniqueId"}, @@ -116,26 +121,52 @@ class ProxyLoader { inline bool noErrors() { return m_loaded; } void *functionByIndex(int index) { - if (index >= XPTI_INITIALIZE && index < XPTI_FW_API_COUNT) { + if (index >= XPTI_FRAMEWORK_INITIALIZE && index < XPTI_FW_API_COUNT) { return reinterpret_cast(m_dispatch_table[index]); } return nullptr; } + static ProxyLoader &instance() { + static ProxyLoader *loader = new ProxyLoader(); + return *loader; + } + private: bool m_loaded; xpti_plugin_handle_t m_fw_plugin_handle; dispatch_table_t m_dispatch_table; xpti::utils::PlatformHelper m_loader; }; - -static ProxyLoader g_loader; } // namespace xpti +XPTI_EXPORT_API void xptiFrameworkInitialize() { + if (xpti::ProxyLoader::instance().noErrors()) { + void *f = xpti::ProxyLoader::instance().functionByIndex( + XPTI_FRAMEWORK_INITIALIZE); + if (f) { + (*reinterpret_cast(f))(); + } + } +} + +XPTI_EXPORT_API void xptiFrameworkFinalize() { + if (xpti::ProxyLoader::instance().noErrors()) { + void *f = + xpti::ProxyLoader::instance().functionByIndex(XPTI_FRAMEWORK_FINALIZE); + if (f) { + (*reinterpret_cast(f))(); + } + } + + delete &xpti::ProxyLoader::instance(); +} + XPTI_EXPORT_API uint16_t xptiRegisterUserDefinedTracePoint( const char *tool_name, uint8_t user_defined_tp) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_REGISTER_USER_DEFINED_TP); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex( + XPTI_REGISTER_USER_DEFINED_TP); if (f) { return (*(xpti_register_user_defined_tp_t)f)(tool_name, user_defined_tp); } @@ -145,8 +176,9 @@ XPTI_EXPORT_API uint16_t xptiRegisterUserDefinedTracePoint( XPTI_EXPORT_API uint16_t xptiRegisterUserDefinedEventType( const char *tool_name, uint8_t user_defined_event) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_REGISTER_USER_DEFINED_ET); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex( + XPTI_REGISTER_USER_DEFINED_ET); if (f) { return (*(xpti_register_user_defined_et_t)f)(tool_name, user_defined_event); @@ -158,8 +190,8 @@ XPTI_EXPORT_API uint16_t xptiRegisterUserDefinedEventType( XPTI_EXPORT_API xpti::result_t xptiInitialize(const char *stream, uint32_t maj, uint32_t min, const char *version) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_INITIALIZE); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex(XPTI_INITIALIZE); if (f) { return (*(xpti_initialize_t)f)(stream, maj, min, version); } @@ -168,8 +200,8 @@ XPTI_EXPORT_API xpti::result_t xptiInitialize(const char *stream, uint32_t maj, } XPTI_EXPORT_API void xptiFinalize(const char *stream) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_FINALIZE); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex(XPTI_FINALIZE); if (f) { (*(xpti_finalize_t)f)(stream); } @@ -177,8 +209,8 @@ XPTI_EXPORT_API void xptiFinalize(const char *stream) { } XPTI_EXPORT_API uint64_t xptiGetUniqueId() { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_GET_UNIQUE_ID); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex(XPTI_GET_UNIQUE_ID); if (f) { return (*(xpti_get_unique_id_t)f)(); } @@ -188,8 +220,9 @@ XPTI_EXPORT_API uint64_t xptiGetUniqueId() { XPTI_EXPORT_API xpti::string_id_t xptiRegisterString(const char *string, char **table_string) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_REGISTER_STRING); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = + xpti::ProxyLoader::instance().functionByIndex(XPTI_REGISTER_STRING); if (f) { return (*(xpti_register_string_t)f)(string, table_string); } @@ -198,8 +231,8 @@ XPTI_EXPORT_API xpti::string_id_t xptiRegisterString(const char *string, } XPTI_EXPORT_API const char *xptiLookupString(xpti::string_id_t id) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_LOOKUP_STRING); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex(XPTI_LOOKUP_STRING); if (f) { return (*(xpti_lookup_string_t)f)(id); } @@ -208,8 +241,9 @@ XPTI_EXPORT_API const char *xptiLookupString(xpti::string_id_t id) { } XPTI_EXPORT_API uint64_t xptiRegisterPayload(xpti::payload_t *payload) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_REGISTER_PAYLOAD); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = + xpti::ProxyLoader::instance().functionByIndex(XPTI_REGISTER_PAYLOAD); if (f) { return (*(xpti_register_payload_t)f)(payload); } @@ -218,8 +252,9 @@ XPTI_EXPORT_API uint64_t xptiRegisterPayload(xpti::payload_t *payload) { } XPTI_EXPORT_API uint8_t xptiRegisterStream(const char *stream_name) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_REGISTER_STREAM); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = + xpti::ProxyLoader::instance().functionByIndex(XPTI_REGISTER_STREAM); if (f) { return (*(xpti_register_stream_t)f)(stream_name); } @@ -228,8 +263,9 @@ XPTI_EXPORT_API uint8_t xptiRegisterStream(const char *stream_name) { } XPTI_EXPORT_API xpti::result_t xptiUnregisterStream(const char *stream_name) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_UNREGISTER_STREAM); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = + xpti::ProxyLoader::instance().functionByIndex(XPTI_UNREGISTER_STREAM); if (f) { return (*(xpti_unregister_stream_t)f)(stream_name); } @@ -239,8 +275,8 @@ XPTI_EXPORT_API xpti::result_t xptiUnregisterStream(const char *stream_name) { XPTI_EXPORT_API xpti::trace_event_data_t * xptiMakeEvent(const char *name, xpti::payload_t *payload, uint16_t event, xpti::trace_activity_type_t activity, uint64_t *instance_no) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_MAKE_EVENT); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex(XPTI_MAKE_EVENT); if (f) { return (*(xpti_make_event_t)f)(name, payload, event, activity, instance_no); @@ -250,8 +286,8 @@ xptiMakeEvent(const char *name, xpti::payload_t *payload, uint16_t event, } XPTI_EXPORT_API const xpti::trace_event_data_t *xptiFindEvent(uint64_t uid) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_FIND_EVENT); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex(XPTI_FIND_EVENT); if (f) { return (*(xpti_find_event_t)f)(uid); } @@ -261,8 +297,8 @@ XPTI_EXPORT_API const xpti::trace_event_data_t *xptiFindEvent(uint64_t uid) { XPTI_EXPORT_API const xpti::payload_t * xptiQueryPayload(xpti::trace_event_data_t *lookup_object) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_QUERY_PAYLOAD); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex(XPTI_QUERY_PAYLOAD); if (f) { return (*(xpti_query_payload_t)f)(lookup_object); } @@ -271,8 +307,9 @@ xptiQueryPayload(xpti::trace_event_data_t *lookup_object) { } XPTI_EXPORT_API const xpti::payload_t *xptiQueryPayloadByUID(uint64_t uid) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_QUERY_PAYLOAD_BY_UID); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex( + XPTI_QUERY_PAYLOAD_BY_UID); if (f) { return (*(xpti_query_payload_by_uid_t)f)(uid); } @@ -283,8 +320,9 @@ 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, xpti::tracepoint_callback_api_t cb) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_REGISTER_CALLBACK); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = + xpti::ProxyLoader::instance().functionByIndex(XPTI_REGISTER_CALLBACK); if (f) { return (*(xpti_register_cb_t)f)(stream_id, trace_type, cb); } @@ -295,8 +333,9 @@ xptiRegisterCallback(uint8_t stream_id, uint16_t trace_type, XPTI_EXPORT_API xpti::result_t xptiUnregisterCallback(uint8_t stream_id, uint16_t trace_type, xpti::tracepoint_callback_api_t cb) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_UNREGISTER_CALLBACK); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = + xpti::ProxyLoader::instance().functionByIndex(XPTI_UNREGISTER_CALLBACK); if (f) { return (*(xpti_unregister_cb_t)f)(stream_id, trace_type, cb); } @@ -309,8 +348,9 @@ xptiNotifySubscribers(uint8_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) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_NOTIFY_SUBSCRIBERS); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = + xpti::ProxyLoader::instance().functionByIndex(XPTI_NOTIFY_SUBSCRIBERS); if (f) { return (*(xpti_notify_subscribers_t)f)(stream_id, trace_type, parent, object, instance, user_data); @@ -320,8 +360,8 @@ xptiNotifySubscribers(uint8_t stream_id, uint16_t trace_type, } XPTI_EXPORT_API bool xptiTraceEnabled() { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_TRACE_ENABLED); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex(XPTI_TRACE_ENABLED); if (f) { return (*(xpti_trace_enabled_t)f)(); } @@ -332,8 +372,8 @@ XPTI_EXPORT_API bool xptiTraceEnabled() { XPTI_EXPORT_API xpti::result_t xptiAddMetadata(xpti::trace_event_data_t *e, const char *key, const char *value) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_ADD_METADATA); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex(XPTI_ADD_METADATA); if (f) { return (*(xpti_add_metadata_t)f)(e, key, value); } @@ -343,8 +383,8 @@ XPTI_EXPORT_API xpti::result_t xptiAddMetadata(xpti::trace_event_data_t *e, XPTI_EXPORT_API xpti::metadata_t * xptiQueryMetadata(xpti::trace_event_data_t *lookup_object) { - if (xpti::g_loader.noErrors()) { - auto f = xpti::g_loader.functionByIndex(XPTI_QUERY_METADATA); + if (xpti::ProxyLoader::instance().noErrors()) { + auto f = xpti::ProxyLoader::instance().functionByIndex(XPTI_QUERY_METADATA); if (f) { return (*(xpti_query_metadata_t)f)(lookup_object); } diff --git a/xptifw/src/xpti_trace_framework.cpp b/xptifw/src/xpti_trace_framework.cpp index 095bc2b09b494..f8af4f56c5a3f 100644 --- a/xptifw/src/xpti_trace_framework.cpp +++ b/xptifw/src/xpti_trace_framework.cpp @@ -7,6 +7,7 @@ #include "xpti_int64_hash_table.hpp" #include "xpti_string_table.hpp" +#include #include #include #include @@ -36,9 +37,16 @@ #define XPTI_VENDOR_DEFINED_EVENT_TYPE16(vendor_id, event_type) \ ((uint16_t)vendor_id << 8 | XPTI_USER_DEFINED_EVENT_TYPE16(event_type)) +static_assert(std::is_trivially_destructible::value, + "SpinLock is not trivial"); +static_assert( + std::is_trivially_destructible::value, + "PlatformHelper is not trivial"); + namespace xpti { constexpr const char *env_subscribers = "XPTI_SUBSCRIBERS"; xpti::utils::PlatformHelper g_helper; +xpti::utils::SpinLock g_framework_mutex; // This class is a helper class to load all the listed subscribers provided by // the user in XPTI_SUBSCRIBERS environment variable. class Subscribers { @@ -971,7 +979,35 @@ class Framework { MTracepoints.printStatistics(); } + static Framework &instance() { + Framework *TmpFramework = MInstance.load(std::memory_order_relaxed); + std::atomic_thread_fence(std::memory_order_acquire); + if (TmpFramework == nullptr) { + std::lock_guard Lock{MSingletoneMutex}; + TmpFramework = MInstance.load(std::memory_order_relaxed); + if (TmpFramework == nullptr) { + TmpFramework = new Framework(); + std::atomic_thread_fence(std::memory_order_release); + MInstance.store(TmpFramework, std::memory_order_relaxed); + } + } + + return *TmpFramework; + } + private: + friend void ::xptiFrameworkFinalize(); + + static void release() { + Framework *TmpFramework = MInstance.load(std::memory_order_relaxed); + MInstance.store(nullptr, std::memory_order_relaxed); + delete TmpFramework; + } + + /// Stores singleton instance + static std::atomic MInstance; + /// Trivially destructible mutex for double-checked lock idiom + static utils::SpinLock MSingletoneMutex; /// Thread-safe counter used for generating universal IDs xpti::safe_uint64_t MUniversalIDs; /// Manages loading the subscribers and calling their init() functions @@ -990,13 +1026,31 @@ class Framework { bool MTraceEnabled; }; -static Framework GXPTIFramework; +static int GFrameworkReferenceCounter = 0; + +std::atomic Framework::MInstance; +utils::SpinLock Framework::MSingletoneMutex; } // namespace xpti extern "C" { + +XPTI_EXPORT_API void xptiFrameworkInitialize() { + std::lock_guard guard{xpti::g_framework_mutex}; + xpti::GFrameworkReferenceCounter++; +} + +XPTI_EXPORT_API void xptiFrameworkFinalize() { + std::lock_guard guard{xpti::g_framework_mutex}; + + xpti::GFrameworkReferenceCounter--; + if (xpti::GFrameworkReferenceCounter == 0) { + xpti::Framework::release(); + } +} + XPTI_EXPORT_API uint16_t xptiRegisterUserDefinedTracePoint(const char *ToolName, uint8_t UserDefinedTP) { - uint8_t ToolID = xpti::GXPTIFramework.registerVendor(ToolName); + uint8_t ToolID = xpti::Framework::instance().registerVendor(ToolName); UserDefinedTP |= (uint8_t)xpti::trace_point_type_t::user_defined; uint16_t UserDefTracepoint = XPTI_PACK08_RET16(ToolID, UserDefinedTP); @@ -1005,7 +1059,7 @@ xptiRegisterUserDefinedTracePoint(const char *ToolName, uint8_t UserDefinedTP) { XPTI_EXPORT_API uint16_t xptiRegisterUserDefinedEventType( const char *ToolName, uint8_t UserDefinedEvent) { - uint8_t ToolID = xpti::GXPTIFramework.registerVendor(ToolName); + uint8_t ToolID = xpti::Framework::instance().registerVendor(ToolName); UserDefinedEvent |= (uint8_t)xpti::trace_event_type_t::user_defined; uint16_t UserDefEventType = XPTI_PACK08_RET16(ToolID, UserDefinedEvent); return UserDefEventType; @@ -1014,68 +1068,72 @@ XPTI_EXPORT_API uint16_t xptiRegisterUserDefinedEventType( XPTI_EXPORT_API xpti::result_t xptiInitialize(const char *Stream, uint32_t maj, uint32_t min, const char *version) { - return xpti::GXPTIFramework.initializeStream(Stream, maj, min, version); + return xpti::Framework::instance().initializeStream(Stream, maj, min, + version); } XPTI_EXPORT_API void xptiFinalize(const char *Stream) { - xpti::GXPTIFramework.finalizeStream(Stream); + xpti::Framework::instance().finalizeStream(Stream); } XPTI_EXPORT_API uint64_t xptiGetUniqueId() { - return xpti::GXPTIFramework.makeUniqueID(); + return xpti::Framework::instance().makeUniqueID(); } XPTI_EXPORT_API xpti::string_id_t xptiRegisterString(const char *String, char **RefTableStr) { - return xpti::GXPTIFramework.registerString(String, RefTableStr); + return xpti::Framework::instance().registerString(String, RefTableStr); } XPTI_EXPORT_API const char *xptiLookupString(xpti::string_id_t ID) { - return xpti::GXPTIFramework.lookupString(ID); + return xpti::Framework::instance().lookupString(ID); } XPTI_EXPORT_API uint64_t xptiRegisterPayload(xpti::payload_t *payload) { - return xpti::GXPTIFramework.registerPayload(payload); + return xpti::Framework::instance().registerPayload(payload); } XPTI_EXPORT_API uint8_t xptiRegisterStream(const char *StreamName) { - return xpti::GXPTIFramework.registerStream(StreamName); + return xpti::Framework::instance().registerStream(StreamName); } XPTI_EXPORT_API xpti::result_t xptiUnregisterStream(const char *StreamName) { - return xpti::GXPTIFramework.unregisterStream(StreamName); + return xpti::Framework::instance().unregisterStream(StreamName); } XPTI_EXPORT_API xpti::trace_event_data_t * xptiMakeEvent(const char * /*Name*/, xpti::payload_t *Payload, uint16_t Event, xpti::trace_activity_type_t Activity, uint64_t *InstanceNo) { - return xpti::GXPTIFramework.createEvent(Payload, Event, Activity, InstanceNo); + return xpti::Framework::instance().createEvent(Payload, Event, Activity, + InstanceNo); } -XPTI_EXPORT_API void xptiReset() { xpti::GXPTIFramework.clear(); } +XPTI_EXPORT_API void xptiReset() { xpti::Framework::instance().clear(); } XPTI_EXPORT_API const xpti::trace_event_data_t *xptiFindEvent(uint64_t UId) { - return xpti::GXPTIFramework.findEvent(UId); + return xpti::Framework::instance().findEvent(UId); } XPTI_EXPORT_API const xpti::payload_t * xptiQueryPayload(xpti::trace_event_data_t *LookupObject) { - return xpti::GXPTIFramework.queryPayload(LookupObject); + return xpti::Framework::instance().queryPayload(LookupObject); } XPTI_EXPORT_API const xpti::payload_t *xptiQueryPayloadByUID(uint64_t uid) { - return xpti::GXPTIFramework.queryPayloadByUID(uid); + return xpti::Framework::instance().queryPayloadByUID(uid); } XPTI_EXPORT_API xpti::result_t xptiRegisterCallback(uint8_t StreamID, uint16_t TraceType, xpti::tracepoint_callback_api_t cbFunc) { - return xpti::GXPTIFramework.registerCallback(StreamID, TraceType, cbFunc); + return xpti::Framework::instance().registerCallback(StreamID, TraceType, + cbFunc); } XPTI_EXPORT_API xpti::result_t xptiUnregisterCallback(uint8_t StreamID, uint16_t TraceType, xpti::tracepoint_callback_api_t cbFunc) { - return xpti::GXPTIFramework.unregisterCallback(StreamID, TraceType, cbFunc); + return xpti::Framework::instance().unregisterCallback(StreamID, TraceType, + cbFunc); } XPTI_EXPORT_API xpti::result_t @@ -1083,18 +1141,18 @@ xptiNotifySubscribers(uint8_t StreamID, uint16_t TraceType, xpti::trace_event_data_t *Parent, xpti::trace_event_data_t *Object, uint64_t InstanceNo, const void *TemporalUserData) { - return xpti::GXPTIFramework.notifySubscribers( + return xpti::Framework::instance().notifySubscribers( StreamID, TraceType, Parent, Object, InstanceNo, TemporalUserData); } XPTI_EXPORT_API bool xptiTraceEnabled() { - return xpti::GXPTIFramework.traceEnabled(); + return xpti::Framework::instance().traceEnabled(); } XPTI_EXPORT_API xpti::result_t xptiAddMetadata(xpti::trace_event_data_t *Event, const char *Key, const char *Value) { - return xpti::GXPTIFramework.addMetadata(Event, Key, Value); + return xpti::Framework::instance().addMetadata(Event, Key, Value); } XPTI_EXPORT_API xpti::metadata_t * @@ -1103,7 +1161,7 @@ xptiQueryMetadata(xpti::trace_event_data_t *Event) { } XPTI_EXPORT_API void xptiForceSetTraceEnabled(bool YesOrNo) { - xpti::GXPTIFramework.setTraceEnabled(YesOrNo); + xpti::Framework::instance().setTraceEnabled(YesOrNo); } } // extern "C"