2010-04-24 82 views
1

我正在嘗試創建一個性能計數器,可以監視應用程序的性能時間,其中之一是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; 
     } 

但是,這似乎並沒有工作 - 我只是多次監視相同的過程。任何人都可以告訴我一種方法來監視具有相同名稱的單獨進程嗎?

回答

1

打開perfmon看。您需要使用名稱,如chrome#2或可能的chrome_2

+0

謝謝!我不知道有什麼和perfmon一樣有用的東西。 – Waffles 2010-04-24 19:08:49

相關問題