Interfaz perfstat_logicalvolume

La interfaz perfstat_logicalvolume devuelve un conjunto de estructuras de tipo perfstat_logicalvolume_t, que se define en el archivo libperfstat.h .

Los campos seleccionados de la estructura perfstat_logicalvolume_t incluyen:
Elemento Descriptor
ppsize Tamaño de partición física (en MB)
Iocnt Número de solicitudes de lectura y grabación
Panes Número de kilobytes leídos
Kbwrites Número de kilobytes grabados
También se devuelven otras métricas relacionadas con el espacio de paginación (como nombre, tipo y activo). Para obtener una lista completa de otras métricas relacionadas con el espacio de paginación, consulte la sección perfstat_logicalvolume_t del archivo de cabecera libperfstat.h en Referencia de archivos.
Nota: Se debe utilizar perfstat_config (PERFSTAT_ENABLE | PERFSTAT_LV, NULL) para habilitar la recopilación de estadísticas de volumen lógico.
El código siguiente muestra un ejemplo de cómo se utiliza la interfaz perfstat_logicalvolume :
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>

int main(){
int lv_count,i, rc;
perfstat_id_t first;
perfstat_logicalvolume_t *lv;


strcpy(first.name,NULL);

/* enable the logical volume statistical collection */
perfstat_config(PERFSTAT_ENABLE | PERFSTAT_LV,NULL);


/* get the number of logical volumes */
lv_count = perfstat_logicalvolume (NULL, NULL, sizeof(perfstat_logicalvolume_t), 0);

/* check the subroutine return code for any error */
if (lv_count == -1){
   perror("perfstat_logicalvolume");
   exit(-1);
}

/* Allocate enough memory to hold all the structures */
lv = (perfstat_logicalvolume_t *)calloc(lv_count, sizeof(perfstat_logicalvolume_t));
if (lv == NULL){
   perror(".malloc");
   exit(-1);
}

/* Call the API to get the data */
rc = perfstat_logicalvolume(&first,(perfstat_logicalvolume_t*)lv, 
sizeof(perfstat_logicalvolume_t),lv_count);

/* check the return code for any error */
if (rc == -1){
   perror("perfstat_logical volume ");
   exit(-1);
}

for(i=0;i<lv_count;i++){
	printf("\n");
	printf("Logical volume name=%s\n",lv[i].name);
	printf("Volume group name=%s\n",lv[i].vgname);
	printf("Physical partition size in MB=%lld\n",lv[i].ppsize);
	printf("total number of logical paritions configured for this logical volume=%lld\n",lv[i].logical_partitions);
	printf("number of physical mirrors for each logical partition=%lu\n",lv[i].mirrors);
	printf("Number of read and write requests=%lu\n",lv[i].iocnt);
	printf("Number of Kilobytes read=%lld\n",lv[i].kbreads);
	printf("Number of Kilobytes written=%lld\n",lv[i].kbwrites);
}

/* disable logical volume statistical collection */
perfstat_config(PERFSTAT_DISABLE | PERFSTAT_LV , NULL);
}
El programa muestra una salida que es similar a la siguiente salida de ejemplo:
Logical volume name=hd5
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=1
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=hd6
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=16
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=hd8
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=1
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=hd4
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=2
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=hd2
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=31
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=hd9var
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=1
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=hd10opt
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=1
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=hd3
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=4
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=hd1
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=74
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=hd11admin
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=4
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=lg_dumplv
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=32
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=livedump
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=8
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=fslv00
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=3
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

Logical volume name=fslv01
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=1
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

El programa anterior emula el comportamiento de vmstat y también muestra cómo se utiliza perfstat_logicalvolume .