Windows性能計數器應用(PART1)

Windows OS中使用計數器來提供有關操作系統或應用程序,服務或驅動程序執行情況的信息。計數器數據可以幫助確定系統資源瓶頸。操作系統,網絡和設備提供應用程序可以消耗的計數器數據,以向用戶提供系統運行狀況的圖形視圖。

System.Diagnostics命名空間提供了允許您與性能計數器進行交互的類。PerformanceCounter類具有不同的構造函數。在我們的代碼中,我們使用以下格式的構造函數:

public PerformanceCounter( string categoryName, string counterName, string instanceName )

參數:

  • categoryName:與此性能計數器關聯的性能計數器類別(性能對象)的名稱。

  • counterName:性能計數器的名稱。

  • i nstanceName:性能計數器類別實例的名稱,如果類別包含單個實例,則爲空字符串(“”)

此構造函數初始化性能計數器,並將實例與本地計算機上的現有計數器關聯。CategoryNameCounterNameInstanceName屬性傳遞的值必須指向本地計算機上的現有性能計數器。

在一些性能計數器下面,以跟蹤處理器利用率,磁盤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 性能計數器

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)上的時間。故障設備產生大量中斷可能會導致較高的特權時間。此計數器將平均繁忙時間顯示爲採樣時間的百分比。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章