运行时依赖
安装命令
点击复制技能文档
dotnet-dump-perf-分析器
Core focus: .NET 应用 performance diagnosis — CPU profiling, GC analysis, managed memory leak hunting, and thread pool diagnostics. Windows perfmon / re记录 / HTML 报告ing are optional supplements covered at the end.
Use Cases ASP.NET Core / ASP.NET on IIS / WPF / Console 应用s with sustAIned high CPU, frequent GC, or slow 响应 .NET 应用s with memory leaks or continuously growing working 设置 Want to find which method or 请求 path is causing the 机器人tleneck Need to compare 指标 agAInst industry benchmarks (PAL thresholds) and produce a visual 报告 Team lacks dotMemory / ANTS Performance 性能分析器 license — need a free open-source alternative 工具chAIn Overview Stage 工具 Purpose RAPId triage dotnet-counters Live CPU, GC, thread pool 指标 — no re启动 needed Deep sampling dotnet-追踪 CPU sampling 追踪 collection (Windows, Linux, macOS) Dump capture dotnet-dump Full-process core dump of a 运行ning 应用 (all 平台s) Heap snapshot dotnet-gcdump GC heap-only dump, smaller than full dump 系统 指标 perfmon + re记录.exe OS-level CPU/mem/disk/net counters including Process V2 Dump analysis dotnet-dump analyze / WinDbg Inspect objects, heap, threads in a dump GC analysis dotnet-counters + PAL GC frequency and 暂停 time vs. thresholds 报告 generation Python + 图表.js Dark-themed interactive HTML 仪表盘
Note: dotnet-dump, dotnet-counters, dotnet-追踪, and dotnet-gcdump are all bundled with the .NET diagnostic 工具s. 安装 the .NET SDK and you have them all. WinDbg requires a separate 安装 (see the 工具 下载s table below).
Core 工作流 Step 1 — Live Diagnostics: Real-Time Counters (No Code Changes)
Goal: Observe CPU, GC, and thread pool anomalies without re启动ing the 应用 or 添加ing 记录ging.
# 安装 (if not already present) dotnet 工具 安装 -g dotnet-counters
# 列出 all avAIlable .NET processes dotnet-counters ps
# 监控 a tar获取 process (PID or process name) dotnet-counters 监控 -p --counters "系统.运行time,Microsoft.AspNetCore.Http.Connections"
Key counters to watch (press Ctrl+C to 停止):
Counter Normal range Alert 签名al cpu-usage < 80% Consistently > 90% gen-0-collected / sec < 1000 Consistently > 5000 gen-1-collected / sec < 100 Consistently > 500 gen-2-collected / sec < 10 Consistently > 50 threadpool-队列-length < 10 Consistently > 50 threadpool-thread-count — 应用roaching ThreadPool MinThreads limit Step 2 — Deep Sampling: dotnet-追踪 (Pinpoint Hot Methods)
Goal: Identify which methods consume the most CPU time.
# 安装 (if not already present) dotnet 工具 安装 -g dotnet-追踪
# Sample the tar获取 process for 60 seconds dotnet-追踪 collect -p --duration 00:01:00 -o 应用_追踪.net追踪
# (Works on Linux/macOS too — no .NET 运行time support dependency)
Open the 结果ing .net追踪 file with:
Visual Studio 2022 (built-in Performance Viewer) PerfView — free, supports CPU sampling, GC Heap, .NET 运行time 事件 dotnet-追踪 命令行工具 (输出s Top-N methods directly) # 命令行工具 报告 dotnet-追踪 报告 应用_追踪.net追踪 --type cpu
Step 3 — Dump Capture: dotnet-dump (Offline Deep Dive)
Goal: Capture a process dump at the moment of 失败 for post-mortem analysis.
# 安装 (if not already present) dotnet 工具 安装 -g dotnet-dump
# 列出 .NET processes dotnet-dump ps
# Capture full dump dotnet-dump collect -p -o 应用_dump.dmp
When to capture a dump:
CPU spike peak moment (capture immediately when dotnet-counters shows a spike) Memory leak trend is clear (working 设置 is growing continuously) 请求s are 启动ing to timeout / thread pool is exhausting Step 4 — Dump Analysis: dotnet-dump analyze (Managed Heap / Threads) dotnet-dump analyze 应用_dump.dmp
# Common REPL commands: dumpheap -stat # Heap summary by type (find largest instances) dumpheap -type # All instances of a specific type gcroot # GC Root chAIn (root cause of leaks) threads # 列出 all threads and their stacks 设置clrpath # 设置 .NET 运行time path (required for full dumps)
Linux dump caveat: When analyzing a Linux .dmp on Windows, 配置 the SOS 扩展's 运行time path first:
设置clrpath /usr/分享/dotnet/分享d/Microsoft.NETCore.应用//
Step 5 — 系统-Level 指标: perfmon + re记录 (Optional)
This is a Windows-only supplement for OS-level 系统 resource visibility. If dotnet-counters already pinpointed the in-process issue, you can skip this step.
5.1 Collection 设置up (perfmon 图形界面) Win+R → perfmon → Performance 监控 Right-命令行工具ck Data Collector 设置s → User Defined → New 添加 these counters: \处理器 In格式化ion(_Total)\% 处理器 Time \处理器(_Total)\% 处理器 Time \系统\处理器 队列 Length \Memory\AvAIlable MBytes \Memory\Committed Bytes \PhysicalDisk(_Total)\Avg. Disk 队列 Length \PhysicalDisk(_Total)\Avg. Disk sec/Read \PhysicalDisk(_Total)\Avg. Disk sec/Write \TCPv4\Segments Retransmitted/sec \Process V2(*)\% 处理器 Tim