Skip to content
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

Issue correct Enable/Disable commands for EventSources with EventPipe #81867

Merged
merged 15 commits into from
Mar 3, 2023

Conversation

davmason
Copy link
Member

@davmason davmason commented Feb 9, 2023

ETW has the behavior that if multiple sessions are open the control code will always be 1 (Enable) in the callback: https://learn.microsoft.com/en-us/windows/win32/api/evntprov/nc-evntprov-penablecallback

We have code in EventSource.DoCommand() that detects this and changes the command sent to a Disable if a session is closing by checking the per session id:

bool bSessionEnable = (commandArgs.perEventSourceSessionId >= 0);

However, EventPipe did not set this up properly. We would detect that it was an EventPipe session by checking if the return value from GetSessions() was empty, and then create a placeholder session:

if (sessionsChanged.Count == 0)
sessionsChanged.Add(new KeyValuePair<SessionInfo, bool>(new SessionInfo(0, 0), true));

But this session would always have the per session id of 0, so it would not trigger the Enable->Disable logic in DoCommand(). The end result is that if you had 3 sessions enabled and then disabled, you would get 5 Enable commands and one Disable command.

This PR does the following

  • Makes Enables and Disables match for EventPipe, as they already do in ETW
  • Refactors ETW specific logic in to the ETWEventProvider class and EventPipe specific logic in to EventPipeEventProvider
  • Adds a test that Enables/Disables are balanced

Partial fix for #61353, there is still a bug in EventListener that means Disable won't be sent

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the direction. More comments on the details inline. Thanks @davmason!

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@davmason
Copy link
Member Author

davmason commented Mar 3, 2023

There were more failures than I'm comfortable merging with, rebasing against the latest in main

@davmason davmason merged commit 86c04cf into dotnet:main Mar 3, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants