Skip to content

Commit

Permalink
Update runtime providers' context object on EventPipe rundown (#36733)
Browse files Browse the repository at this point in the history
* Disable EventPipeProvider Context for runtime providers on EventPipe rundown

* Add comments per code review feedback

* fix GCC build
  • Loading branch information
sywhang authored May 26, 2020
2 parents a559a1c + 1dfd937 commit e1c7d5f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/coreclr/src/vm/eventpipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,15 @@ void EventPipe::Disable(EventPipeSessionID id)
if (s_numberOfSessions > 0)
DisableInternal(id, pEventPipeProviderCallbackDataQueue);
});

#ifdef DEBUG
if ((int)s_numberOfSessions == 0)
{
_ASSERTE(!MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_DOTNET_Context.EventPipeProvider.IsEnabled);
_ASSERTE(!MICROSOFT_WINDOWS_DOTNETRUNTIME_PRIVATE_PROVIDER_DOTNET_Context.EventPipeProvider.IsEnabled);
_ASSERTE(!MICROSOFT_WINDOWS_DOTNETRUNTIME_RUNDOWN_PROVIDER_DOTNET_Context.EventPipeProvider.IsEnabled);
}
#endif
}

static void LogProcessInformationEvent(EventPipeEventSource &eventSource)
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/src/vm/eventpipeprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,14 @@ void EventPipeProvider::AddEvent(EventPipeEvent &event)
isEventFilterDescriptorInitialized = true;
}

// NOTE: When we call the callback, we pass in enabled (which is either 1 or 0) as the ControlCode.
// If we want to add new ControlCode, we have to make corresponding change in eventtrace.cpp:EtwCallbackCommon
// to address this. See https://github.com/dotnet/runtime/pull/36733 for more discussions on this.
if (pCallbackFunction != NULL && !g_fEEShutDown)
{
(*pCallbackFunction)(
NULL, /* providerId */
enabled,
enabled, /* ControlCode */
(UCHAR)providerLevel,
keywords,
0 /* matchAllKeywords */,
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/src/vm/eventtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4267,6 +4267,10 @@ VOID EtwCallbackCommon(
{
ctxToUpdate->EventPipeProvider.Level = Level;
ctxToUpdate->EventPipeProvider.EnabledKeywordsBitmask = MatchAnyKeyword;
ctxToUpdate->EventPipeProvider.IsEnabled = ControlCode;

// For EventPipe, ControlCode can only be either 0 or 1.
_ASSERTE(ControlCode == 0 || ControlCode == 1);
}

if (
Expand Down Expand Up @@ -7612,6 +7616,11 @@ bool EventPipeHelper::IsEnabled(DOTNET_TRACE_CONTEXT Context, UCHAR Level, ULONG
}
CONTRACTL_END

if (!Context.EventPipeProvider.IsEnabled)
{
return false;
}

if (Level <= Context.EventPipeProvider.Level)
{
return (Keyword == (ULONGLONG)0) || (Keyword & Context.EventPipeProvider.EnabledKeywordsBitmask) != 0;
Expand Down

0 comments on commit e1c7d5f

Please sign in to comment.