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