Skip to content

[Diagnostics] Add Linux performance diagnostic scenarios - #7137

Draft
mdh1418 wants to merge 1 commit into
dotnet:mainfrom
mdh1418:diagnostics/performance-scenarios
Draft

[Diagnostics] Add Linux performance diagnostic scenarios#7137
mdh1418 wants to merge 1 commit into
dotnet:mainfrom
mdh1418:diagnostics/performance-scenarios

Conversation

@mdh1418

@mdh1418 mdh1418 commented Sep 8, 2026

Copy link
Copy Markdown
Member

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:

  • Managed, native, optimized, and externally contended CPU activity.
  • Small-object allocation, large object heap pressure, induced GC, managed retention, and native memory growth.
  • Sync-over-async ThreadPool starvation, asynchronous waiting, lock contention, and deadlock formation.
  • Excessive small writes and synchronous durable I/O on ThreadPool workers.
  • JIT-heavy startup, swallowed exceptions, short-lived process churn, mixed CPU and contention, and a healthy negative control.

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/docs walkthrough at /dotnet/core/diagnostics/dotnet-trace-collect-linux-scenarios in PR dotnet/docs#55913

Validation included a Release build with zero warnings or errors and a short execution of all 20 workloads.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.0 console 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,
@mdh1418
mdh1418 requested a review from lateralusX September 9, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants