码迷,mamicode.com
首页 > Windows程序 > 详细

Windows性能计数器应用程序参数设置

时间:2020-03-04 23:37:19      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:net   length   rup   nextval   traffic   包含   add   int   col   

 

{ 

// PerformanceCounter(CategoryName,CounterName,InstanceName) 

performanceNetCounterCategory = newPerformanceCounterCategory("Network Interface"); 

interfaces = performanceNetCounterCategory.GetInstanceNames(); 

int length = interfaces.Length; 

if (length > 0) 

{ 

trafficSentCounters = newPerformanceCounter[length]; 

trafficReceivedCounters = newPerformanceCounter[length]; 

} 

for (int i = 0; i < length; i++) 

{

//初始化PerformanceCounter类的新的只读实例。

//第一个参数:“ categoryName”-与该性能计数器关联的性能计数器类别(性能对象)的名称。

//第二个参数:“ CounterName”-性能计数器的名称。

//第三个参数:“ instanceName”-性能计数器类别实例的名称,如果类别包含单个实例,则为空字符串(“”)。

trafficReceivedCounters[i] = new PerformanceCounter("Network Interface", "Bytes Sent/sec", interfaces[i]); 

trafficSentCounters[i] =new PerformanceCounter("Network Interface", "Bytes Sent/sec", interfaces[i]); 

}

 

//网络接口所有名称的列表 

for (int i = 0; i < length; i++) 

{ 

Console.WriteLine("Name netInterface: {0}", performanceNetCounterCategory.GetInstanceNames()[i]); 

} 

} 

public void getProcessorCpuTime() 

{ 

float tmp = cpuProcessorTime.NextValue(); 

CPUProcessorTime = (float)(Math.Round((double)tmp, 1)); 

// Environment.ProcessorCount:返回内核总数 

} 

public void getCpuPrivilegedTime() 

{ 

float tmp = cpuPrivilegedTime.NextValue(); 

CPUPrivilegedTime = (float)(Math.Round((double)tmp, 1)); 

} 

public void getCpuinterruptTime() 

{ 

float tmp = cpuInterruptTime.NextValue(); 

CPUInterruptTime = (float)(Math.Round((double)tmp, 1)); 

} 

public void getcpuDPCTime() 

{ 

float tmp = cpuDPCTime.NextValue(); 

CPUDPCTime = (float)(Math.Round((double)tmp, 1)); 

} 

public void getPageFile() 

{ 

PageFile = pageFile.NextValue(); 

} 

public void getProcessorQueueLengh() 

{ 

ProcessorQueueLengh = processorQueueLengh.NextValue(); 

} 

public void getMemAvailable() 

{ 

MEMAvailable = memAvailable.NextValue(); 

} 

public void getMemCommited() 

{ 

MEMCommited = memCommited.NextValue() / (1024 * 1024); 

} 

public void getMemCommitLimit() 

{ 

MEMCommitLimit = memCommitLimit.NextValue() / (1024 * 1024); 

} 

public void getMemCommitedPerc() 

{ 

float tmp = memCommitedPerc.NextValue();

//返回内存提交限制的值

MEMCommitedPerc = (float)(Math.Round((double)tmp, 1)); 

} 

public void getMemPoolPaged() 

{ 

float tmp = memPollPaged.NextValue() / (1024 * 1024); 

MEMPoolPaged = (float)(Math.Round((double)tmp, 1)); 

} 

public void getMemPoolNonPaged() 

{ 

float tmp = memPollNonPaged.NextValue() / (1024 * 1024); 

MEMPoolNonPaged = (float)(Math.Round((double)tmp, 1)); 

} 

public void getMemCachedBytes() 

{

//返回以MB为单位的已缓存内存的值

MEMCached = memCached.NextValue() / (1024 * 1024); 

} 

public void getDiskQueueLengh() 

{ 

DISCQueueLengh = diskQueueLengh.NextValue(); 

} 

public void getDiskRead() 

{ 

float tmp=diskRead.NextValue()/1024; 

DISKRead = (float)(Math.Round((double)tmp,1)); 

} 

public void getDiskWrite() 

{ 

float tmp=diskWrite.NextValue()/1024; 

DISKWrite = (float)(Math.Round((double)tmp,1)); // round 1 digit decimal 

} 

public void getDiskAverageTimeRead() 

{ 

float tmp = diskAverageTimeRead.NextValue() * 1000; 

DISKAverageTimeRead = (float)(Math.Round((double)tmp, 1)); // round 1 digit decimal 

} 

public void getDiskAverageTimeWrite() 

{ 

float tmp = diskAverageTimeWrite.NextValue()*1000; 

DISKAverageTimeWrite = (float)(Math.Round((double)tmp, 1)); // round 1 digit decimal 

} 

public void getDiskTime() 

{ 

float tmp = diskTime.NextValue(); 

DISKTime = (float)(Math.Round((double)tmp, 1)); 

} 

public void getHandleCountCounter() 

{ 

HANDLECountCounter = handleCountCounter.NextValue(); 

} 

public void getThreadCount() 

{ 

THREADCount = threadCount.NextValue(); 

} 

public void getContentSwitches() 

{ 

CONTENTSwitches = (int)Math.Ceiling(contentSwitches.NextValue()); 

} 

public void getsystemCalls() 

{ 

SYSTEMCalls = (int)Math.Ceiling(systemCalls.NextValue()); 

} 

public void getCurretTrafficSent() 

{ 

int length = interfaces.Length; 

float sendSum = 0.0F; 

for (int i = 0; i < length; i++) 

{ 

sendSum += trafficSentCounters[i].NextValue(); 

} 

float tmp = 8 * (sendSum / 1024); 

NetTrafficSend = (float)(Math.Round((double)tmp, 1)); 

} 

public void getCurretTrafficReceived() 

{ 

int length = interfaces.Length; 

float receiveSum = 0.0F; 

for (int i = 0; i < length; i++) 

{ 

receiveSum += trafficReceivedCounters[i].NextValue(); 

} 

float tmp = 8 * (receiveSum / 1024); 

NetTrafficReceive = (float)(Math.Round((double)tmp, 1)); 

} 

public void getSampleTime() 

{ 

SamplingTime =DateTime.Now; 

} 

}

Windows性能计数器应用(PART1-4)

Windows性能计数器应用(PART6)

Windows性能计数器应用程序参数设置

标签:net   length   rup   nextval   traffic   包含   add   int   col   

原文地址:https://www.cnblogs.com/Aldj/p/12416599.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!