[Diagnostics] Add Linux performance diagnostic scenarios - #7137
Draft
mdh1418 wants to merge 1 commit into
Draft
Conversation
Add a .NET 10 sample with 20 CPU, memory, GC, blocking, I/O, exception, startup, process, mixed-cause, and healthy-control workloads for the dotnet-trace collect-linux tutorial. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Several scenarios can crash on invalid arguments or run well past the requested duration due to missing cancellation-aware waits and a fixed competitor-worker lifetime.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a new core/diagnostics/PerformanceScenarios .NET console sample intended to generate repeatable Linux performance-investigation workloads for the dotnet-trace collect-linux tutorial.
Changes:
- Introduces a
net10.0console app with scenario routing (--list, per-scenario invocation, and a cpu-competition worker mode). - Adds scenario implementations covering CPU, memory/GC, blocking/lock contention/deadlock, I/O patterns, runtime/JIT startup, exceptions, and system-level behaviors.
- Adds a README with a 20-scenario matrix describing the diagnostic question and differentiating evidence for each workload.
File summaries
| File | Description |
|---|---|
| core/diagnostics/PerformanceScenarios/PerformanceScenarios.csproj | New net10.0 executable sample project definition. |
| core/diagnostics/PerformanceScenarios/Program.cs | CLI entrypoint that lists and runs named scenarios with an optional duration. |
| core/diagnostics/PerformanceScenarios/CpuScenarios.cs | CPU-focused workloads (hotspot, inlining, native CPU via memcpy). |
| core/diagnostics/PerformanceScenarios/MemoryScenarios.cs | Allocation/GC and managed/native memory growth workloads. |
| core/diagnostics/PerformanceScenarios/BlockingScenarios.cs | Starvation, async delay, lock contention, and deadlock workloads. |
| core/diagnostics/PerformanceScenarios/IoScenarios.cs | I/O syscall amplification and sync flush-on-ThreadPool workloads. |
| core/diagnostics/PerformanceScenarios/RuntimeScenarios.cs | JIT-heavy startup and swallowed-exception workloads. |
| core/diagnostics/PerformanceScenarios/SystemScenarios.cs | Machine-wide contention workloads (cpu competition, process churn, mixed causes, healthy control). |
| core/diagnostics/PerformanceScenarios/readme.md | Sample documentation and 20-row scenario investigation matrix. |
Review details
Suppressed comments (1)
core/diagnostics/PerformanceScenarios/Program.cs:56
- The duration argument is parsed with
int.Parse, which will crash the sample on invalid input (and allows zero/negative durations). Since this sample is meant to be run interactively, consider validating the duration and reporting a friendly error with a non-zero exit code.
int durationSeconds = args.Length > 1 ? int.Parse(args[1]) : 30;
using CancellationTokenSource cancellation = new(TimeSpan.FromSeconds(durationSeconds));
- Files reviewed: 9/9 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+11
to
+15
| Task[] tasks = Enumerable.Range(0, taskCount) | ||
| .Select(_ => Task.Run(() => DelayedOperationAsync().Result)) | ||
| .ToArray(); | ||
| Task.WaitAll(tasks); | ||
| } |
Comment on lines
+35
to
+42
| Task[] tasks = Enumerable.Range(0, 64).Select(_ => Task.Run(() => | ||
| { | ||
| using FileStream stream = new(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); | ||
| stream.Write(data); | ||
| stream.Flush(flushToDisk: true); | ||
| })).ToArray(); | ||
| Task.WaitAll(tasks); | ||
| } |
Comment on lines
+40
to
+46
| if (args[0] == SystemScenarios.WorkerArgument) | ||
| { | ||
| int workerDuration = args.Length > 1 ? int.Parse(args[1]) : 30; | ||
| using CancellationTokenSource workerCancellation = new(TimeSpan.FromSeconds(workerDuration)); | ||
| await SystemScenarios.CpuWorkerAsync(workerCancellation.Token); | ||
| return; | ||
| } |
Comment on lines
+16
to
+23
| int competitorCount = Math.Min(32, Math.Max(2, Environment.ProcessorCount * 2)); | ||
| for (int index = 0; index < competitorCount; index++) | ||
| { | ||
| ProcessStartInfo startInfo = new(processPath, $"{WorkerArgument} 60") | ||
| { | ||
| RedirectStandardOutput = true, | ||
| RedirectStandardError = true, | ||
| UseShellExecute = false, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a .NET 10 sample with 20 CPU, memory, GC, blocking, I/O, exception, startup, process, mixed-cause, and healthy-control workloads for the dotnet-trace collect-linux tutorial.
Summary
Add a .NET 10 console sample with 20 runnable workloads for practicing performance investigations with
dotnet-trace collect-linux.The sample covers:
Each workload accepts a configurable duration and reports its process ID and symptom so it can be run in one terminal while collecting a trace in another. The README includes a 20-row scenario matrix that explains the distinct diagnostic question, differentiating evidence, collection requirement, limitation, or next artifact for every workload.
The sample supports the companion
dotnet/docswalkthrough at/dotnet/core/diagnostics/dotnet-trace-collect-linux-scenariosin PR dotnet/docs#55913Validation included a Release build with zero warnings or errors and a short execution of all 20 workloads.