profiling
Uses the free official .NET diagnostics CLI tools for profiling and runtime investigation in a repository: CPU, GC pressure, allocation growth, exception storms, lock contention, and slow code. Use when a .NET application needs performance or runtime profiling. Not for replacing realistic performance or load tests with ad-hoc tracing, production heap collection without a pause-risk plan, crash dumps (use dump-collect), or benchmark design (use microbenchmarking).
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 1
- Forks
- 1
01 前言 Front Matter
- name
- profiling
- license
- MIT
- description
- Uses the free official .NET diagnostics CLI tools for profiling and runtime investigation in a repository: CPU, GC pressure, allocation growth, exception storms, lock contention, and slow code. Use when a .NET application needs performance or runtime profiling. Not for replacing realistic performance or load tests with ad-hoc tracing, production heap collection without a pause-risk plan, crash dumps (use dump-collect), or benchmark design (use microbenchmarking).
- compatibility
- Requires a .NET app or process to inspect; respects the repo's `AGENTS.md` commands first.
02 资源文件 5
- 许可证LICENSE1.1 KB
- 其他NOTICE3.4 KB
- 参考文档references/commands.md10.1 KB
- 参考文档references/patterns.md14.2 KB
- 参考文档references/profiling.md4.8 KB
03 SKILL.md 正文
<!-- cratis-ai-managed: skills/profiling/SKILL.md -->
<!-- Modified by Cratis from managedcode's original (MIT): frontmatter, applicability, navigation and the changes listed in NOTICE. Upstream: https://github.com/managedcode/dotnet-skills (catalog/Tools/Profiling/skills/profiling/SKILL.md; see NOTICE) -->
.NET Profiling
Use only within this skill's stated task; general workflow advice does not apply to unrelated tasks. Cratis rules in .cratis/ai/rules/ (including csharp.md, specs.csharp.md, and orleans.md) and the cratis-* skills win where they differ. Write outputs only to the task's .ai-work/<task>/ folder; run collection commands there, not in profile-output/.
Trigger On
- the repo needs performance or runtime profiling for a .NET application
- the user asks about slow code, high CPU, GC pressure, allocation growth, exception storms, lock contention, or startup diagnostics
- the team wants official CLI-based diagnostics without depending on
dnx
Value
- produce a concrete project delta: code, docs, config, tests, CI, or review artifact
- reduce ambiguity through explicit planning, verification, and final validation skills
- leave reusable project context so future tasks are faster and safer
Do Not Use For
- replacing realistic performance tests or load tests with ad-hoc tracing alone
- production heap collection when the pause risk has not been accepted
- GUI-only workflows that the repo cannot automate or document
Inputs
- the nearest
AGENTS.md - target application, process, or startup path
- the symptom being investigated: CPU, memory, GC, contention, exceptions, or startup
Quick Start
- Read the nearest
AGENTS.mdand confirm scope and constraints. - Run this skill's
Workflowthrough theRalph Loopuntil outcomes are acceptable. - Return the
Required Result Formatwith concrete artifacts and verification evidence.
Workflow
- Build and run a realistic target first:
- prefer
Release - prefer realistic config, inputs, and data volume
- prefer
- Start with the lightest useful tool:
dotnet-countersfor live health signalsdotnet-tracefor CPU, exception, contention, GC, and startup tracesdotnet-gcdumpfor managed heap inspection when memory shape matters
- Prefer installed CLI tools over
dnxone-shot execution so the repo commands stay stable and reproducible. - Capture one focused profile at a time instead of mixing every signal into one run.
- For CPU and general runtime hotspots, start with
dotnet-trace collect. - For live triage, start with
dotnet-counters monitoronSystem.Runtime. - For heap analysis, use
dotnet-gcdumpcarefully and document the pause risk. - After each change, rerun the same measurement path and compare before versus after.
Bootstrap When Missing
If official .NET profiling tools are not available yet:
- Detect current state:
dotnet --infodotnet tool list --globalcommand -v dotnet-counterscommand -v dotnet-tracecommand -v dotnet-gcdump
- Choose the install path deliberately:
- preferred machine-level install:
Cratis: Downloads or installs a tool: requires the user's approval; prefer a pinned version (
dotnet tool install <tool> --version <x>)dotnet tool install --global dotnet-counters --version <x>
Cratis: Downloads or installs a tool: requires the user's approval; prefer a pinned version (
dotnet tool install <tool> --version <x>)dotnet tool install --global dotnet-trace --version <x>
Cratis: Downloads or installs a tool: requires the user's approval; prefer a pinned version (
dotnet tool install <tool> --version <x>)dotnet tool install --global dotnet-gcdump --version <x>
Cratis: Downloads or installs a tool: requires the user's approval; prefer a pinned version (
dotnet tool install <tool> --version <x>)- direct-download fallback when global tools are not suitable:
Cratis: Downloads or installs a tool: requires the user's approval; prefer a pinned version (
dotnet tool install <tool> --version <x>)- use the official Microsoft Learn download links for
dotnet-counters,dotnet-trace, anddotnet-gcdump
- use the official Microsoft Learn download links for
- preferred machine-level install:
- Verify the installed tools resolve correctly:
dotnet-counters --versiondotnet-trace --versiondotnet-gcdump --version
- Record the exact profiling commands in the task's
.ai-work/<task>/notes or the final report (propose anAGENTS.mdor project-doc change only when the user asks for one; managed corpus files are never edited by hand), for example:dotnet-counters monitor --process-id PID --counters System.Runtimedotnet-trace collect --process-id PID --profile dotnet-common,dotnet-sampled-thread-time -o trace.nettracedotnet-gcdump collect --process-id PID --output heap.gcdump
- Run one bounded command and return
status: configuredorstatus: improved. - If the repo intentionally standardizes on another profiling stack and does not want these tools, return
status: not_applicable.
Deliver
- explicit official .NET profiling commands
- a clear profiling path for CPU, counters, and heap inspection
- reproducible diagnostics commands that humans and agents can rerun
Validate
- the chosen tool matches the actual symptom
- commands target a realistic process and configuration
- before/after comparisons use the same scenario
- heap collection warnings are explicit when
dotnet-gcdumpis used
Ralph Loop
Use the Ralph Loop for every task, including docs, architecture, testing, and tooling work.
- Plan first (mandatory):
- analyze current state
- define target outcome, constraints, and risks
- write a detailed execution plan
- list final validation skills to run at the end, with order and reason
- Execute one planned step and produce a concrete delta.
- Review the result and capture findings with actionable next fixes.
- Apply fixes in small batches and rerun the relevant checks or review steps.
- Update the plan after each iteration.
- Repeat until outcomes are acceptable or only explicit exceptions remain.
- If a dependency is missing, bootstrap it or return
status: not_applicablewith explicit reason and fallback path.
Required Result Format
status:complete|clean|improved|configured|not_applicable|blockedplan: concise plan and current iteration stepactions_taken: concrete changes madevalidation_skills: final skills run, or skipped with reasonsverification: commands, checks, or review evidence summaryremaining: top unresolved items ornone
For setup-only requests with no execution, return status: configured and exact next commands.
Load References
Example Requests
- "Profile this .NET app for CPU hotspots."
- "Investigate GC pressure in this service."
- "Capture counters and a trace from startup."
- "Set up official .NET profiling tools for local investigations."
04 同仓库更多 Skills
vectorization
Designs, implements, optimizes, and reviews SIMD code in .NET: vectorizing scalar loops with TensorPrimitives, Vector64, Vector128, Vector256, Vector512, or hardware intrinsics, and reviewing existing SIMD code, including the generic Vector type, for contract equivalence, tail handling, memory safety, portability, fallbacks, and measured performance. Use when a .NET loop or SIMD routine is being written or reviewed. Not for performance work unrelated to SIMD.
target-authoring
Canonical patterns for writing custom MSBuild targets: DependsOnTargets versus BeforeTargets and AfterTargets, the Build-to-CoreBuild three-level pattern, and the XxxDependsOn chain-extension pattern. Use when diagnosing or fixing custom-target anti-patterns: Directory.Build.targets redefining SDK targets, targets that replace CompileDependsOn instead of extending it, Outputs versus Returns misuse that returns stale results, missing Inputs/Outputs causing needless rebuilds, or missing FileWrites registration. Not for incremental build tuning or general anti-pattern review (use the msbuild skill), or non-MSBuild build systems.
run-tests
Chooses and runs the repository-compatible .NET test command: classic, VSTest, bridged MTP, or native MTP syntax for MSTest, xUnit, NUnit, and TUnit. Use before running .NET tests or answering with a test command or flags: run the tests, one test, class, category, trait or target framework, combined filters, --filter-query, --no-build, --diag, TRX, coverage collection, crash or hang dumps, filter errors, or unrecognized options. Not for platform identification alone (use platform-detection), writing or debugging test code, interpreting a coverage report (use coverage-analysis), CI investigation, migration, or a persistent hot-reload loop.
platform-detection
Identifies a .NET project's test platform, framework, command mode, and SDK-style versus classic project system, resolving global.json, project, packages.config, Directory.Build.props, and Directory.Packages.props precedence for MSTest, xUnit, NUnit, and TUnit. Use when asking "which test platform or framework?", "VSTest or MTP?", or "what runner does this project use?", including bridge settings, UseVSTest opt-outs, and conflicting VSTest/MTP configuration. Not for running or filtering tests, commands, flags, TRX, dumps, or test-command errors (use run-tests), or for hot-reload or migration requests.
orleans
Designs Microsoft Orleans systems from each primitive's purpose and failure model: grains, digital twins, state versus databases, transactions, messaging, streams, timers, reminders, Durable Jobs, stateless workers, grain services, startup, and hosting. Use when a task needs an Orleans design decision: inspect version and topology, choose the primitive, implement, and validate. Not for other actor stacks, batch processing, relational-only CRUD, or advice without an Orleans decision.
msbuild
Investigates MSBuild build failures, diagnoses build performance, and reviews build XML and extension contracts using binary logs. Use for failing dotnet build, restore, pack, or publish; .binlog capture and replay; project, props, and targets conditions; custom-target inputs/outputs; Import/Exists hooks and packed NuGet imports; slow evaluation, compilation, copying, or no-change builds; and controlled timing comparisons. Not for legacy or non-SDK project migration, framework or package upgrades, SDK installation, C# refactoring, runtime profiling, assertions after a successful build, or non-MSBuild builds.