-
Notifications
You must be signed in to change notification settings - Fork 358
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
[tools][trace] Add stopping event options to dotnet-trace #4363
Conversation
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 LGTM!
Since the original need for this is to replace Androids profiled AOT scenario where they run automated tooling capturing startup traces that will be passed to dotnet-pgo using the new filter capabilities in dotnet-pgo. The generated mibc file could then be shipped with the release and used when building apps using Mono AOT compiler to optimize Android startup scenarios.
@jonathanpeppers This PR + changes included in dotnet-pgo dotnet/runtime#89853 should give you all tooling needed to fully replace old Mono profiled AOT with use of dotnet-trace and dotnet-pgo. dotnet-monitor already included the stop trigger solution for sometime, but having the same capabilities in dotnet-trace reduce the complexity running this in automation scenarios and the new filters in dotnet-pgo gives you fine grained control on what methods to take from nettrace file -> mibc file(s) for profiled AOT scenarios.
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.
Will you please update the dotnet-trace documentation, which is found here?
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.
LGTM, I also ran the dotnet-monitor
tests relating to stop-on-event with your changes and everything looks good.
@mikelle-rogers @dotnet/dotnet-diag Could I get another review to get this in? |
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.
Looks good to me! Thank you
I don't have permissions to merge in this repo, can I get some help with that too 😄 |
Fixes #3125
This PR provides users another method to stop a dotnet-trace via a stopping event similar to that of dotnet-monitor, originally implemented in dotnet/dotnet-monitor#2557.
Three arguments are added to the
dotnet-trace collect
command to specify a stopping event:--stopping-event-provider-name
--stopping-event-event-name
and/or--stopping-event-payload-filter
.--stopping-event-event-name
--stopping-event-provider-name
to be set. For a more specific stopping event, additionally provide--stopping-event-payload-filter
.--stopping-event-payload-filter
--stopping-event-provider-name
and--stopping-event-event-name
to be set.Note: Though technically
--stopping-event-payload-filter
can be set without needing a--stopping-event-event-name
, this may lead to mismatched payloads should anotherTraceEvent
under the same provider not have that particular payload field name. Until there is a good reason to stop a trace given a payload filter regardless of the event name, we require--stopping-event-event-name
to be set whenever--stopping-event-payload-filter
is provided.To stop a trace at a particular event, dotnet-monitor's approach using an EventMonitor is adopted. Upon hitting a TraceEvent with a matching ProviderName, EventName (if specified), and PayloadFilter (if specified), we trigger dotnet-trace's fallback logic to stop the EventPipeSession before the EventStream ends.
Note: As the EventStream is being parsed asynchronously, there will be some events that pass through between the time a trace event matching the specified stopping event arguments is parsed and the EventPipeSession is stopped.
In addition, this PR modifies
EventMonitor
to use theClrTraceEventParser
to parseTraceEvent
objects under theMicrosoft-Windows-DotNETRuntime
provider, and theDynamicTraceEventParser
otherwise. TheClrTraceEventParser
is generated to understand the ETW event manifest forMicrosoft-Windows-DotNETRuntime
events. The previous implementation defaulting toDynamicTraceEventParser
would not work on non-Windows platforms such as OSX which could not parse the payload to populatePayloadNames
andPayloadValue(i)
because there was no manifest available. On the other hand, Windows is able to locate manifest data for known events through the OS.Testing
With an Android App
Running dotnet-dsrouter to connect the diagnostic tooling with the android device
./artifacts/bin/dotnet-dsrouter/Debug/net6.0/dotnet-dsrouter android -v debug
Tracing with a stopping event args provided
./artifacts/bin/dotnet-trace/Debug/net6.0/dotnet-trace collect -p 16683 --providers Microsoft-Windows-DotNETRuntime:0x1F000080018:5 --stopping-event-provider-name Microsoft-Windows-DotNETRuntime --stopping-event-event-name Method/JittingStarted --stopping-event-payload-filter MethodName:PrintA
dotnet-dsrouter_20231024_165648.nettrace.zip
There are no
Method/JittingStarted
events with MethodNamePrintC
throughPrintK
in the.nettrace
, showing that the trace was indeed stopped after seeing thePrintA
event. The events afterPrintA
are an artifact of the second note above. Below is the JITStats of the .nettrace opened in perfview, showing that the last method wasPrintB
.