-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
EventSourceGenerator for Guid+Name .ctor and Metadata #45699
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
e784f41
to
7f5f35e
Compare
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Parser.cs
Outdated
Show resolved
Hide resolved
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti Issue DetailsHaven't done the manifest generation; which is the largest, because it's a bit wild... Contributes to #44598
|
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Parser.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
Also needs Manifest generation and all the EventSource apis are private so can't be used publicly and would need api review? |
...ystem.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs
Outdated
Show resolved
Hide resolved
...stics.Tracing.EventSource.Redist/src/Microsoft.Diagnostics.Tracing.EventSource.Redist.csproj
Outdated
Show resolved
Hide resolved
And on top of that, as nice a start as this is (thanks, @benaadams), it needs to apply to much more than just the EventSources in corelib to consider that issue addressed. That includes all the other EventSources in netcoreapp and aspnetcoreapp, and then ideally available for 3rd-party use as well. |
Need to rebase after #45738 is merged since I'm changing the |
2b38a05
to
7b2ba7d
Compare
Rebased |
runtime (CoreCLR Pri0 Runtime Tests Run Linux x64 checked) error is #39669
|
7b2ba7d
to
c117aa4
Compare
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.cs
Outdated
Show resolved
Hide resolved
CC @davmason for the profiler test failure, though I suspect the dump from that run is long gone. |
Forgot to mention in my previous comment: I'm currently reviewing this PR. I'm no expert on the Roslyn Code Generator APIs, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks good, but we need to make sure it doesn't add any public types to SPC.
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Parser.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Parser.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/generators/System.Private.CoreLib.Generators.csproj
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs
Outdated
Show resolved
Hide resolved
Another thing to note: I'm not sure we have any source generators in dotnet/runtime right now. This would be the first. @danmosemsft @ericstj has there been any motion on your comment chain #45105 (comment)? |
Yes it would need some of the |
cc @noahfalk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. Thanks, @benaadams.
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Emitter.cs
Show resolved
Hide resolved
private void GenerateConstructor(EventSourceClass ec) | ||
{ | ||
_builder.AppendLine($@" | ||
private {ec.ClassName}() : base(new Guid({ec.Guid.ToString("x").Replace("{", "").Replace("}", "")}), ""{ec.SourceName}"") {{ }}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever, eliminates the parsing at execution time.
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Emitter.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/generators/EventSourceGenerator.Parser.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs
Show resolved
Hide resolved
This reverts commit 5c8092a876d348315c1ea8a81780f46d5f6afb3e.
1707d45
to
8fe5c22
Compare
Rebased to restart CI |
I wonder if, until we can tackle that, it'd be worth adding another internal virtual property that we override on the sources in corelib and hardcode to return the appropriate metadata string/bytes? It would mean we'd need to manually update it any time we wanted to augment or otherwise change the events on these sources, until a source generator would take over. |
Can do in follow up? |
Of course, assuming we even want to do that. |
Hey @benaadams, thanks again for this PR! Sorry for the long review time. We're actively thinking about how to handle this very situation end-to-end and this work gives us a great starting point. The end state of this work will probably result in new public APIs on EventSource which is what is causing the slow down. The conversation on your other PR seems to show consensus on the location of the Source Generator code. I'll try to get another review out soon. As for the manifest generation work (the bit that will probably require a new public API), there is some prior art from the .NET Native days: runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs Lines 646 to 663 in dbcea6b
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @benaadams! I'll look at merging later this afternoon tomorrow morning to give @jkotas, @ericstj, or other reviewers time to chime in since this is modifying SPCL.
// Parameterized constructor to block initialization and ensure the EventSourceGenerator is creating the default constructor | ||
// as you can't make a constructor partial. | ||
private ArrayPoolEventSource(int _) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaredpar is there a canonical way to do this with source generators? I'm not opposed to this method, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private partial ArrayPoolEventSource();
would have worked if it was allowed (though isn't, only works for regular methods, not constructors)
The main aim is to fail compilation if the generator didn't run; rather than to succeed but not use the generated paths.
Pardon the delay, I was unexpectedly out of office yesterday. I'll be merging this morning 😄 |
Haven't done the manifest generation; which is the largest, because it's a bit wild...
Contributes to #44598