-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Introduce a new internal EventSourceGenerator and use it for all ES implementations #121180
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
base: main
Are you sure you want to change the base?
Conversation
|
hm.. probably should move the SLNX update to a separate (last) commit (or maybe even PR?) |
…+ no explicit ctors 2) Introduce a new global SourceGenerators - EventSourceGenerator (and move the existing impl from SPC.Generators to this new project) 3) Update slnx files (via the UpdateSolutionFiles task) 4) Migrate all classes with [EventSource] to use the SG. Except for the ones with EtwSelfDescribingEventFormat
We will likely want more than just this, e.g. it'll need to be |
Do we need to modify the slnx files? Could we instead globally include via .props? |
it's not needed to build the projects, but needed for people opening slnx files for the SG project to show up there in slnx. All other source generator projects are already added there (added automatically by the UpdateSolutionFile task, which is manually invoked (it's slow)) |
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
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.
Pull Request Overview
This PR introduces a source generator for EventSource classes to automatically generate constructors and metadata, eliminating the need for manual boilerplate code. The generator creates parameterless constructors that call the base EventSource constructor with the correct parameter order (name, guid).
Key changes:
- Introduces
EventSourceGeneratorsource generator that triggers on classes with[EventSource]attribute - Removes
[EventSourceAutoGenerate]attribute and makes affected EventSource classespartial - Changes EventSource base constructor parameter order from
(Guid, string)to(string, Guid)for consistency - Removes manual constructors from EventSource classes across the codebase
Reviewed Changes
Copilot reviewed 50 out of 50 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| EventSourceGenerator.cs | New source generator that creates constructors for EventSource classes |
| EventSourceGenerator.Parser.cs | Parser logic to extract EventSource metadata and validate constructors |
| EventSourceGenerator.Emitter.cs | Code generation logic for constructors and provider metadata |
| EventSource.cs | Changes constructor parameter order and visibility for source generator |
| TraceLoggingEventSource.cs | Updates constructor call to match new parameter order |
| Multiple EventSource classes | Removes manual constructors and adds partial keyword |
| NetCoreAppLibrary.props | Registers EventSourceGenerator |
| generators.targets | Enables generator for source projects |
| Directory.Build.props | Suppresses ESGEN001 warnings globally |
Comments suppressed due to low confidence (1)
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Parser.cs:24
- The parser only checks for
NamespaceDeclarationSyntaxbut doesn't check forFileScopedNamespaceDeclarationSyntax. This will cause the generator to skip classes in file-scoped namespaces. UseBaseNamespaceDeclarationSyntaxas the base type to handle both traditional and file-scoped namespace declarations.
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Parser.cs
Outdated
Show resolved
Hide resolved
...es/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyInjection/src/DependencyInjectionEventSource.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.EventSource/src/LoggingEventSource.cs
Outdated
Show resolved
Hide resolved
...es/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
Outdated
Show resolved
Hide resolved
...es/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
Outdated
Show resolved
Hide resolved
...es/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
Outdated
Show resolved
Hide resolved
jkotas
left a comment
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.
Delete redundant comments
...stem.Collections.Concurrent/src/System/Collections/Concurrent/CDSCollectionETWBCLProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/PLINQETWProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs
Outdated
Show resolved
Hide resolved
jkotas
left a comment
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.
Unused?
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs
Outdated
Show resolved
Hide resolved
…acing/RuntimeEventSource.cs
| public EventSource(string eventSourceName, System.Diagnostics.Tracing.EventSourceSettings config) { } | ||
| public EventSource(string eventSourceName, System.Diagnostics.Tracing.EventSourceSettings config, params string[]? traits) { } | ||
| public EventSource(string eventSourceName, Guid eventSourceGuid) { } | ||
| public EventSource(string eventSourceName, Guid eventSourceGuid, System.Diagnostics.Tracing.EventSourceSettings settings, params string[]? traits) { } |
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.
The approved API shape (and the implementation) has default null value for traits, but this has params and no null value. Which one is correct?
Do we need to add a test to validate that the new constructor works as expected?
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.
@jkotas sorry, I am not following - what that test is expected to cover?
PS: added = null and removed params to match exactly the approved shape. Presumably, this particular API is mostly for the SG.
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.
Although, isn't params string[] x and string[] x = null are the same thing? 🤔
I guess adding params (but not removing) shouldn't be a breaking change. However, feels like collections literals effectively made params redundant
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.
Although, isn't params string[] x and string[] x = null are the same thing?
No, if you don't pass an argument for the latter, x will be null, but if you don't pass an argument for the former, x will be Array.Empty<string>().
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.
Ah, indeed
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.
what that test is expected to cover?
The tests for the existing APIs are in https://github.com/dotnet/runtime/blob/5bceb8184fcde55143d2102a65c72bd6233e950b/src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestsTraits.cs and related files.
Add some tests like that for the new APIs?
src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs
Outdated
Show resolved
Hide resolved
| } | ||
| } | ||
|
|
||
| // FrameworkEventSource is on the startup path for the framework, so we have this internal overload that it can use |
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.
This comment should be deleted and replaced with tripple slash comment that will be used to populate the docs.
| { } | ||
|
|
||
| // Used by the internal FrameworkEventSource constructor and the TraceLogging-style event source constructor | ||
| internal EventSource(Guid eventSourceGuid, string eventSourceName, EventSourceSettings settings, string[]? traits = null) |
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.
Same here
|
@copilot address the recent feedback |
|
oh, that doesn't work that way? |
You can ask it to create a PR against your branch, but it will never do a direct push into your branch currently. |
Closes #28290
[EventSourceAutoGenerate], we rely on just [EventSource] + no explicit ctorsEventSourceSettings.EtwSelfDescribingEventFormat-- there are 3 ES impl defining this settings 🤔