PerfView - Advanced Performance Analysis Tool
PerfView is a free tool from Microsoft that you can use to analyze performance issues in your applications. It collects and displays a wide range of performance data, including CPU usage, memory allocations, GC events, and more.
Getting Started with PerfView
To begin analyzing your application's performance, you typically follow these steps:
- Download PerfView: Download the latest release of PerfView from the official Microsoft GitHub repository.
- Run PerfView: Launch PerfView. It's a portable executable, so no installation is required.
- Collect Data:
- Click the "Collect" button in the main window.
- Choose the type of data you want to collect. For general CPU and memory analysis, "
CPU+GC
" is a good starting point. - Click "Start Collection".
- Run your application or perform the actions you want to profile.
- Click "Stop Collection" in PerfView when you are finished.
- Analyze Data: PerfView will display a summary of the collected data. You can then drill down into various views to understand performance bottlenecks.
Key Features and Views
- CPU Usage: Identify which functions are consuming the most CPU time.
- Memory and GC: Analyze memory allocations, garbage collection events, and heap snapshots.
- Thread Time: Understand thread behavior, blocking, and synchronization issues.
- Event Tracing for Windows (ETW): Capture and analyze detailed events from various system components.
- Symbol Loading: PerfView automatically downloads and caches symbols, which are crucial for meaningful stack traces.
Common Scenarios and Usage
CPU Profiling
To capture CPU sampling data:
PerfView.exe collect -EventBufferMB 1024 -Providers "Microsoft-Windows-SampleProfiler"
After collection, open the .etl
file in PerfView and look for the "CPU Usage (Sampled)
" view.
Memory Allocation Profiling
To capture memory allocation data:
PerfView.exe collect -providers "Microsoft-DotNETRuntime:0x10,Microsoft-Windows-DotNETRuntimeGC:0x1"
This collects data for .NET Runtime and Garbage Collector events. You can then explore the ".NET Object Allocations (Bytes)
" or ".NET Object Allocations (Count)
" views.
Note: For the best results, ensure that symbols are correctly configured in PerfView. This is usually handled automatically, but manual configuration might be needed in some environments.
Learning Resources
Tip: Use PerfView's search functionality extensively to find specific events, functions, or types within large trace files.