how I get the CPU and memory usage during the program run?

Bar Rose 0 Reputation points
2026-08-03T12:39:05.41+00:00

how I get the CPU and memory usage during the program run?

Developer technologies | Visual Studio | Debugging

2 answers

Sort by: Most helpful
  1. Taki Ly (WICLOUD CORPORATION) 3,540 Reputation points Microsoft External Staff Moderator
    2026-08-04T03:09:48.7466667+00:00

    Hello @Bar Rose ,

    Thank you for reaching out with your question.

    To monitor CPU and memory usage while your program runs in Visual Studio, it might be beneficial to explore the built-in profiling tools. Depending on your needs, there are two primary ways to approach this:

    1. Using the Diagnostic Tools (During Debugging)

    When you start a regular debugging session (typically by pressing F5), the Diagnostic Tools window should automatically appear on the side of your screen. This window provides real-time graphs for both CPU and Memory usage while you step through your code.

    Note: If the window is not visible, it is possible it was hidden. You can bring it back by navigating to Debug > Windows > Show Diagnostic Tools (or pressing Ctrl+Alt+F2).

    2. Using the Performance Profiler (For detailed analysis)

    If you need highly accurate measurements without the extra overhead of the debugger, it might be better to use the Performance Profiler.

    • You can access this by going to Debug > Performance Profiler... (or pressing Alt + F2).
    • From there, you can check the boxes for CPU Usage and Memory Usage, and then click "Start". This will run your program and collect detailed performance data to review once the program is closed.

    For additional context and step-by-step guidance, you may find the following official documentation helpful:

    I hope this helps you investigate your application's performance. Please let me know if you need any further assistance with these tools. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation.

    Thank you.

    Was this answer helpful?


  2. AI answer

    2026-08-03T12:39:28.33+00:00

    In Visual Studio, CPU and memory usage can be collected while the program runs by using the Diagnostic Tools window during debugging, or the Performance Profiler for release builds.

    For debugging:

    1. Open the project in Visual Studio.
    2. Set a breakpoint where measurement should begin.
    3. Set a second breakpoint where measurement should end.
    4. Open Debug > Windows > Show Diagnostic Tools if the window is not already visible.
    5. In Select Tools, enable CPU Usage, Memory Usage, or both.
    6. Start debugging with F5.
    7. Run until the first breakpoint.
    8. While paused:
      • For CPU, open the CPU Usage tab and select Start Recording.
      • For memory, select Take snapshot on the Memory Usage toolbar.
    9. Press F5 to continue to the second breakpoint.
    10. At the second breakpoint:
    • CPU data is available in the CPU Usage tab for the code region between breakpoints.
    • Take another memory snapshot to compare memory growth.

    Notes:

    • The Diagnostic Tools window appears automatically during debugging unless it was turned off.
    • For native or mixed-mode apps, memory snapshots are disabled by default. Start debugging, open the Memory Usage tab, choose Heap Profiling, then stop and restart debugging.
    • A baseline memory snapshot at the start of the session helps compare later snapshots.

    For release builds without debugging:

    1. Open the project.
    2. In the Debug menu, set the solution configuration to Release.
    3. Select Debug > Performance Profiler.
    4. On the Flexible tab, select Memory Usage and choose Start.
    5. The Diagnostic Tools window shows a timeline graph of memory use while the app runs.
    6. Take snapshots during the session to capture memory state at specific moments.

    If code-based process memory information is needed in a Win32 app, the PSAPI function GetProcessMemoryInfo can be used after opening the process handle with OpenProcess.


    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.