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