been searching around for this for a while, and hoping someone here can answer my question. So I am trying to find the best way to get the average CPU usage of 2 or 4 cores. Currently I am using a Performance Counter which so far as I can tell, only returns the usage of a single core. Ideally I would like it to match or at least resemble the Usage bar in Task Manager, and I have looked into WMI queries but was hoping to get some clarification on the best approach. I am currently using an i7, which has hyperthreading, i.e has “8” cores. Not sure if this makes much difference, but though it might.
Thanks for any pointers
been searching around for this for a while, and hoping someone here can answer
Share
Using
Win32_PerfFormattedData_Counters_ProcessorInformation, you can use the fieldPercentProcessorTimewhich will give instances of every core/thread on your system with its respective usage.I just tried this on mine, and I got 8 Management Objects for my 8 threads.
Update:
That was a slight lie, I got 10 instances.
Their names were:
etc.
You should filter out what you need with a where clause:
SELECT PercentProcessorTime FROM Win32_PerfFormattedData_Counters_ProcessorInformation WHERE NOT Name='_Total' AND NOT Name='0,_Total'