[AIX 성능 도구 10] perfstat API (5) 테이프·스레드·볼륨 그룹·가상 어댑터·SSP
https://archive.horanglab.com/posts/aix-perf-perfstat-5
핵심 정리
perfstat_tape: 테이프마다 크기·빈 부분(MB), 블록 크기, 경로 수.- (6.1)
perfstat_thread·perfstat_thread_util: 커널 스레드마다 PID, TID, 묶인 CPU, 사용자·시스템 CPU 시간. perfstat_volumegroup: VG마다 전체·활성 디스크 수와 I/O 요청 수. LV처럼perfstat_config로 수집을 켭니다.- (6.1) VIOS 쪽 인터페이스:
perfstat_virtualdiskadapter(vhost),perfstat_virtual_fcadapter(vfchost),perfstat_virtualdisktarget(가상 디스크 대상),perfstat_bridgedadapters(SEA 브리지 어댑터). - (6.1)
perfstat_ssp·perfstat_ssp_ext: 공유 스토리지 풀(SSP)의 풀·디스크·노드 정보.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (6.1에서 스레드, 가상 어댑터, 브리지 어댑터, SSP 인터페이스가 더해짐) |
| 원문 | Performance Tools Guide and Reference — 5.3판 6장(170174쪽), 6.1판 159184쪽 |
| 파일 | /usr/include/libperfstat.h, /usr/samples/libperfstat |
| 관련 명령어 | tapechk, lsvg, viostat, seastat |
perfstat_tape 인터페이스
perfstat_tape 인터페이스는 libperfstat.h 파일에 정의된 perfstat_tape_t 구조체 묶음을 돌려줍니다.
perfstat_tape_t 구조체의 주요 필드는 다음과 같습니다.
| 필드 | 설명 |
|---|---|
size |
테이프 크기(MB) |
free |
테이프의 빈 부분(MB) |
bsize |
테이프 블록 크기(바이트) |
paths_count |
테이프로 가는 경로 수 |
이 밖에도 테이프 관련 지표(이름, 유형 등)를 돌려줍니다. 전체 목록은 Files Reference의 libperfstat.h 헤더 파일에서 perfstat_tape_t 부분을 봅니다.
다음 코드는 perfstat_tape 인터페이스를 쓰는 예입니다.
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(){
int ret, tot, i;
perfstat_tape_t *statp;
perfstat_id_t first;
/* check how many perfstat_tape_t structures are available */
tot = perfstat_tape(NULL, NULL, sizeof(perfstat_tape_t), 0);
/* check for error */
if (tot < 0)
{
perror("perfstat_tape");
exit(-1);
}
if (tot == 0)
{
printf("No tape found in the system\n");
exit(-1);
}
/* allocate enough memory for all the structures */
statp = calloc(tot, sizeof(perfstat_tape_t));
if(statp==NULL){
printf("No sufficient memory\n");
exit(-1);
}
/* set name to first interface */
strcpy(first.name, FIRST_TAPE);
/* ask to get all the structures available in one call */
/* return code is number of structures returned */
ret = perfstat_tape(&first, statp,
sizeof(perfstat_tape_t), tot);
/* check for error */
if (ret <= 0)
{
perror("perfstat_tape");
exit(-1);
}
for(i=0;i<ret;i++){
printf("Name of the tape=%s\n",statp[i].name);
printf("Tape description=%s\n",statp[i].description);
printf("Size of the tape (in MB)=%lld\n",statp[i].size);
printf("Free portion of the tape (in MB)=%lld\n",statp[i].free);
printf("Tape block size (in bytes)=%lld\n",statp[i].bsize);
printf("Number of transfers to/from tape=%lld\n",statp[i].xfers);
printf("Number of read transfers to/from tape=%lld\n",statp[i].rxfers);
printf("Number of blocks written to tape=%lld\n",statp[i].wblks);
printf("Number of blocks read from tape=%lld\n",statp[i].rblks);
printf("Amount of time tape is active=%lld\n",statp[i].time);
printf("Tape adapter name =%s\n",statp[i].adapter);
printf("Number of paths to this tape=%d\n",statp[i].paths_count);
printf("\n");
}
}
영어 원문
perfstat_tape Interface
The perfstat_tape interface returns a set of structures of type perfstat_tape_t, which is defined in the libperfstat.h file.
Selected fields from the perfstat_tape_t structure include:
- size — Size of the tape (in MB)
- free — Free portion of the tape (in MB)
- bsize — Tape block size (in bytes)
paths_count— Number of paths to the tape
Several other paging-space-related metrics (such as name, type, and active) are also returned. For a complete list of 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 the perfstat_tape interface is used:
(54줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
(6.1) perfstat_thread 인터페이스
perfstat_thread 인터페이스는 libperfstat.h 파일에 정의된 perfstat_thread_t 구조체 묶음을 돌려줍니다.
perfstat_thread_t 구조체의 필드는 다음과 같습니다.
| 필드 | 설명 |
|---|---|
pid |
스레드의 프로세스 ID |
tid |
스레드의 커널 ID |
cpuid |
스레드가 묶인(bound) 프로세서 |
ucpu_time |
사용자 모드 CPU 시간(ms) |
scpu_time |
시스템 모드 CPU 시간(ms) |
다음은 perfstat_thread API를 쓰는 코드 예입니다.
#include <libperfstat.h>
void main()
{
perfstat_thread_t *threadt;
perfstat_id_t id;
int i,rc,thread_count;
/* Get the count of threads */
thread_count = perfstat_thread(NULL, NULL,sizeof(perfstat_thread_t),0);
/* check for error */
if(thread_count <= 0)
{
perror("Error in perfstat_thread");
exit(-1) ;
}
printf("Number of Threads = %d\n",thread_count);
/* Allocate enough memory */
threadt = (perfstat_thread_t *)calloc(thread_count,sizeof(perfstat_thread_t));
if(threadt == NULL)
{
perror("Memory Allocation Error");
exit(-1) ;
}
strcpy(id.name,"");
rc = perfstat_thread(&id,threadt,sizeof(perfstat_thread_t),thread_count);
if(rc <= 0)
{
free(threadt);
perror("Error in perfstat_thread");
exit(-1) ;
}
printf("\n =======Thread Related metrics =======\n");
for(i=0 ; i<thread_count ;i++)
{
printf("Process ID = %u\n",threadt[i].pid);
printf("Thread ID = %u\n",threadt[i].tid);
printf("\nCPU Related Statistics \n");
printf("User Mode CPU time = %f ms\n",threadt[i].ucpu_time);
printf("System Mode CPU time = %f ms\n",threadt[i].scpu_time);
printf("Processor to which the thread is bound = %d\n", threadt[i].cpuid);
printf("=====================================\n");
printf("\n\n");
}
free(threadt);
}
이 프로그램은 다음과 비슷한 출력을 냅니다.
Process ID = 6553744
Thread ID = 12345
CPU Related Statistics
User Mode CPU time = 714000.000000 ms
System Mode CPU time = 3000.000000 ms
Processor to which the thread is bound = 1
관련 정보
libperfstat.h 파일
영어 원문
perfstat_thread interfaces
The perfstat_thread interface returns a set of structures of type perfstat_thread_t, which is defined in the libperfstat.h file.
The field of the perfstat_thread_t structure includes the following:
Table 2. perfstat_thread_t fields
- Pid — The process ID of the thread.
- Tid — The kernel ID of the thread.
- Cpuid — The processor on which the thread is bound.
ucpu_time— The user mode CPU time in milliseconds.scpu_time— The system mode CPU time in milliseconds.
The following is an example of code for the perfstat_thread_t API:
(44줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
The program displays an output that is similar to the following example output:
Process ID = 6553744
Thread ID = 12345
CPU Related Statistics
User Mode CPU time = 714000.000000 ms
System Mode CPU time = 3000.000000 ms
Processor to which the thread is bound = 1
Related information
libperfstat.h command
(6.1) perfstat_thread_util 인터페이스
perfstat_thread_util 인터페이스는 libperfstat.h 파일에 정의된 perfstat_thread_t 구조체 묶음을 돌려줍니다.
다음은 perfstat_thread_util API를 쓰는 코드 예입니다.
#include <libperfstat.h>
#define PERIOD 5
void main()
{
perfstat_thread_t *cur, *prev;
perfstat_rawdata_t buf;
perfstat_thread_t *thread_util;
perfstat_id_t id;
int cur_thread_count,prev_thread_count;
int i,rc;
prev_thread_count = perfstat_thread(NULL, NULL,sizeof(perfstat_thread_t),0);
if(prev_thread_count <= 0)
{
perror("Error in perfstat_thread");
exit(-1) ;
}
prev = (perfstat_thread_t *)calloc(prev_thread_count,sizeof(perfstat_thread_t));
if(prev == NULL)
{
perror("Memory Allocation Error");
exit(-1) ;
}
strcpy(id.name,"");
prev_thread_count = perfstat_thread(&id,prev,sizeof(perfstat_thread_t),prev_thread_count);
if(prev_thread_count <= 0)
{
free(prev);
perror("Error in perfstat_thread");
exit(-1) ;
}
sleep(PERIOD);
cur_thread_count = perfstat_thread(NULL, NULL,sizeof(perfstat_thread_t),0);
if(cur_thread_count <= 0)
{
free(prev);
perror("Error in perfstat_thread");
exit(-1) ;
}
cur = (perfstat_thread_t *)calloc(cur_thread_count,sizeof(perfstat_thread_t));
thread_util = (perfstat_thread_t *)calloc(cur_thread_count,sizeof(perfstat_thread_t));
if(cur == NULL || thread_util == NULL)
{
free(prev);
perror("Memory Allocation Error");
exit(-1) ;
}
cur_thread_count = perfstat_thread(&id,cur,sizeof(perfstat_thread_t),cur_thread_count);
if(cur_thread_count <= 0)
{
free(prev);
free(cur);
free(thread_util);
perror("Error in perfstat_thread");
exit(-1) ;
}
bzero(&buf, sizeof(perfstat_rawdata_t));
buf.type = UTIL_PROCESS;
buf.curstat = cur;
buf.prevstat = prev;
buf.sizeof_data = sizeof(perfstat_thread_t);
buf.cur_elems = cur_thread_count;
buf.prev_elems = prev_thread_count;
/* Calculate Thread Utilization. This returns the number of thread_util structures that are filled */
rc = perfstat_thread_util(&buf,thread_util,sizeof(perfstat_thread_t),cur_thread_count);
if(rc <= 0)
{
free(prev);
free(cur);
free(thread_util);
perror("Error in perfstat_thread_util");
exit(-1);
}
printf("\n =======Thread Related Utilization Metrics =======\n");
for(i=0 ; i<rc ;i++)
{
printf("Process ID = %u\n",thread_util[i].pid);
printf("Thread ID = %u\n",thread_util[i].tid);
printf("User Mode CPU time = %f \n",thread_util[i].ucpu_time);
printf("System Mode CPU time = %f \n",thread_util[i].scpu_time);
printf(" Bound CPU Id = %d\n", thread_util[i].cpuid);
printf("=====================================\n");
printf("\n\n");
}
free(prev);
free(cur);
free(thread_util);
}
이 프로그램은 다음과 비슷한 출력을 냅니다.
Process ID = 6160532
Thread ID = 123456
User Mode CPU time = 21.824531
System Mode CPU time = 0.000000
Bound CPU Id = 1
관련 정보
libperfstat.h 파일
영어 원문
perfstat_thread_util interface
The perfstat_thread_util interface returns a set of structures of type perfstat_thread_t, which is defined in the libperfstat.h file.
The following is an example of code for the perfstat_thread_util API:
(87줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
The program displays an output that is similar to the following example output:
Process ID = 6160532
Thread ID = 123456
User Mode CPU time = 21.824531
System Mode CPU time = 0.000000
Bound CPU Id = 1
Related information
libperfstat.h command
perfstat_volumegroup 인터페이스
perfstat_volumegroup 인터페이스는 libperfstat.h 파일에 정의된 구조체 묶음을 돌려줍니다(원문은 perfstat_logicalvolume_t라고 적었지만 볼륨 그룹용 구조체는 perfstat_volumegroup_t입니다).
구조체의 주요 필드는 다음과 같습니다.
| 필드 | 설명 |
|---|---|
total_disks |
볼륨 그룹의 전체 디스크 수 |
active_disks |
볼륨 그룹의 활성 디스크 수 |
iocnt |
읽기·쓰기 요청 수 |
다음 코드는 perfstat_volumegroup 인터페이스를 쓰는 예입니다.
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(){
int vg_count, rc,i;
perfstat_id_t first;
perfstat_volumegroup_t *vg;
strcpy(first.name,NULL);
/* to enable the volumegroup statistical collection */
perfstat_config(PERFSTAT_ENABLE|PERFSTAT_LV,NULL);
/* to get the number of volume groups */
vg_count = perfstat_volumegroup (NULL, NULL, sizeof(perfstat_logicalvolume_t), 0);
/* check the subroutine return code for any error */
if (vg_count <=0 ){
perror("perfstat_volumegroup");
exit(-1);
}
/* Allocate enough memory to hold all the structures */
vg = (perfstat_volumegroup_t *)calloc(vg_count, sizeof(perfstat_volumegroup_t));
if (vg == NULL){
perror(".malloc");
exit(-1);
}
/* Call the API to get the data */
rc = perfstat_volumegroup(&first,vg,sizeof(perfstat_volumegroup_t),vg_count);
/* check the return code for any error */
if (rc <= 0){
perror("perfstat_volumegroup ");
exit(-1);
}
for(i=0;i<vg_count;i++){
printf("Volume group name=%s\n",vg[i].name);
printf("Number of physical volumes in the volume group=%lld\n",vg[i].total_disks);
printf("Number of active physical volumes in the volume group=%lld\n",vg[i].active_disks);
printf("Number of logical volumes in the volume group=%lld\n",vg[i].total_logical_volumes);
printf("Number of logical volumes opened in the volume group=%lld\n",vg[i].opened_logical_volumes);
printf("Number of read and write requests=%lld\n",vg[i].iocnt);
printf("Number of Kilobytes read=%lld\n",vg[i].kbreads);
printf("Number of Kilobytes written=%lld\n",vg[i].kbwrites);
}
/* disable logical volume statistical collection */
perfstat_config(PERFSTAT_DISABLE | PERFSTAT_LV , NULL);
return 0;
}
이 프로그램은 다음과 비슷한 출력을 냅니다.
Volume group name=rootvg
Number of physical volumes in the volume group=1
Number of active physical volumes in the volume group=1
Number of logical volumes in the volume group=16
Number of logical volumes opened in the volume group=11
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
영어 원문
perfstat_volumegroup Interface
The perfstat_volumegroup interface returns a set of structures of type perfstat_logicalvolume_t, which is defined in the libperfstat.h file.
Selected fields from the perfstat_logicalvolume_t structure include:
Total_disks— Total number of disks in the volume groupActive_disks— Total number of active disks in the volume group- Iocnt — Number of read and write requests
The following code shows an example of how the perfstat_logicalvolume interface is used:
(44줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
The program displays an output that is similar to the following example output:
Volume group name=rootvg
Number of physical volumes in the volume group=1
Number of active physical volumes in the volume group=1
Number of logical volumes in the volume group=16
Number of logical volumes opened in the volume group=11
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
The preceding program emulates vmstat behavior and also shows how perfstat_volumegroup is used.
(6.1) perfstat_virtualdiskadapter 인터페이스
perfstat_virtualdiskadapter 인터페이스는 libperfstat.h 파일에 정의된 perfstat_diskadapter_t 구조체 묶음을 돌려줍니다.
다음 프로그램은 perfstat_virtualdiskadapter 인터페이스를 쓰는 예입니다.
/* The sample program display the metrics *
* related to each and every Individual *
* Virtual SCSI/SAS adapter stats in the VIOS */
#include<stdio.h>
#include<stdlib.h>
#include<libperfstat.h>
#include<net/if_types.h>
/* define default interval and count values */
#define INTERVAL_DEFAULT 1
#define COUNT_DEFAULT 1
/* Check value returned by malloc for NULL */
#define CHECK_FOR_MALLOC_NULL(X) { if ((X) == NULL) {\
perror ("malloc");\
exit(2);\
}\
}
int count = COUNT_DEFAULT, interval = INTERVAL_DEFAULT, tot;
int returncode;
/* support for remote node statistics collection in a cluster environment */
perfstat_id_node_t nodeid;
static char nodename[MAXHOSTNAMELEN] = "";
static int collect_remote_node_stats = 0;
/* store the data structures */
static perfstat_diskadapter_t *statp ,*statq;
/*
* NAME: showusage
* to display the usage
*
*/
void showusage(char *cmd)
{
fprintf (stderr, "usage: %s [-i <interval in seconds>] [-c <number of iterations>]
[-n <node name in the cluster>]\n", cmd);
exit(1);
}
/*
* NAME: do_initialization
* This function initializes the data structues.
* It also collects initial set of values.
*
* RETURNS:
* On successful completion:
* - returns 0.
* In case of error
* - exits with code 1.
*/
int do_initialization(void)
{
/* check how many perfstat_vhost_adapter_t structures are available */
if(collect_remote_node_stats) {
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
nodeid.spec = NODENAME;
tot = perfstat_virtualdiskadapter_node(&nodeid, NULL, sizeof(perfstat_diskadapter_t), 0);
}
else
{
tot = perfstat_virtualdiskadapter(NULL, NULL, sizeof(perfstat_diskadapter_t), 0);
}
if (tot == 0)
{
printf("There is no net adapter\n");
exit(0);
}
if (tot < 0)
{
perror("perfstat_vhost_adapter: ");
exit(1);
}
/* allocate enough memory for all the structures */
statp = (perfstat_diskadapter_t *)malloc(tot * sizeof(perfstat_diskadapter_t));
CHECK_FOR_MALLOC_NULL(statp);
statq = (perfstat_diskadapter_t *)malloc(tot * sizeof(perfstat_diskadapter_t));
CHECK_FOR_MALLOC_NULL(statq);
return(0);
}
/*
*Name: display_metrics
* collect the metrics and display them
*
*/
void display_metrics()
{
perfstat_id_t first;
int ret, i;
if(collect_remote_node_stats) {
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
nodeid.spec = NODENAME;
strcpy(nodeid.name , FIRST_VHOST);
ret = perfstat_virtualdiskadapter_node(&nodeid, statq, sizeof(perfstat_diskadapter_t), tot);
} else
{
strcpy(first.name , FIRST_VHOST);
ret = perfstat_virtualdiskadapter( &first, statq, sizeof(perfstat_diskadapter_t), tot);
}
if (ret < 0){
free(statp);
free(statq);
perror("perfstat_vhost_adapter: ");
exit(1);
}
while (count)
{
sleep (interval);
if(collect_remote_node_stats)
{
ret = perfstat_virtualdiskadapter_node(&nodei;, statp, sizeof(perfstat_diskadapter_t), tot);
} else {
ret = perfstat_virtualdiskadapter(&first, statp, sizeof(perfstat_diskadapter_t),tot);
}
/* print statistics for each of the interfaces */
for (i = 0; i < ret; i++) {
printf(" Adapter name: %s \n", statp[i].name);
printf(" Adapter Type:%d \n",statp[i].adapter_type);
printf(" Total number of transfers via adapter :%lld \n",statp[i].xfers - statq[i].xfers);
printf(" Blocks written to disk: %lld \n",statp[i].wblks - statq[i].wblks);
printf(" Blocks read from disk: %lld \n",statp[i].rblks - statq[i].rblks);
printf(" Block size: %lld \n",statp[i].dk_bsize);
printf(" Number of transfers from disk : %lld \n",statp[i].dk_rxfers - statq[i].dk_rxfers);
printf(" Read or receive service time : %lld \n",statp[i].dk_rserv - statq[i].dk_rserv);
printf(" Write or send service time : %lld \n",statp[i].dk_wserv - statq[i].dk_wserv);
printf(" ===========================================================\n");
}
memcpy(statq, statp, (tot * sizeof(perfstat_diskadapter_t)));
count--;
}
}
/*
*Name: main
*
*/
int main(int argc, char *argv[])
{
int i, rc;
/* get the interval and count values */
/* Process the arguments */
while ((i = getopt(argc, argv, "i:c:n:")) != EOF)
{
switch(i)
{
case ’i’: /* Interval */
interval = atoi(optarg);
if( interval <= 0 )
interval = INTERVAL_DEFAULT;
break;
case ’c’: /* Number of interations */
count = atoi(optarg);
if( count <= 0 )
count = COUNT_DEFAULT;
break;
case ’n’: /* Node name in a cluster environment */
strncpy(nodename, optarg, MAXHOSTNAMELEN);
nodename[MAXHOSTNAMELEN-1] = ’\0’;
collect_remote_node_stats = 1;
break;
default:
/* Invalid arguments. Print the usage and terminate */
showusage(argv[0]);
}
}
if(collect_remote_node_stats)
{ /* perfstat_config needs to be called to enable cluster statistics collection */
rc = perfstat_config(PERFSTAT_ENABLE|PERFSTAT_CLUSTER_STATS, NULL);
if (rc == -1)
{
perror("cluster statistics collection is not available");
exit(-1);
}
}
do_initialization();
display_metrics();
if(collect_remote_node_stats)
{ /* Now disable cluster statistics by calling perfstat_config */
perfstat_config(PERFSTAT_DISABLE|PERFSTAT_CLUSTER_STATS, NULL);
}
free(statp);
free(statq);
return 0;
}
영어 원문
perfstat_ virtualdiskadapter Interface
The perfstat_virtualdiskadapter interface returns a set of structures of type perfstat_diskadapter_t, which is defined in the libperfstat.h file.
The following program shows an example of how the perfstat_virtualdiskadapter interface is used:
(178줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
(6.1) perfstat_virtual_fcadapter 인터페이스
perfstat_virtual_fcadapter 인터페이스는 libperfstat.h 파일에 정의된 perfstat_fcadapter_t 구조체 묶음을 돌려줍니다.
다음 프로그램은 perfstat_virtual_fcadapter 인터페이스를 쓰는 예입니다.
/* The sample program display the metrics *
* related to each and every Individual *
* virtual FC adapter in the VIOS */
#include<stdio.h>
#include<stdlib.h>
#include<libperfstat.h>
#include<net/if_types.h>
/* define default interval and count values */
#define INTERVAL_DEFAULT 1
#define COUNT_DEFAULT 1
/* Check value returned by malloc for NULL */
#define CHECK_FOR_MALLOC_NULL(X) { if ((X) == NULL) {\
perror ("malloc");\:w!
exit(2);\
}\
}
int count = COUNT_DEFAULT, interval = INTERVAL_DEFAULT, tot;
int returncode;
/* support for remote node statistics collection in a cluster environment */
perfstat_id_node_t nodeid;
static char nodename[MAXHOSTNAMELEN] = "";
static int collect_remote_node_stats = 0;
/* store the data structures */
static perfstat_fcstat_t *statp ,*statq;
/*
* NAME: showusage
* to display the usage
*
*/
void showusage(char *cmd)
{
fprintf (stderr, "usage: %s [-i <interval in seconds>] [-c <number of iterations>]
[-n <node name in the cluster>]/n; ", cmd);
exit(1);
}
/*
* NAME: do_initialization
* This function initializes the data structues.
* It also collects initial set of values.
*
* RETURNS:
* On successful completion:
* - returns 0.
* In case of error
* - exits with code 1.
*/
int do_initialization(void)
{
/* check how many perfstat_vfchost_adapter_t structures are available */
if(collect_remote_node_stats) {
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
nodeid.spec = NODENAME;
tot = perfstat_virtual_fcadapter_node(&nodeid, NULL, sizeof(perfstat_fcstat_t), 0);
} else {
tot = perfstat_virtual_fcadapter(NULL, NULL, sizeof(perfstat_fcstat_t), 0);
}
if (tot == 0)
{
printf("There is no net adapter\n");
exit(0);
}
if (tot < 0)
{
perror("perfstat_vhost_adapter: ");
exit(1);
}
/* allocate enough memory for all the structures */
statp = (perfstat_fcstat_t *)malloc(tot * sizeof(perfstat_fcstat_t));
CHECK_FOR_MALLOC_NULL(statp);
statq = (perfstat_fcstat_t *)malloc(tot * sizeof(perfstat_fcstat_t));
CHECK_FOR_MALLOC_NULL(statq);
return(0);
}
/*
*Name: display_metrics
*collect the metrics and display them *
*/
void display_metrics()
{
perfstat_id_t first;
int ret, i;
if(collect_remote_node_stats) {
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
nodeid.spec = NODENAME;
strcpy(nodeid.name , FIRST_VFCHOST);
ret = perfstat_virtual_fcadapter_node(&nodeid, statq, sizeof(perfstat_fcstat_t), tot);
} else
{
strcpy(first.name , FIRST_VFCHOST);
ret = perfstat_virtual_fcadapter(&first, statq, sizeof(perfstat_fcstat_t), 1);
}
if (ret < 0)
{
free(statp);
free(statq);
perror("perfstat_vhost_adapter: ");
exit(1);
}
while (count)
{
sleep (interval);
if(collect_remote_node_stats)
{
ret = perfstat_virtual_fcadapter_node(&nodeid, statp, sizeof(perfstat_fcstat_t), tot);
} else
{
ret = perfstat_virtual_fcadapter(&first, statp, sizeof(perfstat_fcstat_t), tot);
}
/* print statistics for each of the interfaces */
for (i = 0; i < ret; i++)
{
printf(" Adapter name: %s \n", statp[i].name);
printf(" VFCHOST Adapter name: %s \n", statp[i].vfc_name);
printf(" WWPN : %llu \n", statp[i].PortWWN);
printf(" ====================================================\n");
}
memcpy(statq, statp, (tot * sizeof(perfstat_fcstat_t)));
count--;
}
}
/*
*Name: main
*
*/
int main(int argc, char *argv[])
{
int i, rc;
/* get the interval and count values */
/* Process the arguments */
while ((i = getopt(argc, argv, "i:c:n:")) != EOF)
{
switch(i)
{
case ’i’: /* Interval */
interval = atoi(optarg);
if( interval <= 0 )
interval = INTERVAL_DEFAULT;
break;
case ’c’: /* Number of interations */
count = atoi(optarg);
if( count <= 0 )
count = COUNT_DEFAULT;
break;
case ’n’: /* Node name in a cluster environment */
strncpy(nodename, optarg, MAXHOSTNAMELEN);
nodename[MAXHOSTNAMELEN-1] = ’\0’;
collect_remote_node_stats = 1;
break;
default:
/* Invalid arguments. Print the usage and terminate */
showusage(argv[0]);
}
}
if(collect_remote_node_stats)
{ /* perfstat_config needs to be called to enable cluster statistics collection */
rc = perfstat_config(PERFSTAT_ENABLE|PERFSTAT_CLUSTER_STATS, NULL);
if (rc == -1)
{
perror("cluster statistics collection is not available");
exit(-1);
}
}
do_initialization();
display_metrics();
if(collect_remote_node_stats)
{ /* Now disable cluster statistics by calling perfstat_config */
perfstat_config(PERFSTAT_DISABLE|PERFSTAT_CLUSTER_STATS, NULL);
}
free(statp);
free(statq);
return 0;
}
영어 원문
perfstat_ virtual_fcadapter Interface
The perfstat_virtual_fcadapter interface returns a set of structures of type perfstat_fcadapter_t, which is defined in the libperfstat.h file.
The following program shows an example of how the perfstat_virtual_fcdapter interface is used:
(172줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
(6.1) perfstat_virtualdisktarget 인터페이스
perfstat_virtualdisktarget 인터페이스는 libperfstat.h 파일에 정의된 perfstat_disk_t 구조체 묶음을 돌려줍니다.
다음 프로그램은 perfstat_virtualdisktarget 인터페이스를 쓰는 예입니다.
/* The sample program display the metrics *
* related to each and every Individual *
* Virtual Target Device in the VIOS */
#include<stdio.h>
#include<stdlib.h>
#include<libperfstat.h>
#include<net/if_types.h>
/* define default interval and count values */
#define INTERVAL_DEFAULT 1
#define COUNT_DEFAULT 1
/* Check value returned by malloc for NULL */
CHECK_FOR_MALLOC_NULL(X) { if ((X) == NULL) {\
perror ("malloc");\
exit(2);\
}\
}
int count = COUNT_DEFAULT, interval = INTERVAL_DEFAULT, tot;
int returncode;
/* support for remote node statistics collection in a cluster environment */
perfstat_id_node_t nodeid;
static char nodename[MAXHOSTNAMELEN] = "";
static int collect_remote_node_stats = 0;
/* store the data structures */
static perfstat_disk_t *statp ,*statq;
/*
* NAME: showusage
* to display the usage
*
*/
void showusage(char *cmd)
{
fprintf (stderr, "usage: %s [-i <interval in seconds>] [-c <number of iterations>]
[-n <node name in the cluster>]\n",
cmd);
exit(1);
}
}
/*
* NAME: do_initialization
* This function initializes the data structues.
* It also collects initial set of values.
*
* RETURNS:
* On successful completion:
* - returns 0.
* In case of error
* - exits with code 1.
*/
int do_initialization(void)
{
/* check how many perfstat_vhost_adapter_t structures are available */
if(collect_remote_node_stats)
{
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
nodeid.spec = NODENAME;
tot = perfstat_virtualdisktarget_node(&nodeid, NULL, sizeof(perfstat_disk_t), 0);
} else {
tot = perfstat_virtualdisktarget(NULL, NULL, sizeof(perfstat_disk_t), 0);
}
if (tot == 0) {
printf("There is no VTD’s\n");
exit(0);
}
if (tot < 0) {
perror("perfstat_virtualdisktarget: ");
exit(1);
}
/* allocate enough memory for all the structures */
statp = (perfstat_disk_t *)malloc(tot * sizeof(perfstat_disk_t));
CHECK_FOR_MALLOC_NULL(statp);
statq = (perfstat_disk_t *)malloc(tot * sizeof(perfstat_disk_t));
CHECK_FOR_MALLOC_NULL(statq);
return(0);
}
/*
*Name: display_metrics
*collect the metrics and display them
*
*/
void display_metrics()
{
perfstat_id_t first;
int ret, i;
if(collect_remote_node_stats) {
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
nodeid.spec = NODENAME;
strcpy(nodeid.name , FIRST_VTD);
ret = perfstat_virtualdisktarget_node(&nodeid, statq, sizeof(perfstat_disk_t), tot);
} else {
strcpy(first.name , FIRST_VTD);
ret = perfstat_virtualdisktarget( &first, statq, sizeof(perfstat_disk_t), tot);
}
if (ret < 0)
{
free(statp);
free(statq);
perror("perfstat_virtualdisktarget: ");
exit(1);
}
while (count)
{
sleep (interval);
if(collect_remote_node_stats)
{
ret = perfstat_virtualdisktarget_node(&nodeid, statp, sizeof(perfstat_disk_t), tot);
} else {
ret = perfstat_virtualdisktarget(&first, statp, sizeof(perfstat_disk_t),tot);
}
/* print statistics for each of the interfaces */
for (i = 0; i < ret; i++)
{
printf(" Adapter name: %s \n", statp[i].name);
printf(" Disk block size: %lld \n",statp[i].bsize);
printf(" Number of transfers to/from disk : %lld \n", statp[i].xfers);
printf(" Number of blocks written to disk : %lld \n",statp[i].wblks);
printf(" ====================================================\n");
}
memcpy(statq, statp, (tot * sizeof(perfstat_disk_t)));
count--;
}
}
/*
*Name: main
*
*/
int main(int argc, char *argv[])
{
int i, rc;
/* get the interval and count values */
/* Process the arguments */
while ((i = getopt(argc, argv, "i:c:n:")) != EOF)
{
switch(i)
{
case ’i’:/* Interval */
interval = atoi(optarg);
if( interval <= 0 )
interval = INTERVAL_DEFAULT;
break;
case ’c’:/* Number of interations */
count = atoi(optarg);
if( count <= 0 )
count = COUNT_DEFAULT;
break;
case ’n’: /* Node name in a cluster environment */
strncpy(nodename, optarg, MAXHOSTNAMELEN);
nodename[MAXHOSTNAMELEN-1] = ’\0’;
collect_remote_node_stats = 1;
break;
default:
/* Invalid arguments. Print the usage and terminate */
showusage(argv[0]);
}
}
if(collect_remote_node_stats)
{ /* perfstat_config needs to be called to enable cluster statistics collection */
rc = perfstat_config(PERFSTAT_ENABLE|PERFSTAT_CLUSTER_STATS, NULL);
if (rc == -1)
{
perror("cluster statistics collection is not available");
exit(-1);
}
}
do_initialization();
display_metrics();
if(collect_remote_node_stats)
{ /* Now disable cluster statistics by calling perfstat_config */
perfstat_config(PERFSTAT_DISABLE|PERFSTAT_CLUSTER_STATS, NULL);
}
free(statp);
free(statq);
return 0;
}
영어 원문
perfstat_ virtualdisktarget Interface
The perfstat_virtualdisktarget interface returns a set of structures of type perfstat_disk_t, which is defined in the libperfstat.h file.
The following program shows an example of how the perfstat_virtualdisktarget interface is used:
(173줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
(6.1) perfstat_bridgedadapters 인터페이스
perfstat_bridgedadapters 인터페이스는 libperfstat.h 파일에 정의된 perfstat_netadapter_t 구조체 묶음을 돌려줍니다.
다음 프로그램은 perfstat_bridgedadapters 인터페이스를 쓰는 예입니다.
/* The sample program display the metrics *
* related to each and every Individual *
* physical and virtual/trunk adapters which are under SEA in the VIOS */
#include<stdio.h>
#include<stdlib.h>
#include<libperfstat.h>
#include<net/if_types.h>
/* define default interval and count values */
#define INTERVAL_DEFAULT 1
#define COUNT_DEFAULT 1
/* Check value returned by malloc for NULL */
#define CHECK_FOR_MALLOC_NULL(X) { if ((X) == NULL) {\
perror ("malloc");\
exit(2);\
}\
}
int count = COUNT_DEFAULT, interval = INTERVAL_DEFAULT, tot;
int returncode;
/* support for remote node statistics collection in a cluster environment */
perfstat_id_node_t nodeid;
static char nodename[MAXHOSTNAMELEN] = "";
static int collect_remote_node_stats = 0;
/* store the data structures */
static perfstat_netadapter_t *statp ,*statq;
/*
* NAME: showusage
* to display the usage
*
*/
void showusage(char *cmd)
{
fprintf (stderr, "usage: %s [-i <interval in seconds>] [-c <number of iterations>]
[-n <node name in the cluster>]/n; ", cmd);
exit(1);
}
/*
/*
* NAME: do_initialization
* This function initializes the data structues.
* It also collects initial set of values.
*
* RETURNS:
* On successful completion:
* - returns 0.
* In case of error
* - exits with code 1.
*/
int do_initialization(void)
{
perfstat_id_t first;
/* check how many perfstat_netadapter_t structures are available */
if(collect_remote_node_stats) {
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
/* SEA Adapter Name must be filled */
strcpy(nodeid.name , FIRST_SEA);
/*nodeid.spec = NODENAME; */
tot = perfstat_bridgedadapters_node(&nodeid, NULL, sizeof(perfstat_netadapter_t), 0);
} else
{
/* SEA Adapter Name must be filled */
strcpy(first.name , FIRST_SEA);
tot = perfstat_bridgedadapters(&first, NULL, sizeof(perfstat_netadapter_t), 0);
}
if (tot == 0)
{
printf("There is no SEA Chilren’s\n");
exit(0);
}
if (tot < 0)
{
perror("perfstat_bridgedadapters: ");
exit(1);
}
/* allocate enough memory for all the structures */
statp = (perfstat_netadapter_t *)malloc(tot * sizeof(perfstat_netadapter_t));
CHECK_FOR_MALLOC_NULL(statp);
statq = (perfstat_netadapter_t *)malloc(tot * sizeof(perfstat_netadapter_t));
CHECK_FOR_MALLOC_NULL(statq);
return(0);
}
/*
*Name: display_metrics
* collect the metrics and display them
*
*/
void display_metrics()
{
perfstat_id_t first;
int ret, i;
if(collect_remote_node_stats) {
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
nodeid.spec = NODENAME;
/* Valid SEA Adapter Name Must be passed */
strcpy(nodeid.name , FIRST_SEA);
ret = perfstat_bridgedadapters_node(&nodeid, statq, sizeof(perfstat_netadapter_t), tot);
} else
{
/* Valid SEA Adapter Name Must be passed */
strcpy(first.name , FIRST_SEA);
ret = perfstat_bridgedadapters( &first, statq, sizeof(perfstat_netadapter_t), tot);
}
if (ret < 0)
{
free(statp);
free(statq);
perror("perfstat_netadapter: ");
exit(1);
}
while (count)
{
sleep (interval);
if(collect_remote_node_stats)
{
ret = perfstat_bridgedadapters_node(&nodeid, statp, sizeof(perfstat_netadapter_t), tot);
} else
{
ret = perfstat_bridgedadapters( &first, statp, sizeof(perfstat_netadapter_t), tot);
}
/* print statistics for each of the interfaces */
for (i = 0; i < ret; i++)
{
printf(" Adapter name: %s \n", statp[i].name);
printf(" ======================== Transmit Statistics ====================\n");
printf(" Transmit Packets: %lld \n", statp[i].tx_packets - statq[i].tx_packets);
printf(" Transmit Bytes: %lld \n", statp[i].tx_bytes - statq[i].tx_bytes);
printf(" Transfer Interrupts : %lld \n",
statp[i].tx_interrupts - statq[i].tx_interrupts);
printf(" Transmit Errors : %lld \n", statp[i].tx_errors - statq[i].tx_errors);
printf(" Packets Dropped at the time of Data Transmission : %lld \n",
statp[i].tx_packets_dropped - statq[i].tx_packets_dropped);
printf(" Transmit Queue Size: %lld \n",
statp[i].tx_queue_size - statq[i].tx_queue_size);
printf(" Transmit Queue Length :%lld \n",
statp[i].tx_queue_len - statq[i].tx_queue_len);
printf(" Transmit Queue Overflow : %lld \n",
statp[i].tx_queue_overflow - statq[i].tx_queue_overflow);
printf(" Broadcast Packets Transmitted: %lld \n",
statp[i].tx_broadcast_packets - statq[i].tx_broadcast_packets);
printf(" Multicast packets Transmitted: %lld \n",
statp[i].tx_multicast_packets - statq[i].tx_multicast_packets);
printf(" Lost Carrier Sense signal count : %lld \n",
statp[i].tx_carrier_sense - statq[i].tx_carrier_sense);
printf(" Count of DMA Under-runs for Transmission: %lld \n",
statp[i].tx_DMA_underrun - statq[i].tx_DMA_underrun);
printf(" Number of unsuccessful transmissions : %lld \n",
statp[i].tx_lost_CTS_errors - statq[i].tx_lost_CTS_errors);
printf(" Maximum Collision Errors at Transmission: %lld \n",
statp[i].tx_max_collision_errors - statq[i].tx_max_collision_errors);
printf(" Late Collision Errors at Transmission : %lld \n",
statp[i].tx_late_collision_errors - statq[i].tx_late_collision_errors);
printf(" Number of packets deferred for Transmission : %lld \n",
statp[i].tx_deferred - statq[i].tx_deferred);
printf(" Time Out Errors for Transmission : %lld \n",
statp[i].tx_timeout_errors - statq[i].tx_timeout_errors);
printf(" Count of Single Collision error at Transmission: %lld \n",
statp[i].tx_single_collision_count - statq[i].tx_single_collision_count);
printf(" Count of Multiple Collision error at Transmission : %lld \n",
statp[i].tx_multiple_collision_count - statq[i].tx_multiple_collision_count);
printf(" ========================== Receive Statistics =================\n");
printf(" Receive Packets :%lld \n",statp[i].rx_packets - statq[i].rx_packets);
printf(" Receive Bytes :%lld \n", statp[i].rx_bytes - statq[i].rx_bytes);
printf(" Receive Interrupts : %lld \n",
statp[i].rx_interrupts - statq[i].rx_interrupts);
printf(" Input errors on interface :%lld \n",
statp[i].rx_errors - statq[i].rx_errors);
printf(" Nunber of Packets Dropped : %lld \n",
statp[i].rx_packets_dropped - statq[i].rx_packets_dropped);
printf(" Count of Bad Packets Received : %lld \n",
statp[i].rx_bad_packets - statq[i].rx_bad_packets);
printf(" Number of MultiCast Packets Received : %lld \n",
statp[i].rx_multicast_packets - statq[i].rx_multicast_packets);
printf(" Number of Broadcast Packets Received : %lld \n",
statp[i].rx_broadcast_packets - statq[i].rx_broadcast_packets);
printf(" Count of Packets Received with CRC errors: %lld \n",
statp[i].rx_CRC_errors - statq[i].rx_CRC_errors);
printf(" DMA over-runs : %lld \n",
statp[i].rx_DMA_overrun - statq[i].rx_DMA_overrun);
printf(" Alignment Errors : %lld \n",
statp[i].rx_alignment_errors - statq[i].rx_alignment_errors);
printf(" No Resource Errors : %lld \n",
statp[i].rx_noresource_errors - statq[i].rx_noresource_errors);
printf(" Collision Errors: %lld \n",
statp[i].rx_collision_errors - statq[i].rx_collision_errors);
printf(" Number of Short Packets Received: %lld \n",
statp[i].rx_packet_tooshort_errors - statq[i].rx_packet_tooshort_errors);
printf(" Number of Too Long Packets Received : %lld \n",
statp[i].rx_packet_toolong_errors - statq[i].rx_packet_toolong_errors);
printf(" Number of Received Packets discarded by Adapter: %lld \n",
statp[i].rx_packets_discardedbyadapter -statq[i].rx_packets_discardedbyadapter);
printf(" Adapter Type :%d \n",statp[i].adapter_type);
printf(" ==================================================================\n");
}
memcpy(statq, statp, (tot * sizeof(perfstat_netadapter_t)));
count--;
}
}
/*
*Name: main
*
*/
int main(int argc, char *argv[])
{
int i, rc;
/* get the interval and count values */
/* Process the arguments */
while ((i = getopt(argc, argv, "i:c:n:")) != EOF)
{
switch(i)
{
case ’i’: /* Interval */
interval = atoi(optarg);
if( interval <= 0 )
interval = INTERVAL_DEFAULT;
break;
case ’c’: /* Number of interations */
count = atoi(optarg);
if( count <= 0 )
count = COUNT_DEFAULT;
break;
case ’n’: /* Node name in a cluster environment */
strncpy(nodename, optarg, MAXHOSTNAMELEN);
nodename[MAXHOSTNAMELEN-1] = ’\0’;
collect_remote_node_stats = 1;
break;
default:
/* Invalid arguments. Print the usage and terminate */
showusage(argv[0]);
}
}
if(collect_remote_node_stats)
{ /* perfstat_config needs to be called to enable cluster statistics collection */
rc = perfstat_config(PERFSTAT_ENABLE|PERFSTAT_CLUSTER_STATS, NULL);
if (rc == -1)
{
perror("cluster statistics collection is not available");
exit(-1);
}
}
do_initialization();
display_metrics();
if(collect_remote_node_stats)
{ /* Now disable cluster statistics by calling perfstat_config */
perfstat_config(PERFSTAT_DISABLE|PERFSTAT_CLUSTER_STATS, NULL);
}
free(statp);
free(statq);
return 0;
}
영어 원문
perfstat_bridgedadapters Interface
The perfstat_bridgedadapters interface returns a set of structures of type perfstat_netadapter_t, which is defined in the libperfstat.h file.
The following program shows an example of how the perfstat_bridgedadapters interface is used:
(248줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
(6.1) perfstat_ssp 인터페이스
perfstat_ssp 인터페이스는 libperfstat.h 파일에 정의된 perfstat_ssp_t 구조체 묶음을 돌려줍니다.
다음 프로그램은 perfstat_ssp 인터페이스를 쓰는 예입니다.
/* The sample program used to Display *
* the shared storage pool information */
#include<stdio.h>
#include<libperfstat.h>
#include<errno.h>
/* define default interval and count values */
#define INTERVAL_DEFAULT 1
#define COUNT_DEFAULT 1
#define CHECK_FOR_MALLOC_NULL(X) { if ((X) == NULL) {\
perror ("malloc");\
exit(2);\
}\
}
/* store the data structures */
perfstat_ssp_t *sspstats = NULL;
int rc, returned_count, flag = 0;
/*
* NAME: showusage
* to display the usage
*
*/
void showusage()
{
printf("Usage:simplesspstat -s | -d | -l [-i interval] [-c count]\n");
exit(1);
}
/*
* NAME: do_initialization
* This function initializes the data structues.
* It also collects initial set of values.
*
* RETURNS:
* On successful completion:
* - returns 0.
* In case of error
* - exits with code 1.
*/
int do_initialization()
{
returned_count = perfstat_ssp(NULL, NULL, sizeof(perfstat_ssp_t),0,flag);
if(returned_count < 0){
perror("perfstat_ssp_t:");
exit(-1);
}
/* Allocate memory for the structure*/
if(returned_count==0)
sspstats=( perfstat_ssp_t *) malloc(sizeof(perfstat_ssp_t));
else
sspstats=( perfstat_ssp_t *) malloc(sizeof(perfstat_ssp_t) * returned_count);
CHECK_FOR_MALLOC_NULL(sspstats);
return(0);
}
static void do_cleanup()
{
free(sspstats);
}
/*
*Name: display_metrics
* collect the metrics and display them
*
*/
void display_metrics()
{
int i,rc;
while (count)
{
/* Obtain cluster name, ssp name and vtd list*/
rc=perfstat_ssp(NULL, sspstats, sizeof(perfstat_ssp_t),1,flag);
if(rc<0)
{
perror("perfstat_ssp_t:");
exit(-1);
}
sleep (interval);
fprintf(stdout, "\nCluster Name : %s\n", sspstats->cluster_name);
fprintf(stdout, "Storage Pool Name : %s\n", sspstats->spool_name);
if(flag == 1){
fprintf(stdout, "Total Space : %lld\n", sspstats->u.global.total_space);
fprintf(stdout, "Total Used Space : %lld\n", sspstats->u.global.total_used_space);
}
if(flag == 2){
if(rc!=0)
fprintf(stdout, "Disk name :\n");
else
fprintf(stdout, "There are no disks in the storage pool\n");
for(i=0; i<returned_count; i++){
fprintf(stdout, "%s ",sspstats[i].u.disk.diskname);
}
}
if(flag == 3){
if(rc!=0)
fprintf(stdout, "VTD name :\n");
else{
fprintf(stdout, "There are no VTD’s in the storage pool\n");
exit(-1);
}
for(i=0; i<returned_count; i++){
fprintf(stdout, "%s ",sspstats[i].u.vtd.vtd_name);
fprintf(stdout, "%s ",sspstats[i].u.vtd.lu_name);
}
fprintf(stdout,"\n\nLU type:\n");
for(i=0; i<returned_count; i++){
fprintf(stdout, "%s ",sspstats[i].u.vtd.lu_type);
}
fprintf(stdout,"\n\nLU size:\n");
for(i=0; i<returned_count; i++){
fprintf(stdout, "%lld ",sspstats[i].u.vtd.lu_size);
}
fprintf(stdout,"\n\nLU free:\n");
for(i=0; i<returned_count; i++){
fprintf(stdout, "%lld ",sspstats[i].u.vtd.lu_free);
}
fprintf(stdout,"\n\n");
}
count--;
}
}
int main(int argc, char* argv[])
{
int c,sflag=0,dflag=0,lflag=0;
/* Enable the cluster statistics using perfstat_config */
rc = perfstat_config(PERFSTAT_ENABLE|PERFSTAT_CLUSTER_STATS, NULL);
if (rc == -1)
{
perror("cluster statistics collection is not available");
exit(-1);
}
while((c = getopt(argc, argv, "i:c:sdl"))!= EOF){
switch(c){
case ’i’:
interval = atoi(optarg);
if( interval <= 0 )
interval = INTERVAL_DEFAULT;
break;
case ’c’:
count = atoi(optarg);
if( count <= 0 )
count = COUNT_DEFAULT;
break;
case ’s’:
flag = 1;
sflag = 1;
break;
case ’d’:
flag = 2;
dflag = 1;
break;
case ’l’:
flag = 3;
lflag = 1;
break;
default:
showusage(argv[0]);
}
}
if(flag == 0){
showusage(argv[0]);
}
if(sflag && (dflag || lflag)){
showusage(argv[0]);
}
if(dflag && (sflag || lflag)){
showusage(argv[0]);
}
if(lflag && (sflag || dflag)){
showusage(argv[0]);
}
do_initialization();
display_metrics();
/* Now disable cluster statistics by calling perfstat_config */
perfstat_config(PERFSTAT_DISABLE|PERFSTAT_CLUSTER_STATS, NULL);
do_cleanup();
/*realloc(sspstats);*/
return 0;
}
영어 원문
perfstat_ ssp Interface
The perfstat_ssp interface returns a set of structures of type perfstat_ssp_t, which is defined in the libperfstat.h file.
The following program shows an example of how the perfstat_ssp interface is used:
(175줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
(6.1) perfstat_ssp_ext 인터페이스
perfstat_ssp_ext 서브루틴은 libperfstat.h 파일에 정의된 perfstat_ssp_t 구조체 묶음을 돌려줍니다.
다음 예제 프로그램은 perfstat_ssp_ext 서브루틴의 사용법을 보여 줍니다.
#include <stdio.h>
#include <libperfstat.h>
#include <errno.h>
/* define default interval and count values */
#define INTERVAL_DEFAULT 1
#define COUNT_DEFAULT 1
/* Check value returned by malloc for NULL */
#define CHECK_FOR_MALLOC_NULL(X) { if ((X) == NULL) {\
perror ("malloc");\
exit(2);\
}\
}
int count = COUNT_DEFAULT, interval = INTERVAL_DEFAULT;
/* store the data structures */
perfstat_ssp_t *sspstats = NULL;
int rc, returned_count, flag = 0;
char tiername[VIOS_STR_128];
char fgname[VIOS_STR_128];
char diskname[VIOS_STR_128];
perfstat_ssp_id_t sspid = {0};
int tflag = 0, dflag = 0,fflag = 0;
/*
* NAME: showusage
* to display the usage
*
*/
void showusage()
{
printf("Usage:simplesspstat -T | -F | -D | -N [-i interval] [-c count][-t <tiername> ]
[-f <failuregroupname>] [-d <diskname>] [-n <nodename>]\n");
exit(1);
}
/*
* NAME: do_initialization
* This function initializes the data structues.
* It also collects initial set of values.
*
* RETURNS:
* On successful completion:
* - returns 0.
* In case of error
* - exits with code 1.
*/
int do_initialization()
{
if(fflag || dflag || tflag)
sspid.spec |= PERFFILT_NAME;
else
sspid.spec = PERFFILT_NONE;
if(fflag)
{
sspid.spec |= PERFFILT_FG;
strncpy(sspid.fg.name,fgname,VIOS_STR_128);
}
if(dflag)
{
sspid.spec |= PERFFILT_PHYSV;
strncpy(sspid.pv.name,diskname,VIOS_STR_128);
}
if(tflag)
{
sspid.spec |= PERFFILT_TIER;
strncpy(sspid.tier.name,tiername,VIOS_STR_128);
}
if(nflag)
{
sspid.spec |= PERFFILT_NODE;
strncpy(sspid.node.name,nodename,VIOS_STR_128);
}
returned_count = perfstat_ssp_ext(&sspid, NULL, sizeof(perfstat_ssp_t),0,flag);
if(returned_count <= 0){
printf("perfstat_ssp_exit failed with error:%d",errno);
exit(-1);
}
/* Allocate memory for the structure*/
sspstats=( perfstat_ssp_t *) malloc(sizeof(perfstat_ssp_t) * returned_count);
CHECK_FOR_MALLOC_NULL(sspstats);
return(0);
}
static void do_cleanup()
{
free(sspstats);
}
/*
*Name: display_metrics
* collect the metrics and display them
*
*/
void display_metrics()
{
int i,rc;
while (count)
{
/* Obtain SSP COnfig stats for tier/failure group or PV stats based on the flag*/
rc=perfstat_ssp_ext(&sspid, sspstats, sizeof(perfstat_ssp_t),returned_count,flag);
if(rc<0)
{ /*Tier/FG/PV*/
perror("perfstat_ssp_t:");
exit(-1);
}
sleep (interval);
fprintf(stdout, "\nCluster Name : %s\n", sspstats->cluster_name);
fprintf(stdout, "Storage Pool Name : %s\n", sspstats->spool_name);
if(flag == SSPPV){
if(rc!=0)
fprintf(stdout, "Disk name \t Tier Name\t Failure Group:\n");
else
fprintf(stdout, "There are no disks in the storage pool\n");
for(i=0; i<returned_count; i++){
fprintf(stdout, "%8s\t%8s\t%13s\n ",
sspstats[i].u.disk.diskname,sspstats[i].u.disk.tiername,sspstats[i].u.disk.fgname);
}
}
if(flag == SSPTIER)
{
if(rc!=0)
fprintf(stdout, "Tier name \t Tier ID\n");
else
fprintf(stdout, "There are no tiers in the storage pool\n");
for(i=0; i<returned_count; i++){
fprintf(stdout, "%8s\t%6llu\n ",
sspstats[i].u.tier.tiername,sspstats[i].u.tier.tierid);
}
}
if(flag == SSPFG)
{
if(rc!=0)
fprintf(stdout, "FailureGroupName FailureGroupID TierName Tier ID\n");
else
fprintf(stdout, "There are no failuregroups in the storage pool\n");
for(i=0; i<returned_count; i++){
fprintf(stdout, "%16s\t%15llu\t%8s\t%6llu\n ",
sspstats[i].u.fg.fgname,sspstats[i].u.fg.fgid,
sspstats[i].u.fg.tiername,sspstats[i].u.fg.tierid);
}
}
if(flag == SSPNODE)
{
for ( i =0; i <returned_count ; i++)
{
fprintf(stdout,"Nodename:%s,mtms:%s,status:%d,
poolstatus:%d,ip:%s,lparid:%d\n",
sspstats[i].u.node.hostname,sspstats[i].u.node.mtms,
sspstats[i].u.node.status,sspstats[i].u.node.poolstatus,
sspstats[i].u.node.ip,sspstats[i].u.node.lparid);
}
}
fprintf(stdout,"\n\n");
count--;
}
}
int main(int argc, char* argv[])
{
int c,Tflag=0,Dflag=0,Fflag=0;
/* Enable the cluster statistics using perfstat_config */
rc = perfstat_config(PERFSTAT_ENABLE|PERFSTAT_CLUSTER_STATS, NULL);
if (rc == -1)
{
perror("cluster statistics collection is not available");
exit(-1);
}
while((c = getopt(argc, argv, "i:c:TFDt:f:d:"))!= EOF){
switch(c){
case ’i’:
interval = atoi(optarg);
if( interval <= 0 )
interval = INTERVAL_DEFAULT;
break;
case ’c’:
count = atoi(optarg);
if( count <= 0 )
count = COUNT_DEFAULT;
break;
case ’T’:
flag = SSPTIER;
Tflag = 1;
break;
case ’F’:
flag = SSPFG;
Fflag = 1;
break;
case ’D’:
flag = SSPPV;
Dflag = 1;
break;
case ’N’:
flag = SSPNODE;
Nflag = 1;
break;
case ’t’:
tflag = 1;
strncpy(tiername,optarg,VIOS_STR_128);
break;
case ’f’:
fflag = 1;
strncpy(fgname,optarg,VIOS_STR_128);
break;
case ’d’:
dflag = 1;
strncpy(diskname,optarg,VIOS_STR_128);
break;
case ’n’:
nflag = 1;
strncpy(nodename,optarg,MAXHOSTNAMELEN);
break;
default:
showusage(argv[0]);
}
}
if(flag == 0){
showusage(argv[0]);
}
if(Tflag )
{
if (Fflag || Dflag || fflag || dflag || Nflag || nflag){
showusage(argv[0]);
}
}
if(Fflag)
{
if (Fflag || Dflag || fflag || dflag || Nflag || nflag){
showusage(argv[0]);
}
}
if(Dflag)
{
if (Fflag || Dflag || fflag || dflag || Nflag || nflag)
showusage(argv[0]);
}
if(Nflag)
{
if(Tflag || Fflag || Dflag || fflag || dflag || tflag )
showusage(argv[0]);
}
do_initialization();
display_metrics();
/* Now disable cluster statistics by calling perfstat_config */
perfstat_config(PERFSTAT_DISABLE|PERFSTAT_CLUSTER_STATS, NULL);
do_cleanup();
/*realloc(sspstats);*/
return 0;
}
영어 원문
perfstat_ ssp_ext Interface
The perfstat_ssp_ext subroutine returns a set of structures of type perfstat_ssp_t, which are defined in the libperfstat.h file.
The following example program shows the usage of the perstat_ssp_ext subroutine:
(242줄짜리 예는 위 한글 본문에 그대로 실었습니다.)