Skip to content

Commit

Permalink
Update logging to honor initialization checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheil Kumar committed Jul 23, 2024
1 parent afd6858 commit dbac3b9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion onnxruntime/core/platform/windows/logging/etw_sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,14 @@ void NTAPI EtwRegistrationManager::ORT_TL_EtwEnableCallback(
EtwRegistrationManager::~EtwRegistrationManager() {
std::lock_guard<OrtMutex> lock(callbacks_mutex_);
callbacks_.clear();
::TraceLoggingUnregister(etw_provider_handle);
if (initialized_ || initializing_) {
std::lock_guard<OrtMutex> init_lock(init_mutex_);
assert(!initializing_);
if (initialized_) {
::TraceLoggingUnregister(etw_provider_handle);
initialized_ = false;
}
}
}

EtwRegistrationManager::EtwRegistrationManager() {
Expand Down Expand Up @@ -166,6 +173,11 @@ void EtwRegistrationManager::LazyInitialize() try {
void EtwRegistrationManager::InvokeCallbacks(LPCGUID SourceId, ULONG IsEnabled, UCHAR Level, ULONGLONG MatchAnyKeyword,
ULONGLONG MatchAllKeyword, PEVENT_FILTER_DESCRIPTOR FilterData,
PVOID CallbackContext) {
if (!initialized_) {
// Drop messages until manager is fully initialized.
return;
}

std::lock_guard<OrtMutex> lock(callbacks_mutex_);
for (const auto& callback : callbacks_) {
(*callback)(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext);
Expand Down

0 comments on commit dbac3b9

Please sign in to comment.