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