Print this page
codereview and testing fixes.
6558 kstat: desire type for timestamps
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/stat/kstat/kstat.h
+++ new/usr/src/cmd/stat/kstat/kstat.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 23 * Copyright 2013 David Hoeppner. All rights reserved.
24 24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
25 + * Copyright 2016 Garrett D'Amore
25 26 */
26 27
27 28 #ifndef _STAT_KSTAT_H
28 29 #define _STAT_KSTAT_H
29 30
30 31 /*
31 32 * Structures needed by the kstat reader functions.
32 33 */
33 34 #include <sys/var.h>
34 35 #include <sys/utsname.h>
35 36 #include <sys/sysinfo.h>
36 37 #include <sys/flock.h>
37 38 #include <sys/dnlc.h>
38 39 #include <regex.h>
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
39 40 #include <nfs/nfs.h>
40 41 #include <nfs/nfs_clnt.h>
41 42
42 43 #ifdef __sparc
43 44 #include <vm/hat_sfmmu.h>
44 45 #include <sys/simmstat.h>
45 46 #include <sys/sysctrl.h>
46 47 #include <sys/fhc.h>
47 48 #endif
48 49
49 -#define KSTAT_DATA_HRTIME (KSTAT_DATA_STRING + 1)
50 -
51 50 typedef union ks_value {
52 51 char c[16];
53 52 int32_t i32;
54 53 uint32_t ui32;
55 54 struct {
56 55 union {
57 56 char *ptr;
58 57 char __pad[8];
59 58 } addr;
60 59 uint32_t len;
61 60 } str;
62 61
63 62 int64_t i64;
64 63 uint64_t ui64;
64 + hrtime_t t;
65 65 } ks_value_t;
66 66
67 -#define SAVE_HRTIME(I, S, N) \
68 -{ \
69 - ks_value_t v; \
70 - v.ui64 = S->N; \
71 - nvpair_insert(I, #N, &v, KSTAT_DATA_UINT64); \
67 +#define SAVE_HRTIME(I, S, N) \
68 +{ \
69 + ks_value_t v; \
70 + v.ui64 = S->N; \
71 + if (g_hrtime_fmt == KS_HRFMT_DEFAULT) { \
72 + nvpair_insert(I, #N, &v, KSTAT_DATA_UINT64); \
73 + } else { \
74 + nvpair_insert(I, #N, &v, KSTAT_DATA_TIME); \
75 + } \
72 76 }
73 77
74 78 #define SAVE_INT32(I, S, N) \
75 79 { \
76 80 ks_value_t v; \
77 81 v.i32 = S->N; \
78 82 nvpair_insert(I, #N, &v, KSTAT_DATA_INT32); \
79 83 }
80 84
81 85 #define SAVE_UINT32(I, S, N) \
82 86 { \
83 87 ks_value_t v; \
84 88 v.ui32 = S->N; \
85 89 nvpair_insert(I, #N, &v, KSTAT_DATA_UINT32); \
86 90 }
87 91
88 92 #define SAVE_INT64(I, S, N) \
89 93 { \
90 94 ks_value_t v; \
91 95 v.i64 = S->N; \
92 96 nvpair_insert(I, #N, &v, KSTAT_DATA_INT64); \
93 97 }
94 98
95 99 #define SAVE_UINT64(I, S, N) \
96 100 { \
97 101 ks_value_t v; \
98 102 v.ui64 = S->N; \
99 103 nvpair_insert(I, #N, &v, KSTAT_DATA_UINT64); \
100 104 }
101 105
102 106 /*
103 107 * We dont want const "strings" because we free
104 108 * the instances later.
105 109 */
106 110 #define SAVE_STRING(I, S, N) \
107 111 { \
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
108 112 ks_value_t v; \
109 113 v.str.addr.ptr = safe_strdup(S->N); \
110 114 v.str.len = strlen(S->N); \
111 115 nvpair_insert(I, #N, &v, KSTAT_DATA_STRING); \
112 116 }
113 117
114 118 #define SAVE_HRTIME_X(I, N, V) \
115 119 { \
116 120 ks_value_t v; \
117 121 v.ui64 = V; \
118 - nvpair_insert(I, N, &v, KSTAT_DATA_HRTIME); \
122 + nvpair_insert(I, N, &v, KSTAT_DATA_TIME); \
119 123 }
120 124
121 125 #define SAVE_INT32_X(I, N, V) \
122 126 { \
123 127 ks_value_t v; \
124 128 v.i32 = V; \
125 129 nvpair_insert(I, N, &v, KSTAT_DATA_INT32); \
126 130 }
127 131
128 132 #define SAVE_UINT32_X(I, N, V) \
129 133 { \
130 134 ks_value_t v; \
131 135 v.ui32 = V; \
132 136 nvpair_insert(I, N, &v, KSTAT_DATA_UINT32); \
133 137 }
134 138
135 139 #define SAVE_UINT64_X(I, N, V) \
136 140 { \
137 141 ks_value_t v; \
138 142 v.ui64 = V; \
139 143 nvpair_insert(I, N, &v, KSTAT_DATA_UINT64); \
140 144 }
141 145
142 146 #define SAVE_STRING_X(I, N, V) \
143 147 { \
144 148 ks_value_t v; \
145 149 v.str.addr.ptr = safe_strdup(V); \
146 150 v.str.len = (V) ? strlen(V) : 0; \
147 151 nvpair_insert(I, N, &v, KSTAT_DATA_STRING); \
148 152 }
149 153
150 154 #define SAVE_CHAR_X(I, N, V) \
151 155 { \
152 156 ks_value_t v; \
153 157 (void) asprintf(&v.str.addr.ptr, "%c", V); \
154 158 v.str.len = 1; \
155 159 nvpair_insert(I, N, &v, KSTAT_DATA_STRING); \
156 160 }
157 161
158 162 #define DFLT_FMT \
159 163 "module: %-30.30s instance: %-6d\n" \
160 164 "name: %-30.30s class: %-.30s\n"
161 165
162 166 #define JSON_FMT \
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
163 167 "{\n\t\"module\": \"%s\",\n" \
164 168 "\t\"instance\": %d,\n" \
165 169 "\t\"name\": \"%s\",\n" \
166 170 "\t\"class\": \"%s\",\n" \
167 171 "\t\"type\": %d,\n"
168 172
169 173 #define KS_DFMT "\t%-30s "
170 174 #define KS_JFMT "\t\t\"%s\": "
171 175 #define KS_PFMT "%s:%d:%s:%s"
172 176
177 +#define KS_HRFMT_DEFAULT 'o'
178 +#define KS_HRFMT_BOOT 'b'
179 +#define KS_HRFMT_UNIX 'u'
180 +#define KS_HRFMT_DATE 'd'
181 +#define KS_HRFMT_NANO 'n'
182 +#define KS_HRFMT_ISO 'I'
183 +#define KS_HRFMT_ZISO 'Z'
184 +
173 185 typedef struct ks_instance {
174 186 list_node_t ks_next;
175 187 char ks_name[KSTAT_STRLEN];
176 188 char ks_module[KSTAT_STRLEN];
177 189 char ks_class[KSTAT_STRLEN];
178 190 int ks_instance;
179 191 uchar_t ks_type;
180 192 hrtime_t ks_snaptime;
181 193 list_t ks_nvlist;
182 194 } ks_instance_t;
183 195
184 196 typedef struct ks_nvpair {
185 197 list_node_t nv_next;
186 198 char name[KSTAT_STRLEN];
187 199 uchar_t data_type;
188 200 ks_value_t value;
189 201 } ks_nvpair_t;
190 202
191 203 typedef struct ks_pattern {
192 204 char *pstr;
193 205 regex_t preg;
194 206 } ks_pattern_t;
195 207
196 208 typedef struct ks_selector {
197 209 list_node_t ks_next;
198 210 ks_pattern_t ks_module;
199 211 ks_pattern_t ks_instance;
200 212 ks_pattern_t ks_name;
201 213 ks_pattern_t ks_statistic;
202 214 } ks_selector_t;
203 215
204 216 static void usage(void);
205 217 static int compare_instances(ks_instance_t *, ks_instance_t *);
206 218 static void nvpair_insert(ks_instance_t *, char *, ks_value_t *, uchar_t);
207 219 static boolean_t ks_match(const char *, ks_pattern_t *);
208 220 static ks_selector_t *new_selector(void);
209 221 static void ks_instances_read(kstat_ctl_t *);
210 222 static void ks_value_print(ks_nvpair_t *);
211 223 static void ks_instance_print(ks_instance_t *, ks_nvpair_t *);
212 224 static void ks_instances_print(void);
213 225 static char *ks_safe_strdup(char *);
214 226 static void ks_sleep_until(hrtime_t *, hrtime_t, int, int *);
215 227
216 228 /* Raw kstat readers */
217 229 static void save_cpu_stat(kstat_t *, ks_instance_t *);
218 230 static void save_var(kstat_t *, ks_instance_t *);
219 231 static void save_ncstats(kstat_t *, ks_instance_t *);
220 232 static void save_sysinfo(kstat_t *, ks_instance_t *);
221 233 static void save_vminfo(kstat_t *, ks_instance_t *);
222 234 static void save_nfs(kstat_t *, ks_instance_t *);
223 235 #ifdef __sparc
224 236 static void save_sfmmu_global_stat(kstat_t *, ks_instance_t *);
225 237 static void save_sfmmu_tsbsize_stat(kstat_t *, ks_instance_t *);
226 238 static void save_simmstat(kstat_t *, ks_instance_t *);
227 239 /* Helper function for save_temperature() */
228 240 static char *short_array_to_string(short *, int);
229 241 static void save_temperature(kstat_t *, ks_instance_t *);
230 242 static void save_temp_over(kstat_t *, ks_instance_t *);
231 243 static void save_ps_shadow(kstat_t *, ks_instance_t *);
232 244 static void save_fault_list(kstat_t *, ks_instance_t *);
233 245 #endif
234 246
235 247 /* Named kstat readers */
236 248 static void save_named(kstat_t *, ks_instance_t *);
237 249 static void save_intr(kstat_t *, ks_instance_t *);
238 250 static void save_io(kstat_t *, ks_instance_t *);
239 251 static void save_timer(kstat_t *, ks_instance_t *);
240 252
241 253 /* Typedef for raw kstat reader functions */
242 254 typedef void (*kstat_raw_reader_t)(kstat_t *, ks_instance_t *);
243 255
244 256 static struct {
245 257 kstat_raw_reader_t fn;
246 258 char *name;
247 259 } ks_raw_lookup[] = {
248 260 /* Function name kstat name */
249 261 {save_cpu_stat, "cpu_stat:cpu_stat"},
250 262 {save_var, "unix:var"},
251 263 {save_ncstats, "unix:ncstats"},
252 264 {save_sysinfo, "unix:sysinfo"},
253 265 {save_vminfo, "unix:vminfo"},
254 266 {save_nfs, "nfs:mntinfo"},
255 267 #ifdef __sparc
256 268 {save_sfmmu_global_stat, "unix:sfmmu_global_stat"},
257 269 {save_sfmmu_tsbsize_stat, "unix:sfmmu_tsbsize_stat"},
258 270 {save_simmstat, "unix:simm-status"},
259 271 {save_temperature, "unix:temperature"},
260 272 {save_temp_over, "unix:temperature override"},
261 273 {save_ps_shadow, "unix:ps_shadow"},
262 274 {save_fault_list, "unix:fault_list"},
263 275 #endif
264 276 {NULL, NULL},
265 277 };
266 278
267 279 static kstat_raw_reader_t lookup_raw_kstat_fn(char *, char *);
268 280
269 281 #endif /* _STAT_KSTAT_H */
↓ open down ↓ |
87 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX