perfstat_cpu_total_wpar Interface
The perfstat_cpu_total_wpar interface returns a set of structures of type perfstat_cpu_total_wpar_t, which is defined in the libperfstat.h file.
Selected fields from the perfstat_cpu_total_wpar_t structure
include:
Item | Descriptor |
---|---|
processorHz | Processor speed in Hertz (from ODM) |
Description | Processor type (from ODM) |
Ncpus | Current number of active processors available to the WPAR |
ncpus_cfg | Number of configured processors; that is, the maximum number of processors that this copy of AIX® can handle simultaneously |
Puser | Total number of physical processor ticks spent in user mode |
Psys | Total number of physical processor ticks spent in system (kernel) mode |
Piddle | Total number of physical processor ticks spent idle with no I/O pending |
Pwait | Total number of physical processor ticks spent idle with I/O pending |
Several other paging-space-related metrics (such as number of system calls, number of reads, writes, forks, execs, and load average) are also returned. For a complete list of other paging-space-related metrics, see the perfstat_cpu_total_wpar_t section in the libperfstat.h header file.
The following program emulates wparstat behavior
and also shows an example of how perfstat_cpu_total_wpar_t is
used from the global environment:
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(){
perfstat_cpu_total_wpar_t *cpustats;
perfstat_id_wpar_t wparid;
perfstat_wpar_total_t *winfo;
int i,j,rc,totwpars;
/* Retrieve total number of WPARs in the system */
totwpars = perfstat_wpar_total(NULL, NULL, sizeof(perfstat_wpar_total_t), 0);
if (totwpars < 0) {
perror("Error in perfstat_wpar_total");
exit(-1);
}
if (totwpars == 0) {
printf("No WPARs found in the system\n");
exit(-1);
}
/* allocate enough memory for all the structures */
winfo = calloc(totwpars,sizeof(perfstat_wpar_total_t));
/* Retrieve all WPARs */
bzero(&wparid, sizeof(perfstat_id_wpar_t));
wparid.spec = WPARNAME;
strcpy(wparid.u.wparname, "test");
rc = perfstat_wpar_total(&wparid, winfo, sizeof(perfstat_wpar_total_t), totwpars);
if (rc <= 0) {
perror("Error in perfstat_wpar_total");
exit(-1);
}
for(i=0; i < totwpars; i++)
{
bzero(&wparid, sizeof(perfstat_id_wpar_t));
wparid.spec = WPARID;
wparid.u.wpar_id = winfo[i].wpar_id;
cpustats=calloc(1,sizeof(perfstat_cpu_total_wpar_t));
rc = perfstat_cpu_total_wpar(&wparid, cpustats, sizeof(perfstat_cpu_total_wpar_t), 1);
if (rc != 1) {
perror("perfstat_cpu_total_wpar");
exit(-1);
}
for(j=0;j<rc;j++){
printf("Number of active logical processors in Global=%d\n",cpustats[j].ncpus);
printf("Processor description=%s\n",cpustats[j].description);
printf("Processor speed in Hz=%lld\n",cpustats[j].processorHZ);
printf("Number of process switches=%lld\n",cpustats[j].pswitch);
printf("Number of forks system calls executed=%lld\n",cpustats[j].sysfork);
printf("Length of the run queue=%lld\n",cpustats[j].runque);
printf("Length of the swap queue=%lld\n",cpustats[j].swpque);
}
}
}
The program displays an output that is similar to the
following example output:Number of active logical processors in Global=8
Processor description=PowerPC_POWER7
Processor speed in Hz=3304000000
Number of process switches=1995
Number of forks system calls executed=322
Length of the run queue=3
Length of the swap queue=1
The following code shows
an example of how perfstat_cpu_total_wpar is used from the
WPAR environment:
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(){
perfstat_cpu_total_wpar_t *cpustats;
perfstat_id_wpar_t wparid;
perfstat_wpar_total_t *winfo;
int i,j,rc,totwpars;
/* Retrieve total number of WPARs in the system */
totwpars = perfstat_wpar_total(NULL, NULL, sizeof(perfstat_wpar_total_t), 0);
if (totwpars < 0) {
perror("Error in perfstat_wpar_total");
exit(-1);
}
if (totwpars == 0) {
printf("No WPARs found in the system\n");
exit(-1);
}
/* allocate enough memory for all the structures */
winfo = calloc(totwpars,sizeof(perfstat_wpar_total_t));
/* Retrieve all WPARs */
bzero(&wparid, sizeof(perfstat_id_wpar_t));
wparid.spec = WPARNAME;
strcpy(wparid.u.wparname, "test");
rc = perfstat_wpar_total(NULL, winfo, sizeof(perfstat_wpar_total_t), totwpars);
if (rc <= 0) {
perror("Error in perfstat_wpar_total");
exit(-1);
}
for(i=0; i < totwpars; i++)
{
bzero(&wparid, sizeof(perfstat_id_wpar_t));
wparid.spec = WPARID;
wparid.u.wpar_id = winfo[i].wpar_id;
cpustats=calloc(1,sizeof(perfstat_cpu_total_wpar_t));
rc = perfstat_cpu_total_wpar(NULL, cpustats, sizeof(perfstat_cpu_total_wpar_t), 1);
if (rc != 1) {
perror("perfstat_cpu_total_wpar");
exit(-1);
}
for(j=0;j<rc;j++){
printf("Number of active logical processors in Global=%d\n",cpustats[j].ncpus);
printf("Processor description=%s\n",cpustats[j].description);
printf("Processor speed in Hz=%lld\n",cpustats[j].processorHZ);
printf("Number of process switches=%lld\n",cpustats[j].pswitch);
printf("Number of forks system calls executed=%lld\n",cpustats[j].sysfork);
printf("Length of the run queue=%lld\n",cpustats[j].runque);
printf("Length of the swap queue=%lld\n",cpustats[j].swpque);
}
}
}