Using Visual Studio Performance Profiler for CPU Usage Analysis in .NET Applications
Learn how to configure Visual Studio’s Integrated Profiler to capture CPU usage data, locate hot paths, and verify results for .NET applications.
02 Mar 2026, 18:13 UTC

Desired Outcome
After completing this guide you will be able to collect CPU usage data for a .NET application with Visual Studio’s Integrated Profiler, identify the methods that consume the most processor time (the hot path), and verify that the measurements are reliable.
Prerequisites
- Visual Studio 2022 version 17.6 or later (the Integrated Profiler is bundled with this release).
- A solution targeting .NET 6 or later that can be built in the Release configuration.
- Permission to start a debugging session on the local workstation (no administrator rights are required).
Procedure
1. Prepare the build
Open the solution in Visual Studio. From the solution platform dropdown select Release and the appropriate x64 or x86 architecture. Build the project (Ctrl+Shift+B) to ensure the latest binaries are used. Profiling a Debug build can hide real‑world bottlenecks because the compiler disables optimizations.
2. Launch the Performance Profiler
With the solution loaded, choose Debug → Performance Profiler… or press Alt+F2. The Performance Profiler hub appears.
3. Configure the CPU Usage session
In the hub select CPU Usage. Keep the default Sampling mode unless you need exact call counts; note that sampling introduces minimal overhead while instrumentation can significantly slow the application. Click Start to begin the session.
4. Run the workload
Execute the scenario you want to measure—for example, navigate to a page that triggers a calculation loop or press a button that starts a background job. Let the application run long enough to capture representative data (typically 10–30 seconds). When finished, click Stop collection in the Profiler toolbar.
5. Examine the results
The report shows a call tree with percentages of total CPU time. The top‑most entry is the Hot Path, which highlights the most expensive methods. Right‑click a method and choose Open in Source to jump to the corresponding code. Use the External Code toggle (button with a shield icon) to hide framework and library calls and focus on your own code.
Verification Checks
- Verify that a call tree appears after stopping the session; an empty tree indicates that no samples were collected.
- Identify a known loop in your code (e.g., a
forloop that iterates 1 000 000 times and does a simple addition). The reported CPU percentage for that loop should be roughly proportional to its expected workload; large deviations suggest a configuration issue. - Click the
External Codebutton. System namespaces such asSystem.orMicrosoft.should disappear from the hot‑path view, confirming that the filter works.
Recovery and Rollback
If you notice that the application becomes unresponsive during profiling:
- Stop the profiler immediately (Shift+F5 or the Stop button).
- Close the Performance Profiler tab; the session data is discarded unless you explicitly saved it.
- Re‑build the solution in Release mode and repeat the steps, optionally switching to Sampling mode if you had used Instrumentation.
No permanent changes are made to the project or binaries; profiling is a read‑only operation.
Limitations
- Sampling profilers may miss methods that execute for less than the sampling interval (default ~1 ms). Very short‑lived helper functions can appear with zero percent.
- Instrumentation mode, while precise, adds overhead that can skew timing, especially in heavily multi‑threaded scenarios.
- Always profile a Release build; Debug builds include extra checks and lack optimizations that can mask real performance problems.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.