Print this page
3724 kstat reports idle time as io_wait, kernel as pio_wait, etc
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/stat/kstat/kstat.c
+++ new/usr/src/cmd/stat/kstat/kstat.c
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.
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 /*
23 23 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright (c) 2013 David Hoeppner. All rights reserved.
25 25 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
26 26 */
27 27
28 28 /*
29 29 * Display kernel statistics
30 30 *
31 31 * This is a reimplementation of the perl kstat command originally found
32 32 * under usr/src/cmd/kstat/kstat.pl
33 33 *
34 34 * Incompatibilities:
35 35 * - perl regular expressions replaced with extended REs bracketed by '/'
36 36 *
37 37 * Flags added:
38 38 * -C similar to the -p option but value is separated by a colon
39 39 * -h display help
40 40 * -j json format
41 41 */
42 42
43 43 #include <assert.h>
44 44 #include <ctype.h>
45 45 #include <errno.h>
46 46 #include <kstat.h>
47 47 #include <langinfo.h>
48 48 #include <libgen.h>
49 49 #include <limits.h>
50 50 #include <locale.h>
51 51 #include <signal.h>
52 52 #include <stddef.h>
53 53 #include <stdio.h>
54 54 #include <stdlib.h>
55 55 #include <string.h>
56 56 #include <strings.h>
57 57 #include <time.h>
58 58 #include <unistd.h>
59 59 #include <sys/list.h>
60 60 #include <sys/time.h>
61 61 #include <sys/types.h>
62 62
63 63 #include "kstat.h"
64 64 #include "statcommon.h"
65 65
66 66 char *cmdname = "kstat"; /* Name of this command */
67 67 int caught_cont = 0; /* Have caught a SIGCONT */
68 68
69 69 static uint_t g_timestamp_fmt = NODATE;
70 70
71 71 /* Helper flag - header was printed already? */
72 72 static boolean_t g_headerflg;
73 73
74 74 /* Saved command line options */
75 75 static boolean_t g_cflg = B_FALSE;
76 76 static boolean_t g_jflg = B_FALSE;
77 77 static boolean_t g_lflg = B_FALSE;
78 78 static boolean_t g_pflg = B_FALSE;
79 79 static boolean_t g_qflg = B_FALSE;
80 80 static ks_pattern_t g_ks_class = {"*", 0};
81 81
82 82 /* Return zero if a selector did match */
83 83 static int g_matched = 1;
84 84
85 85 /* Sorted list of kstat instances */
86 86 static list_t instances_list;
87 87 static list_t selector_list;
88 88
89 89 int
90 90 main(int argc, char **argv)
91 91 {
92 92 ks_selector_t *nselector;
93 93 ks_selector_t *uselector;
94 94 kstat_ctl_t *kc;
95 95 hrtime_t start_n;
96 96 hrtime_t period_n;
97 97 boolean_t errflg = B_FALSE;
98 98 boolean_t nselflg = B_FALSE;
99 99 boolean_t uselflg = B_FALSE;
100 100 char *q;
101 101 int count = 1;
102 102 int infinite_cycles = 0;
103 103 int interval = 0;
104 104 int n = 0;
105 105 int c, m, tmp;
106 106
107 107 (void) setlocale(LC_ALL, "");
108 108 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
109 109 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
110 110 #endif
111 111 (void) textdomain(TEXT_DOMAIN);
112 112
113 113 /*
114 114 * Create the selector list and a dummy default selector to match
115 115 * everything. While we process the cmdline options we will add
116 116 * selectors to this list.
117 117 */
118 118 list_create(&selector_list, sizeof (ks_selector_t),
119 119 offsetof(ks_selector_t, ks_next));
120 120
121 121 nselector = new_selector();
122 122
123 123 /*
124 124 * Parse named command line arguments.
125 125 */
126 126 while ((c = getopt(argc, argv, "h?CqjlpT:m:i:n:s:c:")) != EOF)
127 127 switch (c) {
128 128 case 'h':
129 129 case '?':
130 130 usage();
131 131 exit(0);
132 132 break;
133 133 case 'C':
134 134 g_pflg = g_cflg = B_TRUE;
135 135 break;
136 136 case 'q':
137 137 g_qflg = B_TRUE;
138 138 break;
139 139 case 'j':
140 140 g_jflg = B_TRUE;
141 141 break;
142 142 case 'l':
143 143 g_pflg = g_lflg = B_TRUE;
144 144 break;
145 145 case 'p':
146 146 g_pflg = B_TRUE;
147 147 break;
148 148 case 'T':
149 149 switch (*optarg) {
150 150 case 'd':
151 151 g_timestamp_fmt = DDATE;
152 152 break;
153 153 case 'u':
154 154 g_timestamp_fmt = UDATE;
155 155 break;
156 156 default:
157 157 errflg = B_TRUE;
158 158 }
159 159 break;
160 160 case 'm':
161 161 nselflg = B_TRUE;
162 162 nselector->ks_module.pstr =
163 163 (char *)ks_safe_strdup(optarg);
164 164 break;
165 165 case 'i':
166 166 nselflg = B_TRUE;
167 167 nselector->ks_instance.pstr =
168 168 (char *)ks_safe_strdup(optarg);
169 169 break;
170 170 case 'n':
171 171 nselflg = B_TRUE;
172 172 nselector->ks_name.pstr =
173 173 (char *)ks_safe_strdup(optarg);
174 174 break;
175 175 case 's':
176 176 nselflg = B_TRUE;
177 177 nselector->ks_statistic.pstr =
178 178 (char *)ks_safe_strdup(optarg);
179 179 break;
180 180 case 'c':
181 181 g_ks_class.pstr =
182 182 (char *)ks_safe_strdup(optarg);
183 183 break;
184 184 default:
185 185 errflg = B_TRUE;
186 186 break;
187 187 }
188 188
189 189 if (g_qflg && (g_jflg || g_pflg)) {
190 190 (void) fprintf(stderr, gettext(
191 191 "-q and -lpj are mutually exclusive\n"));
192 192 errflg = B_TRUE;
193 193 }
194 194
195 195 if (errflg) {
196 196 usage();
197 197 exit(2);
198 198 }
199 199
200 200 argc -= optind;
201 201 argv += optind;
202 202
203 203 /*
204 204 * Consume the rest of the command line. Parsing the
205 205 * unnamed command line arguments.
206 206 */
207 207 while (argc--) {
208 208 errno = 0;
209 209 tmp = strtoul(*argv, &q, 10);
210 210 if (tmp == ULONG_MAX && errno == ERANGE) {
211 211 if (n == 0) {
212 212 (void) fprintf(stderr, gettext(
213 213 "Interval is too large\n"));
214 214 } else if (n == 1) {
215 215 (void) fprintf(stderr, gettext(
216 216 "Count is too large\n"));
217 217 }
218 218 usage();
219 219 exit(2);
220 220 }
221 221
222 222 if (errno != 0 || *q != '\0') {
223 223 m = 0;
224 224 uselector = new_selector();
225 225 while ((q = (char *)strsep(argv, ":")) != NULL) {
226 226 m++;
227 227 if (m > 4) {
228 228 free(uselector);
229 229 usage();
230 230 exit(2);
231 231 }
232 232
233 233 if (*q != '\0') {
234 234 switch (m) {
235 235 case 1:
236 236 uselector->ks_module.pstr =
237 237 (char *)ks_safe_strdup(q);
238 238 break;
239 239 case 2:
240 240 uselector->ks_instance.pstr =
241 241 (char *)ks_safe_strdup(q);
242 242 break;
243 243 case 3:
244 244 uselector->ks_name.pstr =
245 245 (char *)ks_safe_strdup(q);
246 246 break;
247 247 case 4:
248 248 uselector->ks_statistic.pstr =
249 249 (char *)ks_safe_strdup(q);
250 250 break;
251 251 default:
252 252 assert(B_FALSE);
253 253 }
254 254 }
255 255 }
256 256
257 257 uselflg = B_TRUE;
258 258 list_insert_tail(&selector_list, uselector);
259 259 } else {
260 260 if (tmp < 1) {
261 261 if (n == 0) {
262 262 (void) fprintf(stderr, gettext(
263 263 "Interval must be an "
264 264 "integer >= 1"));
265 265 } else if (n == 1) {
266 266 (void) fprintf(stderr, gettext(
267 267 "Count must be an integer >= 1"));
268 268 }
269 269 usage();
270 270 exit(2);
271 271 } else {
272 272 if (n == 0) {
273 273 interval = tmp;
274 274 count = -1;
275 275 } else if (n == 1) {
276 276 count = tmp;
277 277 } else {
278 278 usage();
279 279 exit(2);
280 280 }
281 281 }
282 282 n++;
283 283 }
284 284 argv++;
285 285 }
286 286
287 287 /*
288 288 * Check if we founded a named selector on the cmdline.
289 289 */
290 290 if (uselflg) {
291 291 if (nselflg) {
292 292 (void) fprintf(stderr, gettext(
293 293 "[module[:instance[:name[:statistic]]]] and "
294 294 "-m -i -n -s are mutually exclusive"));
295 295 usage();
296 296 exit(2);
297 297 } else {
298 298 free(nselector);
299 299 }
300 300 } else {
301 301 list_insert_tail(&selector_list, nselector);
302 302 }
303 303
304 304 assert(!list_is_empty(&selector_list));
305 305
306 306 list_create(&instances_list, sizeof (ks_instance_t),
307 307 offsetof(ks_instance_t, ks_next));
308 308
309 309 while ((kc = kstat_open()) == NULL) {
310 310 if (errno == EAGAIN) {
311 311 (void) poll(NULL, 0, 200);
312 312 } else {
313 313 perror("kstat_open");
314 314 exit(3);
315 315 }
316 316 }
317 317
318 318 if (count > 1) {
319 319 if (signal(SIGCONT, cont_handler) == SIG_ERR) {
320 320 (void) fprintf(stderr, gettext(
321 321 "signal failed"));
322 322 exit(3);
323 323 }
324 324 }
325 325
326 326 period_n = (hrtime_t)interval * NANOSEC;
327 327 start_n = gethrtime();
328 328
329 329 while (count == -1 || count-- > 0) {
330 330 ks_instances_read(kc);
331 331 ks_instances_print();
332 332
333 333 if (interval && count) {
334 334 ks_sleep_until(&start_n, period_n, infinite_cycles,
335 335 &caught_cont);
336 336 (void) kstat_chain_update(kc);
337 337 (void) putchar('\n');
338 338 }
339 339 }
340 340
341 341 (void) kstat_close(kc);
342 342
343 343 return (g_matched);
344 344 }
345 345
346 346 /*
347 347 * Print usage.
348 348 */
349 349 static void
350 350 usage(void)
351 351 {
352 352 (void) fprintf(stderr, gettext(
353 353 "Usage:\n"
354 354 "kstat [ -Cjlpq ] [ -T d|u ] [ -c class ]\n"
355 355 " [ -m module ] [ -i instance ] [ -n name ] [ -s statistic ]\n"
356 356 " [ interval [ count ] ]\n"
357 357 "kstat [ -Cjlpq ] [ -T d|u ] [ -c class ]\n"
358 358 " [ module[:instance[:name[:statistic]]] ... ]\n"
359 359 " [ interval [ count ] ]\n"));
360 360 }
361 361
362 362 /*
363 363 * Sort compare function.
364 364 */
365 365 static int
366 366 compare_instances(ks_instance_t *l_arg, ks_instance_t *r_arg)
367 367 {
368 368 int rval;
369 369
370 370 rval = strcasecmp(l_arg->ks_module, r_arg->ks_module);
371 371 if (rval == 0) {
372 372 if (l_arg->ks_instance == r_arg->ks_instance) {
373 373 return (strcasecmp(l_arg->ks_name, r_arg->ks_name));
374 374 } else if (l_arg->ks_instance < r_arg->ks_instance) {
375 375 return (-1);
376 376 } else {
377 377 return (1);
378 378 }
379 379 } else {
380 380 return (rval);
381 381 }
382 382 }
383 383
384 384 static char *
385 385 ks_safe_strdup(char *str)
386 386 {
387 387 char *ret;
388 388
389 389 if (str == NULL) {
390 390 return (NULL);
391 391 }
392 392
393 393 while ((ret = strdup(str)) == NULL) {
394 394 if (errno == EAGAIN) {
395 395 (void) poll(NULL, 0, 200);
396 396 } else {
397 397 perror("strdup");
398 398 exit(3);
399 399 }
400 400 }
401 401
402 402 return (ret);
403 403 }
404 404
405 405 static void
406 406 ks_sleep_until(hrtime_t *wakeup, hrtime_t interval, int forever,
407 407 int *caught_cont)
408 408 {
409 409 hrtime_t now, pause, pause_left;
410 410 struct timespec pause_tv;
411 411 int status;
412 412
413 413 now = gethrtime();
414 414 pause = *wakeup + interval - now;
415 415
416 416 if (pause <= 0 || pause < (interval / 4)) {
417 417 if (forever || *caught_cont) {
418 418 *wakeup = now + interval;
419 419 pause = interval;
420 420 } else {
421 421 pause = interval / 2;
422 422 *wakeup += interval;
423 423 }
424 424 } else {
425 425 *wakeup += interval;
426 426 }
427 427
428 428 if (pause < 1000) {
429 429 return;
430 430 }
431 431
432 432 pause_left = pause;
433 433 do {
434 434 pause_tv.tv_sec = pause_left / NANOSEC;
435 435 pause_tv.tv_nsec = pause_left % NANOSEC;
436 436 status = nanosleep(&pause_tv, (struct timespec *)NULL);
437 437 if (status < 0) {
438 438 if (errno == EINTR) {
439 439 now = gethrtime();
440 440 pause_left = *wakeup - now;
441 441 if (pause_left < 1000) {
442 442 return;
443 443 }
444 444 } else {
445 445 perror("nanosleep");
446 446 exit(3);
447 447 }
448 448 }
449 449 } while (status != 0);
450 450 }
451 451
452 452 /*
453 453 * Inserts an instance in the per selector list.
454 454 */
455 455 static void
456 456 nvpair_insert(ks_instance_t *ksi, char *name, ks_value_t *value,
457 457 uchar_t data_type)
458 458 {
459 459 ks_nvpair_t *instance;
460 460 ks_nvpair_t *tmp;
461 461
462 462 instance = (ks_nvpair_t *)malloc(sizeof (ks_nvpair_t));
463 463 if (instance == NULL) {
464 464 perror("malloc");
465 465 exit(3);
466 466 }
467 467
468 468 (void) strlcpy(instance->name, name, KSTAT_STRLEN);
469 469 (void) memcpy(&instance->value, value, sizeof (ks_value_t));
470 470 instance->data_type = data_type;
471 471
472 472 tmp = list_head(&ksi->ks_nvlist);
473 473 while (tmp != NULL && strcasecmp(instance->name, tmp->name) > 0)
474 474 tmp = list_next(&ksi->ks_nvlist, tmp);
475 475
476 476 list_insert_before(&ksi->ks_nvlist, tmp, instance);
477 477 }
478 478
479 479 /*
480 480 * Allocates a new all-matching selector.
481 481 */
482 482 static ks_selector_t *
483 483 new_selector(void)
484 484 {
485 485 ks_selector_t *selector;
486 486
487 487 selector = (ks_selector_t *)malloc(sizeof (ks_selector_t));
488 488 if (selector == NULL) {
489 489 perror("malloc");
490 490 exit(3);
491 491 }
492 492
493 493 list_link_init(&selector->ks_next);
494 494
495 495 selector->ks_module.pstr = "*";
496 496 selector->ks_instance.pstr = "*";
497 497 selector->ks_name.pstr = "*";
498 498 selector->ks_statistic.pstr = "*";
499 499
500 500 return (selector);
501 501 }
502 502
503 503 /*
504 504 * This function was taken from the perl kstat module code - please
505 505 * see for further comments there.
506 506 */
507 507 static kstat_raw_reader_t
508 508 lookup_raw_kstat_fn(char *module, char *name)
509 509 {
510 510 char key[KSTAT_STRLEN * 2];
511 511 register char *f, *t;
512 512 int n = 0;
513 513
514 514 for (f = module, t = key; *f != '\0'; f++, t++) {
515 515 while (*f != '\0' && isdigit(*f))
516 516 f++;
517 517 *t = *f;
518 518 }
519 519 *t++ = ':';
520 520
521 521 for (f = name; *f != '\0'; f++, t++) {
522 522 while (*f != '\0' && isdigit(*f))
523 523 f++;
524 524 *t = *f;
525 525 }
526 526 *t = '\0';
527 527
528 528 while (ks_raw_lookup[n].fn != NULL) {
529 529 if (strncmp(ks_raw_lookup[n].name, key, strlen(key)) == 0)
530 530 return (ks_raw_lookup[n].fn);
531 531 n++;
532 532 }
533 533
534 534 return (0);
535 535 }
536 536
537 537 /*
538 538 * Match a string against a shell glob or extended regular expression.
539 539 */
540 540 static boolean_t
541 541 ks_match(const char *str, ks_pattern_t *pattern)
542 542 {
543 543 int regcode;
544 544 char *regstr;
545 545 char *errbuf;
546 546 size_t bufsz;
547 547
548 548 if (pattern->pstr != NULL && gmatch(pattern->pstr, "/*/") != 0) {
549 549 /* All regex patterns are strdup'd copies */
550 550 regstr = pattern->pstr + 1;
551 551 *(strrchr(regstr, '/')) = '\0';
552 552
553 553 regcode = regcomp(&pattern->preg, regstr,
554 554 REG_EXTENDED | REG_NOSUB);
555 555 if (regcode != 0) {
556 556 bufsz = regerror(regcode, NULL, NULL, 0);
557 557 if (bufsz != 0) {
558 558 errbuf = malloc(bufsz);
559 559 if (errbuf == NULL) {
560 560 perror("malloc");
561 561 exit(3);
562 562 }
563 563 (void) regerror(regcode, NULL, errbuf, bufsz);
564 564 (void) fprintf(stderr, "kstat: %s\n", errbuf);
565 565 }
566 566 usage();
567 567 exit(2);
568 568 }
569 569
570 570 pattern->pstr = NULL;
571 571 }
572 572
573 573 if (pattern->pstr == NULL) {
574 574 return (regexec(&pattern->preg, str, 0, NULL, 0) == 0);
575 575 }
576 576
577 577 return ((gmatch(str, pattern->pstr) != 0));
578 578 }
579 579
580 580 /*
581 581 * Iterate over all kernel statistics and save matches.
582 582 */
583 583 static void
584 584 ks_instances_read(kstat_ctl_t *kc)
585 585 {
586 586 kstat_raw_reader_t save_raw = NULL;
587 587 kid_t id;
588 588 ks_selector_t *selector;
589 589 ks_instance_t *ksi;
590 590 ks_instance_t *tmp;
591 591 kstat_t *kp;
592 592 boolean_t skip;
593 593
594 594 for (kp = kc->kc_chain; kp != NULL; kp = kp->ks_next) {
595 595 /* Don't bother storing the kstat headers */
596 596 if (strncmp(kp->ks_name, "kstat_", 6) == 0) {
597 597 continue;
598 598 }
599 599
600 600 /* Don't bother storing raw stats we don't understand */
601 601 if (kp->ks_type == KSTAT_TYPE_RAW) {
602 602 save_raw = lookup_raw_kstat_fn(kp->ks_module,
603 603 kp->ks_name);
604 604 if (save_raw == NULL) {
605 605 #ifdef REPORT_UNKNOWN
606 606 (void) fprintf(stderr,
607 607 "Unknown kstat type %s:%d:%s - "
608 608 "%d of size %d\n", kp->ks_module,
609 609 kp->ks_instance, kp->ks_name,
610 610 kp->ks_ndata, kp->ks_data_size);
611 611 #endif
612 612 continue;
613 613 }
614 614 }
615 615
616 616 /*
617 617 * Iterate over the list of selectors and skip
618 618 * instances we dont want. We filter for statistics
619 619 * later, as we dont know them yet.
620 620 */
621 621 skip = B_TRUE;
622 622 selector = list_head(&selector_list);
623 623 while (selector != NULL) {
624 624 if (ks_match(kp->ks_module, &selector->ks_module) ||
625 625 ks_match(kp->ks_name, &selector->ks_name)) {
626 626 skip = B_FALSE;
627 627 break;
628 628 }
629 629 selector = list_next(&selector_list, selector);
630 630 }
631 631
632 632 if (skip) {
633 633 continue;
634 634 }
635 635
636 636 /*
637 637 * Allocate a new instance and fill in the values
638 638 * we know so far.
639 639 */
640 640 ksi = (ks_instance_t *)malloc(sizeof (ks_instance_t));
641 641 if (ksi == NULL) {
642 642 perror("malloc");
643 643 exit(3);
644 644 }
645 645
646 646 list_link_init(&ksi->ks_next);
647 647
648 648 (void) strlcpy(ksi->ks_module, kp->ks_module, KSTAT_STRLEN);
649 649 (void) strlcpy(ksi->ks_name, kp->ks_name, KSTAT_STRLEN);
650 650 (void) strlcpy(ksi->ks_class, kp->ks_class, KSTAT_STRLEN);
651 651
652 652 ksi->ks_instance = kp->ks_instance;
653 653 ksi->ks_snaptime = kp->ks_snaptime;
654 654 ksi->ks_type = kp->ks_type;
655 655
656 656 list_create(&ksi->ks_nvlist, sizeof (ks_nvpair_t),
657 657 offsetof(ks_nvpair_t, nv_next));
658 658
659 659 SAVE_HRTIME_X(ksi, "crtime", kp->ks_crtime);
660 660 SAVE_HRTIME_X(ksi, "snaptime", kp->ks_snaptime);
661 661 if (g_pflg) {
662 662 SAVE_STRING_X(ksi, "class", kp->ks_class);
663 663 }
664 664
665 665 /* Insert this instance into a sorted list */
666 666 tmp = list_head(&instances_list);
667 667 while (tmp != NULL && compare_instances(ksi, tmp) > 0)
668 668 tmp = list_next(&instances_list, tmp);
669 669
670 670 list_insert_before(&instances_list, tmp, ksi);
671 671
672 672 /* Read the actual statistics */
673 673 id = kstat_read(kc, kp, NULL);
674 674 if (id == -1) {
675 675 #ifdef REPORT_UNKNOWN
676 676 perror("kstat_read");
677 677 #endif
678 678 continue;
679 679 }
680 680
681 681 switch (kp->ks_type) {
682 682 case KSTAT_TYPE_RAW:
683 683 save_raw(kp, ksi);
684 684 break;
685 685 case KSTAT_TYPE_NAMED:
686 686 save_named(kp, ksi);
687 687 break;
688 688 case KSTAT_TYPE_INTR:
689 689 save_intr(kp, ksi);
690 690 break;
691 691 case KSTAT_TYPE_IO:
692 692 save_io(kp, ksi);
693 693 break;
694 694 case KSTAT_TYPE_TIMER:
695 695 save_timer(kp, ksi);
696 696 break;
697 697 default:
698 698 assert(B_FALSE); /* Invalid type */
699 699 break;
700 700 }
701 701 }
702 702 }
703 703
704 704 /*
705 705 * Print the value of a name-value pair.
706 706 */
707 707 static void
708 708 ks_value_print(ks_nvpair_t *nvpair)
709 709 {
710 710 switch (nvpair->data_type) {
711 711 case KSTAT_DATA_CHAR:
712 712 (void) fprintf(stdout, "%s", nvpair->value.c);
713 713 break;
714 714 case KSTAT_DATA_INT32:
715 715 (void) fprintf(stdout, "%d", nvpair->value.i32);
716 716 break;
717 717 case KSTAT_DATA_UINT32:
718 718 (void) fprintf(stdout, "%u", nvpair->value.ui32);
719 719 break;
720 720 case KSTAT_DATA_INT64:
721 721 (void) fprintf(stdout, "%lld", nvpair->value.i64);
722 722 break;
723 723 case KSTAT_DATA_UINT64:
724 724 (void) fprintf(stdout, "%llu", nvpair->value.ui64);
725 725 break;
726 726 case KSTAT_DATA_STRING:
727 727 (void) fprintf(stdout, "%s", KSTAT_NAMED_STR_PTR(nvpair));
728 728 break;
729 729 case KSTAT_DATA_HRTIME:
730 730 if (nvpair->value.ui64 == 0)
731 731 (void) fprintf(stdout, "0");
732 732 else
733 733 (void) fprintf(stdout, "%.9f",
734 734 nvpair->value.ui64 / 1000000000.0);
735 735 break;
736 736 default:
737 737 assert(B_FALSE);
738 738 }
739 739 }
740 740
741 741 /*
742 742 * Print a single instance.
743 743 */
744 744 static void
745 745 ks_instance_print(ks_instance_t *ksi, ks_nvpair_t *nvpair)
746 746 {
747 747 if (g_headerflg) {
748 748 if (!g_pflg) {
749 749 (void) fprintf(stdout, DFLT_FMT,
750 750 ksi->ks_module, ksi->ks_instance,
751 751 ksi->ks_name, ksi->ks_class);
752 752 }
753 753 g_headerflg = B_FALSE;
754 754 }
755 755
756 756 if (g_pflg) {
757 757 (void) fprintf(stdout, KS_PFMT,
758 758 ksi->ks_module, ksi->ks_instance,
759 759 ksi->ks_name, nvpair->name);
760 760 if (!g_lflg) {
761 761 (void) putchar(g_cflg ? ':': '\t');
762 762 ks_value_print(nvpair);
763 763 }
764 764 } else {
765 765 (void) fprintf(stdout, KS_DFMT, nvpair->name);
766 766 ks_value_print(nvpair);
767 767 }
768 768
769 769 (void) putchar('\n');
770 770 }
771 771
772 772 /*
773 773 * Print a single instance in JSON format.
774 774 */
775 775 static void
776 776 ks_instance_print_json(ks_instance_t *ksi, ks_nvpair_t *nvpair)
777 777 {
778 778 if (g_headerflg) {
779 779 (void) fprintf(stdout, JSON_FMT,
780 780 ksi->ks_module, ksi->ks_instance,
781 781 ksi->ks_name, ksi->ks_class,
782 782 ksi->ks_type);
783 783
784 784 if (ksi->ks_snaptime == 0)
785 785 (void) fprintf(stdout, "\t\"snaptime\": 0,\n");
786 786 else
787 787 (void) fprintf(stdout, "\t\"snaptime\": %.9f,\n",
788 788 ksi->ks_snaptime / 1000000000.0);
789 789
790 790 (void) fprintf(stdout, "\t\"data\": {\n");
791 791
792 792 g_headerflg = B_FALSE;
793 793 }
794 794
795 795 (void) fprintf(stdout, KS_JFMT, nvpair->name);
796 796 if (nvpair->data_type == KSTAT_DATA_STRING) {
797 797 (void) putchar('\"');
798 798 ks_value_print(nvpair);
799 799 (void) putchar('\"');
800 800 } else {
801 801 ks_value_print(nvpair);
802 802 }
803 803 if (nvpair != list_tail(&ksi->ks_nvlist))
804 804 (void) putchar(',');
805 805
806 806 (void) putchar('\n');
807 807 }
808 808
809 809 /*
810 810 * Print all instances.
811 811 */
812 812 static void
813 813 ks_instances_print(void)
814 814 {
815 815 ks_selector_t *selector;
816 816 ks_instance_t *ksi, *ktmp;
817 817 ks_nvpair_t *nvpair, *ntmp;
818 818 void (*ks_print_fn)(ks_instance_t *, ks_nvpair_t *);
819 819 char *ks_number;
820 820
821 821 if (g_timestamp_fmt != NODATE)
822 822 print_timestamp(g_timestamp_fmt);
823 823
824 824 if (g_jflg) {
825 825 ks_print_fn = &ks_instance_print_json;
826 826 (void) putchar('[');
827 827 } else {
828 828 ks_print_fn = &ks_instance_print;
829 829 }
830 830
831 831 /* Iterate over each selector */
832 832 selector = list_head(&selector_list);
833 833 while (selector != NULL) {
834 834
835 835 /* Iterate over each instance */
836 836 for (ksi = list_head(&instances_list); ksi != NULL;
837 837 ksi = list_next(&instances_list, ksi)) {
838 838
839 839 (void) asprintf(&ks_number, "%d", ksi->ks_instance);
840 840 if (!(ks_match(ksi->ks_module, &selector->ks_module) &&
841 841 ks_match(ksi->ks_name, &selector->ks_name) &&
842 842 ks_match(ks_number, &selector->ks_instance) &&
843 843 ks_match(ksi->ks_class, &g_ks_class))) {
844 844 free(ks_number);
845 845 continue;
846 846 }
847 847
848 848 free(ks_number);
849 849
850 850 /* Finally iterate over each statistic */
851 851 g_headerflg = B_TRUE;
852 852 for (nvpair = list_head(&ksi->ks_nvlist);
853 853 nvpair != NULL;
854 854 nvpair = list_next(&ksi->ks_nvlist, nvpair)) {
855 855 if (!ks_match(nvpair->name,
856 856 &selector->ks_statistic))
857 857 continue;
858 858
859 859 g_matched = 0;
860 860 if (!g_qflg)
861 861 (*ks_print_fn)(ksi, nvpair);
862 862 }
863 863
864 864 if (!g_headerflg) {
865 865 if (g_jflg) {
866 866 (void) fprintf(stdout, "\t}\n}");
867 867 if (ksi != list_tail(&instances_list))
868 868 (void) putchar(',');
869 869 } else if (!g_pflg) {
870 870 (void) putchar('\n');
871 871 }
872 872 }
873 873 }
874 874
875 875 selector = list_next(&selector_list, selector);
876 876 }
877 877
878 878 if (g_jflg)
879 879 (void) fprintf(stdout, "]\n");
880 880
881 881 (void) fflush(stdout);
882 882
883 883 /* Free the instances list */
884 884 ksi = list_head(&instances_list);
885 885 while (ksi != NULL) {
886 886 nvpair = list_head(&ksi->ks_nvlist);
887 887 while (nvpair != NULL) {
888 888 ntmp = nvpair;
889 889 nvpair = list_next(&ksi->ks_nvlist, nvpair);
890 890 list_remove(&ksi->ks_nvlist, ntmp);
891 891 if (ntmp->data_type == KSTAT_DATA_STRING)
892 892 free(ntmp->value.str.addr.ptr);
893 893 free(ntmp);
894 894 }
895 895
896 896 ktmp = ksi;
897 897 ksi = list_next(&instances_list, ksi);
898 898 list_remove(&instances_list, ktmp);
899 899 list_destroy(&ktmp->ks_nvlist);
900 900 free(ktmp);
901 901 }
902 902 }
903 903
904 904 static void
905 905 save_cpu_stat(kstat_t *kp, ks_instance_t *ksi)
906 906 {
907 907 cpu_stat_t *stat;
908 908 cpu_sysinfo_t *sysinfo;
909 909 cpu_syswait_t *syswait;
910 910 cpu_vminfo_t *vminfo;
↓ open down ↓ |
910 lines elided |
↑ open up ↑ |
911 911
912 912 stat = (cpu_stat_t *)(kp->ks_data);
913 913 sysinfo = &stat->cpu_sysinfo;
914 914 syswait = &stat->cpu_syswait;
915 915 vminfo = &stat->cpu_vminfo;
916 916
917 917 SAVE_UINT32_X(ksi, "idle", sysinfo->cpu[CPU_IDLE]);
918 918 SAVE_UINT32_X(ksi, "user", sysinfo->cpu[CPU_USER]);
919 919 SAVE_UINT32_X(ksi, "kernel", sysinfo->cpu[CPU_KERNEL]);
920 920 SAVE_UINT32_X(ksi, "wait", sysinfo->cpu[CPU_WAIT]);
921 - SAVE_UINT32_X(ksi, "wait_io", sysinfo->cpu[W_IO]);
922 - SAVE_UINT32_X(ksi, "wait_swap", sysinfo->cpu[W_SWAP]);
923 - SAVE_UINT32_X(ksi, "wait_pio", sysinfo->cpu[W_PIO]);
921 + SAVE_UINT32_X(ksi, "wait_io", sysinfo->wait[W_IO]);
922 + SAVE_UINT32_X(ksi, "wait_swap", sysinfo->wait[W_SWAP]);
923 + SAVE_UINT32_X(ksi, "wait_pio", sysinfo->wait[W_PIO]);
924 924 SAVE_UINT32(ksi, sysinfo, bread);
925 925 SAVE_UINT32(ksi, sysinfo, bwrite);
926 926 SAVE_UINT32(ksi, sysinfo, lread);
927 927 SAVE_UINT32(ksi, sysinfo, lwrite);
928 928 SAVE_UINT32(ksi, sysinfo, phread);
929 929 SAVE_UINT32(ksi, sysinfo, phwrite);
930 930 SAVE_UINT32(ksi, sysinfo, pswitch);
931 931 SAVE_UINT32(ksi, sysinfo, trap);
932 932 SAVE_UINT32(ksi, sysinfo, intr);
933 933 SAVE_UINT32(ksi, sysinfo, syscall);
934 934 SAVE_UINT32(ksi, sysinfo, sysread);
935 935 SAVE_UINT32(ksi, sysinfo, syswrite);
936 936 SAVE_UINT32(ksi, sysinfo, sysfork);
937 937 SAVE_UINT32(ksi, sysinfo, sysvfork);
938 938 SAVE_UINT32(ksi, sysinfo, sysexec);
939 939 SAVE_UINT32(ksi, sysinfo, readch);
940 940 SAVE_UINT32(ksi, sysinfo, writech);
941 941 SAVE_UINT32(ksi, sysinfo, rcvint);
942 942 SAVE_UINT32(ksi, sysinfo, xmtint);
943 943 SAVE_UINT32(ksi, sysinfo, mdmint);
944 944 SAVE_UINT32(ksi, sysinfo, rawch);
945 945 SAVE_UINT32(ksi, sysinfo, canch);
946 946 SAVE_UINT32(ksi, sysinfo, outch);
947 947 SAVE_UINT32(ksi, sysinfo, msg);
948 948 SAVE_UINT32(ksi, sysinfo, sema);
949 949 SAVE_UINT32(ksi, sysinfo, namei);
950 950 SAVE_UINT32(ksi, sysinfo, ufsiget);
951 951 SAVE_UINT32(ksi, sysinfo, ufsdirblk);
952 952 SAVE_UINT32(ksi, sysinfo, ufsipage);
953 953 SAVE_UINT32(ksi, sysinfo, ufsinopage);
954 954 SAVE_UINT32(ksi, sysinfo, inodeovf);
955 955 SAVE_UINT32(ksi, sysinfo, fileovf);
956 956 SAVE_UINT32(ksi, sysinfo, procovf);
957 957 SAVE_UINT32(ksi, sysinfo, intrthread);
958 958 SAVE_UINT32(ksi, sysinfo, intrblk);
959 959 SAVE_UINT32(ksi, sysinfo, idlethread);
960 960 SAVE_UINT32(ksi, sysinfo, inv_swtch);
961 961 SAVE_UINT32(ksi, sysinfo, nthreads);
962 962 SAVE_UINT32(ksi, sysinfo, cpumigrate);
963 963 SAVE_UINT32(ksi, sysinfo, xcalls);
964 964 SAVE_UINT32(ksi, sysinfo, mutex_adenters);
965 965 SAVE_UINT32(ksi, sysinfo, rw_rdfails);
966 966 SAVE_UINT32(ksi, sysinfo, rw_wrfails);
967 967 SAVE_UINT32(ksi, sysinfo, modload);
968 968 SAVE_UINT32(ksi, sysinfo, modunload);
969 969 SAVE_UINT32(ksi, sysinfo, bawrite);
970 970 #ifdef STATISTICS /* see header file */
971 971 SAVE_UINT32(ksi, sysinfo, rw_enters);
972 972 SAVE_UINT32(ksi, sysinfo, win_uo_cnt);
973 973 SAVE_UINT32(ksi, sysinfo, win_uu_cnt);
974 974 SAVE_UINT32(ksi, sysinfo, win_so_cnt);
975 975 SAVE_UINT32(ksi, sysinfo, win_su_cnt);
976 976 SAVE_UINT32(ksi, sysinfo, win_suo_cnt);
977 977 #endif
978 978
979 979 SAVE_INT32(ksi, syswait, iowait);
980 980 SAVE_INT32(ksi, syswait, swap);
981 981 SAVE_INT32(ksi, syswait, physio);
982 982
983 983 SAVE_UINT32(ksi, vminfo, pgrec);
984 984 SAVE_UINT32(ksi, vminfo, pgfrec);
985 985 SAVE_UINT32(ksi, vminfo, pgin);
986 986 SAVE_UINT32(ksi, vminfo, pgpgin);
987 987 SAVE_UINT32(ksi, vminfo, pgout);
988 988 SAVE_UINT32(ksi, vminfo, pgpgout);
989 989 SAVE_UINT32(ksi, vminfo, swapin);
990 990 SAVE_UINT32(ksi, vminfo, pgswapin);
991 991 SAVE_UINT32(ksi, vminfo, swapout);
992 992 SAVE_UINT32(ksi, vminfo, pgswapout);
993 993 SAVE_UINT32(ksi, vminfo, zfod);
994 994 SAVE_UINT32(ksi, vminfo, dfree);
995 995 SAVE_UINT32(ksi, vminfo, scan);
996 996 SAVE_UINT32(ksi, vminfo, rev);
997 997 SAVE_UINT32(ksi, vminfo, hat_fault);
998 998 SAVE_UINT32(ksi, vminfo, as_fault);
999 999 SAVE_UINT32(ksi, vminfo, maj_fault);
1000 1000 SAVE_UINT32(ksi, vminfo, cow_fault);
1001 1001 SAVE_UINT32(ksi, vminfo, prot_fault);
1002 1002 SAVE_UINT32(ksi, vminfo, softlock);
1003 1003 SAVE_UINT32(ksi, vminfo, kernel_asflt);
1004 1004 SAVE_UINT32(ksi, vminfo, pgrrun);
1005 1005 SAVE_UINT32(ksi, vminfo, execpgin);
1006 1006 SAVE_UINT32(ksi, vminfo, execpgout);
1007 1007 SAVE_UINT32(ksi, vminfo, execfree);
1008 1008 SAVE_UINT32(ksi, vminfo, anonpgin);
1009 1009 SAVE_UINT32(ksi, vminfo, anonpgout);
1010 1010 SAVE_UINT32(ksi, vminfo, anonfree);
1011 1011 SAVE_UINT32(ksi, vminfo, fspgin);
1012 1012 SAVE_UINT32(ksi, vminfo, fspgout);
1013 1013 SAVE_UINT32(ksi, vminfo, fsfree);
1014 1014 }
1015 1015
1016 1016 static void
1017 1017 save_var(kstat_t *kp, ks_instance_t *ksi)
1018 1018 {
1019 1019 struct var *var = (struct var *)(kp->ks_data);
1020 1020
1021 1021 assert(kp->ks_data_size == sizeof (struct var));
1022 1022
1023 1023 SAVE_INT32(ksi, var, v_buf);
1024 1024 SAVE_INT32(ksi, var, v_call);
1025 1025 SAVE_INT32(ksi, var, v_proc);
1026 1026 SAVE_INT32(ksi, var, v_maxupttl);
1027 1027 SAVE_INT32(ksi, var, v_nglobpris);
1028 1028 SAVE_INT32(ksi, var, v_maxsyspri);
1029 1029 SAVE_INT32(ksi, var, v_clist);
1030 1030 SAVE_INT32(ksi, var, v_maxup);
1031 1031 SAVE_INT32(ksi, var, v_hbuf);
1032 1032 SAVE_INT32(ksi, var, v_hmask);
1033 1033 SAVE_INT32(ksi, var, v_pbuf);
1034 1034 SAVE_INT32(ksi, var, v_sptmap);
1035 1035 SAVE_INT32(ksi, var, v_maxpmem);
1036 1036 SAVE_INT32(ksi, var, v_autoup);
1037 1037 SAVE_INT32(ksi, var, v_bufhwm);
1038 1038 }
1039 1039
1040 1040 static void
1041 1041 save_ncstats(kstat_t *kp, ks_instance_t *ksi)
1042 1042 {
1043 1043 struct ncstats *ncstats = (struct ncstats *)(kp->ks_data);
1044 1044
1045 1045 assert(kp->ks_data_size == sizeof (struct ncstats));
1046 1046
1047 1047 SAVE_INT32(ksi, ncstats, hits);
1048 1048 SAVE_INT32(ksi, ncstats, misses);
1049 1049 SAVE_INT32(ksi, ncstats, enters);
1050 1050 SAVE_INT32(ksi, ncstats, dbl_enters);
1051 1051 SAVE_INT32(ksi, ncstats, long_enter);
1052 1052 SAVE_INT32(ksi, ncstats, long_look);
1053 1053 SAVE_INT32(ksi, ncstats, move_to_front);
1054 1054 SAVE_INT32(ksi, ncstats, purges);
1055 1055 }
1056 1056
1057 1057 static void
1058 1058 save_sysinfo(kstat_t *kp, ks_instance_t *ksi)
1059 1059 {
1060 1060 sysinfo_t *sysinfo = (sysinfo_t *)(kp->ks_data);
1061 1061
1062 1062 assert(kp->ks_data_size == sizeof (sysinfo_t));
1063 1063
1064 1064 SAVE_UINT32(ksi, sysinfo, updates);
1065 1065 SAVE_UINT32(ksi, sysinfo, runque);
1066 1066 SAVE_UINT32(ksi, sysinfo, runocc);
1067 1067 SAVE_UINT32(ksi, sysinfo, swpque);
1068 1068 SAVE_UINT32(ksi, sysinfo, swpocc);
1069 1069 SAVE_UINT32(ksi, sysinfo, waiting);
1070 1070 }
1071 1071
1072 1072 static void
1073 1073 save_vminfo(kstat_t *kp, ks_instance_t *ksi)
1074 1074 {
1075 1075 vminfo_t *vminfo = (vminfo_t *)(kp->ks_data);
1076 1076
1077 1077 assert(kp->ks_data_size == sizeof (vminfo_t));
1078 1078
1079 1079 SAVE_UINT64(ksi, vminfo, freemem);
1080 1080 SAVE_UINT64(ksi, vminfo, swap_resv);
1081 1081 SAVE_UINT64(ksi, vminfo, swap_alloc);
1082 1082 SAVE_UINT64(ksi, vminfo, swap_avail);
1083 1083 SAVE_UINT64(ksi, vminfo, swap_free);
1084 1084 SAVE_UINT64(ksi, vminfo, updates);
1085 1085 }
1086 1086
1087 1087 static void
1088 1088 save_nfs(kstat_t *kp, ks_instance_t *ksi)
1089 1089 {
1090 1090 struct mntinfo_kstat *mntinfo = (struct mntinfo_kstat *)(kp->ks_data);
1091 1091
1092 1092 assert(kp->ks_data_size == sizeof (struct mntinfo_kstat));
1093 1093
1094 1094 SAVE_STRING(ksi, mntinfo, mik_proto);
1095 1095 SAVE_UINT32(ksi, mntinfo, mik_vers);
1096 1096 SAVE_UINT32(ksi, mntinfo, mik_flags);
1097 1097 SAVE_UINT32(ksi, mntinfo, mik_secmod);
1098 1098 SAVE_UINT32(ksi, mntinfo, mik_curread);
1099 1099 SAVE_UINT32(ksi, mntinfo, mik_curwrite);
1100 1100 SAVE_INT32(ksi, mntinfo, mik_timeo);
1101 1101 SAVE_INT32(ksi, mntinfo, mik_retrans);
1102 1102 SAVE_UINT32(ksi, mntinfo, mik_acregmin);
1103 1103 SAVE_UINT32(ksi, mntinfo, mik_acregmax);
1104 1104 SAVE_UINT32(ksi, mntinfo, mik_acdirmin);
1105 1105 SAVE_UINT32(ksi, mntinfo, mik_acdirmax);
1106 1106 SAVE_UINT32_X(ksi, "lookup_srtt", mntinfo->mik_timers[0].srtt);
1107 1107 SAVE_UINT32_X(ksi, "lookup_deviate", mntinfo->mik_timers[0].deviate);
1108 1108 SAVE_UINT32_X(ksi, "lookup_rtxcur", mntinfo->mik_timers[0].rtxcur);
1109 1109 SAVE_UINT32_X(ksi, "read_srtt", mntinfo->mik_timers[1].srtt);
1110 1110 SAVE_UINT32_X(ksi, "read_deviate", mntinfo->mik_timers[1].deviate);
1111 1111 SAVE_UINT32_X(ksi, "read_rtxcur", mntinfo->mik_timers[1].rtxcur);
1112 1112 SAVE_UINT32_X(ksi, "write_srtt", mntinfo->mik_timers[2].srtt);
1113 1113 SAVE_UINT32_X(ksi, "write_deviate", mntinfo->mik_timers[2].deviate);
1114 1114 SAVE_UINT32_X(ksi, "write_rtxcur", mntinfo->mik_timers[2].rtxcur);
1115 1115 SAVE_UINT32(ksi, mntinfo, mik_noresponse);
1116 1116 SAVE_UINT32(ksi, mntinfo, mik_failover);
1117 1117 SAVE_UINT32(ksi, mntinfo, mik_remap);
1118 1118 SAVE_STRING(ksi, mntinfo, mik_curserver);
1119 1119 }
1120 1120
1121 1121 #ifdef __sparc
1122 1122 static void
1123 1123 save_sfmmu_global_stat(kstat_t *kp, ks_instance_t *ksi)
1124 1124 {
1125 1125 struct sfmmu_global_stat *sfmmug =
1126 1126 (struct sfmmu_global_stat *)(kp->ks_data);
1127 1127
1128 1128 assert(kp->ks_data_size == sizeof (struct sfmmu_global_stat));
1129 1129
1130 1130 SAVE_INT32(ksi, sfmmug, sf_tsb_exceptions);
1131 1131 SAVE_INT32(ksi, sfmmug, sf_tsb_raise_exception);
1132 1132 SAVE_INT32(ksi, sfmmug, sf_pagefaults);
1133 1133 SAVE_INT32(ksi, sfmmug, sf_uhash_searches);
1134 1134 SAVE_INT32(ksi, sfmmug, sf_uhash_links);
1135 1135 SAVE_INT32(ksi, sfmmug, sf_khash_searches);
1136 1136 SAVE_INT32(ksi, sfmmug, sf_khash_links);
1137 1137 SAVE_INT32(ksi, sfmmug, sf_swapout);
1138 1138 SAVE_INT32(ksi, sfmmug, sf_tsb_alloc);
1139 1139 SAVE_INT32(ksi, sfmmug, sf_tsb_allocfail);
1140 1140 SAVE_INT32(ksi, sfmmug, sf_tsb_sectsb_create);
1141 1141 SAVE_INT32(ksi, sfmmug, sf_scd_1sttsb_alloc);
1142 1142 SAVE_INT32(ksi, sfmmug, sf_scd_2ndtsb_alloc);
1143 1143 SAVE_INT32(ksi, sfmmug, sf_scd_1sttsb_allocfail);
1144 1144 SAVE_INT32(ksi, sfmmug, sf_scd_2ndtsb_allocfail);
1145 1145 SAVE_INT32(ksi, sfmmug, sf_tteload8k);
1146 1146 SAVE_INT32(ksi, sfmmug, sf_tteload64k);
1147 1147 SAVE_INT32(ksi, sfmmug, sf_tteload512k);
1148 1148 SAVE_INT32(ksi, sfmmug, sf_tteload4m);
1149 1149 SAVE_INT32(ksi, sfmmug, sf_tteload32m);
1150 1150 SAVE_INT32(ksi, sfmmug, sf_tteload256m);
1151 1151 SAVE_INT32(ksi, sfmmug, sf_tsb_load8k);
1152 1152 SAVE_INT32(ksi, sfmmug, sf_tsb_load4m);
1153 1153 SAVE_INT32(ksi, sfmmug, sf_hblk_hit);
1154 1154 SAVE_INT32(ksi, sfmmug, sf_hblk8_ncreate);
1155 1155 SAVE_INT32(ksi, sfmmug, sf_hblk8_nalloc);
1156 1156 SAVE_INT32(ksi, sfmmug, sf_hblk1_ncreate);
1157 1157 SAVE_INT32(ksi, sfmmug, sf_hblk1_nalloc);
1158 1158 SAVE_INT32(ksi, sfmmug, sf_hblk_slab_cnt);
1159 1159 SAVE_INT32(ksi, sfmmug, sf_hblk_reserve_cnt);
1160 1160 SAVE_INT32(ksi, sfmmug, sf_hblk_recurse_cnt);
1161 1161 SAVE_INT32(ksi, sfmmug, sf_hblk_reserve_hit);
1162 1162 SAVE_INT32(ksi, sfmmug, sf_get_free_success);
1163 1163 SAVE_INT32(ksi, sfmmug, sf_get_free_throttle);
1164 1164 SAVE_INT32(ksi, sfmmug, sf_get_free_fail);
1165 1165 SAVE_INT32(ksi, sfmmug, sf_put_free_success);
1166 1166 SAVE_INT32(ksi, sfmmug, sf_put_free_fail);
1167 1167 SAVE_INT32(ksi, sfmmug, sf_pgcolor_conflict);
1168 1168 SAVE_INT32(ksi, sfmmug, sf_uncache_conflict);
1169 1169 SAVE_INT32(ksi, sfmmug, sf_unload_conflict);
1170 1170 SAVE_INT32(ksi, sfmmug, sf_ism_uncache);
1171 1171 SAVE_INT32(ksi, sfmmug, sf_ism_recache);
1172 1172 SAVE_INT32(ksi, sfmmug, sf_recache);
1173 1173 SAVE_INT32(ksi, sfmmug, sf_steal_count);
1174 1174 SAVE_INT32(ksi, sfmmug, sf_pagesync);
1175 1175 SAVE_INT32(ksi, sfmmug, sf_clrwrt);
1176 1176 SAVE_INT32(ksi, sfmmug, sf_pagesync_invalid);
1177 1177 SAVE_INT32(ksi, sfmmug, sf_kernel_xcalls);
1178 1178 SAVE_INT32(ksi, sfmmug, sf_user_xcalls);
1179 1179 SAVE_INT32(ksi, sfmmug, sf_tsb_grow);
1180 1180 SAVE_INT32(ksi, sfmmug, sf_tsb_shrink);
1181 1181 SAVE_INT32(ksi, sfmmug, sf_tsb_resize_failures);
1182 1182 SAVE_INT32(ksi, sfmmug, sf_tsb_reloc);
1183 1183 SAVE_INT32(ksi, sfmmug, sf_user_vtop);
1184 1184 SAVE_INT32(ksi, sfmmug, sf_ctx_inv);
1185 1185 SAVE_INT32(ksi, sfmmug, sf_tlb_reprog_pgsz);
1186 1186 SAVE_INT32(ksi, sfmmug, sf_region_remap_demap);
1187 1187 SAVE_INT32(ksi, sfmmug, sf_create_scd);
1188 1188 SAVE_INT32(ksi, sfmmug, sf_join_scd);
1189 1189 SAVE_INT32(ksi, sfmmug, sf_leave_scd);
1190 1190 SAVE_INT32(ksi, sfmmug, sf_destroy_scd);
1191 1191 }
1192 1192 #endif
1193 1193
1194 1194 #ifdef __sparc
1195 1195 static void
1196 1196 save_sfmmu_tsbsize_stat(kstat_t *kp, ks_instance_t *ksi)
1197 1197 {
1198 1198 struct sfmmu_tsbsize_stat *sfmmut;
1199 1199
1200 1200 assert(kp->ks_data_size == sizeof (struct sfmmu_tsbsize_stat));
1201 1201 sfmmut = (struct sfmmu_tsbsize_stat *)(kp->ks_data);
1202 1202
1203 1203 SAVE_INT32(ksi, sfmmut, sf_tsbsz_8k);
1204 1204 SAVE_INT32(ksi, sfmmut, sf_tsbsz_16k);
1205 1205 SAVE_INT32(ksi, sfmmut, sf_tsbsz_32k);
1206 1206 SAVE_INT32(ksi, sfmmut, sf_tsbsz_64k);
1207 1207 SAVE_INT32(ksi, sfmmut, sf_tsbsz_128k);
1208 1208 SAVE_INT32(ksi, sfmmut, sf_tsbsz_256k);
1209 1209 SAVE_INT32(ksi, sfmmut, sf_tsbsz_512k);
1210 1210 SAVE_INT32(ksi, sfmmut, sf_tsbsz_1m);
1211 1211 SAVE_INT32(ksi, sfmmut, sf_tsbsz_2m);
1212 1212 SAVE_INT32(ksi, sfmmut, sf_tsbsz_4m);
1213 1213 }
1214 1214 #endif
1215 1215
1216 1216 #ifdef __sparc
1217 1217 static void
1218 1218 save_simmstat(kstat_t *kp, ks_instance_t *ksi)
1219 1219 {
1220 1220 uchar_t *simmstat;
1221 1221 char *simm_buf;
1222 1222 char *list = NULL;
1223 1223 int i;
1224 1224
1225 1225 assert(kp->ks_data_size == sizeof (uchar_t) * SIMM_COUNT);
1226 1226
1227 1227 for (i = 0, simmstat = (uchar_t *)(kp->ks_data); i < SIMM_COUNT - 1;
1228 1228 i++, simmstat++) {
1229 1229 if (list == NULL) {
1230 1230 (void) asprintf(&simm_buf, "%d,", *simmstat);
1231 1231 } else {
1232 1232 (void) asprintf(&simm_buf, "%s%d,", list, *simmstat);
1233 1233 free(list);
1234 1234 }
1235 1235 list = simm_buf;
1236 1236 }
1237 1237
1238 1238 (void) asprintf(&simm_buf, "%s%d", list, *simmstat);
1239 1239 SAVE_STRING_X(ksi, "status", simm_buf);
1240 1240 free(list);
1241 1241 free(simm_buf);
1242 1242 }
1243 1243 #endif
1244 1244
1245 1245 #ifdef __sparc
1246 1246 /*
1247 1247 * Helper function for save_temperature().
1248 1248 */
1249 1249 static char *
1250 1250 short_array_to_string(short *shortp, int len)
1251 1251 {
1252 1252 char *list = NULL;
1253 1253 char *list_buf;
1254 1254
1255 1255 for (; len > 1; len--, shortp++) {
1256 1256 if (list == NULL) {
1257 1257 (void) asprintf(&list_buf, "%hd,", *shortp);
1258 1258 } else {
1259 1259 (void) asprintf(&list_buf, "%s%hd,", list, *shortp);
1260 1260 free(list);
1261 1261 }
1262 1262 list = list_buf;
1263 1263 }
1264 1264
1265 1265 (void) asprintf(&list_buf, "%s%hd", list, *shortp);
1266 1266 free(list);
1267 1267 return (list_buf);
1268 1268 }
1269 1269
1270 1270 static void
1271 1271 save_temperature(kstat_t *kp, ks_instance_t *ksi)
1272 1272 {
1273 1273 struct temp_stats *temps = (struct temp_stats *)(kp->ks_data);
1274 1274 char *buf;
1275 1275
1276 1276 assert(kp->ks_data_size == sizeof (struct temp_stats));
1277 1277
1278 1278 SAVE_UINT32(ksi, temps, index);
1279 1279
1280 1280 buf = short_array_to_string(temps->l1, L1_SZ);
1281 1281 SAVE_STRING_X(ksi, "l1", buf);
1282 1282 free(buf);
1283 1283
1284 1284 buf = short_array_to_string(temps->l2, L2_SZ);
1285 1285 SAVE_STRING_X(ksi, "l2", buf);
1286 1286 free(buf);
1287 1287
1288 1288 buf = short_array_to_string(temps->l3, L3_SZ);
1289 1289 SAVE_STRING_X(ksi, "l3", buf);
1290 1290 free(buf);
1291 1291
1292 1292 buf = short_array_to_string(temps->l4, L4_SZ);
1293 1293 SAVE_STRING_X(ksi, "l4", buf);
1294 1294 free(buf);
1295 1295
1296 1296 buf = short_array_to_string(temps->l5, L5_SZ);
1297 1297 SAVE_STRING_X(ksi, "l5", buf);
1298 1298 free(buf);
1299 1299
1300 1300 SAVE_INT32(ksi, temps, max);
1301 1301 SAVE_INT32(ksi, temps, min);
1302 1302 SAVE_INT32(ksi, temps, state);
1303 1303 SAVE_INT32(ksi, temps, temp_cnt);
1304 1304 SAVE_INT32(ksi, temps, shutdown_cnt);
1305 1305 SAVE_INT32(ksi, temps, version);
1306 1306 SAVE_INT32(ksi, temps, trend);
1307 1307 SAVE_INT32(ksi, temps, override);
1308 1308 }
1309 1309 #endif
1310 1310
1311 1311 #ifdef __sparc
1312 1312 static void
1313 1313 save_temp_over(kstat_t *kp, ks_instance_t *ksi)
1314 1314 {
1315 1315 short *sh = (short *)(kp->ks_data);
1316 1316 char *value;
1317 1317
1318 1318 assert(kp->ks_data_size == sizeof (short));
1319 1319
1320 1320 (void) asprintf(&value, "%hu", *sh);
1321 1321 SAVE_STRING_X(ksi, "override", value);
1322 1322 free(value);
1323 1323 }
1324 1324 #endif
1325 1325
1326 1326 #ifdef __sparc
1327 1327 static void
1328 1328 save_ps_shadow(kstat_t *kp, ks_instance_t *ksi)
1329 1329 {
1330 1330 uchar_t *uchar = (uchar_t *)(kp->ks_data);
1331 1331
1332 1332 assert(kp->ks_data_size == SYS_PS_COUNT);
1333 1333
1334 1334 SAVE_CHAR_X(ksi, "core_0", *uchar++);
1335 1335 SAVE_CHAR_X(ksi, "core_1", *uchar++);
1336 1336 SAVE_CHAR_X(ksi, "core_2", *uchar++);
1337 1337 SAVE_CHAR_X(ksi, "core_3", *uchar++);
1338 1338 SAVE_CHAR_X(ksi, "core_4", *uchar++);
1339 1339 SAVE_CHAR_X(ksi, "core_5", *uchar++);
1340 1340 SAVE_CHAR_X(ksi, "core_6", *uchar++);
1341 1341 SAVE_CHAR_X(ksi, "core_7", *uchar++);
1342 1342 SAVE_CHAR_X(ksi, "pps_0", *uchar++);
1343 1343 SAVE_CHAR_X(ksi, "clk_33", *uchar++);
1344 1344 SAVE_CHAR_X(ksi, "clk_50", *uchar++);
1345 1345 SAVE_CHAR_X(ksi, "v5_p", *uchar++);
1346 1346 SAVE_CHAR_X(ksi, "v12_p", *uchar++);
1347 1347 SAVE_CHAR_X(ksi, "v5_aux", *uchar++);
1348 1348 SAVE_CHAR_X(ksi, "v5_p_pch", *uchar++);
1349 1349 SAVE_CHAR_X(ksi, "v12_p_pch", *uchar++);
1350 1350 SAVE_CHAR_X(ksi, "v3_pch", *uchar++);
1351 1351 SAVE_CHAR_X(ksi, "v5_pch", *uchar++);
1352 1352 SAVE_CHAR_X(ksi, "p_fan", *uchar++);
1353 1353 }
1354 1354 #endif
1355 1355
1356 1356 #ifdef __sparc
1357 1357 static void
1358 1358 save_fault_list(kstat_t *kp, ks_instance_t *ksi)
1359 1359 {
1360 1360 struct ft_list *fault;
1361 1361 char name[KSTAT_STRLEN + 7];
1362 1362 int i;
1363 1363
1364 1364 for (i = 1, fault = (struct ft_list *)(kp->ks_data);
1365 1365 i <= 999999 && i <= kp->ks_data_size / sizeof (struct ft_list);
1366 1366 i++, fault++) {
1367 1367 (void) snprintf(name, sizeof (name), "unit_%d", i);
1368 1368 SAVE_INT32_X(ksi, name, fault->unit);
1369 1369 (void) snprintf(name, sizeof (name), "type_%d", i);
1370 1370 SAVE_INT32_X(ksi, name, fault->type);
1371 1371 (void) snprintf(name, sizeof (name), "fclass_%d", i);
1372 1372 SAVE_INT32_X(ksi, name, fault->fclass);
1373 1373 (void) snprintf(name, sizeof (name), "create_time_%d", i);
1374 1374 SAVE_HRTIME_X(ksi, name, fault->create_time);
1375 1375 (void) snprintf(name, sizeof (name), "msg_%d", i);
1376 1376 SAVE_STRING_X(ksi, name, fault->msg);
1377 1377 }
1378 1378 }
1379 1379 #endif
1380 1380
1381 1381 static void
1382 1382 save_named(kstat_t *kp, ks_instance_t *ksi)
1383 1383 {
1384 1384 kstat_named_t *knp;
1385 1385 int n;
1386 1386
1387 1387 for (n = kp->ks_ndata, knp = KSTAT_NAMED_PTR(kp); n > 0; n--, knp++) {
1388 1388 switch (knp->data_type) {
1389 1389 case KSTAT_DATA_CHAR:
1390 1390 nvpair_insert(ksi, knp->name,
1391 1391 (ks_value_t *)&knp->value, KSTAT_DATA_CHAR);
1392 1392 break;
1393 1393 case KSTAT_DATA_INT32:
1394 1394 nvpair_insert(ksi, knp->name,
1395 1395 (ks_value_t *)&knp->value, KSTAT_DATA_INT32);
1396 1396 break;
1397 1397 case KSTAT_DATA_UINT32:
1398 1398 nvpair_insert(ksi, knp->name,
1399 1399 (ks_value_t *)&knp->value, KSTAT_DATA_UINT32);
1400 1400 break;
1401 1401 case KSTAT_DATA_INT64:
1402 1402 nvpair_insert(ksi, knp->name,
1403 1403 (ks_value_t *)&knp->value, KSTAT_DATA_INT64);
1404 1404 break;
1405 1405 case KSTAT_DATA_UINT64:
1406 1406 nvpair_insert(ksi, knp->name,
1407 1407 (ks_value_t *)&knp->value, KSTAT_DATA_UINT64);
1408 1408 break;
1409 1409 case KSTAT_DATA_STRING:
1410 1410 SAVE_STRING_X(ksi, knp->name, KSTAT_NAMED_STR_PTR(knp));
1411 1411 break;
1412 1412 default:
1413 1413 assert(B_FALSE); /* Invalid data type */
1414 1414 break;
1415 1415 }
1416 1416 }
1417 1417 }
1418 1418
1419 1419 static void
1420 1420 save_intr(kstat_t *kp, ks_instance_t *ksi)
1421 1421 {
1422 1422 kstat_intr_t *intr = KSTAT_INTR_PTR(kp);
1423 1423 char *intr_names[] = {"hard", "soft", "watchdog", "spurious",
1424 1424 "multiple_service"};
1425 1425 int n;
1426 1426
1427 1427 for (n = 0; n < KSTAT_NUM_INTRS; n++)
1428 1428 SAVE_UINT32_X(ksi, intr_names[n], intr->intrs[n]);
1429 1429 }
1430 1430
1431 1431 static void
1432 1432 save_io(kstat_t *kp, ks_instance_t *ksi)
1433 1433 {
1434 1434 kstat_io_t *ksio = KSTAT_IO_PTR(kp);
1435 1435
1436 1436 SAVE_UINT64(ksi, ksio, nread);
1437 1437 SAVE_UINT64(ksi, ksio, nwritten);
1438 1438 SAVE_UINT32(ksi, ksio, reads);
1439 1439 SAVE_UINT32(ksi, ksio, writes);
1440 1440 SAVE_HRTIME(ksi, ksio, wtime);
1441 1441 SAVE_HRTIME(ksi, ksio, wlentime);
1442 1442 SAVE_HRTIME(ksi, ksio, wlastupdate);
1443 1443 SAVE_HRTIME(ksi, ksio, rtime);
1444 1444 SAVE_HRTIME(ksi, ksio, rlentime);
1445 1445 SAVE_HRTIME(ksi, ksio, rlastupdate);
1446 1446 SAVE_UINT32(ksi, ksio, wcnt);
1447 1447 SAVE_UINT32(ksi, ksio, rcnt);
1448 1448 }
1449 1449
1450 1450 static void
1451 1451 save_timer(kstat_t *kp, ks_instance_t *ksi)
1452 1452 {
1453 1453 kstat_timer_t *ktimer = KSTAT_TIMER_PTR(kp);
1454 1454
1455 1455 SAVE_STRING(ksi, ktimer, name);
1456 1456 SAVE_UINT64(ksi, ktimer, num_events);
1457 1457 SAVE_HRTIME(ksi, ktimer, elapsed_time);
1458 1458 SAVE_HRTIME(ksi, ktimer, min_time);
1459 1459 SAVE_HRTIME(ksi, ktimer, max_time);
1460 1460 SAVE_HRTIME(ksi, ktimer, start_time);
1461 1461 SAVE_HRTIME(ksi, ktimer, stop_time);
1462 1462 }
↓ open down ↓ |
529 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX