perfstat_disk Interface

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

Selected fields from the perfstat_disk_t structure include:
Item Descriptor
name Disk name (from ODM)
description Disk description (from ODM)
vgname Volume group name (from ODM)
size Disk size (in MB)
free Free space (in MB)
xfers Transfers to/from disk (in KB)
Several other disk-related metrics (such as number of blocks read from and written to disk, and adapter names) are also returned. For a complete list, see the perfstat_disk_t section in the libperfstat.h header file in Files Reference.
The following program emulates diskstat behavior and also shows an example of how the perfstat_disk interface is used:
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>

int main(int argc, char* argv[]) {
    int i, ret, tot;
    perfstat_disk_t *statp;
    perfstat_id_t first;

    /* check how many perfstat_disk_t structures are available */
    tot =  perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0);
    
    /* check for error */
    if (tot < 0)
    {
	perror("perfstat_disk");
	exit(-1);
    }
    if (tot == 0)
    {
        printf("No disks found in the system\n");
        exit(-1);
    }

    /* allocate enough memory for all the structures */
    statp = calloc(tot, sizeof(perfstat_disk_t));
    
    /* set name to first interface */
    strcpy(first.name, FIRST_DISK);
    
    /* ask to get all the structures available in one call */
    /* return code is number of structures returned */
    ret = perfstat_disk(&first, statp,
                        sizeof(perfstat_disk_t), tot);

/* check for error */
    if (ret <= 0)
    {
	perror("perfstat_disk");
	exit(-1);
    }

    /* print statistics for each of the disks */
    for (i = 0; i < ret; i++) {
        printf("\nStatistics for disk : %s\n", statp[i].name);
        printf("-------------------\n");
        printf("description              : %s\n", statp[i].description);
        printf("volume group name        : %s\n", statp[i].vgname);
        printf("adapter name             : %s\n", statp[i].adapter);
        printf("size                     : %llu MB\n", statp[i].size);
        printf("free space               : %llu MB\n", statp[i].free);
        printf("number of blocks read    : %llu blocks of %llu bytes\n", statp[i].rblks, statp[i].bsize);
        printf("number of blocks written : %llu blocks of %llu bytes\n", statp[i].wblks, statp[i].bsize);
        }
     }
The preceding program produces the following output:
Statistics for disk : hdisk1
-------------------
description              : 16 Bit SCSI Disk Drive
volume group name        : rootvg
adapter name             : scsi0
size                     : 4296 MB
free space               : 2912 MB
number of blocks read    : 403946 blocks of 512 bytes
number of blocks written : 768176 blocks of 512 bytes

Statistics for disk : hdisk0
-------------------
description              : 16 Bit SCSI Disk Drive
volume group name        : None
adapter name             : scsi0
size                     : 0 MB
free space               : 0 MB
number of blocks read    : 0 blocks of 512 bytes
number of blocks written : 0 blocks of 512 bytes

Statistics for disk : cd0
-------------------
description              : SCSI Multimedia CD-ROM Drive
volume group name        : not available
adapter name             : scsi0
size                     : 0 MB
free space               : 0 MB
number of blocks read    : 3128 blocks of 2048 bytes
number of blocks written : 0 blocks of 2048 bytes