关于perfstat_cpu_total函数的一点疑问
在AIX主机上使用perfstat_cpu_total获取的系统IDLE等参数为什么总感觉和TOPAS系统返回的值总是不准。
我使用的方法是这样。
请问一下这个函数具体应该怎么用,或在AIX主机上有没有什么其他更好的办法
我使用的方法是这样。
static perfstat_cpu_total_t t1,t2;
double total_cpu;
perfstat_memory_total_t m1;
// EDIT BY PENGXN 为了准确增加查询次数
int nOffset = 8;
total_cpu = 0;
info.iCpuSys = 0;
info.iCpuWait = 0;
info.iCpuUser = 0;
info.iCpuIdle = 0;
for(int i=0;i<nOffset;i++)
{
t2 = t1;
if (perfstat_cpu_total(NULL,&t1,sizeof(perfstat_cpu_total_t),1)<0)
return -1;
total_cpu = (t1.psys+t1.puser+t1.pidle+t1.pwait-(t2.psys+t2.puser+t2.pidle+t2.pwait));
info.iCpuSys += (int)((t1.psys-t2.psys)*1000/total_cpu);
info.iCpuWait += (int)((t1.pwait-t2.pwait)*1000/total_cpu);
info.iCpuUser += (int)((t1.puser-t2.puser)*1000/total_cpu);
info.iCpuIdle += (int)((t1.pidle-t2.pidle)*1000/total_cpu);
usleep(20);
}
info.iCpuSys = info.iCpuSys/nOffset;
info.iCpuWait = info.iCpuWait/nOffset;
info.iCpuUser = info.iCpuUser/nOffset;
info.iCpuIdle = info.iCpuIdle/nOffset;
请问一下这个函数具体应该怎么用,或在AIX主机上有没有什么其他更好的办法
...全文


