1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _POOLSTAT_H 28*0Sstevel@tonic-gate #define _POOLSTAT_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #include <sys/types.h> 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #ifdef __cplusplus 35*0Sstevel@tonic-gate extern "C" { 36*0Sstevel@tonic-gate #endif 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate /* 39*0Sstevel@tonic-gate * The following are types and defines used to collect statistic data. 40*0Sstevel@tonic-gate * Different statistic providers can be used to collect the data. 41*0Sstevel@tonic-gate * Two functions build the interface to each provider: 42*0Sstevel@tonic-gate * 'provider'_init(), and 'provider'_update(). In the update function 43*0Sstevel@tonic-gate * a provider fills out the passed data structure with statistics data 44*0Sstevel@tonic-gate * it is responsible for. 45*0Sstevel@tonic-gate */ 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate /* Error messages for poolstat */ 48*0Sstevel@tonic-gate #define ERR_LOAD_AVERAGE "cannot get load average: %s\n" 49*0Sstevel@tonic-gate #define ERR_BINDING "cannot get resource binding: %s\n" 50*0Sstevel@tonic-gate #define ERR_STATS_POOL_N "cannot get statistics for pool '%s'\n" 51*0Sstevel@tonic-gate #define ERR_STATS_RES_N "cannot get statistics for resource '%s': %s\n" 52*0Sstevel@tonic-gate #define ERR_STATS_POOL "cannot get pool statistics: %s\n" 53*0Sstevel@tonic-gate #define ERR_STATS_RES "cannot get resource statistics: %s\n" 54*0Sstevel@tonic-gate #define ERR_STATS_FORMAT "cannot format statistic line: %s\n" 55*0Sstevel@tonic-gate #define ERR_KSTAT_OPEN "kstat open failed: %s\n" 56*0Sstevel@tonic-gate #define ERR_KSTAT_DATA "cannot get kstat data: %s\n" 57*0Sstevel@tonic-gate #define ERR_KSTAT_DLOOKUP "kstat_data_lookup('%s', '%s') failed: %s\n" 58*0Sstevel@tonic-gate #define ERR_OPTION_ARGS "Option -%c requires an argument\n" 59*0Sstevel@tonic-gate #define ERR_OPTION "poolstat: illegal option -- %c\n" 60*0Sstevel@tonic-gate #define ERR_CONF_UPDATE "pool configuration update failed: %s\n" 61*0Sstevel@tonic-gate #define ERR_UNSUPP_STYPE "unsupported statistic type: %s\n" 62*0Sstevel@tonic-gate #define ERR_UNSUPP_RTYPE "unsupported resource type: %s\n" 63*0Sstevel@tonic-gate #define ERR_UNSUPP_STAT_FIELD "unsupported statistic field: %s\n" 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate #define POOL_TYPE_NAME "pool" 66*0Sstevel@tonic-gate #define PSET_TYPE_NAME "pset" 67*0Sstevel@tonic-gate #define POOL_SYSID "pool.sys_id" 68*0Sstevel@tonic-gate #define PSET_SYSID "pset.sys_id" 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate /* set types */ 71*0Sstevel@tonic-gate typedef enum { ST_PSET } st_t; 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate /* update flag, forces refresh of statistic data */ 74*0Sstevel@tonic-gate #define SA_REFRESH 1 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate /* data bag used to collect statistics for a processor set */ 77*0Sstevel@tonic-gate typedef struct { 78*0Sstevel@tonic-gate int64_t pset_sb_sysid; 79*0Sstevel@tonic-gate uint64_t pset_sb_min; 80*0Sstevel@tonic-gate uint64_t pset_sb_max; 81*0Sstevel@tonic-gate uint64_t pset_sb_size; 82*0Sstevel@tonic-gate double pset_sb_used; 83*0Sstevel@tonic-gate double pset_sb_load; 84*0Sstevel@tonic-gate uint64_t pset_sb_changed; 85*0Sstevel@tonic-gate } pset_statistic_bag_t; 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate /* wrapper for different statistic bags */ 88*0Sstevel@tonic-gate typedef struct { 89*0Sstevel@tonic-gate const char *sb_name; /* pool or resource name used as identifier */ 90*0Sstevel@tonic-gate int64_t sb_sysid; /* the sysid */ 91*0Sstevel@tonic-gate const char *sb_type; /* the type can be "pool", or "pset" */ 92*0Sstevel@tonic-gate uint64_t sb_changed; 93*0Sstevel@tonic-gate void* bag; 94*0Sstevel@tonic-gate } statistic_bag_t; 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate /* shortcut to access a element in the pset statistic bag. */ 97*0Sstevel@tonic-gate #define PSETBAG_ELEM(p, e) (((pset_statistic_bag_t *)(p)->bag)->e) 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate /* statistic adapters */ 100*0Sstevel@tonic-gate extern void sa_libpool_init(void *); 101*0Sstevel@tonic-gate extern void sa_libpool_update(statistic_bag_t *sbag, int flags); 102*0Sstevel@tonic-gate extern void sa_kstat_init(void *); 103*0Sstevel@tonic-gate extern void sa_kstat_update(statistic_bag_t *sbag, int flags); 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate /* 106*0Sstevel@tonic-gate * The following types and defines are used to format statistic lines. 107*0Sstevel@tonic-gate * All formatting information for a particular line are grouped in 'lf_t' 108*0Sstevel@tonic-gate * structure. 109*0Sstevel@tonic-gate * Two data sequences are anchored there: an array with all possible formatting 110*0Sstevel@tonic-gate * directives for fields that can occur in a statistic line, and a list with 111*0Sstevel@tonic-gate * pointers to elements in this array. This list defines which fields and in 112*0Sstevel@tonic-gate * which order should be printed. 113*0Sstevel@tonic-gate * Formatting directives for one field are grouped in 'poolstat_field_format_t' 114*0Sstevel@tonic-gate * structure. Basically it contains a pointer to a formatting function and some 115*0Sstevel@tonic-gate * formatting parameters used by this function. 116*0Sstevel@tonic-gate */ 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate /* the length of a statistic line */ 119*0Sstevel@tonic-gate #define MAXLINE 160 120*0Sstevel@tonic-gate /* default print field */ 121*0Sstevel@tonic-gate #define D_FIELD 0x01 122*0Sstevel@tonic-gate /* -x option print field */ 123*0Sstevel@tonic-gate #define X_FIELD 0x02 124*0Sstevel@tonic-gate /* -o option print field */ 125*0Sstevel@tonic-gate #define O_FIELD 0x04 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate /* print field in default and extended mode */ 128*0Sstevel@tonic-gate #define DX_FIELD (D_FIELD | X_FIELD) 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate /* marks a field as printable */ 131*0Sstevel@tonic-gate #define PABLE_FIELD 0x80 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate #define KILO 1000 134*0Sstevel@tonic-gate #define MEGA ((uint64_t)(KILO * 1000)) 135*0Sstevel@tonic-gate #define GIGA ((uint64_t)(MEGA * 1000)) 136*0Sstevel@tonic-gate #define TERA ((uint64_t)(GIGA * 1000)) 137*0Sstevel@tonic-gate #define PETA ((uint64_t)(TERA * 1000)) 138*0Sstevel@tonic-gate #define EXA ((uint64_t)(PETA * 1000)) 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate #define KBYTE 1024 141*0Sstevel@tonic-gate #define MBYTE ((uint64_t)(KBYTE * 1024)) 142*0Sstevel@tonic-gate #define GBYTE ((uint64_t)(MBYTE * 1024)) 143*0Sstevel@tonic-gate #define TBYTE ((uint64_t)(GBYTE * 1024)) 144*0Sstevel@tonic-gate #define PBYTE ((uint64_t)(TBYTE * 1024)) 145*0Sstevel@tonic-gate #define EBYTE ((uint64_t)(PBYTE * 1024)) 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate /* statistic data types */ 148*0Sstevel@tonic-gate typedef enum { ULL, LL, FL, STR } dt_t; 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate /* poolstat_field_format_t contains information for one statistic field */ 151*0Sstevel@tonic-gate typedef struct poolstat_field_format { 152*0Sstevel@tonic-gate int pff_prt; /* printable flag */ 153*0Sstevel@tonic-gate const char *pff_name; /* name of the statistic */ 154*0Sstevel@tonic-gate const char *pff_header; 155*0Sstevel@tonic-gate const dt_t pff_type; /* the data type */ 156*0Sstevel@tonic-gate int pff_width; /* width, excluding whitespace */ 157*0Sstevel@tonic-gate const int pff_minwidth; 158*0Sstevel@tonic-gate char **pff_data_ptr; 159*0Sstevel@tonic-gate const size_t pff_offset; /* offset in a data block */ 160*0Sstevel@tonic-gate /* formatter */ 161*0Sstevel@tonic-gate int (* pff_format) 162*0Sstevel@tonic-gate (char *, int, int, struct poolstat_field_format *, char *); 163*0Sstevel@tonic-gate } poolstat_field_format_t; 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gate /* list element, used to link arbitrary objects in a list */ 166*0Sstevel@tonic-gate typedef struct _myself { 167*0Sstevel@tonic-gate void *ple_obj; 168*0Sstevel@tonic-gate struct _myself *ple_next; 169*0Sstevel@tonic-gate } poolstat_list_element_t; 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate /* 172*0Sstevel@tonic-gate * poolstat_line_format_t contains formatting information for one 173*0Sstevel@tonic-gate * statistics line. 174*0Sstevel@tonic-gate */ 175*0Sstevel@tonic-gate typedef struct { 176*0Sstevel@tonic-gate /* pointer to an array with all format fields */ 177*0Sstevel@tonic-gate poolstat_field_format_t *plf_ffs; 178*0Sstevel@tonic-gate /* the lenght of format field array */ 179*0Sstevel@tonic-gate int plf_ff_len; 180*0Sstevel@tonic-gate /* the field's print sequence */ 181*0Sstevel@tonic-gate poolstat_list_element_t *plf_prt_seq; 182*0Sstevel@tonic-gate /* pointer to the last field in prt. sequence */ 183*0Sstevel@tonic-gate poolstat_list_element_t *plf_last; 184*0Sstevel@tonic-gate } poolstat_line_format_t; 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate #ifdef __cplusplus 187*0Sstevel@tonic-gate } 188*0Sstevel@tonic-gate #endif 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate #endif /* _POOLSTAT_H */ 191