|
| 1 | +--- |
| 2 | +name: mcaf-dotnet-profiling |
| 3 | +description: "Use the free official .NET diagnostics CLI tools for profiling and runtime investigation in .NET repositories. Use when a repo needs CPU tracing, live counters, GC and allocation investigation, exception or contention tracing, heap snapshots, or startup diagnostics without GUI-only tooling." |
| 4 | +compatibility: "Requires a .NET app or process to inspect; respects the repo's `AGENTS.md` commands first." |
| 5 | +--- |
| 6 | + |
| 7 | +# MCAF: .NET Profiling |
| 8 | + |
| 9 | +## Trigger On |
| 10 | + |
| 11 | +- the repo needs performance or runtime profiling for a .NET application |
| 12 | +- the user asks about slow code, high CPU, GC pressure, allocation growth, exception storms, lock contention, or startup diagnostics |
| 13 | +- the team wants official CLI-based diagnostics without depending on `dnx` |
| 14 | + |
| 15 | +## Value |
| 16 | + |
| 17 | +- produce a concrete project delta: code, docs, config, tests, CI, or review artifact |
| 18 | +- reduce ambiguity through explicit planning, verification, and final validation skills |
| 19 | +- leave reusable project context so future tasks are faster and safer |
| 20 | + |
| 21 | +## Do Not Use For |
| 22 | + |
| 23 | +- replacing realistic performance tests or load tests with ad-hoc tracing alone |
| 24 | +- production heap collection when the pause risk has not been accepted |
| 25 | +- GUI-only workflows that the repo cannot automate or document |
| 26 | + |
| 27 | +## Inputs |
| 28 | + |
| 29 | +- the nearest `AGENTS.md` |
| 30 | +- target application, process, or startup path |
| 31 | +- the symptom being investigated: CPU, memory, GC, contention, exceptions, or startup |
| 32 | + |
| 33 | +## Quick Start |
| 34 | + |
| 35 | +1. Read the nearest `AGENTS.md` and confirm scope and constraints. |
| 36 | +2. Run this skill's `Workflow` through the `Ralph Loop` until outcomes are acceptable. |
| 37 | +3. Return the `Required Result Format` with concrete artifacts and verification evidence. |
| 38 | + |
| 39 | +## Workflow |
| 40 | + |
| 41 | +1. Build and run a realistic target first: |
| 42 | + - prefer `Release` |
| 43 | + - prefer realistic config, inputs, and data volume |
| 44 | +2. Start with the lightest useful tool: |
| 45 | + - `dotnet-counters` for live health signals |
| 46 | + - `dotnet-trace` for CPU, exception, contention, GC, and startup traces |
| 47 | + - `dotnet-gcdump` for managed heap inspection when memory shape matters |
| 48 | +3. Prefer installed CLI tools over `dnx` one-shot execution so the repo commands stay stable and reproducible. |
| 49 | +4. Capture one focused profile at a time instead of mixing every signal into one run. |
| 50 | +5. For CPU and general runtime hotspots, start with `dotnet-trace collect`. |
| 51 | +6. For live triage, start with `dotnet-counters monitor` on `System.Runtime`. |
| 52 | +7. For heap analysis, use `dotnet-gcdump` carefully and document the pause risk. |
| 53 | +8. After each change, rerun the same measurement path and compare before versus after. |
| 54 | + |
| 55 | +## Bootstrap When Missing |
| 56 | + |
| 57 | +If official .NET profiling tools are not available yet: |
| 58 | + |
| 59 | +1. Detect current state: |
| 60 | + - `dotnet --info` |
| 61 | + - `dotnet tool list --global` |
| 62 | + - `command -v dotnet-counters` |
| 63 | + - `command -v dotnet-trace` |
| 64 | + - `command -v dotnet-gcdump` |
| 65 | +2. Choose the install path deliberately: |
| 66 | + - preferred machine-level install: |
| 67 | + - `dotnet tool install --global dotnet-counters` |
| 68 | + - `dotnet tool install --global dotnet-trace` |
| 69 | + - `dotnet tool install --global dotnet-gcdump` |
| 70 | + - direct-download fallback when global tools are not suitable: |
| 71 | + - use the official Microsoft Learn download links for `dotnet-counters`, `dotnet-trace`, and `dotnet-gcdump` |
| 72 | +3. Verify the installed tools resolve correctly: |
| 73 | + - `dotnet-counters --version` |
| 74 | + - `dotnet-trace --version` |
| 75 | + - `dotnet-gcdump --version` |
| 76 | +4. Record exact profiling commands in `AGENTS.md`, for example: |
| 77 | + - `dotnet-counters monitor --process-id <pid> --counters System.Runtime` |
| 78 | + - `dotnet-trace collect --process-id <pid> --profile dotnet-common,dotnet-sampled-thread-time -o trace.nettrace` |
| 79 | + - `dotnet-gcdump collect --process-id <pid> --output heap.gcdump` |
| 80 | +5. Run one bounded command and return `status: configured` or `status: improved`. |
| 81 | +6. If the repo intentionally standardizes on another profiling stack and does not want these tools, return `status: not_applicable`. |
| 82 | + |
| 83 | +## Deliver |
| 84 | + |
| 85 | +- explicit official .NET profiling commands |
| 86 | +- a clear profiling path for CPU, counters, and heap inspection |
| 87 | +- reproducible diagnostics commands that humans and agents can rerun |
| 88 | + |
| 89 | +## Validate |
| 90 | + |
| 91 | +- the chosen tool matches the actual symptom |
| 92 | +- commands target a realistic process and configuration |
| 93 | +- before/after comparisons use the same scenario |
| 94 | +- heap collection warnings are explicit when `dotnet-gcdump` is used |
| 95 | + |
| 96 | +## Ralph Loop |
| 97 | + |
| 98 | +Use the Ralph Loop for every task, including docs, architecture, testing, and tooling work. |
| 99 | + |
| 100 | +1. Plan first (mandatory): |
| 101 | + - analyze current state |
| 102 | + - define target outcome, constraints, and risks |
| 103 | + - write a detailed execution plan |
| 104 | + - list final validation skills to run at the end, with order and reason |
| 105 | +2. Execute one planned step and produce a concrete delta. |
| 106 | +3. Review the result and capture findings with actionable next fixes. |
| 107 | +4. Apply fixes in small batches and rerun the relevant checks or review steps. |
| 108 | +5. Update the plan after each iteration. |
| 109 | +6. Repeat until outcomes are acceptable or only explicit exceptions remain. |
| 110 | +7. If a dependency is missing, bootstrap it or return `status: not_applicable` with explicit reason and fallback path. |
| 111 | + |
| 112 | +### Required Result Format |
| 113 | + |
| 114 | +- `status`: `complete` | `clean` | `improved` | `configured` | `not_applicable` | `blocked` |
| 115 | +- `plan`: concise plan and current iteration step |
| 116 | +- `actions_taken`: concrete changes made |
| 117 | +- `validation_skills`: final skills run, or skipped with reasons |
| 118 | +- `verification`: commands, checks, or review evidence summary |
| 119 | +- `remaining`: top unresolved items or `none` |
| 120 | + |
| 121 | +For setup-only requests with no execution, return `status: configured` and exact next commands. |
| 122 | + |
| 123 | +## Load References |
| 124 | + |
| 125 | +- read `references/profiling.md` first |
| 126 | + |
| 127 | +## Example Requests |
| 128 | + |
| 129 | +- "Profile this .NET app for CPU hotspots." |
| 130 | +- "Investigate GC pressure in this service." |
| 131 | +- "Capture counters and a trace from startup." |
| 132 | +- "Set up official .NET profiling tools for local investigations." |
0 commit comments