Repository navigation
Modernize crank's dotnet-trace plumbing (no default-behavior change) - #886
Conversation
PR A of the dotnet-trace modernization series. Strictly additive: every
existing `--application.dotNetTrace true` invocation produces the same
trace contents it did before, byte-for-byte.
What changed
------------
* Bump `Microsoft.Diagnostics.NETCore.Client` to 0.2.661903 to pick up
the 3-arg `StartEventPipeSession(providers, requestRundown,
circularBufferMB)` overload. `Microsoft.Diagnostics.Tracing.TraceEvent`
stays at 3.1.23 -- bumping it transitively forces a 4-package STJ-pack
bump across the whole solution, which is out of scope here and is now
tracked as a follow-up.
* Refresh `TraceExtensions.cs` against `dotnet/diagnostics` `main`:
* Add modern CLR keywords (`monitoring`, `codesymbols`,
`compilation` family, `waithandle`, `allocationsampling`, etc.)
* Add modern aliases `assemblyloader` (=`fusion`) and
`managedheapcollect` (=`gcheapcollect`); preserve the legacy
keys for back-compat.
* Add corrected `gcsampledobjectallocation{high,low}` aliases;
preserve the legacy typo'd `gcsampledobjectallcation{high,low}`
keys for back-compat.
* Add modern profiles `dotnet-common`, `dotnet-sampled-thread-time`,
`sample-profiler`, `database` from
`ListProfilesCommandHandler`. The legacy `cpu-sampling` profile
is left untouched so default invocations keep producing identical
trace contents.
* New `Job` knobs (defaults reproduce today's exact behavior):
* `DotNetTraceBufferSizeMB` (default 256, today's hardcoded value).
* `DotNetTraceRequestRundown` (default true, today's implicit
overload behavior).
Surface as `--[JOB].dotnetTraceBufferSizeMB` and
`--[JOB].dotnetTraceRequestRundown`.
* `Startup.Collect(...)` and `Startup.StartDotNetTrace(...)` wire the
new knobs through to `StartEventPipeSession`.
* Documentation fixes:
* `dotnet/diagnostics/blob/master/...` -> `.../main/...` in
`Documentation.cs`, `README.md`, and `default.config.yml`.
* Document the two new flags.
* Add a two-row 'which trace collection mode?' matrix
(`DotNetTrace=true` vs `Collect=true`). The `collect-linux`
row lands in PR B.
* Tests:
* `TraceExtensionsTests` cover legacy + modern keyword resolution,
typo<->corrected alias equivalence, profile lookup,
provider-string parsing, and a smoke test that exercises the new
3-arg `StartEventPipeSession` overload end-to-end (gracefully
skips in sandboxes where diagnostic IPC is unavailable).
* `JobMixedVersionCompatTests` validate that a pre-PR-A job JSON
payload deserializes into the legacy default values, so new-agent +
old-controller and new-controller + old-agent both keep behaving
like today.
Tested
------
* `dotnet build Microsoft.Crank.sln -c Release` clean.
* `dotnet test test/Microsoft.Crank.UnitTests` -- 67 passed, 0 failed,
0 skipped (28 new TraceExtensions + 3 new mixed-version compat + 36
pre-existing).
* Manual cobalt aarch64 Ubuntu 24.04 validation pending.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR modernizes Crank’s dotnet-trace integration in a strictly additive way by updating provider/profile plumbing and surfacing new (default-preserving) configuration knobs for EventPipe session creation.
Changes:
- Bumps
Microsoft.Diagnostics.NETCore.Clientto use the 3-argStartEventPipeSession(providers, requestRundown, circularBufferMB)overload. - Adds
JobknobsDotNetTraceBufferSizeMB(default 256) andDotNetTraceRequestRundown(default true) and wires them through the agent trace collection path. - Refreshes
TraceExtensionskeyword/profile mappings and adds unit tests (including mixed-version/default-compat coverage).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.Crank.UnitTests/TraceExtensionsTests.cs | Adds coverage for keyword/profile/provider parsing and a smoke test for the new EventPipe overload. |
| test/Microsoft.Crank.UnitTests/JobMixedVersionCompatTests.cs | Verifies new Job defaults and backward-compatible JSON behavior. |
| src/Microsoft.Crank.Models/Job.cs | Introduces new dotnet-trace configuration properties with legacy-preserving defaults. |
| src/Microsoft.Crank.Controller/README.md | Documents new flags and updates diagnostics docs link to main. |
| src/Microsoft.Crank.Controller/Documentation.cs | Updates help text with new flags and refreshed docs link. |
| src/Microsoft.Crank.Controller/default.config.yml | Updates a reference link from master to main. |
| src/Microsoft.Crank.Agent/TraceExtensions.cs | Adds modern CLR keywords/aliases and modern dotnet-trace profiles while preserving legacy behavior. |
| src/Microsoft.Crank.Agent/Startup.cs | Plumbs new Job knobs into EventPipe session creation via the 3-arg overload. |
| Directory.Packages.props | Bumps Microsoft.Diagnostics.NETCore.Client package version. |
Comments suppressed due to low confidence (1)
src/Microsoft.Crank.Agent/Startup.cs:6266
buffersizenow comes from user-configurableJob.DotNetTraceBufferSizeMB, butCollectdoesn't validate it before passing it toDiagnosticsClient.StartEventPipeSession(...). A value of 0 or negative will likely causeStartEventPipeSessionto throw and abort trace collection without a clear error. Consider rejecting invalid values early with a helpful log message (or clamping to a minimum).
if (String.IsNullOrWhiteSpace(providers))
{
providers = "cpu-sampling";
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
It would be nice to test it with aditya's new dotnet tool to export traces as LLM consumable. https://github.com/adityamandaleeka/pvanalyze Some crank skill may document that too. |
The matrix was added to crank's controller help text in the dotnet-trace modernization PR. On review, embedding decision guidance directly in the flag listing crowds the help output, and the matrix will go stale as the trace collection story keeps evolving (collect-linux is still a preview verb, perfcollect's behavior on modern distros varies, etc.). Remove it here so the help text stays a flat flag reference; the same guidance will be rehomed to a dedicated docs page once the trace collection surface stabilizes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Definitely, with this capability being updated I will make sure to update my crank investigation skill to know about the tracing capabilities of crank (it already uses (or tries to use) pvanalyze). |
PR A of the dotnet-trace modernization series. Strictly additive. Every existing
--application.dotNetTrace trueinvocation produces the same trace contents it did before, byte-for-byte.What changed
Package bump (minimal).
Microsoft.Diagnostics.NETCore.Client0.2.621003 → 0.2.661903 to pick up the 3-argStartEventPipeSession(providers, requestRundown, circularBufferMB)overload.Microsoft.Diagnostics.Tracing.TraceEventstayed at 3.1.23 — bumping it transitively forcesSystem.Text.Json8.0.5 → 9.0.8 and cascades intoSystem.Text.Encodings.WebandSystem.IO.Pipelines9.x across every project in the solution. That's a runtime-version-pack-style change that doesn't belong in a strictly additive PR. Crank uses TraceEvent only for stableClrTraceEventParser.Keywordsenum values, so the bump is safe to defer to its own PR.TraceExtensions.csrefreshed fromdotnet/diagnostics's currentProviderUtils.csandListProfilesCommandHandler.cs:monitoring,codesymbols,eventsource,compilation,compilationdiagnostic,methoddiagnostic,typediagnostic,jitinstrumentationdata,profiler,waithandle,allocationsampling.assemblyloader(=fusion) andmanagedheapcollect(=gcheapcollect). Legacy keys preserved.gcsampledobjectallocation{high,low}aliases added; legacy typo'dgcsampledobjectallcation{high,low}preserved.dotnet-common,dotnet-sampled-thread-time,sample-profiler,database.cpu-samplingprofile is intentionally left untouched — that's the empty-providers fallback for--dotNetTrace true, and changing it would be a silent behavior change for every existing crank pipeline.New
Jobknobs (defaults reproduce today's exact behavior):DotNetTraceBufferSizeMB— int, default 256 (today's hardcoded value). Surface:--[JOB].dotnetTraceBufferSizeMB.DotNetTraceRequestRundown— bool, default true (today's implicit 2-arg-overload behavior). Surface:--[JOB].dotnetTraceRequestRundown.Startup.csplumbing —Collect(...)grew arequestRundownparameter and now calls the 3-argStartEventPipeSessionoverload;StartDotNetTrace(...)passes the newJobknobs through. The empty-providers fallback stays"cpu-sampling".Documentation/README updates:
dotnet/diagnostics/blob/master/...→.../main/...inDocumentation.cs,README.md, anddefault.config.yml.DotNetTrace=truevsCollect=true). Thecollect-linuxrow lands in PR B.Tests:
TraceExtensionsTests— legacy + modern keyword resolution, typo/corrected alias equivalence, profile lookup (case-insensitive),ToProviderparsing, plus a smoke test that exercises the new 3-argStartEventPipeSessionoverload end-to-end (gracefully skips in sandboxes where diagnostic IPC is unavailable).JobMixedVersionCompatTests— a pre-PR-A job JSON payload (no new fields) deserializes into the legacy default values. Validates that new-agent + old-controller and new-controller + old-agent both keep behaving like today.Tested
dotnet build Microsoft.Crank.sln -c Release— clean, 0 warnings, 0 errors.dotnet test test/Microsoft.Crank.UnitTests— 67 passed, 0 failed, 0 skipped (28 newTraceExtensions+ 3 new mixed-version compat + 36 pre-existing).dotnet/crank).Out of scope (intentional)
collect-linuxmode. That's PR B (stacked on this branch asloopedbard3/dotnet-trace-collect-linux).cpu-samplingfallback for--dotNetTrace trueis unchanged; promoting it todotnet-sampled-thread-time,dotnet-commonis a separate (optional) future PR with its own back-compat justification.TraceEventbump. Deferred to its own PR — see "Package bump" above.Follow-ups
DotNetTraceCollectMode=collect-linux(lazydotnet-traceCLI install + shell-out + Linux/root/kernel preflights with a hard-fail no-silent-fallback). Stacks on this branch.TraceEvent3.1.23 → 3.2.x together with the System.Text.Json 9.0.x pack.defaultmode fromcpu-samplingto the modern recommended pair.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com