我正在尝试创建一个性能计数器,可以监视应用程序的性能时间,其中之一是Google Chrome。不过,我注意到我为chrome获得的性能时间不自然很低 - 我在任务管理器下查看我的问题,即chrome有多个进程在同一名称下运行,但每个进程的工作集大小不同并因此(我相信)不同的处理器时间。我试过这样做:如何在C#中使用性能计数器来监视4个具有相同名称的进程?
// 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;
}
但是,这似乎并没有工作 - 我只是多次监视相同的过程。任何人都可以告诉我一种方法来监视具有相同名称的单独进程吗?
谢谢!我不知道有什么和perfmon一样有用的东西。 – Waffles 2010-04-24 19:08:49