欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

.net中调用windows performance记录性能信息

程序员文章站 2022-03-30 22:17:34
记录skype的cpu 占用率   var processorcounter = new performancecounter {   &nb...

记录skype的cpu 占用率
 
var processorcounter = new performancecounter
{
       categoryname = "process",
       countername = "% processor time",
       instancename = “skype”,
       machinename = "."
};

processorcounter.nextvalue()
 
 
 记录skype的内存占用
 
var memorycounter = new performancecounter
{
    categoryname = "process",
    countername = "working set - private",
    instancename = “skype”,
    machinename = "."
};

memorycounter.rawvalue  返回的是字节为计量单位
 
获取当前计算计算机的cpu和内存占用情况
 
counter = new performancecounter("processor", "% processor time", “_total”);

counter.nextvalue() cpu占用

computerinfo computerinfo = new computerinfo();

computerinfo.totalphysicalmemory - computerinfo.availablephysicalmemory 内存占用
 
注意, 使用counter的时候,如果instancename 不存在, 会出现异常。

 

 

摘自 justrun1983