.net中调用windows performance记录性能信息
记录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