我正在尝试创建一个性能计数器,它可以监控应用程序的性能时间,其中之一就是Google Chrome。然而,我注意到我在chrome上得到的性能时间是不自然的低-我在任务管理器下发现我的问题是chrome有多个进程在完全相同的名称下运行,但每个进程都有不同的工作集大小,因此(我相信)不同的处理器时间。我试过这样做:
// 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;
}但这似乎根本不起作用--我只是多次监视相同的过程。有没有人能告诉我一种监视相同名称的独立进程的方法?
发布于 2010-04-24 12:09:56
打开perfmon并查看。您需要使用像chrome#2或chrome_2这样的名称。
发布于 2011-04-05 20:15:17
重要的是要确保实例名称中没有使用'#‘。这篇http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter.instancename.aspx值得一读,还要特别注意字符映射--它只花了我几个小时的时间。
https://stackoverflow.com/questions/2703166
复制相似问题