Calculate CPU usage for a Windows process?

Given a process id, how can I get CPU utilization from this process using C #?

I tried using PerformanceCounter as described in C # to calculate CPU usage for a specific application

I also tried to manually take two values โ€‹โ€‹of the total processor time for the process during the timeframe and divide the delta-cpu time with the delta-total time.

Both of these methods work fine, but if I put my application next to the window manager, my application will always be about twice as large as the task manager does. I tried updating various timestamps from 10 ms to 10 sec and getting the same result all the time.

Hmm, I realized when I wrote this that it could be some kind of dual-core problem ...

+2
source share
1 answer

If you have two cores, the task manager will report 100% utilization of 1 processor as 50%. This is probably your problem.

+3
source

Source: https://habr.com/ru/post/1628580/


All Articles