Performance monitor to log CPU & memory usage

J.Elena.Suh 11 Reputation points
2021-12-30T06:57:42.56+00:00

Hello,

I want to log CPU usage & memory usage of my code (run it via Visual studio, windows 10).

I found performance monitor, and want to know how to use it.

My question is: which counter is CPU usage and which one is memory usage?

Or Is there any user guide, manual or reference?

I logged some counts in this way:

Performance monitor > Data Collector Sets > User Defined > right click > new > Data Collector Set >
Create manually > Next > Create data logs, v Performance counter > Next > Add >
Process > % User Time > my program to log CPU usage,

Process > Private Bytes > my program to log memory usage.

Also set time, and I saved as csv file.

Is that right to select '% User Time' and 'Private Bytes' to see the CPU usage and Memory usage?

According to the description,

% User Time is

the percentage of elapsed time that the process threads spent executing code in user mode. Applications, environment subsystems, and integral subsystems execute in user mode. Code executing in user mode cannot damage the integrity of the Windows executive, kernel, and device drivers. Unlike some early operating systems, Windows uses process boundaries for subsystem protection in addition to the traditional protection of user and privileged modes. Some work done by Windows on behalf of the application might appear in other subsystem processes in addition to the privileged time in the process.

Private Bytes is

the current size, in bytes, of memory that this process has allocated that cannot be shared with other processes.

However, they seems quite different from what I can see in the Task Manager.

For example,

Task manager says CPU usage of my program is 7%, but Performance Monitor says % User Time is 45%.

Also, Task manager says Memory usage is ~390MB but Performance Monitor, is about 430MB (~446000000 bytes. I divided this value by 1024 twice to scale it. There is no information of unit, but it should be bytes I guess..am I right?)

Please let me know if you need further information.

Thank you in advance!

Best wishes,
JESuh

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,871 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 39,441 Reputation points
    2021-12-30T15:32:08.387+00:00

    Hi @J.Elena.Suh

    maybe this one would help you:

    Measure application performance by analyzing CPU usage
    https://learn.microsoft.com/en-us/visualstudio/profiling/beginners-guide-to-performance-profiling?view=vs-2022

    and this one for Windows:

    Measure memory usage in Visual Studio
    https://learn.microsoft.com/en-us/visualstudio/profiling/memory-usage?view=vs-2022

    Hope this helps with your query!

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

  2. S.Sengupta 16,156 Reputation points MVP
    2022-01-02T02:22:17.75+00:00
    0 comments No comments