From 9337c92d6b75a21c0cb3aea0a36afb2bc0d692a3 Mon Sep 17 00:00:00 2001 From: ankitm3k Date: Mon, 6 Oct 2025 22:35:16 +0530 Subject: [PATCH 1/8] Update: Enable OVEP ETW Tracing & Logging --- .../openvino/openvino_execution_provider.cc | 54 +++ .../openvino/openvino_execution_provider.h | 12 + .../core/providers/openvino/ov_telemetry.cc | 347 ++++++++++++++++++ .../core/providers/openvino/ov_telemetry.h | 111 ++++++ ort.wprp | 10 + 5 files changed, 534 insertions(+) create mode 100644 onnxruntime/core/providers/openvino/ov_telemetry.cc create mode 100644 onnxruntime/core/providers/openvino/ov_telemetry.h diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index a0fa885cbfc38..5b80d851afe4a 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -21,6 +21,8 @@ namespace onnxruntime { namespace openvino_ep { +std::atomic OpenVINOExecutionProvider::global_session_counter_{0}; + // Parking this code here for now before it's moved to the factory #if defined OPENVINO_CONFIG_HETERO || defined OPENVINO_CONFIG_MULTI || defined OPENVINO_CONFIG_AUTO static std::vector parseDevices(const std::string& device_string, @@ -58,6 +60,33 @@ OpenVINOExecutionProvider::OpenVINOExecutionProvider(const ProviderInfo& info, s shared_context_{std::move(shared_context)}, ep_ctx_handle_{session_context_.openvino_sdk_version, *GetLogger()} { InitProviderOrtApi(); +#ifdef _WIN32 + session_id_ = ++global_session_counter_; + auto& telem = onnxruntime::openvino_ep::OVTelemetry::Instance(); + telem.LogSessionCreation(session_id_, + session_context_.onnx_model_path_name.string(), + session_context_.openvino_sdk_version); + telem.LogProviderOptions(session_id_, { + {"device_type", session_context_.device_type}, + {"precision", session_context_.precision}, + {"enable_qdq_optimizer", session_context_.enable_qdq_optimizer ? "1":"0"}, + {"enable_dynamic_shapes", session_context_.disable_dynamic_shapes ? "0":"1"} + }); + telem.LogProviderInit(session_id_, session_context_.device_type, session_context_.precision); + + if (logging::EtwRegistrationManager::SupportsETW()) { + auto& mgr = logging::EtwRegistrationManager::Instance(); + callback_etw_ = logging::EtwRegistrationManager::EtwInternalCallback( + [](LPCGUID, ULONG en, UCHAR lvl, ULONGLONG any, ULONGLONG, PEVENT_FILTER_DESCRIPTOR, PVOID) { + if (en == EVENT_CONTROL_CODE_ENABLE_PROVIDER && + (any & static_cast(logging::ORTTraceLoggingKeyword::Logs))) { + LOGS_DEFAULT(VERBOSE) << "[OVEP] ETW enabled lvl=" << static_cast(lvl); + } + }); + mgr.RegisterInternalCallback(callback_etw_); + } +#endif + } OpenVINOExecutionProvider::~OpenVINOExecutionProvider() { @@ -65,6 +94,14 @@ OpenVINOExecutionProvider::~OpenVINOExecutionProvider() { backend_manager.ShutdownBackendManager(); } backend_managers_.clear(); +#ifdef _WIN32 + auto& telem = onnxruntime::openvino_ep::OVTelemetry::Instance(); + telem.LogSessionDestruction(session_id_); + telem.LogProviderShutdown(session_id_); + if (callback_etw_) + logging::EtwRegistrationManager::Instance().UnregisterInternalCallback(callback_etw_); +#endif + } std::vector> @@ -94,6 +131,16 @@ common::Status OpenVINOExecutionProvider::Compile( auto& logger = *GetLogger(); Status status = Status::OK(); + auto t0 = std::chrono::high_resolution_clock::now(); +#ifdef _WIN32 + OVTelemetry::Instance().LogCompileStart( + session_id_, + static_cast(fused_nodes.size()), + session_context_.device_type, + session_context_.precision); +#endif + + bool is_epctx_model = false; if (!fused_nodes.empty()) { // Assume these properties are constant for all the model subgraphs, otherwise move to SubGraphContext @@ -214,6 +261,13 @@ common::Status OpenVINOExecutionProvider::Compile( file << metadata; } +#ifdef _WIN32 + auto t1 = std::chrono::high_resolution_clock::now(); + int64_t ms = std::chrono::duration_cast(t1 - t0).count(); + OVTelemetry::Instance().LogCompileEnd(session_id_, status.IsOK(), status.ErrorMessage(), ms); +#endif + + return status; } diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.h b/onnxruntime/core/providers/openvino/openvino_execution_provider.h index 020aec16e507c..f7610ef23f693 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.h +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.h @@ -11,10 +11,15 @@ #include #include #include +#include #include "core/providers/openvino/backend_manager.h" #include "core/providers/openvino/contexts.h" +#ifdef _WIN32 +#include "core/providers/openvino/ov_telemetry.h" +#endif + namespace onnxruntime { namespace openvino_ep { @@ -74,6 +79,13 @@ class OpenVINOExecutionProvider : public IExecutionProvider { std::shared_ptr shared_context_; std::list backend_managers_; // EP session owns the backend objects EPCtxHandler ep_ctx_handle_; + + // Telemetry and session tracking + mutable uint32_t session_id_; + static std::atomic global_session_counter_; +#ifdef _WIN32 + onnxruntime::logging::EtwRegistrationManager::EtwInternalCallback callback_etw_; +#endif }; } // namespace openvino_ep diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.cc b/onnxruntime/core/providers/openvino/ov_telemetry.cc new file mode 100644 index 0000000000000..5b5d7e678fc7f --- /dev/null +++ b/onnxruntime/core/providers/openvino/ov_telemetry.cc @@ -0,0 +1,347 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +#include "core/providers/openvino/ov_telemetry.h" + +#ifdef _WIN32 +#if !BUILD_OPENVINO_EP_STATIC_LIB +#include +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 26440) +#endif +#include +#include +#include +#include "core/platform/windows/TraceLoggingConfig.h" + +// UTF-8 workarounds +#ifdef _TlgPragmaUtf8Begin +#undef _TlgPragmaUtf8Begin +#define _TlgPragmaUtf8Begin +#endif +#ifdef _TlgPragmaUtf8End +#undef _TlgPragmaUtf8End +#define _TlgPragmaUtf8End +#endif + +TRACELOGGING_DEFINE_PROVIDER( + ov_telemetry_provider_handle, + "Microsoft.ML.ONNXRuntime.OpenVINO", + (0xb5a8c2e1, 0x4d7f, 0x4a3b, 0x9c, 0x2e, 0x1f, 0x8e, 0x5a, 0x6b, 0x7c, 0x9d), + TraceLoggingOptionMicrosoftTelemetry()); + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // !BUILD_OPENVINO_EP_STATIC_LIB + +namespace onnxruntime { +namespace openvino_ep { + +#if !BUILD_OPENVINO_EP_STATIC_LIB +std::mutex OVTelemetry::mutex_; +std::mutex OVTelemetry::provider_change_mutex_; +uint32_t OVTelemetry::global_register_count_ = 0; +bool OVTelemetry::enabled_ = true; +UCHAR OVTelemetry::level_ = 0; +UINT64 OVTelemetry::keyword_ = 0; +std::vector OVTelemetry::callbacks_; +std::mutex OVTelemetry::callbacks_mutex_; +#endif + +OVTelemetry::OVTelemetry() { +#if !BUILD_OPENVINO_EP_STATIC_LIB + std::lock_guard lock(mutex_); + if (global_register_count_ == 0) { + HRESULT hr = TraceLoggingRegisterEx(ov_telemetry_provider_handle, ORT_TL_EtwEnableCallback, nullptr); + if (SUCCEEDED(hr)) { + global_register_count_ += 1; + } + } +#endif +} + +OVTelemetry::~OVTelemetry() { +#if !BUILD_OPENVINO_EP_STATIC_LIB + std::lock_guard lock(mutex_); + if (global_register_count_ > 0) { + global_register_count_ -= 1; + if (global_register_count_ == 0) { + TraceLoggingUnregister(ov_telemetry_provider_handle); + } + } + std::lock_guard lock_callbacks(callbacks_mutex_); + callbacks_.clear(); +#endif +} + +OVTelemetry& OVTelemetry::Instance() { + static OVTelemetry instance; + return instance; +} + +bool OVTelemetry::IsEnabled() const { +#if BUILD_OPENVINO_EP_STATIC_LIB + return false; // Simplified for now +#else + std::lock_guard lock(provider_change_mutex_); + return enabled_; +#endif +} + +UCHAR OVTelemetry::Level() const { +#if BUILD_OPENVINO_EP_STATIC_LIB + return 0; +#else + std::lock_guard lock(provider_change_mutex_); + return level_; +#endif +} + +UINT64 OVTelemetry::Keyword() const { +#if BUILD_OPENVINO_EP_STATIC_LIB + return 0; +#else + std::lock_guard lock(provider_change_mutex_); + return keyword_; +#endif +} + +std::string OVTelemetry::SerializeOptionsMap(const std::unordered_map& options) const { + std::stringstream ss; + bool first = true; + for (const auto& [key, value] : options) { + if (!first) ss << ", "; + ss << key << "=" << value; + first = false; + } + return ss.str(); +} + +void OVTelemetry::LogProviderInit(uint32_t session_id, const std::string& device_type, const std::string& precision) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVProviderInit", + TraceLoggingKeyword(ov_keywords::OV_PROVIDER), + TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingString(device_type.c_str(), "device_type"), + TraceLoggingString(precision.c_str(), "precision")); +#endif +} + +void OVTelemetry::LogProviderShutdown(uint32_t session_id) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVProviderShutdown", + TraceLoggingKeyword(ov_keywords::OV_PROVIDER), + TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingUInt32(session_id, "session_id")); +#endif +} + +void OVTelemetry::LogSessionOptions(uint32_t session_id, const std::unordered_map& session_options) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + std::string options_str = SerializeOptionsMap(session_options); + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVSessionOptions", + TraceLoggingKeyword(ov_keywords::OV_SESSION | ov_keywords::OV_OPTIONS), + TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingUInt32(static_cast(session_options.size()), "options_count"), + TraceLoggingString(options_str.c_str(), "session_options")); +#endif +} + +void OVTelemetry::LogProviderOptions(uint32_t session_id, const std::unordered_map& provider_options) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + std::string options_str = SerializeOptionsMap(provider_options); + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVProviderOptions", + TraceLoggingKeyword(ov_keywords::OV_PROVIDER | ov_keywords::OV_OPTIONS), + TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingUInt32(static_cast(provider_options.size()), "options_count"), + TraceLoggingString(options_str.c_str(), "provider_options")); +#endif +} + +void OVTelemetry::LogSessionCreation(uint32_t session_id, const std::string& model_path, const std::string& openvino_version) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVSessionCreation", + TraceLoggingKeyword(ov_keywords::OV_SESSION), + TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingString(model_path.c_str(), "model_path"), + TraceLoggingString(openvino_version.c_str(), "openvino_version")); +#endif +} + +void OVTelemetry::LogSessionDestruction(uint32_t session_id) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVSessionDestruction", + TraceLoggingKeyword(ov_keywords::OV_SESSION), + TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingUInt32(session_id, "session_id")); +#endif +} + +void OVTelemetry::LogCapabilityDetection(uint32_t session_id, uint32_t node_count, bool wholly_supported, + bool has_external_weights, const std::string& device_type) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVCapabilityDetection", + TraceLoggingKeyword(ov_keywords::OV_CAPABILITY), + TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingUInt32(node_count, "node_count"), + TraceLoggingBool(wholly_supported, "wholly_supported"), + TraceLoggingBool(has_external_weights, "has_external_weights"), + TraceLoggingString(device_type.c_str(), "device_type")); +#endif +} + +void OVTelemetry::LogCompileStart(uint32_t session_id, uint32_t fused_node_count, const std::string& device_type, + const std::string& precision) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVCompileStart", + TraceLoggingKeyword(ov_keywords::OV_COMPILATION), + TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingUInt32(fused_node_count, "fused_node_count"), + TraceLoggingString(device_type.c_str(), "device_type"), + TraceLoggingString(precision.c_str(), "precision")); +#endif +} + +void OVTelemetry::LogCompileEnd(uint32_t session_id, bool success, const std::string& error_message, + int64_t compile_duration_ms) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVCompileEnd", + TraceLoggingKeyword(ov_keywords::OV_COMPILATION | ov_keywords::OV_PERFORMANCE), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingBool(success, "success"), + TraceLoggingString(error_message.c_str(), "error_message"), + TraceLoggingInt64(compile_duration_ms, "compile_duration_ms")); +#endif +} + +void OVTelemetry::LogComputeStart(uint32_t session_id, const std::string& subgraph_name, const std::string& device_type) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVComputeStart", + TraceLoggingKeyword(ov_keywords::OV_EXECUTION), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingString(subgraph_name.c_str(), "subgraph_name"), + TraceLoggingString(device_type.c_str(), "device_type")); +#endif +} + +void OVTelemetry::LogComputeEnd(uint32_t session_id, int64_t duration_microseconds, const std::string& subgraph_name, + bool success, const std::string& error_message) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVComputeEnd", + TraceLoggingKeyword(ov_keywords::OV_EXECUTION | ov_keywords::OV_PERFORMANCE), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingInt64(duration_microseconds, "duration_microseconds"), + TraceLoggingString(subgraph_name.c_str(), "subgraph_name"), + TraceLoggingBool(success, "success"), + TraceLoggingString(error_message.c_str(), "error_message")); +#endif +} + +void OVTelemetry::LogBackendManagerEvent(uint32_t session_id, const std::string& event_type, const std::string& details) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVBackendEvent", + TraceLoggingKeyword(ov_keywords::OV_BACKEND), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingString(event_type.c_str(), "event_type"), + TraceLoggingString(details.c_str(), "details")); +#endif +} + +void OVTelemetry::LogDeviceSelection(uint32_t session_id, const std::string& requested_device, + const std::string& actual_device, const std::string& selection_reason) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVDeviceSelection", + TraceLoggingKeyword(ov_keywords::OV_PROVIDER | ov_keywords::OV_OPTIONS), + TraceLoggingLevel(WINEVENT_LEVEL_INFO), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingString(requested_device.c_str(), "requested_device"), + TraceLoggingString(actual_device.c_str(), "actual_device"), + TraceLoggingString(selection_reason.c_str(), "selection_reason")); +#endif +} + +void OVTelemetry::LogError(uint32_t session_id, const std::string& error_category, const std::string& error_message, + const std::string& function_name, int line_number) const { +#if !BUILD_OPENVINO_EP_STATIC_LIB + TraceLoggingWrite( + ov_telemetry_provider_handle, "OVError", + TraceLoggingKeyword(ov_keywords::OV_ERROR), + TraceLoggingLevel(WINEVENT_LEVEL_ERROR), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingString(error_category.c_str(), "error_category"), + TraceLoggingString(error_message.c_str(), "error_message"), + TraceLoggingString(function_name.c_str(), "function_name"), + TraceLoggingInt32(line_number, "line_number")); +#endif +} + +void OVTelemetry::RegisterInternalCallback(const EtwInternalCallback& callback) { +#if BUILD_OPENVINO_EP_STATIC_LIB + // Handle static case if needed +#else + std::lock_guard lock_callbacks(callbacks_mutex_); + callbacks_.push_back(&callback); +#endif +} + +void OVTelemetry::UnregisterInternalCallback(const EtwInternalCallback& callback) { +#if BUILD_OPENVINO_EP_STATIC_LIB + // Handle static case if needed +#else + std::lock_guard lock_callbacks(callbacks_mutex_); + auto new_end = std::remove_if(callbacks_.begin(), callbacks_.end(), + [&callback](const EtwInternalCallback* ptr) { + return ptr == &callback; + }); + callbacks_.erase(new_end, callbacks_.end()); +#endif +} + +#if !BUILD_OPENVINO_EP_STATIC_LIB +void NTAPI OVTelemetry::ORT_TL_EtwEnableCallback( + _In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, + _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData, _In_opt_ PVOID CallbackContext) { + std::lock_guard lock(provider_change_mutex_); + enabled_ = (IsEnabled != 0); + level_ = Level; + keyword_ = MatchAnyKeyword; + InvokeCallbacks(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext); +} + +void OVTelemetry::InvokeCallbacks(LPCGUID SourceId, ULONG IsEnabled, UCHAR Level, ULONGLONG MatchAnyKeyword, + ULONGLONG MatchAllKeyword, PEVENT_FILTER_DESCRIPTOR FilterData, PVOID CallbackContext) { + std::lock_guard lock_callbacks(callbacks_mutex_); + for (const auto& callback : callbacks_) { + (*callback)(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext); + } +} +#endif + +} // namespace openvino_ep +} // namespace onnxruntime + +#endif // defined(_WIN32) diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.h b/onnxruntime/core/providers/openvino/ov_telemetry.h new file mode 100644 index 0000000000000..b2e64e3eb9d3a --- /dev/null +++ b/onnxruntime/core/providers/openvino/ov_telemetry.h @@ -0,0 +1,111 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +#pragma once + +#ifdef _WIN32 +#include +#if !BUILD_OPENVINO_EP_STATIC_LIB +#include +#endif +#include +#include +#include +#include +#include +// #include "core/common/logging/logging.h" + +#if !BUILD_OPENVINO_EP_STATIC_LIB +TRACELOGGING_DECLARE_PROVIDER(ov_telemetry_provider_handle); +#endif + +namespace onnxruntime { +namespace openvino_ep { + +class OVTelemetry { + public: + static OVTelemetry& Instance(); + bool IsEnabled() const; + unsigned char Level() const; + UINT64 Keyword() const; + + // Provider lifecycle events + void LogProviderInit(uint32_t session_id, const std::string& device_type, const std::string& precision) const; + void LogProviderShutdown(uint32_t session_id) const; + + // Session and Provider Options logging + void LogSessionOptions(uint32_t session_id, const std::unordered_map& session_options) const; + void LogProviderOptions(uint32_t session_id, const std::unordered_map& provider_options) const; + void LogSessionCreation(uint32_t session_id, const std::string& model_path, const std::string& openvino_version) const; + void LogSessionDestruction(uint32_t session_id) const; + + // Core OpenVINO EP events + void LogCapabilityDetection(uint32_t session_id, uint32_t node_count, bool wholly_supported, + bool has_external_weights, const std::string& device_type) const; + void LogCompileStart(uint32_t session_id, uint32_t fused_node_count, const std::string& device_type, + const std::string& precision) const; + void LogCompileEnd(uint32_t session_id, bool success, const std::string& error_message, + int64_t compile_duration_ms = 0) const; + void LogComputeStart(uint32_t session_id, const std::string& subgraph_name, const std::string& device_type) const; + void LogComputeEnd(uint32_t session_id, int64_t duration_microseconds, const std::string& subgraph_name, + bool success = true, const std::string& error_message = "") const; + + // Backend and configuration events + void LogBackendManagerEvent(uint32_t session_id, const std::string& event_type, const std::string& details) const; + void LogDeviceSelection(uint32_t session_id, const std::string& requested_device, + const std::string& actual_device, const std::string& selection_reason) const; + void LogError(uint32_t session_id, const std::string& error_category, const std::string& error_message, + const std::string& function_name = "", int line_number = 0) const; + + using EtwInternalCallback = std::function; + + static void RegisterInternalCallback(const EtwInternalCallback& callback); + static void UnregisterInternalCallback(const EtwInternalCallback& callback); + + private: + OVTelemetry(); + ~OVTelemetry(); + OVTelemetry(const OVTelemetry&) = delete; + OVTelemetry& operator=(const OVTelemetry&) = delete; + OVTelemetry(OVTelemetry&&) = delete; + OVTelemetry& operator=(OVTelemetry&&) = delete; + + std::string SerializeOptionsMap(const std::unordered_map& options) const; + +#if !BUILD_OPENVINO_EP_STATIC_LIB + static std::mutex mutex_; + static uint32_t global_register_count_; + static bool enabled_; + static std::vector callbacks_; + static std::mutex callbacks_mutex_; + static std::mutex provider_change_mutex_; + static UCHAR level_; + static ULONGLONG keyword_; + + static void InvokeCallbacks(LPCGUID SourceId, ULONG IsEnabled, UCHAR Level, ULONGLONG MatchAnyKeyword, + ULONGLONG MatchAllKeyword, PEVENT_FILTER_DESCRIPTOR FilterData, PVOID CallbackContext); + + static void NTAPI ORT_TL_EtwEnableCallback( + _In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, + _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData, _In_opt_ PVOID CallbackContext); +#endif +}; + +// Keywords for comprehensive OpenVINO EP tracing +namespace ov_keywords { + constexpr uint64_t OV_PROVIDER = 0x1; + constexpr uint64_t OV_SESSION = 0x2; + constexpr uint64_t OV_OPTIONS = 0x4; + constexpr uint64_t OV_CAPABILITY = 0x8; + constexpr uint64_t OV_COMPILATION = 0x10; + constexpr uint64_t OV_EXECUTION = 0x20; + constexpr uint64_t OV_BACKEND = 0x40; + constexpr uint64_t OV_PERFORMANCE = 0x80; + constexpr uint64_t OV_ERROR = 0x100; +} + +} // namespace openvino_ep +} // namespace onnxruntime + +#endif // defined(_WIN32) diff --git a/ort.wprp b/ort.wprp index 5dd2332cb1f9f..2e4737e612fa9 100644 --- a/ort.wprp +++ b/ort.wprp @@ -17,6 +17,15 @@ + + + + + + + + @@ -24,6 +33,7 @@ + From 81aff66fc07b3f62655d4494b450a9684431ea5e Mon Sep 17 00:00:00 2001 From: ankitm3k Date: Wed, 8 Oct 2025 20:50:41 +0530 Subject: [PATCH 2/8] fix: Refactor code & fix load_config tracing logic --- .../openvino/openvino_execution_provider.cc | 32 +- .../core/providers/openvino/ov_telemetry.cc | 365 ++++++++++-------- .../core/providers/openvino/ov_telemetry.h | 123 +++--- 3 files changed, 280 insertions(+), 240 deletions(-) diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index 5b80d851afe4a..0d73f9021a200 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -62,29 +62,15 @@ OpenVINOExecutionProvider::OpenVINOExecutionProvider(const ProviderInfo& info, s InitProviderOrtApi(); #ifdef _WIN32 session_id_ = ++global_session_counter_; - auto& telem = onnxruntime::openvino_ep::OVTelemetry::Instance(); - telem.LogSessionCreation(session_id_, - session_context_.onnx_model_path_name.string(), - session_context_.openvino_sdk_version); - telem.LogProviderOptions(session_id_, { - {"device_type", session_context_.device_type}, - {"precision", session_context_.precision}, - {"enable_qdq_optimizer", session_context_.enable_qdq_optimizer ? "1":"0"}, - {"enable_dynamic_shapes", session_context_.disable_dynamic_shapes ? "0":"1"} - }); - telem.LogProviderInit(session_id_, session_context_.device_type, session_context_.precision); - - if (logging::EtwRegistrationManager::SupportsETW()) { - auto& mgr = logging::EtwRegistrationManager::Instance(); - callback_etw_ = logging::EtwRegistrationManager::EtwInternalCallback( - [](LPCGUID, ULONG en, UCHAR lvl, ULONGLONG any, ULONGLONG, PEVENT_FILTER_DESCRIPTOR, PVOID) { - if (en == EVENT_CONTROL_CODE_ENABLE_PROVIDER && - (any & static_cast(logging::ORTTraceLoggingKeyword::Logs))) { - LOGS_DEFAULT(VERBOSE) << "[OVEP] ETW enabled lvl=" << static_cast(lvl); - } - }); - mgr.RegisterInternalCallback(callback_etw_); - } + OV_LOG_SESSION_CREATION(session_id_, + session_context_.onnx_model_path_name.string(), + session_context_.openvino_sdk_version); + // Trace all provider options as one event + OVTelemetry::Instance().LogAllProviderOptions(session_id_, session_context_); + // Trace all session-related flags and inferred states + OVTelemetry::Instance().LogAllSessionOptions(session_id_, session_context_); + // Optionally: log provider init message also + OV_LOG_PROVIDER_INIT(session_id_, session_context_.device_type, session_context_.precision); #endif } diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.cc b/onnxruntime/core/providers/openvino/ov_telemetry.cc index 5b5d7e678fc7f..7a360553afb22 100644 --- a/onnxruntime/core/providers/openvino/ov_telemetry.cc +++ b/onnxruntime/core/providers/openvino/ov_telemetry.cc @@ -11,19 +11,8 @@ #endif #include #include -#include #include "core/platform/windows/TraceLoggingConfig.h" -// UTF-8 workarounds -#ifdef _TlgPragmaUtf8Begin -#undef _TlgPragmaUtf8Begin -#define _TlgPragmaUtf8Begin -#endif -#ifdef _TlgPragmaUtf8End -#undef _TlgPragmaUtf8End -#define _TlgPragmaUtf8End -#endif - TRACELOGGING_DEFINE_PROVIDER( ov_telemetry_provider_handle, "Microsoft.ML.ONNXRuntime.OpenVINO", @@ -82,7 +71,7 @@ OVTelemetry& OVTelemetry::Instance() { bool OVTelemetry::IsEnabled() const { #if BUILD_OPENVINO_EP_STATIC_LIB - return false; // Simplified for now + return false; #else std::lock_guard lock(provider_change_mutex_); return enabled_; @@ -107,201 +96,240 @@ UINT64 OVTelemetry::Keyword() const { #endif } -std::string OVTelemetry::SerializeOptionsMap(const std::unordered_map& options) const { - std::stringstream ss; - bool first = true; - for (const auto& [key, value] : options) { - if (!first) ss << ", "; - ss << key << "=" << value; - first = false; +std::string OVTelemetry::SerializeLoadConfig(const SessionContext& ctx) const { + if (ctx.load_config.empty()) return "{}"; + + std::ostringstream json; + json << "{"; + bool first_device = true; + + for (const auto& [device, anymap] : ctx.load_config) { + if (!first_device) json << ","; + json << "\"" << device << "\":{"; + + bool first_entry = true; + for (const auto& [key, value] : anymap) { + if (!first_entry) json << ","; + json << "\"" << key << "\":"; + + // Use ov::Any's type checking and extraction capabilities + if (value.is()) { + std::string str_val = value.as(); + // Escape quotes in string + std::string escaped; + for (char c : str_val) { + if (c == '\"' || c == '\\') escaped.push_back('\\'); + escaped.push_back(c); + } + json << "\"" << escaped << "\""; + } else if (value.is()) { + json << value.as(); + } else if (value.is()) { + json << value.as(); + } else if (value.is()) { + json << value.as(); + } else if (value.is()) { + json << (value.as() ? "true" : "false"); + } else if (value.is()) { + json << value.as(); + } else if (value.is()) { + json << value.as(); + } else { + // Use ov::Any's print method for unknown types + std::ostringstream temp; + value.print(temp); + std::string val_str = temp.str(); + + // Escape quotes in the printed string + std::string escaped; + for (char c : val_str) { + if (c == '\"' || c == '\\') escaped.push_back('\\'); + escaped.push_back(c); + } + json << "\"" << escaped << "\""; + } + first_entry = false; + } + json << "}"; + first_device = false; } - return ss.str(); + json << "}"; + return json.str(); } -void OVTelemetry::LogProviderInit(uint32_t session_id, const std::string& device_type, const std::string& precision) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVProviderInit", - TraceLoggingKeyword(ov_keywords::OV_PROVIDER), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingString(device_type.c_str(), "device_type"), - TraceLoggingString(precision.c_str(), "precision")); -#endif -} -void OVTelemetry::LogProviderShutdown(uint32_t session_id) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVProviderShutdown", - TraceLoggingKeyword(ov_keywords::OV_PROVIDER), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), - TraceLoggingUInt32(session_id, "session_id")); -#endif -} +std::string OVTelemetry::SerializeReshapeConfig(const SessionContext& ctx) const { + if (ctx.reshape.empty()) return "{}"; -void OVTelemetry::LogSessionOptions(uint32_t session_id, const std::unordered_map& session_options) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - std::string options_str = SerializeOptionsMap(session_options); - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVSessionOptions", - TraceLoggingKeyword(ov_keywords::OV_SESSION | ov_keywords::OV_OPTIONS), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingUInt32(static_cast(session_options.size()), "options_count"), - TraceLoggingString(options_str.c_str(), "session_options")); -#endif -} + std::ostringstream json; + json << "{"; + bool first = true; -void OVTelemetry::LogProviderOptions(uint32_t session_id, const std::unordered_map& provider_options) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - std::string options_str = SerializeOptionsMap(provider_options); - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVProviderOptions", - TraceLoggingKeyword(ov_keywords::OV_PROVIDER | ov_keywords::OV_OPTIONS), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingUInt32(static_cast(provider_options.size()), "options_count"), - TraceLoggingString(options_str.c_str(), "provider_options")); -#endif + for (const auto& [tensor_name, partial_shape] : ctx.reshape) { + if (!first) json << ","; + json << "\"" << tensor_name << "\":["; + + bool first_dim = true; + // Use ov::PartialShape's iterator interface to iterate through dimensions + for (const auto& dimension : partial_shape) { + if (!first_dim) json << ","; + + if (dimension.is_dynamic()) { + // Handle dynamic dimensions + if (dimension.get_interval().has_upper_bound()) { + // Dynamic dimension with bounds: {min..max} + json << "{\"min\":" << dimension.get_min_length() + << ",\"max\":" << dimension.get_max_length() << "}"; + } else { + // Fully dynamic dimension + json << "\"dynamic\""; + } + } else { + // Static dimension - use get_length() for ov::Dimension + json << dimension.get_length(); + } + first_dim = false; + } + json << "]"; + first = false; + } + json << "}"; + return json.str(); } -void OVTelemetry::LogSessionCreation(uint32_t session_id, const std::string& model_path, const std::string& openvino_version) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVSessionCreation", - TraceLoggingKeyword(ov_keywords::OV_SESSION), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingString(model_path.c_str(), "model_path"), - TraceLoggingString(openvino_version.c_str(), "openvino_version")); -#endif -} +std::string OVTelemetry::SerializeLayoutConfig(const SessionContext& ctx) const { + if (ctx.layout.empty()) return "{}"; -void OVTelemetry::LogSessionDestruction(uint32_t session_id) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVSessionDestruction", - TraceLoggingKeyword(ov_keywords::OV_SESSION), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), - TraceLoggingUInt32(session_id, "session_id")); -#endif -} + std::ostringstream json; + json << "{"; + bool first = true; -void OVTelemetry::LogCapabilityDetection(uint32_t session_id, uint32_t node_count, bool wholly_supported, - bool has_external_weights, const std::string& device_type) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVCapabilityDetection", - TraceLoggingKeyword(ov_keywords::OV_CAPABILITY), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingUInt32(node_count, "node_count"), - TraceLoggingBool(wholly_supported, "wholly_supported"), - TraceLoggingBool(has_external_weights, "has_external_weights"), - TraceLoggingString(device_type.c_str(), "device_type")); -#endif -} + for (const auto& [tensor_name, ov_layout] : ctx.layout) { + if (!first) json << ","; + json << "\"" << tensor_name << "\":"; -void OVTelemetry::LogCompileStart(uint32_t session_id, uint32_t fused_node_count, const std::string& device_type, - const std::string& precision) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVCompileStart", - TraceLoggingKeyword(ov_keywords::OV_COMPILATION), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingUInt32(fused_node_count, "fused_node_count"), - TraceLoggingString(device_type.c_str(), "device_type"), - TraceLoggingString(precision.c_str(), "precision")); -#endif + // Use ov::Layout's to_string() method for proper string representation + std::string layout_str = ov_layout.to_string(); + + // Escape quotes in the layout string if any + std::string escaped; + for (char c : layout_str) { + if (c == '\"' || c == '\\') escaped.push_back('\\'); + escaped.push_back(c); + } + + json << "\"" << escaped << "\""; + first = false; + } + json << "}"; + return json.str(); } -void OVTelemetry::LogCompileEnd(uint32_t session_id, bool success, const std::string& error_message, - int64_t compile_duration_ms) const { + +void OVTelemetry::LogAllProviderOptions(uint32_t session_id, const SessionContext& ctx) const { #if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVCompileEnd", - TraceLoggingKeyword(ov_keywords::OV_COMPILATION | ov_keywords::OV_PERFORMANCE), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingBool(success, "success"), - TraceLoggingString(error_message.c_str(), "error_message"), - TraceLoggingInt64(compile_duration_ms, "compile_duration_ms")); + if (!IsEnabled()) return; + + std::ostringstream opts; + opts << "{" + << "\"device_type\":\"" << ctx.device_type << "\"," + << "\"precision\":\"" << ctx.precision << "\"," + << "\"num_of_threads\":" << ctx.num_of_threads << "," + << "\"model_priority\":\"" << ctx.model_priority << "\"," + << "\"num_streams\":" << ctx.num_streams << "," + << "\"enable_opencl_throttling\":" << (ctx.enable_opencl_throttling ? "true" : "false") << "," + << "\"disable_dynamic_shapes\":" << (ctx.disable_dynamic_shapes ? "true" : "false") << "," + << "\"enable_qdq_optimizer\":" << (ctx.enable_qdq_optimizer ? "true" : "false") << "," + << "\"enable_causallm\":" << (ctx.enable_causallm ? "true" : "false") << "," + << "\"cache_dir\":\"" << ctx.cache_dir.string() << "\"," + << "\"context\":" << (ctx.context ? "\"set\"" : "null") << "," + << "\"load_config\":" << SerializeLoadConfig(ctx) << "," + << "\"reshape\":" << SerializeReshapeConfig(ctx) << "," + << "\"layout\":" << SerializeLayoutConfig(ctx) + << "}"; + + TraceLoggingWrite(ov_telemetry_provider_handle, "OVProviderOptionsComplete", + TraceLoggingKeyword(ov_keywords::OV_PROVIDER | ov_keywords::OV_OPTIONS), + TraceLoggingLevel(5), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingString(opts.str().c_str(), "provider_options")); #endif } -void OVTelemetry::LogComputeStart(uint32_t session_id, const std::string& subgraph_name, const std::string& device_type) const { +void OVTelemetry::LogAllSessionOptions(uint32_t session_id, const SessionContext& ctx) const { #if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVComputeStart", - TraceLoggingKeyword(ov_keywords::OV_EXECUTION), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingString(subgraph_name.c_str(), "subgraph_name"), - TraceLoggingString(device_type.c_str(), "device_type")); + if (!IsEnabled()) return; + + std::ostringstream sopts; + sopts << "{" + << "\"onnx_model_path_name\":\"" << ctx.onnx_model_path_name.string() << "\"," + << "\"onnx_opset_version\":" << ctx.onnx_opset_version << "," + << "\"wholly_supported_graph\":" << (ctx.is_wholly_supported_graph ? "true" : "false") << "," + << "\"has_external_weights\":" << (ctx.has_external_weights ? "true" : "false") << "," + << "\"openvino_sdk_version\":\"" << ctx.openvino_sdk_version << "\"," + << "\"so_context_enable\":" << (ctx.so_context_enable ? "true" : "false") << "," + << "\"so_disable_cpu_ep_fallback\":" << (ctx.so_disable_cpu_ep_fallback ? "true" : "false") << "," + << "\"so_context_embed_mode\":" << (ctx.so_context_embed_mode ? "true" : "false") << "," + << "\"so_share_ep_contexts\":" << (ctx.so_share_ep_contexts ? "true" : "false") << "," + << "\"so_context_file_path\":\"" << ctx.so_context_file_path.string() << "\"" + << "}"; + + TraceLoggingWrite(ov_telemetry_provider_handle, "OVSessionOptionsComplete", + TraceLoggingKeyword(ov_keywords::OV_SESSION | ov_keywords::OV_OPTIONS), + TraceLoggingLevel(5), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingString(sopts.str().c_str(), "session_options")); #endif } -void OVTelemetry::LogComputeEnd(uint32_t session_id, int64_t duration_microseconds, const std::string& subgraph_name, - bool success, const std::string& error_message) const { +void OVTelemetry::LogSessionDestruction(uint32_t session_id) const { #if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVComputeEnd", - TraceLoggingKeyword(ov_keywords::OV_EXECUTION | ov_keywords::OV_PERFORMANCE), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingInt64(duration_microseconds, "duration_microseconds"), - TraceLoggingString(subgraph_name.c_str(), "subgraph_name"), - TraceLoggingBool(success, "success"), - TraceLoggingString(error_message.c_str(), "error_message")); + if (!IsEnabled()) return; + TraceLoggingWrite(ov_telemetry_provider_handle, "OVSessionDestruction", + TraceLoggingKeyword(ov_keywords::OV_SESSION), + TraceLoggingLevel(5), + TraceLoggingUInt32(session_id, "session_id")); #endif } -void OVTelemetry::LogBackendManagerEvent(uint32_t session_id, const std::string& event_type, const std::string& details) const { +void OVTelemetry::LogProviderShutdown(uint32_t session_id) const { #if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVBackendEvent", - TraceLoggingKeyword(ov_keywords::OV_BACKEND), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingString(event_type.c_str(), "event_type"), - TraceLoggingString(details.c_str(), "details")); + if (!IsEnabled()) return; + TraceLoggingWrite(ov_telemetry_provider_handle, "OVProviderShutdown", + TraceLoggingKeyword(ov_keywords::OV_PROVIDER), + TraceLoggingLevel(5), + TraceLoggingUInt32(session_id, "session_id")); #endif } -void OVTelemetry::LogDeviceSelection(uint32_t session_id, const std::string& requested_device, - const std::string& actual_device, const std::string& selection_reason) const { +void OVTelemetry::LogCompileStart(uint32_t session_id, uint32_t fused_node_count, const std::string& device_type, const std::string& precision) const { #if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVDeviceSelection", - TraceLoggingKeyword(ov_keywords::OV_PROVIDER | ov_keywords::OV_OPTIONS), - TraceLoggingLevel(WINEVENT_LEVEL_INFO), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingString(requested_device.c_str(), "requested_device"), - TraceLoggingString(actual_device.c_str(), "actual_device"), - TraceLoggingString(selection_reason.c_str(), "selection_reason")); + if (!IsEnabled()) return; + TraceLoggingWrite(ov_telemetry_provider_handle, "OVCompileStart", + TraceLoggingKeyword(ov_keywords::OV_COMPILATION), + TraceLoggingLevel(5), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingUInt32(fused_node_count, "fused_node_count"), + TraceLoggingString(device_type.c_str(), "device_type"), + TraceLoggingString(precision.c_str(), "precision")); #endif } -void OVTelemetry::LogError(uint32_t session_id, const std::string& error_category, const std::string& error_message, - const std::string& function_name, int line_number) const { +void OVTelemetry::LogCompileEnd(uint32_t session_id, bool success, const std::string& error_message, int64_t duration_ms) const { #if !BUILD_OPENVINO_EP_STATIC_LIB - TraceLoggingWrite( - ov_telemetry_provider_handle, "OVError", - TraceLoggingKeyword(ov_keywords::OV_ERROR), - TraceLoggingLevel(WINEVENT_LEVEL_ERROR), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingString(error_category.c_str(), "error_category"), - TraceLoggingString(error_message.c_str(), "error_message"), - TraceLoggingString(function_name.c_str(), "function_name"), - TraceLoggingInt32(line_number, "line_number")); + if (!IsEnabled()) return; + TraceLoggingWrite(ov_telemetry_provider_handle, "OVCompileEnd", + TraceLoggingKeyword(ov_keywords::OV_COMPILATION | ov_keywords::OV_PERFORMANCE), + TraceLoggingLevel(4), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingBool(success, "success"), + TraceLoggingString(error_message.c_str(), "error_message"), + TraceLoggingInt64(duration_ms, "compile_duration_ms")); #endif } void OVTelemetry::RegisterInternalCallback(const EtwInternalCallback& callback) { #if BUILD_OPENVINO_EP_STATIC_LIB - // Handle static case if needed #else std::lock_guard lock_callbacks(callbacks_mutex_); callbacks_.push_back(&callback); @@ -310,7 +338,6 @@ void OVTelemetry::RegisterInternalCallback(const EtwInternalCallback& callback) void OVTelemetry::UnregisterInternalCallback(const EtwInternalCallback& callback) { #if BUILD_OPENVINO_EP_STATIC_LIB - // Handle static case if needed #else std::lock_guard lock_callbacks(callbacks_mutex_); auto new_end = std::remove_if(callbacks_.begin(), callbacks_.end(), diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.h b/onnxruntime/core/providers/openvino/ov_telemetry.h index b2e64e3eb9d3a..f484b57e0be33 100644 --- a/onnxruntime/core/providers/openvino/ov_telemetry.h +++ b/onnxruntime/core/providers/openvino/ov_telemetry.h @@ -6,13 +6,16 @@ #include #if !BUILD_OPENVINO_EP_STATIC_LIB #include +#include #endif #include #include #include #include +#include #include -// #include "core/common/logging/logging.h" +#include "core/providers/openvino/contexts.h" +#include "nlohmann/json.hpp" #if !BUILD_OPENVINO_EP_STATIC_LIB TRACELOGGING_DECLARE_PROVIDER(ov_telemetry_provider_handle); @@ -21,6 +24,18 @@ TRACELOGGING_DECLARE_PROVIDER(ov_telemetry_provider_handle); namespace onnxruntime { namespace openvino_ep { +namespace ov_keywords { + constexpr uint64_t OV_PROVIDER = 0x1; + constexpr uint64_t OV_SESSION = 0x2; + constexpr uint64_t OV_OPTIONS = 0x4; + constexpr uint64_t OV_CAPABILITY = 0x8; + constexpr uint64_t OV_COMPILATION= 0x10; + constexpr uint64_t OV_EXECUTION = 0x20; + constexpr uint64_t OV_BACKEND = 0x40; + constexpr uint64_t OV_PERFORMANCE= 0x80; + constexpr uint64_t OV_ERROR = 0x100; +} + class OVTelemetry { public: static OVTelemetry& Instance(); @@ -28,38 +43,18 @@ class OVTelemetry { unsigned char Level() const; UINT64 Keyword() const; - // Provider lifecycle events - void LogProviderInit(uint32_t session_id, const std::string& device_type, const std::string& precision) const; - void LogProviderShutdown(uint32_t session_id) const; + // Comprehensive provider options logging + void LogAllProviderOptions(uint32_t session_id, const SessionContext& ctx) const; + void LogAllSessionOptions(uint32_t session_id, const SessionContext& ctx) const; - // Session and Provider Options logging - void LogSessionOptions(uint32_t session_id, const std::unordered_map& session_options) const; - void LogProviderOptions(uint32_t session_id, const std::unordered_map& provider_options) const; - void LogSessionCreation(uint32_t session_id, const std::string& model_path, const std::string& openvino_version) const; + // Individual logging methods to avoid template issues void LogSessionDestruction(uint32_t session_id) const; - - // Core OpenVINO EP events - void LogCapabilityDetection(uint32_t session_id, uint32_t node_count, bool wholly_supported, - bool has_external_weights, const std::string& device_type) const; - void LogCompileStart(uint32_t session_id, uint32_t fused_node_count, const std::string& device_type, - const std::string& precision) const; - void LogCompileEnd(uint32_t session_id, bool success, const std::string& error_message, - int64_t compile_duration_ms = 0) const; - void LogComputeStart(uint32_t session_id, const std::string& subgraph_name, const std::string& device_type) const; - void LogComputeEnd(uint32_t session_id, int64_t duration_microseconds, const std::string& subgraph_name, - bool success = true, const std::string& error_message = "") const; - - // Backend and configuration events - void LogBackendManagerEvent(uint32_t session_id, const std::string& event_type, const std::string& details) const; - void LogDeviceSelection(uint32_t session_id, const std::string& requested_device, - const std::string& actual_device, const std::string& selection_reason) const; - void LogError(uint32_t session_id, const std::string& error_category, const std::string& error_message, - const std::string& function_name = "", int line_number = 0) const; + void LogProviderShutdown(uint32_t session_id) const; + void LogCompileStart(uint32_t session_id, uint32_t fused_node_count, const std::string& device_type, const std::string& precision) const; + void LogCompileEnd(uint32_t session_id, bool success, const std::string& error_message, int64_t duration_ms) const; using EtwInternalCallback = std::function; - + LPCGUID, ULONG, UCHAR, ULONGLONG, ULONGLONG, PEVENT_FILTER_DESCRIPTOR, PVOID)>; static void RegisterInternalCallback(const EtwInternalCallback& callback); static void UnregisterInternalCallback(const EtwInternalCallback& callback); @@ -71,7 +66,10 @@ class OVTelemetry { OVTelemetry(OVTelemetry&&) = delete; OVTelemetry& operator=(OVTelemetry&&) = delete; - std::string SerializeOptionsMap(const std::unordered_map& options) const; + // Helper functions for complex serialization + std::string SerializeLoadConfig(const SessionContext& ctx) const; + std::string SerializeReshapeConfig(const SessionContext& ctx) const; + std::string SerializeLayoutConfig(const SessionContext& ctx) const; #if !BUILD_OPENVINO_EP_STATIC_LIB static std::mutex mutex_; @@ -83,27 +81,56 @@ class OVTelemetry { static UCHAR level_; static ULONGLONG keyword_; - static void InvokeCallbacks(LPCGUID SourceId, ULONG IsEnabled, UCHAR Level, ULONGLONG MatchAnyKeyword, - ULONGLONG MatchAllKeyword, PEVENT_FILTER_DESCRIPTOR FilterData, PVOID CallbackContext); - - static void NTAPI ORT_TL_EtwEnableCallback( - _In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, - _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData, _In_opt_ PVOID CallbackContext); + static void InvokeCallbacks(LPCGUID, ULONG, UCHAR, ULONGLONG, ULONGLONG, PEVENT_FILTER_DESCRIPTOR, PVOID); + static void NTAPI ORT_TL_EtwEnableCallback(_In_ LPCGUID, _In_ ULONG, _In_ UCHAR, _In_ ULONGLONG, + _In_ ULONGLONG, _In_opt_ PEVENT_FILTER_DESCRIPTOR, _In_opt_ PVOID); #endif }; -// Keywords for comprehensive OpenVINO EP tracing -namespace ov_keywords { - constexpr uint64_t OV_PROVIDER = 0x1; - constexpr uint64_t OV_SESSION = 0x2; - constexpr uint64_t OV_OPTIONS = 0x4; - constexpr uint64_t OV_CAPABILITY = 0x8; - constexpr uint64_t OV_COMPILATION = 0x10; - constexpr uint64_t OV_EXECUTION = 0x20; - constexpr uint64_t OV_BACKEND = 0x40; - constexpr uint64_t OV_PERFORMANCE = 0x80; - constexpr uint64_t OV_ERROR = 0x100; -} +// Direct macro definitions to avoid template conflicts +#define OV_LOG_SESSION_CREATION(session_id, model_path, version) \ + do { \ + if (OVTelemetry::Instance().IsEnabled()) { \ + TraceLoggingWrite(ov_telemetry_provider_handle, "OVSessionCreation", \ + TraceLoggingKeyword(ov_keywords::OV_SESSION), \ + TraceLoggingLevel(5), \ + TraceLoggingUInt32(session_id, "session_id"), \ + TraceLoggingString(model_path.c_str(), "model_path"), \ + TraceLoggingString(version.c_str(), "openvino_version")); \ + } \ + } while(0) + +#define OV_LOG_PROVIDER_INIT(session_id, device_type, precision) \ + do { \ + if (OVTelemetry::Instance().IsEnabled()) { \ + TraceLoggingWrite(ov_telemetry_provider_handle, "OVProviderInit", \ + TraceLoggingKeyword(ov_keywords::OV_PROVIDER), \ + TraceLoggingLevel(5), \ + TraceLoggingUInt32(session_id, "session_id"), \ + TraceLoggingString(device_type.c_str(), "device_type"), \ + TraceLoggingString(precision.c_str(), "precision")); \ + } \ + } while(0) + +#define OV_LOG_CAPABILITY_DETECTION(session_id, node_count, wholly_supported, has_external_weights, device_type) \ + do { \ + if (OVTelemetry::Instance().IsEnabled()) { \ + TraceLoggingWrite(ov_telemetry_provider_handle, "OVCapabilityDetection", \ + TraceLoggingKeyword(ov_keywords::OV_CAPABILITY), \ + TraceLoggingLevel(5), \ + TraceLoggingUInt32(session_id, "session_id"), \ + TraceLoggingUInt32(node_count, "node_count"), \ + TraceLoggingBool(wholly_supported, "wholly_supported"), \ + TraceLoggingBool(has_external_weights, "has_external_weights"), \ + TraceLoggingString(device_type.c_str(), "device_type")); \ + } \ + } while(0) + +#define OV_LOG_COMPILE_START(session_id, fused_node_count, device_type, precision) \ + OVTelemetry::Instance().LogCompileStart(session_id, fused_node_count, device_type, precision) + +#define OV_LOG_COMPILE_END(session_id, success, error_message, duration_ms) \ + OVTelemetry::Instance().LogCompileEnd(session_id, success, error_message, duration_ms) } // namespace openvino_ep } // namespace onnxruntime From 0ff27954323b9ebb122a09eff72bca3d49774058 Mon Sep 17 00:00:00 2001 From: ankitm3k Date: Thu, 9 Oct 2025 14:57:13 +0530 Subject: [PATCH 3/8] fix: refactor logging logic --- .../openvino/openvino_execution_provider.cc | 30 --- .../core/providers/openvino/ov_telemetry.cc | 230 +++++++++--------- .../core/providers/openvino/ov_telemetry.h | 73 +----- 3 files changed, 120 insertions(+), 213 deletions(-) diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index 0d73f9021a200..26ddd0522acbb 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -62,15 +62,10 @@ OpenVINOExecutionProvider::OpenVINOExecutionProvider(const ProviderInfo& info, s InitProviderOrtApi(); #ifdef _WIN32 session_id_ = ++global_session_counter_; - OV_LOG_SESSION_CREATION(session_id_, - session_context_.onnx_model_path_name.string(), - session_context_.openvino_sdk_version); // Trace all provider options as one event OVTelemetry::Instance().LogAllProviderOptions(session_id_, session_context_); // Trace all session-related flags and inferred states OVTelemetry::Instance().LogAllSessionOptions(session_id_, session_context_); - // Optionally: log provider init message also - OV_LOG_PROVIDER_INIT(session_id_, session_context_.device_type, session_context_.precision); #endif } @@ -80,14 +75,6 @@ OpenVINOExecutionProvider::~OpenVINOExecutionProvider() { backend_manager.ShutdownBackendManager(); } backend_managers_.clear(); -#ifdef _WIN32 - auto& telem = onnxruntime::openvino_ep::OVTelemetry::Instance(); - telem.LogSessionDestruction(session_id_); - telem.LogProviderShutdown(session_id_); - if (callback_etw_) - logging::EtwRegistrationManager::Instance().UnregisterInternalCallback(callback_etw_); -#endif - } std::vector> @@ -117,16 +104,6 @@ common::Status OpenVINOExecutionProvider::Compile( auto& logger = *GetLogger(); Status status = Status::OK(); - auto t0 = std::chrono::high_resolution_clock::now(); -#ifdef _WIN32 - OVTelemetry::Instance().LogCompileStart( - session_id_, - static_cast(fused_nodes.size()), - session_context_.device_type, - session_context_.precision); -#endif - - bool is_epctx_model = false; if (!fused_nodes.empty()) { // Assume these properties are constant for all the model subgraphs, otherwise move to SubGraphContext @@ -247,13 +224,6 @@ common::Status OpenVINOExecutionProvider::Compile( file << metadata; } -#ifdef _WIN32 - auto t1 = std::chrono::high_resolution_clock::now(); - int64_t ms = std::chrono::duration_cast(t1 - t0).count(); - OVTelemetry::Instance().LogCompileEnd(session_id_, status.IsOK(), status.ErrorMessage(), ms); -#endif - - return status; } diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.cc b/onnxruntime/core/providers/openvino/ov_telemetry.cc index 7a360553afb22..33d8a364adf13 100644 --- a/onnxruntime/core/providers/openvino/ov_telemetry.cc +++ b/onnxruntime/core/providers/openvino/ov_telemetry.cc @@ -1,9 +1,8 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Intel Corporation. All rights reserved. // Licensed under the MIT License. #include "core/providers/openvino/ov_telemetry.h" #ifdef _WIN32 -#if !BUILD_OPENVINO_EP_STATIC_LIB #include #ifdef _MSC_VER #pragma warning(push) @@ -15,19 +14,18 @@ TRACELOGGING_DEFINE_PROVIDER( ov_telemetry_provider_handle, - "Microsoft.ML.ONNXRuntime.OpenVINO", + "Intel.ML.ONNXRuntime.OpenVINO", + // {"b5a8c2e1-4d7f-4a3b-9c2e-1f8e5a6b7c9d"} (0xb5a8c2e1, 0x4d7f, 0x4a3b, 0x9c, 0x2e, 0x1f, 0x8e, 0x5a, 0x6b, 0x7c, 0x9d), TraceLoggingOptionMicrosoftTelemetry()); #ifdef _MSC_VER #pragma warning(pop) #endif -#endif // !BUILD_OPENVINO_EP_STATIC_LIB namespace onnxruntime { namespace openvino_ep { -#if !BUILD_OPENVINO_EP_STATIC_LIB std::mutex OVTelemetry::mutex_; std::mutex OVTelemetry::provider_change_mutex_; uint32_t OVTelemetry::global_register_count_ = 0; @@ -36,10 +34,8 @@ UCHAR OVTelemetry::level_ = 0; UINT64 OVTelemetry::keyword_ = 0; std::vector OVTelemetry::callbacks_; std::mutex OVTelemetry::callbacks_mutex_; -#endif OVTelemetry::OVTelemetry() { -#if !BUILD_OPENVINO_EP_STATIC_LIB std::lock_guard lock(mutex_); if (global_register_count_ == 0) { HRESULT hr = TraceLoggingRegisterEx(ov_telemetry_provider_handle, ORT_TL_EtwEnableCallback, nullptr); @@ -47,11 +43,9 @@ OVTelemetry::OVTelemetry() { global_register_count_ += 1; } } -#endif } OVTelemetry::~OVTelemetry() { -#if !BUILD_OPENVINO_EP_STATIC_LIB std::lock_guard lock(mutex_); if (global_register_count_ > 0) { global_register_count_ -= 1; @@ -61,7 +55,6 @@ OVTelemetry::~OVTelemetry() { } std::lock_guard lock_callbacks(callbacks_mutex_); callbacks_.clear(); -#endif } OVTelemetry& OVTelemetry::Instance() { @@ -70,32 +63,37 @@ OVTelemetry& OVTelemetry::Instance() { } bool OVTelemetry::IsEnabled() const { -#if BUILD_OPENVINO_EP_STATIC_LIB - return false; -#else std::lock_guard lock(provider_change_mutex_); return enabled_; -#endif } UCHAR OVTelemetry::Level() const { -#if BUILD_OPENVINO_EP_STATIC_LIB - return 0; -#else std::lock_guard lock(provider_change_mutex_); return level_; -#endif } UINT64 OVTelemetry::Keyword() const { -#if BUILD_OPENVINO_EP_STATIC_LIB - return 0; -#else std::lock_guard lock(provider_change_mutex_); return keyword_; -#endif } +template +void AddOptionalValue(std::ostringstream& json, const std::string& key, const T& value, const T& default_value, bool& first) { + if (value != default_value) { + if (!first) json << ","; + json << "\"" << key << "\":"; + if constexpr (std::is_same_v) { + json << "\"" << value << "\""; + } else if constexpr (std::is_same_v) { + json << (value ? "true" : "false"); + } else { + json << value; + } + first = false; + } +} + + std::string OVTelemetry::SerializeLoadConfig(const SessionContext& ctx) const { if (ctx.load_config.empty()) return "{}"; @@ -158,7 +156,7 @@ std::string OVTelemetry::SerializeLoadConfig(const SessionContext& ctx) const { } -std::string OVTelemetry::SerializeReshapeConfig(const SessionContext& ctx) const { +std::string OVTelemetry::SerializeReshapeInputConfig(const SessionContext& ctx) const { if (ctx.reshape.empty()) return "{}"; std::ostringstream json; @@ -227,128 +225,129 @@ std::string OVTelemetry::SerializeLayoutConfig(const SessionContext& ctx) const void OVTelemetry::LogAllProviderOptions(uint32_t session_id, const SessionContext& ctx) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB if (!IsEnabled()) return; std::ostringstream opts; - opts << "{" - << "\"device_type\":\"" << ctx.device_type << "\"," - << "\"precision\":\"" << ctx.precision << "\"," - << "\"num_of_threads\":" << ctx.num_of_threads << "," - << "\"model_priority\":\"" << ctx.model_priority << "\"," - << "\"num_streams\":" << ctx.num_streams << "," - << "\"enable_opencl_throttling\":" << (ctx.enable_opencl_throttling ? "true" : "false") << "," - << "\"disable_dynamic_shapes\":" << (ctx.disable_dynamic_shapes ? "true" : "false") << "," - << "\"enable_qdq_optimizer\":" << (ctx.enable_qdq_optimizer ? "true" : "false") << "," - << "\"enable_causallm\":" << (ctx.enable_causallm ? "true" : "false") << "," - << "\"cache_dir\":\"" << ctx.cache_dir.string() << "\"," - << "\"context\":" << (ctx.context ? "\"set\"" : "null") << "," - << "\"load_config\":" << SerializeLoadConfig(ctx) << "," - << "\"reshape\":" << SerializeReshapeConfig(ctx) << "," - << "\"layout\":" << SerializeLayoutConfig(ctx) - << "}"; - - TraceLoggingWrite(ov_telemetry_provider_handle, "OVProviderOptionsComplete", - TraceLoggingKeyword(ov_keywords::OV_PROVIDER | ov_keywords::OV_OPTIONS), - TraceLoggingLevel(5), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingString(opts.str().c_str(), "provider_options")); -#endif + opts << "{"; + bool first = true; + + // Only log non-default values + AddOptionalValue(opts, "device_type", ctx.device_type, std::string(""), first); + AddOptionalValue(opts, "precision", ctx.precision, std::string(""), first); + AddOptionalValue(opts, "num_of_threads", ctx.num_of_threads, 0u, first); + AddOptionalValue(opts, "model_priority", ctx.model_priority, std::string("DEFAULT"), first); + AddOptionalValue(opts, "num_streams", ctx.num_streams, 1u, first); + AddOptionalValue(opts, "enable_opencl_throttling", ctx.enable_opencl_throttling, false, first); + AddOptionalValue(opts, "disable_dynamic_shapes", ctx.disable_dynamic_shapes, false, first); + AddOptionalValue(opts, "enable_qdq_optimizer", ctx.enable_qdq_optimizer, false, first); + AddOptionalValue(opts, "enable_causallm", ctx.enable_causallm, false, first); + + if (!ctx.cache_dir.empty()) { + if (!first) opts << ","; + opts << "\"cache_dir\":\"" << ctx.cache_dir.string() << "\""; + first = false; + } + + if (ctx.context != nullptr) { + if (!first) opts << ","; + opts << "\"context\":\"set\""; + first = false; + } + + std::string load_config_json = SerializeLoadConfig(ctx); + if (load_config_json != "{}") { + if (!first) opts << ","; + opts << "\"load_config\":" << load_config_json; + first = false; + } + + std::string reshape_json = SerializeReshapeInputConfig(ctx); + if (reshape_json != "{}") { + if (!first) opts << ","; + opts << "\"reshape_input\":" << reshape_json; + first = false; + } + + std::string layout_json = SerializeLayoutConfig(ctx); + if (layout_json != "{}") { + if (!first) opts << ","; + opts << "\"layout\":" << layout_json; + first = false; + } + + opts << "}"; + + // Only log if there are actual provider options + if (opts.str() != "{}") { + TraceLoggingWrite(ov_telemetry_provider_handle, "OVEPProviderOptions", + TraceLoggingKeyword(ov_keywords::OV_PROVIDER | ov_keywords::OV_OPTIONS), + TraceLoggingLevel(5), + TraceLoggingUInt32(session_id, "session_id"), + TraceLoggingString(opts.str().c_str(), "provider_options")); + } } void OVTelemetry::LogAllSessionOptions(uint32_t session_id, const SessionContext& ctx) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB if (!IsEnabled()) return; std::ostringstream sopts; - sopts << "{" - << "\"onnx_model_path_name\":\"" << ctx.onnx_model_path_name.string() << "\"," - << "\"onnx_opset_version\":" << ctx.onnx_opset_version << "," - << "\"wholly_supported_graph\":" << (ctx.is_wholly_supported_graph ? "true" : "false") << "," - << "\"has_external_weights\":" << (ctx.has_external_weights ? "true" : "false") << "," - << "\"openvino_sdk_version\":\"" << ctx.openvino_sdk_version << "\"," - << "\"so_context_enable\":" << (ctx.so_context_enable ? "true" : "false") << "," - << "\"so_disable_cpu_ep_fallback\":" << (ctx.so_disable_cpu_ep_fallback ? "true" : "false") << "," - << "\"so_context_embed_mode\":" << (ctx.so_context_embed_mode ? "true" : "false") << "," - << "\"so_share_ep_contexts\":" << (ctx.so_share_ep_contexts ? "true" : "false") << "," - << "\"so_context_file_path\":\"" << ctx.so_context_file_path.string() << "\"" - << "}"; - - TraceLoggingWrite(ov_telemetry_provider_handle, "OVSessionOptionsComplete", - TraceLoggingKeyword(ov_keywords::OV_SESSION | ov_keywords::OV_OPTIONS), - TraceLoggingLevel(5), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingString(sopts.str().c_str(), "session_options")); -#endif -} + sopts << "{"; + bool first = true; -void OVTelemetry::LogSessionDestruction(uint32_t session_id) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - if (!IsEnabled()) return; - TraceLoggingWrite(ov_telemetry_provider_handle, "OVSessionDestruction", - TraceLoggingKeyword(ov_keywords::OV_SESSION), - TraceLoggingLevel(5), - TraceLoggingUInt32(session_id, "session_id")); -#endif -} + // Always log model path if available + if (!ctx.onnx_model_path_name.empty()) { + if (!first) sopts << ","; + sopts << "\"onnx_model_path_name\":\"" << ctx.onnx_model_path_name.string() << "\""; + first = false; + } -void OVTelemetry::LogProviderShutdown(uint32_t session_id) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - if (!IsEnabled()) return; - TraceLoggingWrite(ov_telemetry_provider_handle, "OVProviderShutdown", - TraceLoggingKeyword(ov_keywords::OV_PROVIDER), - TraceLoggingLevel(5), - TraceLoggingUInt32(session_id, "session_id")); -#endif -} + // Only log non-zero opset version + AddOptionalValue(sopts, "onnx_opset_version", ctx.onnx_opset_version, 0u, first); -void OVTelemetry::LogCompileStart(uint32_t session_id, uint32_t fused_node_count, const std::string& device_type, const std::string& precision) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - if (!IsEnabled()) return; - TraceLoggingWrite(ov_telemetry_provider_handle, "OVCompileStart", - TraceLoggingKeyword(ov_keywords::OV_COMPILATION), - TraceLoggingLevel(5), - TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingUInt32(fused_node_count, "fused_node_count"), - TraceLoggingString(device_type.c_str(), "device_type"), - TraceLoggingString(precision.c_str(), "precision")); -#endif -} + // Only log if explicitly set + AddOptionalValue(sopts, "wholly_supported_graph", ctx.is_wholly_supported_graph, false, first); + AddOptionalValue(sopts, "has_external_weights", ctx.has_external_weights, false, first); -void OVTelemetry::LogCompileEnd(uint32_t session_id, bool success, const std::string& error_message, int64_t duration_ms) const { -#if !BUILD_OPENVINO_EP_STATIC_LIB - if (!IsEnabled()) return; - TraceLoggingWrite(ov_telemetry_provider_handle, "OVCompileEnd", - TraceLoggingKeyword(ov_keywords::OV_COMPILATION | ov_keywords::OV_PERFORMANCE), - TraceLoggingLevel(4), + // Always log SDK version + if (!first) sopts << ","; + sopts << "\"openvino_sdk_version\":\"" << ctx.openvino_sdk_version << "\""; + first = false; + + // Only log session options if they're non-default + AddOptionalValue(sopts, "ep.context_enable", ctx.so_context_enable, false, first); + AddOptionalValue(sopts, "session.disable_cpu_ep_fallback", ctx.so_disable_cpu_ep_fallback, false, first); + AddOptionalValue(sopts, "ep.context_embed_mode", ctx.so_context_embed_mode, false, first); + AddOptionalValue(sopts, "ep.context_file_path", ctx.so_share_ep_contexts, false, first); + + if (!ctx.so_context_file_path.empty()) { + if (!first) sopts << ","; + sopts << "\"ep.context_file_path\":\"" << ctx.so_context_file_path.string() << "\""; + first = false; + } + + sopts << "}"; + + TraceLoggingWrite(ov_telemetry_provider_handle, "OVEPSessionOptions", + TraceLoggingKeyword(ov_keywords::OV_SESSION | ov_keywords::OV_OPTIONS), + TraceLoggingLevel(5), TraceLoggingUInt32(session_id, "session_id"), - TraceLoggingBool(success, "success"), - TraceLoggingString(error_message.c_str(), "error_message"), - TraceLoggingInt64(duration_ms, "compile_duration_ms")); -#endif + TraceLoggingString(sopts.str().c_str(), "session_options")); } void OVTelemetry::RegisterInternalCallback(const EtwInternalCallback& callback) { -#if BUILD_OPENVINO_EP_STATIC_LIB -#else std::lock_guard lock_callbacks(callbacks_mutex_); callbacks_.push_back(&callback); -#endif } void OVTelemetry::UnregisterInternalCallback(const EtwInternalCallback& callback) { -#if BUILD_OPENVINO_EP_STATIC_LIB -#else std::lock_guard lock_callbacks(callbacks_mutex_); auto new_end = std::remove_if(callbacks_.begin(), callbacks_.end(), [&callback](const EtwInternalCallback* ptr) { return ptr == &callback; }); callbacks_.erase(new_end, callbacks_.end()); -#endif } -#if !BUILD_OPENVINO_EP_STATIC_LIB void NTAPI OVTelemetry::ORT_TL_EtwEnableCallback( _In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData, _In_opt_ PVOID CallbackContext) { @@ -366,7 +365,6 @@ void OVTelemetry::InvokeCallbacks(LPCGUID SourceId, ULONG IsEnabled, UCHAR Level (*callback)(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext); } } -#endif } // namespace openvino_ep } // namespace onnxruntime diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.h b/onnxruntime/core/providers/openvino/ov_telemetry.h index f484b57e0be33..42e1b0bf629b2 100644 --- a/onnxruntime/core/providers/openvino/ov_telemetry.h +++ b/onnxruntime/core/providers/openvino/ov_telemetry.h @@ -1,25 +1,23 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Intel Corporation. All rights reserved. // Licensed under the MIT License. #pragma once #ifdef _WIN32 #include -#if !BUILD_OPENVINO_EP_STATIC_LIB #include #include -#endif + #include #include #include #include #include #include +#include #include "core/providers/openvino/contexts.h" #include "nlohmann/json.hpp" -#if !BUILD_OPENVINO_EP_STATIC_LIB TRACELOGGING_DECLARE_PROVIDER(ov_telemetry_provider_handle); -#endif namespace onnxruntime { namespace openvino_ep { @@ -27,13 +25,7 @@ namespace openvino_ep { namespace ov_keywords { constexpr uint64_t OV_PROVIDER = 0x1; constexpr uint64_t OV_SESSION = 0x2; - constexpr uint64_t OV_OPTIONS = 0x4; - constexpr uint64_t OV_CAPABILITY = 0x8; - constexpr uint64_t OV_COMPILATION= 0x10; - constexpr uint64_t OV_EXECUTION = 0x20; - constexpr uint64_t OV_BACKEND = 0x40; - constexpr uint64_t OV_PERFORMANCE= 0x80; - constexpr uint64_t OV_ERROR = 0x100; + constexpr uint64_t OV_OPTIONS = 0x3; } class OVTelemetry { @@ -43,16 +35,9 @@ class OVTelemetry { unsigned char Level() const; UINT64 Keyword() const; - // Comprehensive provider options logging void LogAllProviderOptions(uint32_t session_id, const SessionContext& ctx) const; void LogAllSessionOptions(uint32_t session_id, const SessionContext& ctx) const; - // Individual logging methods to avoid template issues - void LogSessionDestruction(uint32_t session_id) const; - void LogProviderShutdown(uint32_t session_id) const; - void LogCompileStart(uint32_t session_id, uint32_t fused_node_count, const std::string& device_type, const std::string& precision) const; - void LogCompileEnd(uint32_t session_id, bool success, const std::string& error_message, int64_t duration_ms) const; - using EtwInternalCallback = std::function; static void RegisterInternalCallback(const EtwInternalCallback& callback); @@ -68,10 +53,9 @@ class OVTelemetry { // Helper functions for complex serialization std::string SerializeLoadConfig(const SessionContext& ctx) const; - std::string SerializeReshapeConfig(const SessionContext& ctx) const; + std::string SerializeReshapeInputConfig(const SessionContext& ctx) const; std::string SerializeLayoutConfig(const SessionContext& ctx) const; -#if !BUILD_OPENVINO_EP_STATIC_LIB static std::mutex mutex_; static uint32_t global_register_count_; static bool enabled_; @@ -84,53 +68,8 @@ class OVTelemetry { static void InvokeCallbacks(LPCGUID, ULONG, UCHAR, ULONGLONG, ULONGLONG, PEVENT_FILTER_DESCRIPTOR, PVOID); static void NTAPI ORT_TL_EtwEnableCallback(_In_ LPCGUID, _In_ ULONG, _In_ UCHAR, _In_ ULONGLONG, _In_ ULONGLONG, _In_opt_ PEVENT_FILTER_DESCRIPTOR, _In_opt_ PVOID); -#endif -}; - -// Direct macro definitions to avoid template conflicts -#define OV_LOG_SESSION_CREATION(session_id, model_path, version) \ - do { \ - if (OVTelemetry::Instance().IsEnabled()) { \ - TraceLoggingWrite(ov_telemetry_provider_handle, "OVSessionCreation", \ - TraceLoggingKeyword(ov_keywords::OV_SESSION), \ - TraceLoggingLevel(5), \ - TraceLoggingUInt32(session_id, "session_id"), \ - TraceLoggingString(model_path.c_str(), "model_path"), \ - TraceLoggingString(version.c_str(), "openvino_version")); \ - } \ - } while(0) -#define OV_LOG_PROVIDER_INIT(session_id, device_type, precision) \ - do { \ - if (OVTelemetry::Instance().IsEnabled()) { \ - TraceLoggingWrite(ov_telemetry_provider_handle, "OVProviderInit", \ - TraceLoggingKeyword(ov_keywords::OV_PROVIDER), \ - TraceLoggingLevel(5), \ - TraceLoggingUInt32(session_id, "session_id"), \ - TraceLoggingString(device_type.c_str(), "device_type"), \ - TraceLoggingString(precision.c_str(), "precision")); \ - } \ - } while(0) - -#define OV_LOG_CAPABILITY_DETECTION(session_id, node_count, wholly_supported, has_external_weights, device_type) \ - do { \ - if (OVTelemetry::Instance().IsEnabled()) { \ - TraceLoggingWrite(ov_telemetry_provider_handle, "OVCapabilityDetection", \ - TraceLoggingKeyword(ov_keywords::OV_CAPABILITY), \ - TraceLoggingLevel(5), \ - TraceLoggingUInt32(session_id, "session_id"), \ - TraceLoggingUInt32(node_count, "node_count"), \ - TraceLoggingBool(wholly_supported, "wholly_supported"), \ - TraceLoggingBool(has_external_weights, "has_external_weights"), \ - TraceLoggingString(device_type.c_str(), "device_type")); \ - } \ - } while(0) - -#define OV_LOG_COMPILE_START(session_id, fused_node_count, device_type, precision) \ - OVTelemetry::Instance().LogCompileStart(session_id, fused_node_count, device_type, precision) - -#define OV_LOG_COMPILE_END(session_id, success, error_message, duration_ms) \ - OVTelemetry::Instance().LogCompileEnd(session_id, success, error_message, duration_ms) +}; } // namespace openvino_ep } // namespace onnxruntime From acfa7b20d4a70273c9c7867d0dcaff154dd60625 Mon Sep 17 00:00:00 2001 From: ankitm3k Date: Mon, 13 Oct 2025 13:06:27 +0530 Subject: [PATCH 4/8] fix: amend review changes --- .../core/providers/openvino/ov_telemetry.cc | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.cc b/onnxruntime/core/providers/openvino/ov_telemetry.cc index 33d8a364adf13..0fc4b8b738a81 100644 --- a/onnxruntime/core/providers/openvino/ov_telemetry.cc +++ b/onnxruntime/core/providers/openvino/ov_telemetry.cc @@ -46,17 +46,25 @@ OVTelemetry::OVTelemetry() { } OVTelemetry::~OVTelemetry() { - std::lock_guard lock(mutex_); - if (global_register_count_ > 0) { - global_register_count_ -= 1; - if (global_register_count_ == 0) { - TraceLoggingUnregister(ov_telemetry_provider_handle); + // Clean up TraceLogging, only hold mutex_ + { + std::lock_guard lock(mutex_); + if (global_register_count_ > 0) { + global_register_count_ -= 1; + if (global_register_count_ == 0) { + TraceLoggingUnregister(ov_telemetry_provider_handle); + } } } - std::lock_guard lock_callbacks(callbacks_mutex_); - callbacks_.clear(); + + // Clean up callbacks, only hold callbacks_mutex_ + { + std::lock_guard lock_callbacks(callbacks_mutex_); + callbacks_.clear(); + } } + OVTelemetry& OVTelemetry::Instance() { static OVTelemetry instance; return instance; @@ -84,6 +92,8 @@ void AddOptionalValue(std::ostringstream& json, const std::string& key, const T& json << "\"" << key << "\":"; if constexpr (std::is_same_v) { json << "\"" << value << "\""; + } else if constexpr (std::is_same_v) { + json << "\"" << value.string() << "\""; } else if constexpr (std::is_same_v) { json << (value ? "true" : "false"); } else { @@ -317,13 +327,8 @@ void OVTelemetry::LogAllSessionOptions(uint32_t session_id, const SessionContext AddOptionalValue(sopts, "ep.context_enable", ctx.so_context_enable, false, first); AddOptionalValue(sopts, "session.disable_cpu_ep_fallback", ctx.so_disable_cpu_ep_fallback, false, first); AddOptionalValue(sopts, "ep.context_embed_mode", ctx.so_context_embed_mode, false, first); - AddOptionalValue(sopts, "ep.context_file_path", ctx.so_share_ep_contexts, false, first); - - if (!ctx.so_context_file_path.empty()) { - if (!first) sopts << ","; - sopts << "\"ep.context_file_path\":\"" << ctx.so_context_file_path.string() << "\""; - first = false; - } + AddOptionalValue(sopts, "ep.share_ep_contexts", ctx.so_share_ep_contexts, false, first); + AddOptionalValue(sopts, "ep.context_file_path", ctx.so_context_file_path, std::filesystem::path(), first); sopts << "}"; From ac3b92f6c723831b13aafc0b5ac44fce0744936b Mon Sep 17 00:00:00 2001 From: ankitm3k Date: Mon, 13 Oct 2025 14:43:58 +0530 Subject: [PATCH 5/8] fix: amend review changes. --- .../core/providers/openvino/ov_telemetry.cc | 69 +++++++++++-------- .../core/providers/openvino/ov_telemetry.h | 1 + 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.cc b/onnxruntime/core/providers/openvino/ov_telemetry.cc index 0fc4b8b738a81..fb298cb20c05b 100644 --- a/onnxruntime/core/providers/openvino/ov_telemetry.cc +++ b/onnxruntime/core/providers/openvino/ov_telemetry.cc @@ -23,6 +23,40 @@ TRACELOGGING_DEFINE_PROVIDER( #pragma warning(pop) #endif +namespace { + std::string EscapeJsonString(const std::string& input) { + std::string escaped; + // Reserve extra space for escaping + escaped.reserve(input.size() + input.size() / 5); + + for (char c : input) { + switch (c) { + case '\"': escaped += "\\\""; break; + case '\\': escaped += "\\\\"; break; + case '\b': escaped += "\\b"; break; + case '\f': escaped += "\\f"; break; + case '\n': escaped += "\\n"; break; + case '\r': escaped += "\\r"; break; + case '\t': escaped += "\\t"; break; + default: + if (c < 0x20) { + escaped += "\\u"; + escaped += "0000"[0]; + escaped += "0000"[1]; + char hex[3]; + sprintf_s(hex, "%02x", static_cast(c)); + escaped += hex; + } else { + escaped += c; + } + break; + } + } + return escaped; + } +} + + namespace onnxruntime { namespace openvino_ep { @@ -91,9 +125,9 @@ void AddOptionalValue(std::ostringstream& json, const std::string& key, const T& if (!first) json << ","; json << "\"" << key << "\":"; if constexpr (std::is_same_v) { - json << "\"" << value << "\""; + json << "\"" << EscapeJsonString(value) << "\""; } else if constexpr (std::is_same_v) { - json << "\"" << value.string() << "\""; + json << "\"" << EscapeJsonString(value.string()) << "\""; } else if constexpr (std::is_same_v) { json << (value ? "true" : "false"); } else { @@ -123,13 +157,7 @@ std::string OVTelemetry::SerializeLoadConfig(const SessionContext& ctx) const { // Use ov::Any's type checking and extraction capabilities if (value.is()) { std::string str_val = value.as(); - // Escape quotes in string - std::string escaped; - for (char c : str_val) { - if (c == '\"' || c == '\\') escaped.push_back('\\'); - escaped.push_back(c); - } - json << "\"" << escaped << "\""; + json << "\"" << EscapeJsonString(str_val) << "\""; } else if (value.is()) { json << value.as(); } else if (value.is()) { @@ -147,14 +175,7 @@ std::string OVTelemetry::SerializeLoadConfig(const SessionContext& ctx) const { std::ostringstream temp; value.print(temp); std::string val_str = temp.str(); - - // Escape quotes in the printed string - std::string escaped; - for (char c : val_str) { - if (c == '\"' || c == '\\') escaped.push_back('\\'); - escaped.push_back(c); - } - json << "\"" << escaped << "\""; + json << "\"" << EscapeJsonString(val_str) << "\""; } first_entry = false; } @@ -218,15 +239,7 @@ std::string OVTelemetry::SerializeLayoutConfig(const SessionContext& ctx) const // Use ov::Layout's to_string() method for proper string representation std::string layout_str = ov_layout.to_string(); - - // Escape quotes in the layout string if any - std::string escaped; - for (char c : layout_str) { - if (c == '\"' || c == '\\') escaped.push_back('\\'); - escaped.push_back(c); - } - - json << "\"" << escaped << "\""; + json << "\"" << EscapeJsonString(layout_str) << "\""; first = false; } json << "}"; @@ -254,7 +267,7 @@ void OVTelemetry::LogAllProviderOptions(uint32_t session_id, const SessionContex if (!ctx.cache_dir.empty()) { if (!first) opts << ","; - opts << "\"cache_dir\":\"" << ctx.cache_dir.string() << "\""; + opts << "\"cache_dir\":\"" << EscapeJsonString(ctx.cache_dir.string()) << "\""; first = false; } @@ -307,7 +320,7 @@ void OVTelemetry::LogAllSessionOptions(uint32_t session_id, const SessionContext // Always log model path if available if (!ctx.onnx_model_path_name.empty()) { if (!first) sopts << ","; - sopts << "\"onnx_model_path_name\":\"" << ctx.onnx_model_path_name.string() << "\""; + sopts << "\"onnx_model_path_name\":\"" << EscapeJsonString(ctx.onnx_model_path_name.string()) << "\""; first = false; } diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.h b/onnxruntime/core/providers/openvino/ov_telemetry.h index 42e1b0bf629b2..ba03d9685b9ff 100644 --- a/onnxruntime/core/providers/openvino/ov_telemetry.h +++ b/onnxruntime/core/providers/openvino/ov_telemetry.h @@ -14,6 +14,7 @@ #include #include #include +#include #include "core/providers/openvino/contexts.h" #include "nlohmann/json.hpp" From 8d54276f47e85ee59d6d7ca8c2a26fc271538a4e Mon Sep 17 00:00:00 2001 From: ankitm3k Date: Mon, 13 Oct 2025 17:03:54 +0530 Subject: [PATCH 6/8] fix: amend string parsing & add linking advapi32 in cmake --- cmake/onnxruntime_providers_openvino.cmake | 5 ++ .../core/providers/openvino/ov_telemetry.cc | 48 +++++++++---------- .../core/providers/openvino/ov_telemetry.h | 3 +- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/cmake/onnxruntime_providers_openvino.cmake b/cmake/onnxruntime_providers_openvino.cmake index 5a831a106ae08..8c8d58c30f594 100644 --- a/cmake/onnxruntime_providers_openvino.cmake +++ b/cmake/onnxruntime_providers_openvino.cmake @@ -51,6 +51,11 @@ target_include_directories(onnxruntime_providers_openvino SYSTEM PUBLIC ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${OpenVINO_INCLUDE_DIR} ${OPENVINO_INCLUDE_DIR_LIST} ${PYTHON_INCLUDE_DIRS} $ENV{OPENCL_INCS} $ENV{OPENCL_INCS}/../../cl_headers/) target_link_libraries(onnxruntime_providers_openvino ${ONNXRUNTIME_PROVIDERS_SHARED} Boost::mp11 ${OPENVINO_LIB_LIST} ${ABSEIL_LIBS} Eigen3::Eigen onnx_proto) + # ETW TraceLogging depends on Advapi32 on Windows + if(WIN32) + target_link_libraries(onnxruntime_providers_openvino advapi32) + endif() + target_compile_definitions(onnxruntime_providers_openvino PRIVATE FILE_NAME=\"onnxruntime_providers_openvino.dll\") if(MSVC) diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.cc b/onnxruntime/core/providers/openvino/ov_telemetry.cc index fb298cb20c05b..7d5cf930c1f02 100644 --- a/onnxruntime/core/providers/openvino/ov_telemetry.cc +++ b/onnxruntime/core/providers/openvino/ov_telemetry.cc @@ -39,13 +39,10 @@ namespace { case '\r': escaped += "\\r"; break; case '\t': escaped += "\\t"; break; default: - if (c < 0x20) { - escaped += "\\u"; - escaped += "0000"[0]; - escaped += "0000"[1]; - char hex[3]; - sprintf_s(hex, "%02x", static_cast(c)); - escaped += hex; + if (static_cast(c) < 0x20) { + char unicode_escape[7]; + sprintf_s(unicode_escape, sizeof(unicode_escape), "\\u%04x", static_cast(c)); + escaped += unicode_escape; } else { escaped += c; } @@ -54,6 +51,24 @@ namespace { } return escaped; } + + template + void AddOptionalValue(std::ostringstream& json, const std::string& key, const T& value, const T& default_value, bool& first) { + if (value != default_value) { + if (!first) json << ","; + json << "\"" << key << "\":"; + if constexpr (std::is_same_v) { + json << "\"" << EscapeJsonString(value) << "\""; + } else if constexpr (std::is_same_v) { + json << "\"" << EscapeJsonString(value.string()) << "\""; + } else if constexpr (std::is_same_v) { + json << (value ? "true" : "false"); + } else { + json << value; + } + first = false; + } + } } @@ -119,25 +134,6 @@ UINT64 OVTelemetry::Keyword() const { return keyword_; } -template -void AddOptionalValue(std::ostringstream& json, const std::string& key, const T& value, const T& default_value, bool& first) { - if (value != default_value) { - if (!first) json << ","; - json << "\"" << key << "\":"; - if constexpr (std::is_same_v) { - json << "\"" << EscapeJsonString(value) << "\""; - } else if constexpr (std::is_same_v) { - json << "\"" << EscapeJsonString(value.string()) << "\""; - } else if constexpr (std::is_same_v) { - json << (value ? "true" : "false"); - } else { - json << value; - } - first = false; - } -} - - std::string OVTelemetry::SerializeLoadConfig(const SessionContext& ctx) const { if (ctx.load_config.empty()) return "{}"; diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.h b/onnxruntime/core/providers/openvino/ov_telemetry.h index ba03d9685b9ff..ef26434e42dcd 100644 --- a/onnxruntime/core/providers/openvino/ov_telemetry.h +++ b/onnxruntime/core/providers/openvino/ov_telemetry.h @@ -16,7 +16,6 @@ #include #include #include "core/providers/openvino/contexts.h" -#include "nlohmann/json.hpp" TRACELOGGING_DECLARE_PROVIDER(ov_telemetry_provider_handle); @@ -26,7 +25,7 @@ namespace openvino_ep { namespace ov_keywords { constexpr uint64_t OV_PROVIDER = 0x1; constexpr uint64_t OV_SESSION = 0x2; - constexpr uint64_t OV_OPTIONS = 0x3; + constexpr uint64_t OV_OPTIONS = 0x4; } class OVTelemetry { From 0aef13b300e1c2cad897ee1123f34c1cf772abd8 Mon Sep 17 00:00:00 2001 From: ankitm3k Date: Tue, 14 Oct 2025 11:52:29 +0530 Subject: [PATCH 7/8] fix: refine options parsing --- .../core/providers/openvino/ov_telemetry.cc | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/onnxruntime/core/providers/openvino/ov_telemetry.cc b/onnxruntime/core/providers/openvino/ov_telemetry.cc index 7d5cf930c1f02..0be1b0230b90c 100644 --- a/onnxruntime/core/providers/openvino/ov_telemetry.cc +++ b/onnxruntime/core/providers/openvino/ov_telemetry.cc @@ -253,10 +253,6 @@ void OVTelemetry::LogAllProviderOptions(uint32_t session_id, const SessionContex // Only log non-default values AddOptionalValue(opts, "device_type", ctx.device_type, std::string(""), first); AddOptionalValue(opts, "precision", ctx.precision, std::string(""), first); - AddOptionalValue(opts, "num_of_threads", ctx.num_of_threads, 0u, first); - AddOptionalValue(opts, "model_priority", ctx.model_priority, std::string("DEFAULT"), first); - AddOptionalValue(opts, "num_streams", ctx.num_streams, 1u, first); - AddOptionalValue(opts, "enable_opencl_throttling", ctx.enable_opencl_throttling, false, first); AddOptionalValue(opts, "disable_dynamic_shapes", ctx.disable_dynamic_shapes, false, first); AddOptionalValue(opts, "enable_qdq_optimizer", ctx.enable_qdq_optimizer, false, first); AddOptionalValue(opts, "enable_causallm", ctx.enable_causallm, false, first); @@ -267,12 +263,7 @@ void OVTelemetry::LogAllProviderOptions(uint32_t session_id, const SessionContex first = false; } - if (ctx.context != nullptr) { - if (!first) opts << ","; - opts << "\"context\":\"set\""; - first = false; - } - + // Load configuration std::string load_config_json = SerializeLoadConfig(ctx); if (load_config_json != "{}") { if (!first) opts << ","; @@ -280,6 +271,7 @@ void OVTelemetry::LogAllProviderOptions(uint32_t session_id, const SessionContex first = false; } + // Reshape configuration std::string reshape_json = SerializeReshapeInputConfig(ctx); if (reshape_json != "{}") { if (!first) opts << ","; @@ -287,6 +279,7 @@ void OVTelemetry::LogAllProviderOptions(uint32_t session_id, const SessionContex first = false; } + // Layout configuration std::string layout_json = SerializeLayoutConfig(ctx); if (layout_json != "{}") { if (!first) opts << ","; @@ -296,7 +289,7 @@ void OVTelemetry::LogAllProviderOptions(uint32_t session_id, const SessionContex opts << "}"; - // Only log if there are actual provider options + // Log only if there are provider options available if (opts.str() != "{}") { TraceLoggingWrite(ov_telemetry_provider_handle, "OVEPProviderOptions", TraceLoggingKeyword(ov_keywords::OV_PROVIDER | ov_keywords::OV_OPTIONS), @@ -313,22 +306,7 @@ void OVTelemetry::LogAllSessionOptions(uint32_t session_id, const SessionContext sopts << "{"; bool first = true; - // Always log model path if available - if (!ctx.onnx_model_path_name.empty()) { - if (!first) sopts << ","; - sopts << "\"onnx_model_path_name\":\"" << EscapeJsonString(ctx.onnx_model_path_name.string()) << "\""; - first = false; - } - - // Only log non-zero opset version - AddOptionalValue(sopts, "onnx_opset_version", ctx.onnx_opset_version, 0u, first); - - // Only log if explicitly set - AddOptionalValue(sopts, "wholly_supported_graph", ctx.is_wholly_supported_graph, false, first); - AddOptionalValue(sopts, "has_external_weights", ctx.has_external_weights, false, first); - // Always log SDK version - if (!first) sopts << ","; sopts << "\"openvino_sdk_version\":\"" << ctx.openvino_sdk_version << "\""; first = false; From e872ca8724b70371ebdfd53f39280ea606b2655a Mon Sep 17 00:00:00 2001 From: ankitm3k Date: Tue, 14 Oct 2025 13:25:58 +0530 Subject: [PATCH 8/8] fix: perform atomic add for the global session counter --- .../core/providers/openvino/openvino_execution_provider.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index 26ddd0522acbb..5b93914328ce1 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -61,7 +61,7 @@ OpenVINOExecutionProvider::OpenVINOExecutionProvider(const ProviderInfo& info, s ep_ctx_handle_{session_context_.openvino_sdk_version, *GetLogger()} { InitProviderOrtApi(); #ifdef _WIN32 - session_id_ = ++global_session_counter_; + session_id_ = global_session_counter_.fetch_add(1) + 1; // Trace all provider options as one event OVTelemetry::Instance().LogAllProviderOptions(session_id_, session_context_); // Trace all session-related flags and inferred states