How can I use Performance Counters in C# to monitor 4 processes with the same name?
Posted
by Waffles
on Stack Overflow
See other posts from Stack Overflow
or by Waffles
Published on 2010-04-24T04:00:19Z
Indexed on
2010/04/24
4:03 UTC
Read the original article
Hit count: 470
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?
© Stack Overflow or respective owner