关于perfstat_cpu_total函数的一点疑问

pengxn 2009-03-23 10:12:05
在AIX主机上使用perfstat_cpu_total获取的系统IDLE等参数为什么总感觉和TOPAS系统返回的值总是不准。

我使用的方法是这样。

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主机上有没有什么其他更好的办法
...全文
183 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
morris88 2009-04-22
  • 打赏
  • 举报
回复
呵呵,他们之间是有一些细微的差别的...
独孤过儿 2009-03-23
  • 打赏
  • 举报
回复

perfstat_cpu_total Subroutine

Purpose

Retrieves global processor usage statistics.
Library

Perfstat library (libperfstat.a)
Syntax

#include <libperfstat.h>

int perfstat_cpu_total (name, userbuff, sizeof_struct, desired_number)
perfstat_id_t *name;
perfstat_cpu_total_t *userbuff;
size_t sizeof_struct;
int desired_number;
Description

The perfstat_cpu_total subroutine returns global processor usage statistics in a perfstat_cpu_total_t structure.

To get statistics that are global to the whole system, the name parameter must be set to NULL, the
userbuff parameter must be allocated, and the desired_number parameter must be set to 1.

The perfstat_cpu_total subroutine retrieves information from the ODM database. This information is
automatically cached into a dictionary which is assumed to be frozen once loaded. The
perfstat_reset subroutine must be called to flush the dictionary whenever the machine configuration
has changed.

In AIX 5.3 and later, SPLPAR environments virtualize physical processors. To help accurately
measure the resource used in a virtualized environment, the POWER5 family of processors implements
a register PURR (Processor Utilization Resource Register) for each core. The PURR is a 64-bit
counter with the same units as the timebase register and tracks the real physical processor
resource used on a per-thread or per-partition level. The PURR registers are not compatible with
previous global counters (user, system, idle and wait fields) returned by the perfstat_cpu and the
perfstat_cpu_total subroutines. All data consumers requiring processor use must be modified to
support PURR-based computations as shown in the example for the perfstat_partition_total interface
under Perfstat API programming.

This subroutine returns only global processor statistics inside a workload partition (WPAR).
Parameters

name Must set to NULL.
userbuff Points to the memory area that is to be filled with the perfstat_cpu_total_t
structure.
sizeof_struct Specifies the size of the perfstat_cpu_total_t structure: sizeof(perfstat_cpu_total_t).
desired_number Must set to 1.
Return Values

Upon successful completion, the number of structures filled is returned. If unsuccessful, a value
of -1 is returned and the errno global variable is set.
Error Codes

The perfstat_cpu_total subroutine is unsuccessful if one of the following is true:
EINVAL One of the parameters is not valid.
EFAULT Insufficient memory.
ENOMEM The string default length is too short.
Files

The libperfstat.h file defines standard macros, data types, and subroutines.
Related Information

perfstat_netbuffer Subroutine, perfstat_cpu Subroutine, perfstat_disk Subroutine,
perfstat_diskadapter Subroutine, perfstat_diskpath Subroutine, perfstat_disk_total Subroutine,
perfstat_memory_total Subroutine, perfstat_netinterface Subroutine, perfstat_netinterface_total
Subroutine, perfstat_pagingspace Subroutine, perfstat_partial_reset Subroutine, and
perfstat_protocol Subroutine.

Perfstat API in AIX Version 6.1 Performance Tools Guide and Reference.
  • 打赏
  • 举报
回复
http://www-900.ibm.com/cn/support/faqhtmlfaq/2011993000001.htm
libperfstat API接口函数的使用

参考下吧

4,450

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧