AGENT SKILL

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

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

  1. Read the nearest AGENTS.md and confirm scope and constraints.
  2. Run this skill's Workflow through the Ralph Loop until outcomes are acceptable.
  3. Return the Required Result Format with concrete artifacts and verification evidence.

Workflow

  1. Build and run a realistic target first:
    • prefer Release
    • prefer realistic config, inputs, and data volume
  2. Start with the lightest useful tool:
    • dotnet-counters for live health signals
    • dotnet-trace for CPU, exception, contention, GC, and startup traces
    • dotnet-gcdump for managed heap inspection when memory shape matters
  3. Prefer installed CLI tools over dnx one-shot execution so the repo commands stay stable and reproducible.
  4. Capture one focused profile at a time instead of mixing every signal into one run.
  5. For CPU and general runtime hotspots, start with dotnet-trace collect.
  6. For live triage, start with dotnet-counters monitor on System.Runtime.
  7. For heap analysis, use dotnet-gcdump carefully and document the pause risk.
  8. 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:

  1. Detect current state:
    • dotnet --info
    • dotnet tool list --global
    • command -v dotnet-counters
    • command -v dotnet-trace
    • command -v dotnet-gcdump
  2. 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, and dotnet-gcdump
  3. Verify the installed tools resolve correctly:
    • dotnet-counters --version
    • dotnet-trace --version
    • dotnet-gcdump --version
  4. Record the exact profiling commands in the task's .ai-work/<task>/ notes or the final report (propose an AGENTS.md or 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.Runtime
    • dotnet-trace collect --process-id PID --profile dotnet-common,dotnet-sampled-thread-time -o trace.nettrace
    • dotnet-gcdump collect --process-id PID --output heap.gcdump
  5. Run one bounded command and return status: configured or status: improved.
  6. 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-gcdump is used

Ralph Loop

Use the Ralph Loop for every task, including docs, architecture, testing, and tooling work.

  1. 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
  2. Execute one planned step and produce a concrete delta.
  3. Review the result and capture findings with actionable next fixes.
  4. Apply fixes in small batches and rerun the relevant checks or review steps.
  5. Update the plan after each iteration.
  6. Repeat until outcomes are acceptable or only explicit exceptions remain.
  7. If a dependency is missing, bootstrap it or return status: not_applicable with explicit reason and fallback path.

Required Result Format

  • status: complete | clean | improved | configured | not_applicable | blocked
  • plan: concise plan and current iteration step
  • actions_taken: concrete changes made
  • validation_skills: final skills run, or skipped with reasons
  • verification: commands, checks, or review evidence summary
  • remaining: top unresolved items or none

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

Cratis
Cratis/Specifications

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.

律师与法务测试与质量
★ 1
Cratis
Cratis/Specifications

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.

★ 1
Cratis
Cratis/Specifications

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.

★ 1
Cratis
Cratis/Specifications

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.

测试与质量
★ 1
Cratis
Cratis/Specifications

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.

后端与接口
★ 1
Cratis
Cratis/Specifications

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.

★ 1