Windows OS中使用計數器來提供有關操做系統或應用程序,服務或驅動程序執行狀況的信息。計數器數據能夠幫助肯定系統資源瓶頸。操做系統,網絡和設備提供應用程序能夠消耗的計數器數據,以向用戶提供系統運行情況的圖形視圖。網絡
System.Diagnostics命名空間提供了容許您與性能計數器進行交互的類。PerformanceCounter類具備不一樣的構造函數。在咱們的代碼中,咱們使用如下格式的構造函數:ide
public PerformanceCounter( string categoryName, string counterName, string instanceName )
參數:函數
categoryName:與此性能計數器關聯的性能計數器類別(性能對象)的名稱。性能
counterName:性能計數器的名稱。spa
i nstanceName:性能計數器類別實例的名稱,若是類別包含單個實例,則爲空字符串(「」)操作系統
此構造函數初始化性能計數器,並將實例與本地計算機上的現有計數器關聯。CategoryName,CounterName和InstanceName屬性傳遞的值必須指向本地計算機上的現有性能計數器。線程
在一些性能計數器下面,以跟蹤處理器利用率,磁盤I / O,內存和網絡設計
PerformanceCounter("Processor", "% Processor Time", "_Total");
PerformanceCounter("Processor", "% Privileged Time", "_Total");
PerformanceCounter("Processor", "% Interrupt Time", "_Total");
PerformanceCounter("Processor", "% DPC Time", "_Total");
PerformanceCounter("Memory", "Available MBytes", null);
PerformanceCounter("Memory", "Committed Bytes", null);
PerformanceCounter("Memory", "Commit Limit", null);
PerformanceCounter("Memory", "% Committed Bytes In Use", null);
PerformanceCounter("Memory", "Pool Paged Bytes", null);
PerformanceCounter("Memory", "Pool Nonpaged Bytes", null);
PerformanceCounter("Memory", "Cache Bytes", null);
PerformanceCounter("Paging File", "% Usage", "_Total");
PerformanceCounter("PhysicalDisk", "Avg. Disk Queue Length", "_Total");
PerformanceCounter("PhysicalDisk", "Disk Read Bytes/sec", "_Total");
PerformanceCounter("PhysicalDisk", "Disk Write Bytes/sec", "_Total");
PerformanceCounter("PhysicalDisk", "Avg. Disk sec/Read", "_Total");
PerformanceCounter("PhysicalDisk", "Avg. Disk sec/Write", "_Total");
PerformanceCounter("PhysicalDisk", "% Disk Time", "_Total");
PerformanceCounter("Process", "Handle Count", "_Total");
PerformanceCounter("Process", "Thread Count", "_Total");
PerformanceCounter("System", "Context Switches/sec", null);
PerformanceCounter("System", "System Calls/sec", null);
PerformanceCounter("System", "Processor Queue Length", null);
2 性能計數器orm
2.1 CategoryName:Processor對象
PerformanceCounter("Processor", "% Processor Time", "_Total");
Processor\% Processor Time計數器肯定的時間,所述處理器忙經過測量的空閒進程的線程運行時間的百分比,而後減去由100%的百分比。測算處理器利用率的數量
PerformanceCounter("Processor", "% Interrupt Time", "_Total");
每秒平均突發事件中斷數的速率,處理器接收和處理硬件中斷的速率。它不包括延遲過程調用,這些過程將單獨計算。
PerformanceCounter("Processor", "% DPC Time", "_Total");
在採樣間隔內,處理器花費在接收和服務延遲過程調用上的時間百分比。延遲過程調用是優先級低於標準中斷的中斷。
PerformanceCounter("Processor", "% Privileged Time", "_Total");
在特殊模式下花費的非空閒處理器時間的百分比。特殊模式是一種爲操做系統組件和硬件操縱驅動程序設計的處理模式。它容許直接訪問硬件和全部內存。替代的用戶模式是爲應用程序,環境子系統和集成子系統設計的受限處理模式。操做系統將應用程序線程切換到特權模式,以訪問操做系統服務。這包括花在服務中斷和延遲過程調用(DPC)上的時間。故障設備產生大量中斷可能會致使較高的特權時間。此計數器將平均繁忙時間顯示爲採樣時間的百分比。