2

I want to measure the cpu usage of each processor.

When I run the following program, I get instance name 2, 3, 0, 1, and _Total. I thought I should get 0, 1, 0,_Total, 1,_Total.

What does the result mean? How to get the total cpu usage of each processor. Not each core?

 class PerfMonitor
{
    static void Main()
    {
        var pc = new PerformanceCounter("Processor", "% Processor Time");
        var cat = new PerformanceCounterCategory("Processor");
        var instances = cat.GetInstanceNames();

        foreach (var s in instances)
        { 
            pc.InstanceName = s;
            Console.WriteLine("instance name is {0}", s);
        }
    }
}
ericyoung
  • 621
  • 2
  • 15
  • 21
  • I don't think operating systems break things down by CPU - every system monitor I've seen has only had options to see each core or to see a sum of everything. – Bobson Jan 10 '13 at 19:25
  • You've got 4 processor cores so you got counters for each individual one and for the sum of them. Hard to guess what you could mean with "0,_Total". – Hans Passant Jan 10 '13 at 19:25
  • maybe you have a dual core intel machine so due to hyperthreading it may be showing 4 cores and usage of each core – prthrokz Jan 10 '13 at 19:27
  • As a followup, [this source](http://superuser.com/a/260029/92910) suggests there is no practical difference between multi-core and multi-CPU, so trying to group by CPU is probably irrelevant. – Bobson Jan 10 '13 at 19:30
  • @hans-passant. "0,Total" is what I got something from this [link](http://stackoverflow.com/questions/2938629/how-can-i-get-cpu-load-per-core-in-c?lq=1) – ericyoung Jan 10 '13 at 19:35
  • The guy probably has more than one processor in his machine. You don't. – Hans Passant Jan 10 '13 at 19:42

3 Answers3

1

What does the result mean?

Your result is this:

instance name is 2
instance name is 3
instance name is 0
instance name is 1
instance name is 6
instance name is 7
instance name is 4
instance name is 5
instance name is _Total

Each instance is a logical id for the processer (hyper-V logical ones included) except for the last one which is a cumulative instance of all processors on the system.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
0

Since Windows sees cores as processors, this is not an easy thing to do. You might start by trying to determine the number of physical CPUs, but it is a pain.

Andy West
  • 12,302
  • 4
  • 34
  • 52
0

Download OpenHardwareMonitor, it is open source and contains a dll that you can use to do this

Kris
  • 1