1

I'm trying to create a performance counter that can monitor the performance time of applications, one of which is Google Chrome. However, I notice that the performance time I get for chrome is unnaturally low - I look under the task-manager to realize my problem that chrome has more than one process running under the exact same name, but each process has a different working set size and thus(what I would believe) different processor times. I tried doing this:

// get all processes running under the same name, and make a performance counter
// for each one.
Process[] toImport = Process.GetProcessesByName("chrome");

        instances = new PerformanceCounter[toImport.Length];

        for (int i = 0; i < instances.Length; i++)
        {

           PerformanceCounter toPopulate = new PerformanceCounter
                ("Process", "% Processor Time",
                    toImport[i].ProcessName,
                   true);

            //Console.WriteLine(toImport[i].ProcessName + "#" + i);

            instances[i] = toPopulate;
        }

But that doesn't seem to work at all - I just monitor the same process several times over. Can anyone tell me of a way to monitor separate processes with the same name?

Waffles
  • 63
  • 2
  • 4

2 Answers2

1

Open perfmon and look. You need to use names like chrome#2 or, possibly, chrome_2.

Anton Tykhyy
  • 19,370
  • 5
  • 54
  • 56
1

Important is to make sure you are not using '#' in the instance name. It worth reading this http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter.instancename.aspx and pay special attention to character mapping - it just cost me few hours.

Vojtiik
  • 2,558
  • 1
  • 17
  • 21