[AIX 성능 도구 9] perfstat API (4) 메모리 페이지·네트워크·페이징 공간·프로세스

핵심 정리

  • perfstat_memory_page: 페이지 크기(4KB, 64KB, 16MB 등)마다 실메모리·빈 메모리·고정 메모리와 페이지 인·아웃 수.
  • perfstat_netinterface, perfstat_netbuffer, (6.1) perfstat_netadapter: 인터페이스별 패킷·오류, 크기별 네트워크 버퍼 할당, entstat과 같은 이더넷 어댑터 통계.
  • perfstat_pagingspace: 페이징 공간마다 크기(MB, LP)와 쓴 양. perfstat_protocol: ip, tcp, udp, icmp, rpc, nfs 등 프로토콜별 지표.
  • (6.1) perfstat_process·perfstat_process_util: 프로세스마다 메모리(실·가상·고정·페이징), CPU 시간, 디스크 I/O. topas·ps에 해당하는 정보를 프로그램에서 얻습니다.
  • (6.1) perfstat_processor_pool_util: 공유 프로세서 풀의 용량, 유휴·바쁜 코어 수.
항목 내용
버전 AIX 5.3, AIX 6.1 (6.1에서 perfstat_netadapter, perfstat_process, perfstat_process_util, perfstat_processor_pool_util이 더해짐)
원문 Performance Tools Guide and Reference — 5.3판 6장(159170쪽), 6.1판 139158쪽
파일 /usr/include/libperfstat.h, /usr/samples/libperfstat
관련 명령어 vmstat, netstat, entstat, lsps, ps, lparstat

perfstat_memory_page 인터페이스

perfstat_memory_page 인터페이스는 libperfstat.h 파일에 정의된 perfstat_memory_page_t 구조체 묶음을 돌려줍니다.

perfstat_memory_page_t 구조체의 주요 필드는 다음과 같습니다.

필드 설명
psize 페이지 크기(바이트)
real_total 실메모리 양(psize 단위)
real_free 사용 가능한 실메모리 양(psize 단위)
real_pinned 고정 메모리 양(psize에 4를 곱한 단위)
pgins 페이지 인된 페이지 수
pgouts 페이지 아웃된 페이지 수

이 밖에도 메모리 페이지 관련 지표를 돌려줍니다. 전체 목록은 libperfstat.h 헤더 파일의 perfstat_memory_page_t 부분을 봅니다.

다음 프로그램은 perfstat_memory_page 인터페이스를 쓰는 예입니다.

text
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main (){
 int total_psizes, avail_psizes;
 perfstat_memory_page_t *psize_mem_values;
 perfstat_psize_t pagesize;
 int i;
 /*get the total number of page sizez */
 total_psizes = perfstat_memory_page(NULL, NULL, sizeof(perfstat_memory_page_t), 0);
 /*check for any error*/
    if(total_psizes < 1)
    {
        perror("do_initialization:"
               " Unable to retrieve the number of available pagesizes.");
        exit(-1);
    }
 /* allocate sufficient memory to store the structures */
 psize_mem_values = (perfstat_memory_page_t *)malloc(sizeof(perfstat_memory_page_t) * total_psizes);
 /*check for bad malloc */
    if(psize_mem_values == NULL)
    {
        perror("do_initialization: Unable to allocate sufficient"
               " memory for psize_mem_values buffer.");
        exit(-1);
    }
 pagesize.psize = FIRST_PSIZE;
   avail_psizes = perfstat_memory_page(&pagesize, psize_mem_values, sizeof(perfstat_memory_page_t),
  total_psizes);
  /*check the return value for any error */
    if(avail_psizes < 1)
    {
        perror("display_psize_memory_stats: Unable to retrieve memory "
               "statistics for the available page sizes.");
        exit(-1);
   }
   for(i=0;i<avail_psizes;i++){
        printf("Page size in bytes=%llu\n",psize_mem_values[i].psize);
        printf("Number of real memory frames of this page size=%lld\n",psize_mem_values[i].real_total);
        printf("Number of pages on free list=%lld\n",psize_mem_values[i].real_free);
        printf("Number of pages pinned=%lld\n",psize_mem_values[i].real_pinned);
        printf("Number of pages in use=%lld\n",psize_mem_values[i].real_inuse);
        printf("Number of page faults =%lld\n",psize_mem_values[i].pgexct);
        printf("Number of pages paged in=%lld\n",psize_mem_values[i].pgins);
        printf("Number of pages paged out=%lld\n",psize_mem_values[i].pgouts);
        printf("\n");
   }
 return 0;
}

이 프로그램은 다음과 비슷한 출력을 냅니다.

text
Page size in bytes=4096
Number of real memory frames of this page size=572640
Number of pages on free list=364101
Number of pages pinned=171770
Number of pages in use=208539
Number of page faults =1901334
Number of pages paged in=40569
Number of pages paged out=10381
Page size in bytes=65536
Number of real memory frames of this page size=29746
Number of pages on free list=24741
Number of pages pinned=4333
Number of pages in use=5005
Number of page faults =28495
Number of pages paged in=0
Number of pages paged out=0
영어 원문

perfstat_memory_page Interface

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

Selected fields from the perfstat_memory_page_t structure include:

  • psize — Page size in bytes
  • real_total — Amount of real memory (in units of psize)
  • real_freesize — Amount of free real memory (in units of psize)
  • real_pinned — Amount of pinned memory (in units of psize multiplied by 4)
  • Pgins — Number of pages paged in
  • Pgouts — Number of pages paged out

Several other disk-adapter related metrics (such as the number of blocks read from and written to the adapter) are also returned. For a complete list of other disk-adapter-related metrics, see the perfstat_memory_page_t section in the libperfstat.h header file.

The following program shows an example of how the perfstat_memory_page interface is used:

(49줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The program displays an output that is similar to the following example output:

(16줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

perfstat_netinterface 인터페이스

perfstat_netinterface 인터페이스는 libperfstat.h 파일에 정의된 perfstat_netinterface_t 구조체 묶음을 돌려줍니다.

perfstat_netinterface_t 구조체의 주요 필드는 다음과 같습니다.

필드 설명
name 인터페이스 이름(ODM에서)
description 인터페이스 설명(ODM에서)
ipackets 이 네트워크 인터페이스에서 받은 입력 패킷의 전체 수
opackets 이 네트워크 인터페이스로 보낸 출력 패킷의 전체 수
ierrors 이 네트워크 인터페이스의 입력 오류 전체 수
oerrors 이 네트워크 인터페이스의 출력 오류 전체 수

이 밖에도 네트워크 인터페이스 관련 지표(보내고 받은 바이트 수, 유형, 비트 전송률 등)를 돌려줍니다. 전체 목록은 Files Reference의 libperfstat.h 헤더 파일에서 perfstat_netinterface_t 부분을 봅니다.

다음 코드는 perfstat_netinterface를 쓰는 예입니다.

text
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
#include <net/if_types.h>
char *
decode(uchar type) {
    switch(type) {
    case IFT_LOOP:
        return("loopback");
    case IFT_ISO88025:
        return("token-ring");
    case IFT_ETHER:
        return("ethernet");
    }
    return("other");
}
int main(int argc, char* argv[]) {
   int i, ret, tot;
   perfstat_netinterface_t *statp;
   perfstat_id_t first;
   /* check how many perfstat_netinterface_t structures are available */
   tot = perfstat_netinterface(NULL, NULL, sizeof(perfstat_netinterface_t), 0);
   /* check for error */
   if (tot < 0)
   {
   /* check for error */
   if (tot == 0)
   {
 printf("No network interfaces found\n");
 exit(-1);
   }
 perror("perfstat_netinterface");
 exit(-1);
   }
   /* allocate enough memory for all the structures */
   statp = calloc(tot, sizeof(perfstat_netinterface_t));
   /* set name to first interface */
   strcpy(first.name, FIRST_NETINTERFACE);
   /* ask to get all the structures available in one call */
   /* return code is number of structures returned */
   ret = perfstat_netinterface(&first, statp, sizeof(perfstat_netinterface_t), tot);
   /* check for error */
   if (ret <= 0)
   {
 perror("perfstat_netinterface");
 exit(-1);
   }
   /* print statistics for each of the interfaces */
   for (i = 0; i < ret; i++) {
       printf("\nStatistics for interface : %s\n", statp[i].name);
       printf("------------------------\n");
       printf("type : %s\n", decode(statp[i].type));
       printf("\ninput statistics:\n");
       printf("number of packets : %llu\n", statp[i].ipackets);
       printf("number of errors  : %llu\n", statp[i].ierrors);
       printf("number of bytes   : %llu\n", statp[i].ibytes);
       printf("\noutput statistics:\n");
       printf("number of packets : %llu\n", statp[i].opackets);
       printf("number of bytes   : %llu\n", statp[i].obytes);
       printf("number of errors  : %llu\n", statp[i].oerrors);
       }
}

이 프로그램은 다음과 같은 출력을 냅니다.

text
Statistics for interface : tr0
------------------------
type : token-ring
input statistics:
number of packets : 306352
number of errors  : 0
number of bytes   : 24831776
output statistics:
number of packets : 62669
number of bytes   : 11497679
number of errors  : 0
Statistics for interface : lo0
------------------------
type : loopback
input statistics:
number of packets : 336
number of errors  : 0
number of bytes   : 20912
output statistics:
number of packets : 336
number of bytes   : 20912
number of errors  : 0

위 프로그램은 netstat처럼 인터페이스 통계를 보여 주며 perfstat_netinterface를 쓰는 방법을 보여 줍니다.

영어 원문

perfstat_netinterface Interface

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

Selected fields from the perfstat_netinterface_t structure include:

name Interface name (from ODM) description Interface description (from ODM) ipackets Total number of input packets received on this network interface opackets Total number of output packets sent on this network interface ierror Total number of input errors on this network interface oerror Total number of output errors on this network interface

Several other network-interface related metrics (such as number of bytes sent and received, type, and bitrate) are also returned. For a complete list of other network-interfaced related metrics, see the perfstat_netinterface_t section in the libperfstat.h header file in Files Reference.

The following code shows an example of how perfstat_netinterface is used:

(62줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The preceding program produces the following output:

(22줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The preceding program emulates diskadapterstat behavior and also shows how perfstat_netinterface is used.

perfstat_netbuffer 인터페이스

perfstat_netbuffer 인터페이스는 libperfstat.h 파일에 정의된 perfstat_netbuffer_t 구조체 묶음을 돌려줍니다.

perfstat_netbuffer_t 구조체의 주요 필드는 다음과 같습니다.

필드 설명
size 할당 크기(바이트 수를 나타내는 문자열)
inuse 이 크기의 현재 할당
failed 이 크기의 할당 실패
free 이 크기의 빈 목록

이 밖에도 할당 관련 지표(최고 수위(high-water mark), 해제 수 등)를 돌려줍니다. 전체 목록은 libperfstat.h 헤더 파일의 perfstat_netbuffer_t 부분을 봅니다.

다음 코드는 perfstat_netbuffer 인터페이스를 쓰는 예입니다.

text
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(int argc, char* argv[]) {
   int i, ret, tot;
   perfstat_netbuffer_t *statp;
   perfstat_id_t first;
   /* check how many perfstat_netbuffer_t structures are available */
   tot = perfstat_netbuffer(NULL, NULL, sizeof(perfstat_netbuffer_t), 0);
   /* check for error */
   if (tot <= 0)
   {
 perror("perfstat_netbuffer");
 exit(-1);
   }
   /* allocate enough memory for all the structures */
   statp = calloc(tot, sizeof(perfstat_netbuffer_t));
   if(statp==NULL){
 printf("No sufficient memory\n");
 exit(-1);
   }
   /* set name to first interface */
   strcpy(first.name, FIRST_NETBUFFER);
   /* ask to get all the structures available in one call */
   /* return code is number of structures returned */
   ret = perfstat_netbuffer(&first, statp,
                          sizeof(perfstat_netbuffer_t), tot);
   /* check for error */
   if (ret <= 0)
   {
 perror("perfstat_netbuffer");
 exit(-1);
   }
   /* print info in netstat -m format */
   printf("%-12s %10s %9s %6s %9s %7s %7s %7s\n",
          "By size", "inuse", "calls", "failed",
          "delayed", "free", "hiwat", "freed");
   for (i = 0; i < ret; i++) {
       printf("%-12s %10llu %9llu %6llu %9llu %7llu %7llu %7llu\n",
           statp[i].name,
           statp[i].inuse,
           statp[i].calls,
           statp[i].delayed,
           statp[i].free,
           statp[i].failed,
           statp[i].highwatermark,
           statp[i].freed);
       }
}

이 프로그램은 다음과 비슷한 출력을 냅니다.

text
By size           inuse     calls failed   delayed    free   hiwat   freed
64                  598     12310     14       682       0   10480       0
128                 577      8457     16       287       0    7860       0
256                1476    287157     88       716       0   15720       0
512                2016   1993915    242       808       0   32750       0
1024                218      8417     81       158       0    7860       0
2048                563      2077    277       307       0   19650       0
4096                 39       127     15       143       0    1310       0
8192                  4        16      4         0       0     327       0
16384               128       257     19         4       0     163       0
32768                25        55      9         4       0      81       0
65536                59       121     35         5       0      81       0
131072                3         7      0       217       0     204       0
영어 원문

perfstat_netbuffer Interface

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

Selected fields from the perfstat_netbuffer_t structure include:

  • size — Size of the allocation (string expressing size in bytes)
  • inuse — Current allocation of this size
  • failed — Failed allocation of this size
  • free — Free list for this size

Several other allocation-related metrics (such as high-water mark and freed) are also returned. For a complete list of other allocation-related metrics, see the perfstat_netbuffer_t section in the libperfstat.h header file.

The following code shows an example of how the perfstat_netbuffer interface is used: The preceding program produces the following output:

(49줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The program displays an output that is similar to the following example output:

(13줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

(6.1) perfstat_netadapter 인터페이스

perfstat_netadapter 인터페이스는 libperfstat.h 파일에 정의된 perfstat_netadapter_t 구조체 묶음을 돌려줍니다.

참고: perfstat_netadapter 인터페이스는 entstat 명령과 비슷하게 이더넷 네트워크 어댑터 통계만 돌려줍니다.

다음 프로그램은 perfstat_netadapter 인터페이스를 쓰는 예입니다.

text
/* The sample program displays the metrics *
 * related to every Individual  *
 * network adapter in the LPAR*/
#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;
/* store the data structures */
static perfstat_netadapter_t *statp ,*statq;
/* 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;
/*
 * 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 the 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_netadapter_t structures are available */
        if(collect_remote_node_stats) {
        strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
        nodeid.spec = NODENAME;
        tot = perfstat_netadapter_node(&nodeid, NULL, sizeof(perfstat_netadapter_t), 0);
        }
       else
       {
       tot = perfstat_netadapter(NULL, NULL, sizeof(perfstat_netadapter_t), 0);
       }
       if (tot == 0)
       {
       printf("There is no net adapter\n");
       exit(0);
       }
       if (tot < 0)
       {
       perror("perfstat_netadapter: ");
       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;
        strcpy(nodeid.name , FIRST_NETINTERFACE);
        ret = perfstat_netadapter_node(&nodeid, statq, sizeof(perfstat_netadapter_t), tot);
     }
     else {
         strcpy(first.name , FIRST_NETINTERFACE);
         ret = perfstat_netadapter( &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_netadapter_node(&nodeid, statp, sizeof(perfstat_netadapter_t), tot);
         }
         else {
            ret = perfstat_netadapter(&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(" Number 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(" ==================================================================\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 iterations */
                    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;
}
The program produces the output similar to the following:
Adapter name: ent0
 ======================== Transmit Statistics=====================
 Transmit Packets: 0
 Transmit Bytes: 0
 Transfer Interrupts : 0
 Transmit Errors : 0
 Packets Dropped at the time of Data Transmission : 0
 Transmit Queue Size: 0
 Transmit Queue Length :0
 Transmit Queue Overflow : 0
 Broadcast Packets Transmitted: 0
 Multicast packets Transmitted: 0
 Lost Carrier Sense signal count : 0
 Count of DMA Under-runs for Transmission: 0
 Number of unsuccessful transmissions : 0
 Maximum Collision Errors at Transmission: 0
 Late Collision Errors at Transmission : 0
 Number of packets deferred for Transmission : 0
 Time Out Errors for Transmission : 0
 Count of Single Collision error at Transmission: 0
 Count of Multiple Collision error at Transmission : 0
 ========================== Receive Statistics ====================
 Receive Packets :48
 Receive Bytes :2962
 Receive Interrupts : 44
 Input errors on interface :0
 Number of Packets Dropped : 0
 Count of Bad Packets Received : 0
 Number of MultiCast Packets Received : 0
 Number of Broadcast Packets Received : 47
 Count of Packets Received with CRC errors: 0
 DMA over-runs : 0
 Alignment Errors : 0
 No Resource Errors : 0
 Collision Errors: 0
 Number of Short Packets Received: 0
 Number of Too Long Packets Received : 0
 Number of Received Packets discarded by Adapter: 0
영어 원문

perfstat_netadapter Interface

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

Note: The perfstat_netadpater interface returns only the network Ethernet adapter statistics similar to the entstat command.

The following program shows an example of how the perfstat_netadapter interface is used:

(281줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

perfstat_pagingspace 인터페이스

perfstat_pagingspace 인터페이스는 libperfstat.h 파일에 정의된 perfstat_pagingspace_t 구조체 묶음을 돌려줍니다.

perfstat_pagingspace_t 구조체의 주요 필드는 다음과 같습니다.

필드 설명
mb_size 페이징 공간 크기(MB)
lp_size 페이징 공간 크기(논리 파티션 수)
mb_used 페이징 공간 가운데 쓴 부분(MB)

이 밖에도 페이징 공간 관련 지표(이름, 유형, 활성 여부 등)를 돌려줍니다. 전체 목록은 Files Reference의 libperfstat.h 헤더 파일에서 perfstat_pagingspace_t 부분을 봅니다.

다음 코드는 perfstat_pagingspace를 쓰는 예입니다.

text
#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);
    }
}

이 프로그램은 다음과 같은 출력을 냅니다.

text
Statistics for paging space : hd6
---------------------------
type         : logical volume
volume group : rootvg
size (in LP) : 64
size (in MB) : 512
used (in MB) : 4
영어 원문

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:

  • 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:

(40줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The preceding program produces the following output:

text
Statistics for paging space : hd6
---------------------------
type         : logical volume
volume group : rootvg
size (in LP) : 64
size (in MB) : 512
used (in MB) : 4

perfstat_protocol 인터페이스

perfstat_protocol 인터페이스는 libperfstat.h 파일에 정의된 perfstat_protocol_t 구조체 묶음을 돌려줍니다. 이 구조체는 프로토콜마다 필요한 필드 묶음이 다르므로 공용체(union)의 묶음으로 되어 있습니다.

perfstat_protocol_t 구조체의 주요 필드는 다음과 같습니다.

필드 설명
name 프로토콜 이름. ip, ip6, icmp, icmp6, udp, tcp, rpc, nfs, nfsv2, nfsv3 가운데 하나
ipackets 이 프로토콜로 받은 입력 패킷 수. ip, ipv6, udp, tcp에만 있습니다.
opackets 이 프로토콜로 보낸 출력 패킷 수. ip, ipv6, udp, tcp에만 있습니다.
received 이 프로토콜로 받은 패킷 수. icmp와 icmpv6에만 있습니다.
calls 이 프로토콜로 한 호출 수. rpc, nfs, nfsv2, nfsv3에만 있습니다.

이 밖에도 네트워크 프로토콜 관련 지표를 많이 돌려줍니다. 전체 목록은 libperfstat.h 헤더 파일의 perfstat_protocol_t 부분을 봅니다.

다음 코드는 perfstat_protocol 인터페이스를 쓰는 예입니다.

text
#include <stdio.h>
#include <string.h>
#include <libperfstat.h>
int main(int argc, char* argv[]) {
    int ret, tot, retrieved = 0;
    perfstat_protocol_t pinfo;
    perfstat_id_t protid;
    /* check how many perfstat_protocol_t structures are available */
    tot = perfstat_protocol(NULL, NULL, sizeof(perfstat_protocol_t), 0);
    /* check for error */
    if (tot <= 0)
    {
     perror("perfstat_protocol");
   exit(-1);
    }
    printf("number of protocol usage structures available : %d\n", tot);
    /* set name to first protocol */
    strcpy(protid.name, FIRST_PROTOCOL);
    /* retrieve first protocol usage information */
    ret = perfstat_protocol(&protid, &pinfo, sizeof(perfstat_protocol_t), 1);
    if (ret < 0)
    {
   perror("perfstat_protocol");
   exit(-1);
    }
   retrieved += ret;
    do {
       printf("\nStatistics for protocol : %s\n", pinfo.name);
       printf("-----------------------\n");
       if (!strcmp(pinfo.name,"ip")) {
           printf("number of input packets  : %llu\n", pinfo.u.ip.ipackets);
           printf("number of input errors   : %llu\n", pinfo.u.ip.ierrors);
           printf("number of output packets : %llu\n", pinfo.u.ip.opackets);
           printf("number of output errors  : %llu\n", pinfo.u.ip.oerrors);
       } else if (!strcmp(pinfo.name,"ipv6")) {
           printf("number of input packets  : %llu\n", pinfo.u.ipv6.ipackets);
           printf("number of input errors   : %llu\n", pinfo.u.ipv6.ierrors);
    printf("number of output packets : %llu\n", pinfo.u.ipv6.opackets);
    printf("number of output errors  : %llu\n", pinfo.u.ipv6.oerrors);
} else if (!strcmp(pinfo.name,"icmp")) {
    printf("number of packets received : %llu\n", pinfo.u.icmp.received);
    printf("number of packets sent     : %llu\n", pinfo.u.icmp.sent);
    printf("number of errors           : %llu\n", pinfo.u.icmp.errors);
} else if (!strcmp(pinfo.name,"icmpv6")) {
    printf("number of packets received : %llu\n", pinfo.u.icmpv6.received);
    printf("number of packets sent     : %llu\n", pinfo.u.icmpv6.sent);
    printf("number of errors           : %llu\n", pinfo.u.icmpv6.errors);
} else if (!strcmp(pinfo.name,"udp")) {
    printf("number of input packets  : %llu\n", pinfo.u.udp.ipackets);
    printf("number of input errors   : %llu\n", pinfo.u.udp.ierrors);
    printf("number of output packets : %llu\n", pinfo.u.udp.opackets);
} else if (!strcmp(pinfo.name,"tcp")) {
    printf("number of input packets  : %llu\n", pinfo.u.tcp.ipackets);
    printf("number of input errors   : %llu\n", pinfo.u.tcp.ierrors);
    printf("number of output packets : %llu\n", pinfo.u.tcp.opackets);
} else if (!strcmp(pinfo.name,"rpc")) {
    printf("client statistics:\n");
    printf("number of connection-oriented RPC requests  : %llu\n",
           pinfo.u.rpc.client.stream.calls);
    printf("number of rejected connection-oriented RPCs : %llu\n",
           pinfo.u.rpc.client.stream.badcalls);
    printf("number of connectionless RPC requests       : %llu\n",
           pinfo.u.rpc.client.dgram.calls);
    printf("number of rejected connectionless RPCs      : %llu\n",
           pinfo.u.rpc.client.dgram.badcalls);
    printf("\nserver statistics:\n");
    printf("number of connection-oriented RPC requests  : %llu\n",
           pinfo.u.rpc.server.stream.calls);
    printf("number of rejected connection-oriented RPCs : %llu\n",
           pinfo.u.rpc.server.stream.badcalls);
    printf("number of connectionless RPC requests       : %llu\n",
           pinfo.u.rpc.server.dgram.calls);
    printf("number of rejected connectionless RPCs      : %llu\n",
           pinfo.u.rpc.server.dgram.badcalls);
} else if (!strcmp(pinfo.name,"nfs")) {
    printf("total number of NFS client requests        : %llu\n",
           pinfo.u.nfs.client.calls);
    printf("total number of NFS client failed calls    : %llu\n",
           pinfo.u.nfs.client.badcalls);
    printf("total number of NFS server requests        : %llu\n",
           pinfo.u.nfs.server.calls);
    printf("total number of NFS server failed calls    : %llu\n",
           pinfo.u.nfs.server.badcalls);
    printf("total number of NFS version 2 server calls : %llu\n",
           pinfo.u.nfs.server.public_v2);
    printf("total number of NFS version 3 server calls : %llu\n",
           pinfo.u.nfs.server.public_v3);
} else if (!strcmp(pinfo.name,"nfsv2")) {
    printf("number of NFS V2 client requests : %llu\n",
           pinfo.u.nfsv2.client.calls);
    printf("number of NFS V2 server requests : %llu\n",
           pinfo.u.nfsv2.server.calls);
} else if (!strcmp(pinfo.name,"nfsv3")) {
    printf("number of NFS V3 client requests : %llu\n",
           pinfo.u.nfsv3.client.calls);
    printf("number of NFS V3 server requests : %llu\n",
           pinfo.u.nfsv3.server.calls);
}
/* make sure we stop after the last protocol */
if (ret = strcmp(protid.name, "")) {
    printf("\nnext protocol name : %s\n", protid.name);
    /* retrieve information for next protocol */
           ret = perfstat_protocol(&protid, &pinfo, sizeof(perfstat_protocol_t), 1);
    if (ret < 0)
           {
        perror("perfstat_protocol");
        exit(-1);
           }
           retrieved += ret;
       }
    } while (ret == 1);
   printf("\nnumber of protocol usage structures retrieved : %d\n", retrieved);
}

이 프로그램은 다음과 비슷한 출력을 냅니다.

text
number of protocol usage structures available : 11
Statistics for protocol : ip
-----------------------
number of input packets  : 155855
number of input errors   : 32911
number of output packets : 25635
number of output errors  : 32909
next protocol name : ipv6
Statistics for protocol : ipv6
-----------------------
number of input packets  : 0
number of input errors   : 0
number of output packets : 0
number of output errors  : 0
next protocol name : icmp
Statistics for protocol : icmp
-----------------------
number of packets received : 2
number of packets sent     : 1
number of errors           : 1
next protocol name : icmpv6
Statistics for protocol : icmpv6
-----------------------
number of packets received : 0
number of packets sent     : 0
number of errors           : 0
next protocol name : udp
Statistics for protocol : udp
-----------------------
number of input packets  : 106630
number of input errors   : 91625
number of output packets : 14435
next protocol name : tcp
Statistics for protocol : tcp
-----------------------
number of input packets  : 16313
number of input errors   : 0
number of output packets : 11196
next protocol name : rpc
Statistics for protocol : rpc
-----------------------
client statistics:
number of connection-oriented RPC requests  : 41
number of rejected connection-oriented RPCs : 0
number of connectionless RPC requests       : 24
number of rejected connectionless RPCs      : 0
server statistics:
number of connection-oriented RPC requests  : 0
number of rejected connection-oriented RPCs : 0
number of connectionless RPC requests       : 0
number of rejected connectionless RPCs      : 0
next protocol name : nfs
Statistics for protocol : nfs
-----------------------
total number of NFS client requests        : 41
total number of NFS client failed calls    : 0
total number of NFS server requests        : 0
total number of NFS server failed calls    : 0
total number of NFS version 2 server calls : 0
total number of NFS version 3 server calls : 0
next protocol name : nfsv2
Statistics for protocol : nfsv2
-----------------------
number of NFS V2 client requests : 0
number of NFS V2 server requests : 0
next protocol name : nfsv3
Statistics for protocol : nfsv3
-----------------------
number of NFS V3 client requests : 41
number of NFS V3 server requests : 0
next protocol name : nfsv4
Statistics for protocol : nfsv4
-----------------------
number of protocol usage structures retrieved : 11

위 프로그램은 protocolstat의 동작을 흉내 내며 perfstat_protocol을 쓰는 방법을 보여 줍니다.

영어 원문

perfstat_protocol Interface

The perfstat_protocol interface returns a set of structures of type perfstat_protocol_t, which consists of a set of unions to accommodate the different sets of fields needed for each protocol, as defined in the libperfstat.h file.

Selected fields from the perfstat_protocol_t structure include:

  • name — Protocol name, which can be any of the following values: ip, ip6, icmp, icmp6, udp, tcp, rpc, nfs, nfsv2, or nfsv3.
  • ipackets — Number of input packets received using this protocol. This field exists only for protocols ip, ipv6, udp, and tcp.
  • opackets — Number of output packets sent using this protocol. This field exists only for protocols ip, ipv6, udp, and tcp.
  • received — Number of packets received using this protocol. This field exists only for protocols icmp and icmpv6.
  • calls — Number of calls made to this protocol. This field exists only for protocols rpc, nfs, nfsv2, and nfsv3.

Many other network-protocol related metrics are also returned. For a complete list of network-protocol related metrics, see the perfstat_protocol_t section in the libperfstat.h header file.

The following code shows an example of how the perfstat_protocol interface is used:

(113줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The program displays an output that is similar to the following example output:

(74줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The preceding program emulates protocolstat behavior and also shows how perfstat_protocol is used.

(6.1) perfstat_process 인터페이스

perfstat_process 인터페이스는 libperfstat.h 파일에 정의된 perfstat_process_t 구조체 묶음을 돌려줍니다.

perfstat_process_t 구조체의 필드는 다음과 같습니다.

필드 설명
pid 프로세스 ID
proc_name 프로세스 이름
proc_priority 프로세스 우선순위
num_threads 스레드 수
proc_uid 소유자 정보
proc_classid WLM 클래스 이름
proc_size 프로세스의 가상 크기
proc_real_mem_data 데이터에 쓴 실메모리(KB)
proc_real_mem_text 텍스트에 쓴 실메모리(KB)
proc_virt_mem_data 데이터에 쓴 가상 메모리(KB)
proc_virt_mem_text 텍스트에 쓴 가상 메모리(KB)
shared_lib_data_size 공유 라이브러리의 데이터 크기(KB)
heap_size 힙 크기(KB)
real_inuse 세그먼트를 포함해 프로세스가 쓰는 실메모리(KB)
virt_inuse 세그먼트를 포함해 프로세스가 쓰는 가상 메모리(KB)
pinned 모든 세그먼트를 포함해 프로세스가 쓰는 고정 메모리(KB)
pgsp_inuse 모든 세그먼트를 포함해 쓰는 페이징 공간(KB)
filepages 공유 페이지를 포함해 쓰는 파일 페이지(KB)
real_inuse_map 공유 메모리와 메모리 매핑 영역에 쓰는 실메모리(KB)
virt_inuse_map 공유 메모리와 메모리 매핑 영역에 쓰는 가상 메모리(KB)
pinned_inuse_map 공유 메모리와 메모리 매핑 영역의 고정 메모리(KB)
ucpu_time 사용자 모드 CPU 시간(ms)
scpu_time 시스템 모드 CPU 시간(ms)
last_timebase timebase 카운터
inBytes 디스크에서 읽은 바이트
outBytes 디스크에 쓴 바이트
inOps 디스크 읽기 작업 수
outOps 디스크 쓰기 작업 수

다음은 perfstat_process API를 쓰는 코드 예입니다.

text
#include <libperfstat.h>
void main()
{
  perfstat_process_t *proct;
  perfstat_id_t id;
  int i,rc,proc_count;
  /* Get the count of processes */
  proc_count = perfstat_process(NULL, NULL,sizeof(perfstat_process_t),0);
  /* check for error */
  if(proc_count <= 0)
  {
    perror("Error in perfstat_process");
    exit(-1) ;
  }
  printf("Number of Processes = %d\n",proc_count);
  /* Allocate enough memory */
  proct = (perfstat_process_t *)calloc(proc_count,sizeof(perfstat_process_t));
  if(proct == NULL)
  {
    perror("Memory Allocation Error");
    exit(-1) ;
  }
  strcpy(id.name,"");
  rc = perfstat_process(&id,proct,sizeof(perfstat_process_t),proc_count);
  if(rc <= 0)
  {
    perror("Error in perfstat_process");
    exit(-1) ;
  }
  printf("\n =======Process Related metrics =======\n");
  for(i=0 ; i<proc_count ;i++)
  {
    printf("Process Name =                     %s\n",proct[i].proc_name);
    printf("Process ID =                       %lld\n",proct[i].pid);
    printf("Process priority =                 %d\n",proct[i].proc_priority);
    printf("Thread Count =                     %d\n",proct[i].num_threads);
    printf("\nCredential Information\n");
    printf("Owner Info =                       %lld\n",proct[i].proc_uid);
    printf("WLM Class Name =                   %lld\n",proct[i].proc_classid);
    printf("\nMemory Related Statistics \n");
    printf("Process Virtual Size =             %lld KB \n",proct[i].proc_size);
    printf("Real Memory used for Data =        %lld KB \n",proct[i].proc_real_mem_data);
    printf("Real Memory used for Text =        %lld KB \n",proct[i].proc_real_mem_text);
    printf("Virtual Memory used for Data =     %lld KB \n",proct[i].proc_virt_mem_data);
    printf("Virtual Memory used for Text =     %lld KB \n",proct[i].proc_virt_mem_text);
    printf("Data Size from Shared Library =    %lld KB \n",proct[i].shared_lib_data_size);
    printf("Heap Size =                        %lld KB \n",proct[i].heap_size);
    printf("Real memory in use by process =    %lld KB \n",proct[i].real_inuse);
    printf("Virtual memory in use by process=  %lld KB \n",proct[i].virt_inuse);
    printf("Pinned Memory for this process =   %lld KB \n",proct[i].pinned);
    printf("Paging Space in use =              %lld KB \n",proct[i].pgsp_inuse);
    printf("File Pages used =                  %lld KB \n",proct[i].filepages);
    printf("Real memory used for Shared Memory and Memory Mapped regions =%lld KB \n", proct[i].real_inuse_map);
    printf("Virtual Memory used for Shared Memory and Memory Mapped regions =%lld KB \n", proct[i].virt_inuse_map);
    printf("Pinned memory for Shared Memory and Memory Mapped regions =%lld KB \n", proct[i].pinned_inuse_map);
    printf("\nCPU Related Statistics \n");
    printf("User Mode CPU time =               %lf ms\n",proct[i].ucpu_time);
    printf("System Mode CPU time =             %lf ms\n",proct[i].scpu_time);
    printf("Timebase Counter =                 %lld\n", proct[i].last_timebase);
    printf("\nDisk Related Statistics \n");
    printf("Bytes Written to Disk =            %lld\n",proct[i].inBytes);
    printf("Bytes Read from Disk =             %lld\n",proct[i].outBytes);
    printf("In Operations from Disk =          %lld\n",proct[i].inOps);
    printf("Out Operations from Disk =         %lld\n",proct[i].outOps);
    printf("=====================================\n");
    printf("\n\n");
    }
}
The program produces the output similar to the following:
Number of Processes = 77
 =======Process Related metrics =======
Process Name =                     swapper
Process ID =                       0
Process priority =                 16
Thread Count =                     0
Credential Information
Owner Info =                       0
WLM Class Name =                   257
Memory Related Statistics
Process Virtual Size =             384 KB
Real Memory used for Data =        384 KB
Real Memory used for Text =        0 KB
Virtual Memory used for Data =     384 KB
Virtual Memory used for Text =     0 KB
Data Size from Shared Library =    0 KB
Heap Size =                        0 KB
Real memory in use by process =    384 KB
Virtual memory in use by process=  384 KB
Pinned Memory for this process =   320 KB
Paging Space in use =              0 KB
File Pages used =                  0 KB
Real memory used for Shared Memory and Memory Mapped regions =0 KB
Virtual Memory used for Shared Memory and Memory Mapped regions =0 KB
Pinned memory for Shared Memory and Memory Mapped regions =0 KB
CPU Related Statistics
User Mode CPU time =               0.000000 ms
System Mode CPU time =             9262.345828 ms
Timebase Counter =                 7290723200327369
Disk Related Statistics
Bytes Written to Disk =            0
Bytes Read from Disk =             32768
In Operations from Disk =          0
Out Operations from Disk =         8
=====================================

이 프로그램은 다음과 비슷한 출력을 냅니다.

text
Number of Processes = 77
 =======Process Related metrics =======
Process Name =                     swapper
Process ID =                       0
Process priority =                 16
Thread Count =                     0
Credential Information
Owner Info =                       0
WLM Class Name =                   257
Memory Related Statistics
Process Virtual Size =             384 KB
Real Memory used for Data =        384 KB
Real Memory used for Text =        0 KB
Virtual Memory used for Data =     384 KB
Virtual Memory used for Text =     0 KB
Data Size from Shared Library =    0 KB
Heap Size =                        0 KB
Real memory in use by process =    384 KB
Virtual memory in use by process=  384 KB
Pinned Memory for this process =   320 KB
Paging Space in use =              0 KB
File Pages used =                  0 KB
Real memory used for Shared Memory and Memory Mapped regions =0 KB
Virtual Memory used for Shared Memory and Memory Mapped regions =0 KB
Pinned memory for Shared Memory and Memory Mapped regions =0 KB
CPU Related Statistics
User Mode CPU time =               0.000000 ms
System Mode CPU time =             9262.345828 ms
Timebase Counter =                 7290723200327369
Disk Related Statistics
Bytes Written to Disk =            0
Bytes Read from Disk =             32768
In Operations from Disk =          0
Out Operations from Disk =         8
=====================================
영어 원문

perfstat_process interfaces

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

The field of the perfstat_process_t structure includes:

  • pid — Process ID
  • proc_name — Name of the process
  • proc_priority — Priority of the process
  • num_threads — Thread count
  • proc_uid — Information of the owner
  • proc_classid — WLM class name
  • proc_size — Virtual size of the process
  • proc_real_mem_data — Real memory used for the data in kilobytes
  • proc_real_mem_text — Real memory used for text in kilobytes
  • proc_virt_mem_data — Virtual memory used for data in kilobytes
  • proc_virt_mem_text — Virtual memory used for text in kilobytes
  • shared_lib_data_size — Data size from shared library in kilobytes
  • heap_size — Heap size in kilobytes
  • real_inuse — The real memory in kilobytes used by the process including the segments
  • virt_inuse — The virtual memory in kilobytes used by the process including the segments
  • pinned — Pinned memory in kilobytes used for the process that is inclusive of all segments
  • pgsp_inuse — Paging space in kilobytes uses inclusive of all segments
  • filepages — File pages in kilobytes used including shared pages
  • real_inuse_map — Real memory in kilobytes used for shared memory and memory mapped regions
  • virt_inuse_map — Virtual memory in kilobytes used for shared memory and memory mapped regions
  • pinned_inuse_map — Pinned memory in kilobytes for shared memory and memory mapped regions
  • ucpu_time — User mode CPU time in milliseconds
  • scpu_time — System mode CPU time in milliseconds
  • last_timebase — Timebase counter
  • inBytes — Bytes read from the disk
  • outBytes — Bytes written to the disk
  • inOps — In operations from disk
  • outOps — Out operations from disk

The following is an example of code for the perfstat_process API:

(104줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The program displays an output that is similar to the following example output:

(35줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

(6.1) perfstat_process_util 인터페이스

perfstat_process_util 인터페이스는 libperfstat.h 파일에 정의된 perfstat_process_t 구조체 묶음을 돌려줍니다.

다음은 perfstat_process_util API를 쓰는 코드 예입니다.

text
#include <libperfstat.h>
#include <stdio.h>
#include <stdlib.h>
#define PERIOD 5
void main()
{
  perfstat_process_t *cur, *prev;
  perfstat_rawdata_t buf;
  perfstat_process_t *proc_util;
  perfstat_id_t id;
  int cur_proc_count,prev_proc_count;
  int i,rc;
  prev_proc_count = perfstat_process(NULL, NULL,sizeof(perfstat_process_t),0);
  if(prev_proc_count <= 0)
  {
    perror("Error in perfstat_process");
    exit(-1) ;
  }
  prev = (perfstat_process_t *)calloc(prev_proc_count,sizeof(perfstat_process_t));
  if(prev == NULL)
  {
    perror("Memory Allocation Error");
    exit(-1) ;
  }
  strcpy(id.name,"");
  rc = perfstat_process(&id,prev,sizeof(perfstat_process_t),prev_proc_count);
  if(rc <= 0)
  {
    perror("Error in perfstat_process");
    exit(-1) ;
  }
  sleep(PERIOD);
  cur_proc_count = perfstat_process(NULL, NULL,sizeof(perfstat_process_t),0);
  if(cur_proc_count <= 0)
  {
    perror("Error in perfstat_process");
    exit(-1) ;
  }
  cur = (perfstat_process_t *)calloc(cur_proc_count,sizeof(perfstat_process_t));
  proc_util = (perfstat_process_t *)calloc(cur_proc_count,sizeof(perfstat_process_t));
  if(cur == NULL || proc_util == NULL)
  {
    perror("Memory Allocation Error");
    exit(-1) ;
  }
  rc = perfstat_process(&id,cur,sizeof(perfstat_process_t),cur_proc_count);
  if(rc < 0)
  {
    perror("Error in perfstat_process");
    exit(-1) ;
  }
  bzero(&buf, sizeof(perfstat_rawdata_t));
  buf.type = UTIL_PROCESS;
  buf.curstat = cur;
  buf.prevstat = prev;
  buf.sizeof_data = sizeof(perfstat_process_t);
  buf.cur_elems = cur_proc_count;
  buf.prev_elems = prev_proc_count;
/* Calculate Process Utilization */
  rc = perfstat_process_util(&buf,proc_util,sizeof(perfstat_process_t),cur_proc_count);
  if(rc <= 0)
  {
    perror("Error in perfstat_process_util");
    exit(-1);
  }
  printf("\n =======Process Related Utilization Metrics =======\n");
  for(i=0 ; i<cur_proc_count ;i++)
  {
    printf("Process ID =                %lld\n",proc_util[i].pid);
    printf("User Mode CPU time =        %lf \n",proc_util[i].ucpu_time);
    printf("System Mode CPU time =      %lf \n",proc_util[i].scpu_time);
    printf("Bytes Written to Disk =     %lld\n",proc_util[i].inBytes);
    printf("Bytes Read from Disk =      %lld\n",proc_util[i].outBytes);
    printf("In Operations from Disk =   %lld\n",proc_util[i].inOps);
    printf("Out Operations from Disk =  %lld\n",proc_util[i].outOps);
    printf("=====================================\n");
    printf("\n\n");
}
}

이 프로그램은 다음과 비슷한 출력을 냅니다.

text
=======Process Related Utilization Metrics =======
Process ID =                0
User Mode CPU time =        0.000000
System Mode CPU time =      0.013752
Bytes Written to Disk =     0
Bytes Read from Disk =      0
In Operations from Disk =   0
Out Operations from Disk =  0
=====================================
Process ID =                1
User Mode CPU time =        0.000000
System Mode CPU time =      0.000000
Bytes Written to Disk =     0
Bytes Read from Disk =      0
In Operations from Disk =   0
Out Operations from Disk =  0
=====================================
Process ID =                196614
User Mode CPU time =        0.000000
System Mode CPU time =      0.000000
Bytes Written to Disk =     0
Bytes Read from Disk =      0
In Operations from Disk =   0
Out Operations from Disk =  0
=====================================
Process ID =                262152
User Mode CPU time =        0.000000
System Mode CPU time =      0.000000
Bytes Written to Disk =     0
Bytes Read from Disk =      0
In Operations from Disk =   0
Out Operations from Disk =  0
=====================================
영어 원문

perfstat_process_util interface

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

The following is an example of code that uses the perfstat_process_util API:

(79줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

The program displays an output that is similar to the following example output:

(33줄짜리 예는 위 한글 본문에 그대로 실었습니다.)

(6.1) perfstat_processor_pool_util 인터페이스

perfstat_processor_pool_util 인터페이스는 libperfstat.h 파일에 정의된 perfstat_processor_pool_util_t 구조체 묶음을 돌려줍니다.

필드 설명
max_capacity 파티션의 최대 풀 프로세서 용량
entitled_capacity 파티션의 권리 풀 프로세서 용량
phys_cpus_pool 파티션이 연결된 공유 프로세서 풀에서 쓸 수 있는 물리 프로세서 수
idle_cores 마지막 구간 동안 공유 프로세서 풀에서 쓸 수 있었던(유휴) 물리 프로세서 수
max_cores 파티션이 연결된 공유 프로세서 풀이 마지막 구간에 쓴 최대 코어 수
busy_cores 파티션이 연결된 공유 프로세서 풀의 모든 파티션에서 마지막 구간 동안 누적된 바쁜(유휴가 아닌) 코어 수의 최댓값
sbusy_cores 파티션이 연결된 공유 프로세서 풀의 모든 파티션에서 누적된 바쁜 코어 수를 정규화해 더한 값. 코어가 공칭(정격) 주파수로 동작할 때 적용됩니다.
gpool_tot_cores (모든 풀에 걸쳐) 공유 프로세서용으로 할당된 모든 물리 프로세서의 전체 코어 수
gpool_busy_cores (모든 풀에 걸쳐) 모든 공유 프로세서 파티션에서 마지막 구간 동안 누적된 바쁜 코어 수의 합
gpool_sbusy_cores (모든 풀에 걸쳐) 모든 공유 프로세서 파티션에서 마지막 구간 동안 누적된 바쁜 코어 수를 정규화해 더한 값. 코어가 공칭(정격) 주파수로 동작할 때 적용됩니다.
tb_last_delta 경과한 클록 틱 수
version 데이터 구조의 버전 번호

시스템 수준 사용률을 구하는 perfstat_processor_pool_util API 사용 예입니다.

text
#include <libperfstat.h>
#include <sys/dr.h>
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#define COUNT 2
#define INTERVAL 2
void main(int argc, char **argv)
{
    perfstat_rawdata_t data;
    perfstat_partition_total_t oldt,newt;
    perfstat_processor_pool_util_t util,*uti;
    static int once=0;
    int rc;
        u_longlong_t x=0;
        int iInter=0,iCount=0;
        int c;
        while( (c = getopt(argc,argv,"i:c:"))!= EOF ){
                switch(c) {
                        case ’i’:
                        iInter=atoi(optarg);
                        break;
                        case ’c’:
                        iCount=atoi(optarg);
                        break;
                }
        }
if(iCount<=0 && iInter<=0)
{
 iCount=COUNT;
 iInter=INTERVAL;
}
  while(iCount--)
  {
    rc = perfstat_partition_total(NULL, &oldt, sizeof(perfstat_partition_total_t), 1);
     if (rc != 1)
 {
     perror("Error in perfstat_partition_total");
     exit(-1);
     }
     sleep(INTERVAL);
     rc = perfstat_partition_total(NULL, &newt, sizeof(perfstat_partition_total_t), 1);
     if (rc != 1)
 {
     perror("Error in perfstat_partition_total");
     exit(-1);
     }
   data.type = SHARED_POOL_UTIL;
   data.curstat = &newt; data.prevstat= &oldt;
   data.sizeof_data = sizeof(perfstat_partition_total_t);
   data.cur_elems = 1;
   data.prev_elems = 1;
    rc = perfstat_processor_pool_util(&data, &util,sizeof(perfstat_processor_pool_util_t),1);
    if(rc <= 0)
    {
      perror("Error in perfstat_processor_util");
      exit(-1);
    }
      if(!once)
         {
         printf("Pool_id\tCapacity\tPhys_cpus_pool\tApp\t\tPool_utlization\t\tGlobal_pool\n");
         printf("\tMax|Entitled\t\t\t\t\tBusy|Scaled_busy\tMax|busy\n");
         printf("-------------------------------------------------------------------------\n");
         once=1;
         }
        printf("%u ", util.ssp_id);
        printf("\t%llu ", util.max_capacity/100);
        /*Convert physical units to cores*/
        printf("  %llu ", util.entitled_capacity/100);
        /*Convert physical units to cores*/
        printf("\t\t\t%d ", util.phys_cpus_pool);
        printf("\t%5.2f ",util.idle_cores);
        printf("\t\t%5.2f ", util.busy_cores );
        printf("%5.2f ", util.sbusy_cores );
        printf("\t\t%5.2f ", util.gpool_tot_cores );
        printf("%5.2f \n", util.gpool_busy_cores );
 }
}
영어 원문

perfstat_processor_pool_util interface

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

  • max_capacity — Maximum pool processor capacity of the partition.
  • entitled_capacity — Entitled pool processor capacity of the partition.
  • phys_cpus_pool — Physical processors that are available in the Shared processor Pool to which the partition is associated.
  • idle_cores — Physical processors that are available in the Shared processor Pool from the last interval.
  • max_cores — Maximum cores used by the Shared processor Pool for the last interval, which is associated with the partition.
  • busy_cores — Maximum busy (non-idle) cores that are accumulated for the last interval across all partitions in the Shared processor Pool, which is associated with the partition.
  • sbusy_cores — Normalized summation of busy (non-idle) cores that are accumulated across all partitions in the Shared processor Pool, which is associated with the partition. This option applies if the cores run at nominal or rated frequency.
  • gpool_tot_cores — Total number of cores across all physical processors that are allocated for shared processor use (across all pools).
  • gpool_busy_cores — Summation of the busy (non-idle) cores that are accumulated across all shared processor partitions (across all pools) for the last interval.
  • gpool_sbusy_cores — Normalized summation of the busy cores that are accumulated across all shared processor partitions (across all pools) for the last interval. This option applies if the cores run at nominal or rated frequency.
  • tb_last_delta — Elapsed number of clock ticks.
  • version — Version number of the data structure.

The use of the perfstat_processor_pool_util API for the system-level utilization follows:

(79줄짜리 예는 위 한글 본문에 그대로 실었습니다.)