-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Improve Windows ETW callback registration and fix issues #24877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6d6aa47
b8bb316
eaeffa8
6ab0185
0a14578
e62225b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
#include "core/framework/execution_provider.h" | ||
#include "core/framework/execution_providers.h" | ||
|
||
#include "core/graph/graph_viewer.h" | ||
#include "core/framework/compute_capability.h" | ||
|
@@ -9,6 +10,8 @@ | |
#include "core/framework/murmurhash3.h" | ||
#include "core/framework/op_kernel.h" | ||
|
||
#include <stdint.h> | ||
Check warning on line 13 in onnxruntime/core/framework/execution_provider.cc
|
||
|
||
namespace onnxruntime { | ||
|
||
std::vector<std::unique_ptr<ComputeCapability>> | ||
|
@@ -37,4 +40,99 @@ | |
} | ||
|
||
#endif | ||
|
||
ExecutionProviders::ExecutionProviders() { | ||
#ifdef _WIN32 | ||
// Register callback for ETW capture state (rundown) | ||
etw_callback_key_ = "ExecutionProviders_rundown_"; | ||
etw_callback_key_.append(std::to_string(reinterpret_cast<uintptr_t>(this))); | ||
WindowsTelemetry::RegisterInternalCallback( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So each session will register a callback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each instance of ExecutionProviders would register a callback, this has not changed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be that each EP logs it's options. Taking a trace with captureState rundown is an unusual diagnostic event so happens quite rarely |
||
etw_callback_key_, | ||
[this](LPCGUID SourceId, | ||
ULONG IsEnabled, | ||
UCHAR Level, | ||
ULONGLONG MatchAnyKeyword, | ||
ULONGLONG MatchAllKeyword, | ||
PEVENT_FILTER_DESCRIPTOR FilterData, | ||
PVOID CallbackContext) { this->EtwProvidersCallback(SourceId, IsEnabled, Level, | ||
MatchAnyKeyword, MatchAllKeyword, | ||
FilterData, CallbackContext); }); | ||
#endif | ||
} | ||
|
||
ExecutionProviders::~ExecutionProviders() { | ||
#ifdef _WIN32 | ||
WindowsTelemetry::UnregisterInternalCallback(etw_callback_key_); | ||
#endif | ||
} | ||
|
||
common::Status ExecutionProviders::Add(const std::string& provider_id, | ||
const std::shared_ptr<IExecutionProvider>& p_exec_provider) { | ||
Check warning on line 70 in onnxruntime/core/framework/execution_provider.cc
|
||
// make sure there are no issues before we change any internal data structures | ||
if (provider_idx_map_.find(provider_id) != provider_idx_map_.end()) { | ||
auto status = ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Provider ", provider_id, " has already been registered."); | ||
LOGS_DEFAULT(ERROR) << status.ErrorMessage(); | ||
return status; | ||
} | ||
|
||
// index that provider will have after insertion | ||
auto new_provider_idx = exec_providers_.size(); | ||
|
||
ORT_IGNORE_RETURN_VALUE(provider_idx_map_.insert({provider_id, new_provider_idx})); | ||
|
||
// update execution provider options | ||
auto providerOptions = p_exec_provider->GetProviderOptions(); | ||
exec_provider_options_[provider_id] = providerOptions; | ||
|
||
#ifdef _WIN32 | ||
LogProviderOptions(provider_id, providerOptions, false); | ||
#endif | ||
|
||
exec_provider_ids_.push_back(provider_id); | ||
exec_providers_.push_back(p_exec_provider); | ||
return Status::OK(); | ||
} | ||
|
||
#ifdef _WIN32 | ||
void ExecutionProviders::EtwProvidersCallback(LPCGUID /* SourceId */, | ||
ULONG IsEnabled, | ||
UCHAR /* Level */, | ||
ULONGLONG MatchAnyKeyword, | ||
ULONGLONG /* MatchAllKeyword */, | ||
PEVENT_FILTER_DESCRIPTOR /* FilterData */, | ||
PVOID /* CallbackContext */) { | ||
// Check if this callback is for capturing state | ||
if ((IsEnabled == EVENT_CONTROL_CODE_CAPTURE_STATE) && | ||
((MatchAnyKeyword & static_cast<ULONGLONG>(onnxruntime::logging::ORTTraceLoggingKeyword::Session)) != 0)) { | ||
for (size_t i = 0; i < exec_providers_.size(); ++i) { | ||
const auto& provider_id = exec_provider_ids_[i]; | ||
|
||
auto it = exec_provider_options_.find(provider_id); | ||
if (it != exec_provider_options_.end()) { | ||
const auto& options = it->second; | ||
|
||
LogProviderOptions(provider_id, options, true); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void ExecutionProviders::LogProviderOptions(const std::string& provider_id, | ||
Check warning on line 120 in onnxruntime/core/framework/execution_provider.cc
|
||
const ProviderOptions& providerOptions, | ||
bool captureState) { | ||
for (const auto& config_pair : providerOptions) { | ||
TraceLoggingWrite( | ||
telemetry_provider_handle, | ||
"ProviderOptions", | ||
TraceLoggingKeyword(static_cast<uint64_t>(onnxruntime::logging::ORTTraceLoggingKeyword::Session)), | ||
TraceLoggingLevel(WINEVENT_LEVEL_INFO), | ||
TraceLoggingString(provider_id.c_str(), "ProviderId"), | ||
TraceLoggingString(config_pair.first.c_str(), "Key"), | ||
TraceLoggingString(config_pair.second.c_str(), "Value"), | ||
TraceLoggingBool(captureState, "isCaptureState")); | ||
} | ||
} | ||
|
||
#endif | ||
|
||
} // namespace onnxruntime |
Uh oh!
There was an error while loading. Please reload this page.