perfstat_diskpath Interface
The perfstat_diskpath interface returns a set of structures of type perfstat_diskpath_t, which is defined in the libperfstat.h file.
Selected fields from the perfstat_diskpath_t structure include:
Several other disk path-related metrics (such as the number of blocks read from and written
through the path) are also returned. For a complete list, see the perfstat_diskpath_t section
in the libperfstat.h header file.
Item | Descriptor |
---|---|
name | Path name (<disk_name>_Path<path_id>) |
xfers | Total transfers through this path (in KB) |
adapter | Name of the adapter linked to the path |
The following code shows an example of how the perfstat_diskpath
interface is used:
The
program displays an output that is similar to the following example
output:#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(int argc, char* argv[]) {
int ret, tot, i;
perfstat_diskpath_t *statp;
perfstat_id_t first;
char *substring;
perfstat_disk_t dstat;
/* check how many perfstat_diskpath_t structures are available */
tot = perfstat_diskpath(NULL, NULL, sizeof(perfstat_diskpath_t), 0);
/* check for error */
if (tot < 0)
{
perror("perfstat_diskpath");
exit(-1);
}
if (tot == 0)
{
printf("No Paths found in the system\n");
exit(-1);
}
/* allocate enough memory for all the structures */
statp = calloc(tot, sizeof(perfstat_diskpath_t));
if(statp==NULL){
printf("No sufficient memory\n");
exit(-1);
}
/* set name to first interface */
strcpy(first.name, FIRST_DISKPATH);
/* ask to get all the structures available in one call */
/* return code is number of structures returned */
ret = perfstat_diskpath(&first, statp, sizeof(perfstat_diskpath_t), tot);
/* check for error */
if (ret <= 0)
{
perror("perfstat_diskpath");
exit(-1);
}
/* print statistics for each of the disk paths */
for (i = 0; i < ret; i++) {
printf("\nStatistics for disk path : %s\n", statp[i].name);
printf("----------------------\n");
printf("number of blocks read : %llu\n", statp[i].rblks);
printf("number of blocks written : %llu\n", statp[i].wblks);
printf("adapter name : %s\n", statp[i].adapter);
}
/* retrieve paths for last disk if any */
if (ret > 0) {
/* extract the disk name from the last disk path name */
substring = strstr(statp[ret-1].name, "_Path");
if (substring == NULL) {
return (-1);
}
substring[0] = '\0';
/* set name to the disk name */
strcpy(first.name, substring);
/* retrieve info about disk */
ret = perfstat_disk(&first, &dstat, sizeof(perfstat_disk_t),1);
if (ret <= 0)
{
perror("perfstat_diskpath");
exit(-1);
}
printf("\nPaths for disk path : %s (%d)\n", dstat.name, dstat.paths_count);
printf("----------------------\n");
/* retrieve all paths for this disk */
ret = perfstat_diskpath(&first, statp, sizeof(perfstat_diskpath_t), dstat.paths_count);
if (ret <= 0)
{
perror("perfstat_diskpath");
exit(-1);
}
/* print statistics for each of the paths */
for (i = 0; i < ret; i++) {
printf("\nStatistics for disk path : %s\n", statp[i].name);
printf("----------------------\n");
printf("number of blocks read : %llu\n", statp[i].rblks);
printf("number of blocks written : %llu\n", statp[i].wblks);
printf("adapter name : %s\n", statp[i].adapter);
}
}
}
Statistics for disk path : hdisk0_Path0
----------------------
number of blocks read : 335354
number of blocks written : 291416
adapter name : vscsi0
Paths for disk path : hdisk0 (1)
----------------------
Statistics for disk path : hdisk0_Path0
----------------------
number of blocks read : 335354
number of blocks written : 291416
adapter name : vscsi0