perfstat_cpu_util Subroutine

Purpose

Calculates central processing unit utilization.

Library

perfstat library (libperfstat.a)

Syntax

#include <libperfstat.h>
int perfstat_cpu_util (cpustats, userbuff, sizeof_userbuff, desired_number)
perfstat_rawdata_t * cpustats;
perfstat_cpu_util_t * userbuff;
int  sizeof_userbuff ;
int  desired_number ;

Description

The perfstat_cpu_util subroutine calculates the CPU utilization-related metrics for the current and the previous values passed to the perfstat_rawdata_t data structure. Both the system utilization and the per CPU utilization values can be obtained, using the same API, by mentioning the type field of the perfstat_rawdata_t data structure as UTIL_CPU_TOTAL or UTIL_CPU. The UTIL_CPU_TOTAL and UTIL_CPU are the macros, which can be referred to in the definition of the perfstat_rawdata_t data structure. If the attributes name and userbuff are set to NULL, and the sizeof_userbuff parameter is set to zero, the size of the current version of the perfstat_cpu_util_t structure is returned. If the desired_elements parameter is set to zero, the number of current elements, from the cpustats parameter, are returned.

Parameters

Item Description
cpustats

Calculates the utilization-related metrics from the current and the previous values. The cpustats parameter is of the type perfstat_rawdata_t. The curstat and the prevstat attributes, points to the perfstat_cpu_util_t data structure.

Note: To calculate the partition level CPU utilization, set the cpustats parameter to UTIL_CPU_TOTAL . For the individual CPU utilization, set the cpustats parameter to UTIL_CPU. The ID of the individual CPU can also be specified in the cpustats parameter if utilization to be calculated applies only to a specific CPU.
userbuff

Specifies the memory area that is to be filled with one or more perfstat_cpu_util_t structures.

sizeof_userbuff

Specifies the size of the perfstat_cpu_util_t structure.

Note: To obtain the size of the latest version of perfstat_cpu_util_t structure, set the sizeof_userbuff parameter to 0, and set the name and userbuff parameters to NULL.
desired_number

Specifies the number of perfstat_cpu_util_t structures to copy to the userbuff parameter.

Return Values

Unless the perfstat_cpu_util subroutine is used to retrieve the number of available structures, the number of structures filled is returned upon successful completion. If unsuccessful, a value of -1 is returned and the errno global variable is set.

Error Codes

The perfstat_cpu_util subroutine is unsuccessful if the following is true:

Item Description
EINVAL One of the parameters is not valid.

Files

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