perfstat_pagingspace Interface

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

Selected fields from the perfstat_pagingspace_t structure include:
Item Descriptor
mb_size Size of the paging space in MB
lp_size Size of the paging space in logical partitions
mb_used Portion of the paging space used in MB
Several other paging-space-related metrics (such as name, type, and active) are also returned. For a complete list of other paging-space-related metrics, see the perfstat_pagingspace_t section in the libperfstat.h header file in Files Reference.
The following code shows an example of how perfstat_pagingspace is used:
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>

int main(int argc, char agrv[]) {
    int i, ret, tot;
    perfstat_id_t first;
    perfstat_pagingspace_t *pinfo;
    
    tot = perfstat_pagingspace(NULL, NULL, sizeof(perfstat_pagingspace_t), 0);
    /* check for error */
    if (tot <= 0)
    {
	  perror("perfstat_pagingspace");
	  exit(-1);
    }    

    pinfo = calloc(tot,sizeof(perfstat_pagingspace_t));

    strcpy(first.name, FIRST_PAGINGSPACE);

    ret = perfstat_pagingspace(&first, pinfo, sizeof(perfstat_pagingspace_t), tot);
    /* check for error */
    if (tot <= 0)
    {
	  perror("perfstat_pagingspace");
	  exit(-1);
    }
    for (i = 0; i < ret; i++) {
        printf("\nStatistics for paging space : %s\n", pinfo[i].name);
        printf("---------------------------\n");
        printf("type         : %s\n",
               pinfo[i].type == LV_PAGING ? "logical volume" : "NFS file");
        if (pinfo[i].type == LV_PAGING) {
    	    printf("volume group : %s\n", pinfo[i].u.lv_paging.vgname);
        }
        else {
    	    printf("hostname : %s\n", pinfo[i].u.nfs_paging.hostname);
    	    printf("filename : %s\n", pinfo[i].u.nfs_paging.filename);
        }
        printf("size (in LP) : %llu\n", pinfo[i].lp_size);
        printf("size (in MB) : %llu\n", pinfo[i].mb_size);
        printf("used (in MB) : %llu\n", pinfo[i].mb_used);
    }
}
The preceding program produces the following output:
Statistics for paging space : hd6
---------------------------
type         : logical volume
volume group : rootvg
size (in LP) : 64
size (in MB) : 512
used (in MB) : 4