Windows性能計數器應用(PART4)

Windows性能計數器應用(PART1)app

Windows性能計數器應用(PART2)ide

Windows性能計數器應用(PART3)性能

SysField.XML文件指定在日誌文件中存儲PerformanceCounter()值所需的全部參數以及性能計數器的採樣時間。spa

:應用程序存儲日誌文件的文件夾。debug

:日誌文件的文件名。日誌

:指定一個布爾值orm

:單個日誌文件存儲的最大記錄數xml

PerformanceCounter()的採樣間隔get

爲了天天生成一個日誌文件,咱們須要將MaxNumberRecordsInLogFile設置爲等於:string

MaxNumberRecordsInLogFile =(一天中的第二個)/ PollingSysParamsInterval

若是咱們每1秒採樣一次(PollingSysParamsInterval = 1),則MaxNumberRecordsInLogFile = 86400secondi /(1秒)= 86400

使用存儲在app.config中的參數能夠定義咱們要包含在採樣中的性能參數以及性能計數器的結構(順序)。

app.config的完整結構報告以下:

<?xml version =「 1.0」?>

<Start>

<ADD key=「 NodeName」value=「 false」 />

<ADD key=「 CPUProcessorTime」value=「 true」 />

<ADD key=「 CPUPrivilegedTime」value=「 true」 />

<ADD key =「 MEMPoolNonPaged」 value =「 true」 />

<ADD key =「 DISKTime」 value =「 true」 />

<ADD key =「 HANDLECountCounter」 value =「 true」 />

<ADD key =「 THREADCount」 value =「 true「 />

<ADD key =「 CONTENTSwitches」 value =「 true」 />

<ADD key =「 SYSTEMCalls」 value =「 true」 />

<ADD key =「 NumProcess」 value =「 true」 />

<ADD key =「 NetTrafficSend」 value = 「 true」 /

鍵值的含義是比較清楚的,與每一個鍵關聯的值是布爾值:

  • 等於「 true 」的值表示跟蹤性能計數器的值

  • 等於「 false 」的值表示能夠跳過性能計數器的值  

編譯應用程序時,Visual Studio將在bin \ debug文件夾中自動建立一個名爲<您的應用程序名稱> .exe.config的文件。編譯應用程序時,app.config的內容將自動複製到此新的配置文件中。當將應用程序交付給最終用戶時,您必須交付exe和名爲<您的應用程序名稱> .exe.config的新配置文件,而不是app.config。用戶能夠在<您的應用程序名稱> .exe.config中修改數據從新啓動後,文件和應用程序將從配置文件讀取數據。在app.config中更改(key,value)的順序可肯定將性能計數器的其餘順序打印到控制檯和日誌文件中。

該項目使用名爲SysParams的公共類來存儲全部性能計數器。

public class SysParams

{

public string NodeName { get; set; }

public float CPUProcessorTime { get; set; }

public float CPUPrivilegedTime { get; set; }

public float CPUInterruptTime { get; set; }

public float CPUDPCTime { get; set; }

public float MEMAvailable { get; set; }

public float MEMCommited { get; set; }

public float MEMCommitLimit { get; set; }

public float MEMCommitedPerc { get; set; }

public float MEMPoolPaged { get; set; }

public float MEMPoolNonPaged { get; set; }

public float MEMCached { get; set; }

public float PageFile { get; set; }

public float ProcessorQueueLengh { get; set; }

public float DISCQueueLengh { get; set; }

public float DISKRead {get; set;}

public float DISKWrite { get; set; }

public float DISKAverageTimeRead { get; set; }

public float DISKAverageTimeWrite { get; set; }

public float DISKTime { get; set; }

public float HANDLECountCounter { get; set; }

public float THREADCount { get; set; }

public int CONTENTSwitches { get; set; }

public int SYSTEMCalls { get; set; }

public float NetTrafficSend { get; set; }

public float NetTrafficReceive { get; set; }

public DateTime SamplingTime { get; set; }

 

private PerformanceCounter cpuProcessorTime = new PerformanceCounter("Processor", "% Processor Time", "_Total");

private PerformanceCounter cpuPrivilegedTime = new PerformanceCounter("Processor", "% Privileged Time", "_Total");

private PerformanceCounter cpuInterruptTime = new PerformanceCounter("Processor", "% Interrupt Time", "_Total");

private PerformanceCounter cpuDPCTime = new PerformanceCounter("Processor", "% DPC Time", "_Total");

private PerformanceCounter memAvailable = new PerformanceCounter("Memory", "Available MBytes", null);

private PerformanceCounter memCommited = new PerformanceCounter("Memory", "Committed Bytes", null);

private PerformanceCounter memCommitLimit = new PerformanceCounter("Memory", "Commit Limit", null);

private PerformanceCounter memCommitedPerc = new PerformanceCounter("Memory", "% Committed Bytes In Use", null);

private PerformanceCounter memPollPaged = new PerformanceCounter("Memory", "Pool Paged Bytes", null);

private PerformanceCounter memPollNonPaged = new PerformanceCounter("Memory", "Pool Nonpaged Bytes", null);

private PerformanceCounter memCached = new PerformanceCounter("Memory", "Cache Bytes", null);

private PerformanceCounter pageFile = new PerformanceCounter("Paging File", "% Usage", "_Total");

private PerformanceCounter processorQueueLengh = new PerformanceCounter("System", "Processor Queue Length", null);

private PerformanceCounter diskQueueLengh = new PerformanceCounter("PhysicalDisk", "Avg. Disk Queue Length", "_Total");

private PerformanceCounter diskRead = new PerformanceCounter("PhysicalDisk", "Disk Read Bytes/sec", "_Total");

private PerformanceCounter diskWrite = new PerformanceCounter("PhysicalDisk", "Disk Write Bytes/sec", "_Total");

private PerformanceCounter diskAverageTimeRead = new PerformanceCounter("PhysicalDisk", "Avg. Disk sec/Read", "_Total");

private PerformanceCounter diskAverageTimeWrite = new PerformanceCounter("PhysicalDisk", "Avg. Disk sec/Write", "_Total");

private PerformanceCounter diskTime = new PerformanceCounter("PhysicalDisk", "% Disk Time", "_Total");

private PerformanceCounter handleCountCounter = new PerformanceCounter("Process", "Handle Count", "_Total");

private PerformanceCounter threadCount = new PerformanceCounter("Process", "Thread Count", "_Total");

private PerformanceCounter contentSwitches = new PerformanceCounter("System", "Context Switches/sec", null);

private PerformanceCounter systemCalls = new PerformanceCounter("System", "System Calls/sec", null);

private PerformanceCounterCategory performanceNetCounterCategory;

private PerformanceCounter[] trafficSentCounters;

private PerformanceCounter[] trafficReceivedCounters;

private string[] interfaces = null;

public void initNetCounters()

 

Windows性能計數器應用(PART1)

Windows性能計數器應用(PART2)

Windows性能計數器應用(PART3)

Windows性能計數器應用(PART5)

相關文章
相關標籤/搜索