Advanced PerfView Workflows: Traces, ETW, and Flame Graphs

Getting Started with PerfView: A Beginner’s Guide

What PerfView is

PerfView is a free Microsoft tool for collecting and analyzing performance data from .NET applications and Windows systems. It focuses on CPU sampling, memory allocation/GC analysis, and event tracing (ETW).

When to use it

  • Investigating high CPU usage or performance regressions
  • Finding memory leaks or excessive allocations
  • Analyzing startup or long-running operation latency
  • Collecting ETW traces for I/O, thread, and system-level events

Quick setup (Windows)

  1. Download PerfView from the official Microsoft GitHub releases page and unzip.
  2. Run PerfView.exe (no install required). If UAC blocks collection, run as Administrator when needed.
  3. Ensure the target app is available and reproduce the performance issue during capture.

Basic workflow

  1. Capture a trace: click “Collect” → choose options (default is usually fine) → “Start Collection” → run the workload → “Stop Collection.”
  2. Open the generated .etl file shown in PerfView.
  3. Use the “CPU Stacks” view to inspect hotspots (stack traces with inclusive/exclusive times).
  4. Use the “Heap” and “GC Stats” views to analyze allocations, object types, and GC pauses.
  5. Use “Events” or “Thread Time” for tracing I/O, thread waits, and system events.

Key views explained

  • CPU Stacks: shows where CPU time is spent with call stacks and JIT inlining awareness.
  • Processes/Threads: overview of thread activity and blocking.
  • Heap (GC Heap: Allocation stacks and top allocating types; helpful for finding large or frequent allocations.
  • GC Stats: GC pause times and generation details.
  • Event Viewer/Events: raw ETW events for advanced investigations.

Practical tips

  • Use sampling mode for CPU (lower overhead) and tracing for allocations when you need exact allocation stacks.
  • Enable “Include .NET Runtime” and “Clr” providers for richer managed data.
  • Symbol files (.pdb) improve stack frame names—point PerfView to symbol servers (Microsoft symbol server + your private symbols).
  • Start with a short capture to verify reproducibility, then increase duration as needed.
  • Save and share the .etl/.zip file for collaboration.

Common pitfalls

  • Capturing too much data can produce large ETL files—filter providers and events.
  • Running without symbols yields obfuscated/missing method names.
  • Interpreting samples as exact timing—sampling estimates hotspots, not precise per-call durations.

Short checklist to run now

  1. Download and run PerfView.exe.
  2. Reproduce the issue.
  3. Collect a short trace.
  4. Open CPU Stacks and Heap views.
  5. Save and inspect the ETL; enable symbols if needed.

Further learning resources

  • Official PerfView GitHub README and documentation.
  • Microsoft blog posts and sample walkthroughs on .NET performance analysis.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *