-
Notifications
You must be signed in to change notification settings - Fork 738
Extend PredefinedDynamicTraceEventParser to Support Dynamic Events from EventPipeEventSource #2232
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
Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
@copilot, this code looks correct. I'd now like for you to update |
…micTraceEventParser Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
I've updated
The implementation provides both dynamic event support (for EventPipe sources) and backward compatibility for existing code. Commit: 87a570a |
@copilot please update the |
Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
I've updated the
The events now properly leverage the |
@@ -97,8 +98,24 @@ protected internal override void EnumerateTemplates(Func<string, string, EventFi | |||
/// </summary> | |||
private bool OnUnhandledEvent(TraceEvent data) | |||
{ | |||
// Parse event metadata. | |||
DynamicTraceEventData dynamicTraceEventData = RegisteredTraceEventParser.TryLookupWorker(data); | |||
// Parse event metadata based on the source type |
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.
There is a more structural problem here that I hadn't appreciated. PredefinedDynamicTraceEventParser
has an implementation that handles unknown events, and so does ExternalTraceEventParser
. I think we should make PredefinedDynamicTraceEventParser
inherit from ExternalTraceEventParser
and that way it can use the implementation for unknown events in ExternalTraceEventParser
. This will also require changing the implementation of ExternalTraceEventParser
- specifically the implementation of delegate passed to RegisterUnhandledEvent
so that it can find both events in the ExternalTraceEventParserState
and those in PredefinedDynamicTraceEventParser
. I think that we should be able to merge their implementations into ExternalTraceEventParser
instead of having a separate implementation in PredefinedDynamicTraceEventParser
.
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.
I've refactored the architecture as requested. Changes made:
- Changed inheritance:
PredefinedDynamicTraceEventParser
now inherits fromExternalTraceEventParser
instead ofTraceEventParser
- Implemented
TryLookup
: Replaced the customOnUnhandledEvent
handler with the standardTryLookup
method - Eliminated duplication: Removed the separate unhandled event registration logic
- Unified implementation: Both ETW and EventPipe event metadata parsing now use the same
ExternalTraceEventParser
framework
The implementations are now merged - ExternalTraceEventParser
handles the unhandled event registration, and PredefinedDynamicTraceEventParser.TryLookup
provides the predefined dynamic event lookup. This eliminates the structural problem while maintaining all existing functionality.
Commit: 618992c
PredefinedDynamicTraceEventParser. Ensure we don't spend lots of time decoding metadata over and over.
618992c
to
4fb67c1
Compare
using Microsoft.Diagnostics.Tracing.Parsers; | ||
using Microsoft.Diagnostics.Tracing.Parsers.Universal.Events; | ||
|
||
string inputFileName = args[0]; |
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.
@copilot, this file contains a standalone repro test case that can be built and run, passing in an argument with the path to repro.nettrace
.
Current Behavior: If an instance of DynamicParser
is used to parse an event, then the event is not properly dispatched to the UniversalEventsTraceEventParser
. For this repro case, the CPU events are written to the console with the prefix "Dynamic Parser:".
Expected Behavior: I expect the events to be dispatched by both the DynamicTraceEventParser
and the UniversalEventsTraceEventParser
if they both register to receive the event. Thus for cpu events, I expect to see console output that is prefixed by Dynamic Parser:
and then on a separate line CPU:
. Which of these prefixes shows up first does not matter.
Given that this is not working, can you please build and run the test case, confirm that is not working, and see if you can develop a fix.
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.
I've confirmed the issue and identified the root cause. The problem occurs when both DynamicTraceEventParser
and UniversalEventsTraceEventParser
register handlers for the same event - only one parser receives the events due to template registration conflicts.
Key Findings:
- ✅
UniversalEventsTraceEventParser
works correctly when used alone - ✅ Both parsers work when handling different events
- ❌ When both handle the same event, only the first-registered parser gets events
Current Status:
I've made partial fixes to the template registration mechanism, but the core issue with multiple parsers handling identical events still needs to be resolved. The template chaining logic exists but appears to have dispatch issues.
Working on a complete solution to ensure both parsers can receive the same events simultaneously. Commit: 37104ad
…lEventsTraceEventParser Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
This PR extends
PredefinedDynamicTraceEventParser
to support dynamic events fromEventPipeEventSource
in addition toETWTraceEventSource
.Problem
Previously,
PredefinedDynamicTraceEventParser.OnUnhandledEvent
only handled ETW events usingRegisteredTraceEventParser.TryLookupWorker()
, which doesn't work for EventPipe events. This meant that predefined dynamic event templates couldn't be used with EventPipe trace sources.Solution
Modified the
OnUnhandledEvent
method to:data.Source as EventPipeEventSource
to detect EventPipe sourcesEventPipeEventSource.TryGetTemplateFromMetadata()
to retrieve event templatesRegisteredTraceEventParser.TryLookupWorker()
Benefits
EventPipeTraceEventParser.TryLookup
The implementation follows the same architectural pattern already established in the codebase and enables unified dynamic event handling across both ETW and EventPipe trace sources.
Fixes #2231.