2010-03-04 103 views

回答

2

Windows機器的性能信息存儲在註冊表的特定部分。您可以使用註冊表API來枚舉計數器並獲取它們的名稱和值。

即使世界在這裏的教程:http://www.tenouk.com/ModuleP1.html

0

您是否使用託管或非託管代碼時沒有說明。如果是後者,則可以使用PerformanceCounter對象並像這樣初始化它。

Process currentProcess = System.Diagnostics.Process.GetCurrentProcess(); 
PerformanceCounter pc = new PerformanceCounter(); 
pc.CategoryName = "Process"; 
pc.CounterName = "Working Set - Private"; 
pc.InstanceName = currentProcess.ProcessName; 
var myProcessMemoryUsage = (long)pc.NextValue(); 

作爲示例,上述代碼檢索當前進程的私有工作集性能計數器信息。

PerformanceCounter pcRam = new PerformanceCounter(); 
pcRam.CategoryName = "Memory"; 
pcRam.CounterName = "Available MBytes"; 
int mem = (int)pcRam.NextValue(); 

此計數器將以兆字節顯示機器上可用的RAM數量。

您可以查看性能監視器本身中的所有性能計數器。您應該能夠看到類別和計數器名稱。

+0

注意:它看起來像Windows Server 2003上的Working Set - Private不可用 – surfen 2012-10-17 21:01:44