perfstat_memory_total_wpar Interface

The perfstat_memory_total_wpar interface returns a set of structures of type perfstat_memory_total_wpar_t, which is defined in the libperfstat.h file.

Selected fields from the perfstat_memory_total_wpar_t structure include:
Item Descriptor
real_total Amount of Global real memory (in units of 4 KB pages)
real_free Amount of Global free real memory (in units of 4 KB pages)
real_pinned Amount of WPAR pinned memory (in units of 4 KB pages)
Pgins Number of WPAR pages paged in
Pgouts Number of WPAR pages paged out

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_memory_total_wpar_t section in the libperfstat.h header file.

The following program emulates wparstat behavior and also shows an example of how perfstat_memory_total_wpar is used from the global environment:

#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(){
    perfstat_memory_total_wpar_t *memstats;
    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;

        memstats=calloc(1,sizeof(perfstat_memory_total_wpar_t));
        rc =  perfstat_memory_total_wpar(&wparid, memstats, sizeof(perfstat_memory_total_wpar_t), 1);
        if (rc != 1) {
            perror("perfstat_memory_total_wpar");
            exit(-1);
        }
for(j=0;j<rc;j++){
                printf("Global total real memory=%lld\n",memstats[j].real_total);
                printf("Global free real memory=%lld\n",memstats[j].real_free);
                printf("Real memory which is pinned=%lld\n",memstats[j].real_pinned);
                printf("Real memory which is in use=%lld\n",memstats[j].real_inuse);
                printf("Number of page faults=%lld\n",memstats[j].pgexct);
                printf("Number of pages paged in=%lld\n",memstats[j].pgins);
                printf("Number of pages paged out=%lld\n",memstats[j].pgouts);
        }
    }
}
The program produces output that is similar to the following output:
Global total real memory=1048576
Global free real memory=721338
Real memory which is pinned=464
Real memory which is in use=2886
Number of page faults=37176802
Number of pages paged in=1304
Number of pages paged out=64
The following code shows an example of how perfstat_memory_total_wpar is used from the WPAR environment:
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(){
    perfstat_memory_total_wpar_t *memstats;
    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;

        memstats=calloc(1,sizeof(perfstat_memory_total_wpar_t));
        rc =  perfstat_memory_total_wpar(NULL, memstats, sizeof(perfstat_memory_total_wpar_t), 1);
        if (rc != 1) {
            perror("perfstat_memory_total_wpar");
            exit(-1);
        }
for(j=0;j<rc;j++){
                printf("Global total real memory=%lld\n",memstats[j].real_total);
                printf("Global free real memory=%lld\n",memstats[j].real_free);
                printf("Real memory which is pinned=%lld\n",memstats[j].real_pinned);
                printf("Real memory which is in use=%lld\n",memstats[j].real_inuse);
                printf("Number of page faults=%lld\n",memstats[j].pgexct);
                printf("Number of pages paged in=%lld\n",memstats[j].pgins);
                printf("Number of pages paged out=%lld\n",memstats[j].pgouts);
        }
    }
}