Skip to content

Latest commit

 

History

History
59 lines (40 loc) · 3.75 KB

File metadata and controls

59 lines (40 loc) · 3.75 KB

C++ Profiling Guide using Visual Studio Profiler

This guide outlines the steps to configure and use the Visual Studio Performance Profiler for analyzing the C++ components of the AgentSimMiddleware project.

Prerequisites

  • Visual Studio 2022 or later with the "Desktop development with C++" workload installed.
  • The project successfully built with CMake and opened in Visual Studio. (To generate the Visual Studio project, navigate to the project root and run: cmake -B build -S . -G "Visual Studio 18 2026")

Profiling the C++ Core Components

The Visual Studio Performance Profiler (part of the Diagnostic Tools) allows you to collect various types of performance data, such as CPU usage, memory usage, function timings, and more.

Steps to Run a Performance Profiling Session:

  1. Open the Project in Visual Studio:

    • Navigate to the build directory (e.g., C:\Users\dgooding\source\repos\AgentSimMiddleware\build).
    • Open the generated Visual Studio solution file (AgentSimMiddleware.sln).
  2. Set Build Configuration to Release:

    • For accurate performance profiling, always profile Release builds. Debug builds include extra debugging information and disabled optimizations that can significantly skew performance results.
    • In Visual Studio, select Release from the Solution Configurations dropdown menu (usually found in the Standard toolbar, next to "Any CPU" or "x64").
  3. Select Target Project:

    • In the Solution Explorer, right-click on the executable project you wish to profile (e.g., AgentSimBenchmarks, AgentSimMiddlewareTests, SimTestApp).
    • Select "Set as Startup Project".
  4. Open Performance Profiler:

    • Go to Debug > Performance Profiler (or press Alt+F2).
    • The "Diagnostic Tools" window (or a new profiling session window) will appear.
  5. Choose Profiling Tools:

    • In the Performance Profiler window, you can select the types of data you want to collect. Common choices for CPU performance analysis include:

      • CPU Usage: Measures CPU consumption by your application. This is often the primary tool for identifying performance bottlenecks.
      • Instrumentation: (Older method, but can be very detailed) Injects probes into your code to measure exact function call times.
      • Memory Usage: If you suspect memory-related issues (e.g., excessive allocations/deallocations).
    • Select "CPU Usage" for a general performance overview.

  6. Start Profiling:

    • Click the Start button at the bottom of the Performance Profiler window.
    • Your selected startup project will launch. Interact with your application or let the benchmark run as needed.
    • Once your application finishes or you manually stop the collection, Visual Studio will analyze the data and present a report.
  7. Analyze the Report:

    • The report will highlight functions and call stacks that consumed the most CPU time.
    • Look for "Hot Path" sections, which indicate areas of your code with high CPU activity.
    • Double-click on functions in the report to navigate directly to the source code.

Profiling Benchmarks

When profiling AgentSimBenchmarks.exe, simply follow the above steps. The benchmarks will run, and the profiler will collect data on their execution. This is particularly useful for validating the performance characteristics captured by your Google Benchmarks.

Compiler Flags for Profiling (Generally Handled by Visual Studio)

Visual Studio's Release configuration typically sets appropriate compiler flags (/O2 for optimization, /Zi for debug information) that allow for good profiling results. Manual intervention for compiler flags is rarely needed when using the integrated Visual Studio Profiler.