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