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

Correctly apply EventSourceSupport feature switch to NativeRuntimeEventSource #43602

Merged

Conversation

vitek-karas
Copy link
Member

NativeRuntimeEventSource.ProcessEvent is called from native code in CoreCLR and as such is rooted in the descriptor. But if event source is disabled via feature switch it should not do anything.

…ntSource

`NativeRuntimeEventSource.Process` is called from native code in CoreCLR and as such is rooted in the descriptor. But if event source is disabled via feature switch it should not do anything.
@vitek-karas vitek-karas added the linkable-framework Issues associated with delivering a linker friendly framework label Oct 19, 2020
@vitek-karas vitek-karas added this to the 6.0.0 milestone Oct 19, 2020
@vitek-karas vitek-karas self-assigned this Oct 19, 2020
@ghost
Copy link

ghost commented Oct 19, 2020

Tagging subscribers to this area: @vitek-karas, @agocke
See info in area-owners.md if you want to be subscribed.

@ghost
Copy link

ghost commented Oct 19, 2020

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -28,6 +28,11 @@ internal sealed partial class NativeRuntimeEventSource : EventSource
[NonEvent]
internal unsafe void ProcessEvent(uint eventID, uint osThreadID, DateTime timeStamp, Guid activityId, Guid childActivityId, ReadOnlySpan<byte> payload)
{
if (!IsSupported)
Copy link
Member

Choose a reason for hiding this comment

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

(nit) since this is an instance method, could this use IsEnabled() instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually don't know - the runtime event source is weird in many ways, so using IsSupported felt like the safe option here.

Copy link
Member

Choose a reason for hiding this comment

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

@noahfalk may advise better here. using IsEnabled looks the right way to check but I'll let @noahfalk comment on that.

Copy link
Member

Choose a reason for hiding this comment

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

I think both IsSupported or IsEnabled() would work fine, but in the interest of simplicity (and performance) I'd say leave it as IsSupported. I'd suggest adding a comment to pull this out when its time to do #43657. This change feels like the quick and dirty version, #43657 would be the good version that prunes far more code and eliminates the need for this change.

@noahfalk
Copy link
Member

noahfalk commented Oct 20, 2020

NativeRuntimeEventSource.ProcessEvent is called from native code in CoreCLR

Its been a while since I last looked at this code but that wasn't what I recalled? Looking at the code I see EventPipeEventDispatcher start a task that spins in a loop p/invoking to GetNextEvent. Is there another calling path I missed or is it this path that leads to the EventSource being rooted?

Ideally I'd recommend linking out the EventPipeEventDispatcher type entirely if your goal is to shrink code size when EventSource/EventListener isn't supported.

@vitek-karas
Copy link
Member Author

This is probably more complicated then that. There's also this:

<!-- Accessed via private reflection by an external tracing controller. -->
<type fullname="System.Diagnostics.Tracing.EventPipe*" />
<!-- The private Event methods are accessed by private reflection in the base EventSource class. -->
<type fullname="System.Diagnostics.Tracing.NativeRuntimeEventSource" />

Which roots all of the EventPipe* types fully - which in turn will bring in the NativeRuntimeEventSource, but that is also rooted explicitly above. I don't understand this system well enough to be able to tell if it's OK to remove all of these types if EventSource is disabled. It would be really nice to be able to do that though - I tried trimming it away and it saves 60KB - that's actually very interesting size win.

I also verified that simple hello world console app still works with all of the EventPipe* trimmed away. There's also no direct dependency on anything EventPipe* from managed code (linker removed all of it). Most of NativeRuntimeEventSource also went away (there are some direct dependencies on its instance, but nothing else).

That said I don't know what native code dependencies there are and how the system will behave if the managed counterparts are not present.

@vitek-karas
Copy link
Member Author

I created #43657 to track the somewhat wider problem of EventPipe behavior if we start removing parts of it.

@noahfalk
Copy link
Member

That said I don't know what native code dependencies there are and how the system will behave if the managed counterparts are not present.

The design is intended to behave fine, in practice its possible we'd find some dependency slipped in unintentionally and we need to snip it. If you want help understanding anything when you are ready to work on #43657 just let me know and we can dig in. Thanks!

@vitek-karas vitek-karas merged commit 8edb1ad into dotnet:master Dec 3, 2020
@vitek-karas vitek-karas deleted the EventSourceFSForRuntimeSource branch December 3, 2020 15:36
@ghost ghost locked as resolved and limited conversation to collaborators Jan 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Diagnostics.Tracing linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants