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:
Item Descriptoryes a
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:
#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);
       }
}
The program displays an output that is similar to the following example output:
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