10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52723Scth * Common Development and Distribution License (the "License"). 62723Scth * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 213331Sas158974 220Sstevel@tonic-gate /* 235957Swroche * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate * 260Sstevel@tonic-gate * rewritten from UCB 4.13 83/09/25 270Sstevel@tonic-gate * rewritten from SunOS 4.1 SID 1.18 89/10/06 280Sstevel@tonic-gate */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <stdio.h> 330Sstevel@tonic-gate #include <stdlib.h> 340Sstevel@tonic-gate #include <stdarg.h> 350Sstevel@tonic-gate #include <ctype.h> 360Sstevel@tonic-gate #include <unistd.h> 370Sstevel@tonic-gate #include <memory.h> 380Sstevel@tonic-gate #include <errno.h> 390Sstevel@tonic-gate #include <string.h> 400Sstevel@tonic-gate #include <signal.h> 410Sstevel@tonic-gate #include <sys/types.h> 420Sstevel@tonic-gate #include <time.h> 430Sstevel@tonic-gate #include <sys/time.h> 440Sstevel@tonic-gate #include <sys/sysinfo.h> 450Sstevel@tonic-gate #include <inttypes.h> 460Sstevel@tonic-gate #include <strings.h> 470Sstevel@tonic-gate #include <sys/systeminfo.h> 480Sstevel@tonic-gate #include <kstat.h> 490Sstevel@tonic-gate 500Sstevel@tonic-gate #include "dsr.h" 510Sstevel@tonic-gate #include "statcommon.h" 520Sstevel@tonic-gate 530Sstevel@tonic-gate #define DISK_OLD 0x0001 540Sstevel@tonic-gate #define DISK_NEW 0x0002 550Sstevel@tonic-gate #define DISK_EXTENDED 0x0004 560Sstevel@tonic-gate #define DISK_ERRORS 0x0008 570Sstevel@tonic-gate #define DISK_EXTENDED_ERRORS 0x0010 582907Scth #define DISK_IOPATH_LI 0x0020 /* LunInitiator */ 592907Scth #define DISK_IOPATH_LTI 0x0040 /* LunTargetInitiator */ 602907Scth 610Sstevel@tonic-gate #define DISK_NORMAL (DISK_OLD | DISK_NEW) 620Sstevel@tonic-gate #define DISK_IO_MASK (DISK_OLD | DISK_NEW | DISK_EXTENDED) 630Sstevel@tonic-gate #define DISK_ERROR_MASK (DISK_ERRORS | DISK_EXTENDED_ERRORS) 642907Scth #define PRINT_VERTICAL (DISK_ERROR_MASK | DISK_EXTENDED) 650Sstevel@tonic-gate 660Sstevel@tonic-gate #define REPRINT 19 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * It's really a pseudo-gigabyte. We use 1000000000 bytes so that the disk 700Sstevel@tonic-gate * labels don't look bad. 1GB is really 1073741824 bytes. 710Sstevel@tonic-gate */ 720Sstevel@tonic-gate #define DISK_GIGABYTE 1000000000.0 730Sstevel@tonic-gate 740Sstevel@tonic-gate /* 750Sstevel@tonic-gate * Function desciptor to be called when extended 760Sstevel@tonic-gate * headers are used. 770Sstevel@tonic-gate */ 780Sstevel@tonic-gate typedef struct formatter { 790Sstevel@tonic-gate void (*nfunc)(void); 800Sstevel@tonic-gate struct formatter *next; 810Sstevel@tonic-gate } format_t; 820Sstevel@tonic-gate 830Sstevel@tonic-gate /* 840Sstevel@tonic-gate * Used to get formatting right when printing tty/cpu 850Sstevel@tonic-gate * data to the right of disk data 860Sstevel@tonic-gate */ 870Sstevel@tonic-gate enum show_disk_mode { 880Sstevel@tonic-gate SHOW_FIRST_ONLY, 890Sstevel@tonic-gate SHOW_SECOND_ONWARDS, 900Sstevel@tonic-gate SHOW_ALL 910Sstevel@tonic-gate }; 920Sstevel@tonic-gate 930Sstevel@tonic-gate enum show_disk_mode show_disk_mode = SHOW_ALL; 940Sstevel@tonic-gate 955461Stc35445 char *cmdname = "iostat"; 965461Stc35445 int caught_cont = 0; 970Sstevel@tonic-gate 980Sstevel@tonic-gate static char one_blank[] = " "; 990Sstevel@tonic-gate static char two_blanks[] = " "; 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate /* 1020Sstevel@tonic-gate * count for number of lines to be emitted before a header is 1030Sstevel@tonic-gate * shown again. Only used for the basic format. 1040Sstevel@tonic-gate */ 1050Sstevel@tonic-gate static uint_t tohdr = 1; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate /* 1080Sstevel@tonic-gate * If we're in raw format, have we printed a header? We only do it 1090Sstevel@tonic-gate * once for raw but we emit it every REPRINT lines in non-raw format. 1100Sstevel@tonic-gate * This applies only for the basic header. The extended header is 1110Sstevel@tonic-gate * done only once in both formats. 1120Sstevel@tonic-gate */ 1130Sstevel@tonic-gate static uint_t hdr_out; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate /* 1160Sstevel@tonic-gate * Flags representing arguments from command line 1170Sstevel@tonic-gate */ 1180Sstevel@tonic-gate static uint_t do_tty; /* show tty info (-t) */ 1190Sstevel@tonic-gate static uint_t do_disk; /* show disk info per selected */ 1202907Scth /* format (-d, -D, -e, -E, -x -X -Y) */ 1210Sstevel@tonic-gate static uint_t do_cpu; /* show cpu info (-c) */ 1220Sstevel@tonic-gate static uint_t do_interval; /* do intervals (-I) */ 1230Sstevel@tonic-gate static int do_partitions; /* per-partition stats (-p) */ 1240Sstevel@tonic-gate static int do_partitions_only; /* per-partition stats only (-P) */ 1250Sstevel@tonic-gate /* no per-device stats for disks */ 1260Sstevel@tonic-gate static uint_t do_conversions; /* display disks as cXtYdZ (-n) */ 1270Sstevel@tonic-gate static uint_t do_megabytes; /* display data in MB/sec (-M) */ 1280Sstevel@tonic-gate static uint_t do_controller; /* display controller info (-C) */ 1290Sstevel@tonic-gate static uint_t do_raw; /* emit raw format (-r) */ 1300Sstevel@tonic-gate static uint_t do_timestamp; /* timestamp each display (-T) */ 1310Sstevel@tonic-gate static uint_t do_devid; /* -E should show devid */ 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate /* 1340Sstevel@tonic-gate * Definition of allowable types of timestamps 1350Sstevel@tonic-gate */ 1360Sstevel@tonic-gate #define CDATE 1 1370Sstevel@tonic-gate #define UDATE 2 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate /* 1400Sstevel@tonic-gate * Default number of disk drives to be displayed in basic format 1410Sstevel@tonic-gate */ 1420Sstevel@tonic-gate #define DEFAULT_LIMIT 4 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate struct iodev_filter df; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate static uint_t suppress_state; /* skip state change messages */ 1470Sstevel@tonic-gate static uint_t suppress_zero; /* skip zero valued lines */ 1480Sstevel@tonic-gate static uint_t show_mountpts; /* show mount points */ 1490Sstevel@tonic-gate static int interval; /* interval (seconds) to output */ 1500Sstevel@tonic-gate static int iter; /* iterations from command line */ 1510Sstevel@tonic-gate 1522907Scth #define SMALL_SCRATCH_BUFLEN MAXNAMELEN 1532907Scth 1542907Scth static int iodevs_nl; /* name field width */ 1552907Scth #define IODEVS_NL_MIN 6 /* not too thin for "device" */ 1562907Scth #define IODEVS_NL_MAX 24 /* but keep full width under 80 */ 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate static char disk_header[132]; 1590Sstevel@tonic-gate static uint_t dh_len; /* disk header length for centering */ 1600Sstevel@tonic-gate static int lineout; /* data waiting to be printed? */ 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate static struct snapshot *newss; 1630Sstevel@tonic-gate static struct snapshot *oldss; 1642907Scth static double getime; /* elapsed time */ 1652907Scth static double percent; /* 100 / etime */ 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate /* 1680Sstevel@tonic-gate * List of functions to be called which will construct the desired output 1690Sstevel@tonic-gate */ 1700Sstevel@tonic-gate static format_t *formatter_list; 1710Sstevel@tonic-gate static format_t *formatter_end; 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate static u_longlong_t ull_delta(u_longlong_t, u_longlong_t); 1740Sstevel@tonic-gate static uint_t u32_delta(uint_t, uint_t); 1750Sstevel@tonic-gate static void setup(void (*nfunc)(void)); 1760Sstevel@tonic-gate static void print_timestamp(void); 1770Sstevel@tonic-gate static void print_tty_hdr1(void); 1780Sstevel@tonic-gate static void print_tty_hdr2(void); 1790Sstevel@tonic-gate static void print_cpu_hdr1(void); 1800Sstevel@tonic-gate static void print_cpu_hdr2(void); 1810Sstevel@tonic-gate static void print_tty_data(void); 1820Sstevel@tonic-gate static void print_cpu_data(void); 1830Sstevel@tonic-gate static void print_err_hdr(void); 1840Sstevel@tonic-gate static void print_disk_header(void); 1850Sstevel@tonic-gate static void hdrout(void); 1860Sstevel@tonic-gate static void disk_errors(void); 1870Sstevel@tonic-gate static void do_newline(void); 1880Sstevel@tonic-gate static void push_out(const char *, ...); 1890Sstevel@tonic-gate static void printhdr(int); 1900Sstevel@tonic-gate static void printxhdr(void); 1910Sstevel@tonic-gate static void usage(void); 1920Sstevel@tonic-gate static void do_args(int, char **); 1930Sstevel@tonic-gate static void do_format(void); 1940Sstevel@tonic-gate static void show_all_disks(void); 1950Sstevel@tonic-gate static void show_first_disk(void); 1960Sstevel@tonic-gate static void show_other_disks(void); 1970Sstevel@tonic-gate static void show_disk_errors(void *, void *, void *); 1980Sstevel@tonic-gate static void write_core_header(void); 1990Sstevel@tonic-gate static int fzero(double value); 2000Sstevel@tonic-gate static int safe_strtoi(char const *val, char *errmsg); 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate int 2030Sstevel@tonic-gate main(int argc, char **argv) 2040Sstevel@tonic-gate { 2050Sstevel@tonic-gate enum snapshot_types types = SNAP_SYSTEM; 2060Sstevel@tonic-gate kstat_ctl_t *kc; 2070Sstevel@tonic-gate long hz; 2085957Swroche int forever; 2095461Stc35445 hrtime_t start_n; 2105461Stc35445 hrtime_t period_n; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate do_args(argc, argv); 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate /* 2150Sstevel@tonic-gate * iostat historically showed CPU changes, even though 2160Sstevel@tonic-gate * it doesn't provide much useful information 2170Sstevel@tonic-gate */ 2180Sstevel@tonic-gate types |= SNAP_CPUS; 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate if (do_disk) 2210Sstevel@tonic-gate types |= SNAP_IODEVS; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate if (do_disk && !do_partitions_only) 2240Sstevel@tonic-gate df.if_allowed_types |= IODEV_DISK; 2252907Scth if (do_disk & DISK_IOPATH_LI) { 2262907Scth df.if_allowed_types |= IODEV_IOPATH_LTI; 2272907Scth types |= SNAP_IOPATHS_LI; 2282907Scth } 2292907Scth if (do_disk & DISK_IOPATH_LTI) { 2302907Scth df.if_allowed_types |= IODEV_IOPATH_LTI; 2312907Scth types |= SNAP_IOPATHS_LTI; 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate if (do_disk & DISK_ERROR_MASK) 2340Sstevel@tonic-gate types |= SNAP_IODEV_ERRORS; 2350Sstevel@tonic-gate if (do_partitions || do_partitions_only) 2360Sstevel@tonic-gate df.if_allowed_types |= IODEV_PARTITION; 2370Sstevel@tonic-gate if (do_conversions) 2380Sstevel@tonic-gate types |= SNAP_IODEV_PRETTY; 2392723Scth if (do_devid) 2402723Scth types |= SNAP_IODEV_DEVID; 2410Sstevel@tonic-gate if (do_controller) { 2420Sstevel@tonic-gate if (!(do_disk & PRINT_VERTICAL) || 2432907Scth (do_disk & DISK_EXTENDED_ERRORS)) 2440Sstevel@tonic-gate fail(0, "-C can only be used with -e or -x."); 2450Sstevel@tonic-gate types |= SNAP_CONTROLLERS; 2460Sstevel@tonic-gate df.if_allowed_types |= IODEV_CONTROLLER; 2470Sstevel@tonic-gate } 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate hz = sysconf(_SC_CLK_TCK); 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate /* 2520Sstevel@tonic-gate * Undocumented behavior - sending a SIGCONT will result 2530Sstevel@tonic-gate * in a new header being emitted. Used only if we're not 2540Sstevel@tonic-gate * doing extended headers. This is a historical 2550Sstevel@tonic-gate * artifact. 2560Sstevel@tonic-gate */ 2570Sstevel@tonic-gate if (!(do_disk & PRINT_VERTICAL)) 2580Sstevel@tonic-gate (void) signal(SIGCONT, printhdr); 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate if (interval) 2615461Stc35445 period_n = (hrtime_t)interval * NANOSEC; 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate kc = open_kstat(); 2645461Stc35445 if (interval) 2655461Stc35445 start_n = gethrtime(); 2660Sstevel@tonic-gate newss = acquire_snapshot(kc, types, &df); 2670Sstevel@tonic-gate 2682907Scth /* compute width of "device" field */ 2692907Scth iodevs_nl = newss->s_iodevs_is_name_maxlen; 2702907Scth iodevs_nl = (iodevs_nl < IODEVS_NL_MIN) ? 2712907Scth IODEVS_NL_MIN : iodevs_nl; 2722907Scth iodevs_nl = (iodevs_nl > IODEVS_NL_MAX) ? 2732907Scth IODEVS_NL_MAX : iodevs_nl; 2742907Scth 2752907Scth do_format(); 2762907Scth 2775957Swroche forever = (iter == 0); 2780Sstevel@tonic-gate do { 279*6266Swroche if (do_conversions && show_mountpts) 280*6266Swroche do_mnttab(); 281*6266Swroche 2820Sstevel@tonic-gate if (do_tty || do_cpu) { 2830Sstevel@tonic-gate kstat_t *oldks; 2840Sstevel@tonic-gate oldks = oldss ? &oldss->s_sys.ss_agg_sys : NULL; 2850Sstevel@tonic-gate getime = cpu_ticks_delta(oldks, 2860Sstevel@tonic-gate &newss->s_sys.ss_agg_sys); 2870Sstevel@tonic-gate percent = (getime > 0.0) ? 100.0 / getime : 0.0; 2880Sstevel@tonic-gate getime = (getime / nr_active_cpus(newss)) / hz; 2890Sstevel@tonic-gate if (getime == 0.0) 2900Sstevel@tonic-gate getime = (double)interval; 2910Sstevel@tonic-gate if (getime == 0.0 || do_interval) 2920Sstevel@tonic-gate getime = 1.0; 2930Sstevel@tonic-gate } 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate if (formatter_list) { 2960Sstevel@tonic-gate format_t *tmp; 2970Sstevel@tonic-gate tmp = formatter_list; 2980Sstevel@tonic-gate while (tmp) { 2990Sstevel@tonic-gate (tmp->nfunc)(); 3000Sstevel@tonic-gate tmp = tmp->next; 3010Sstevel@tonic-gate } 3020Sstevel@tonic-gate (void) fflush(stdout); 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate 3055957Swroche /* only remaining/doing a single iteration, we are done */ 3065957Swroche if (iter == 1) 3072723Scth continue; 3082723Scth 3095957Swroche if (interval > 0) 3105461Stc35445 /* Have a kip */ 3115957Swroche sleep_until(&start_n, period_n, forever, &caught_cont); 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate free_snapshot(oldss); 3140Sstevel@tonic-gate oldss = newss; 3150Sstevel@tonic-gate newss = acquire_snapshot(kc, types, &df); 3162907Scth iodevs_nl = (newss->s_iodevs_is_name_maxlen > iodevs_nl) ? 3172907Scth newss->s_iodevs_is_name_maxlen : iodevs_nl; 3182907Scth iodevs_nl = (iodevs_nl < IODEVS_NL_MIN) ? 3192907Scth IODEVS_NL_MIN : iodevs_nl; 3202907Scth iodevs_nl = (iodevs_nl > IODEVS_NL_MAX) ? 3212907Scth IODEVS_NL_MAX : iodevs_nl; 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate if (!suppress_state) 3240Sstevel@tonic-gate snapshot_report_changes(oldss, newss); 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate /* if config changed, show stats from boot */ 3270Sstevel@tonic-gate if (snapshot_has_changed(oldss, newss)) { 3280Sstevel@tonic-gate free_snapshot(oldss); 3290Sstevel@tonic-gate oldss = NULL; 3300Sstevel@tonic-gate } 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate } while (--iter); 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate free_snapshot(oldss); 3350Sstevel@tonic-gate free_snapshot(newss); 3362723Scth (void) kstat_close(kc); 3372907Scth free(df.if_names); 3380Sstevel@tonic-gate return (0); 3390Sstevel@tonic-gate } 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate /* 3420Sstevel@tonic-gate * Some magic numbers used in header formatting. 3430Sstevel@tonic-gate * 3440Sstevel@tonic-gate * DISK_LEN = length of either "kps tps serv" or "wps rps util" 3450Sstevel@tonic-gate * using 0 as the first position 3460Sstevel@tonic-gate * 3470Sstevel@tonic-gate * DISK_ERROR_LEN = length of "s/w h/w trn tot" with one space on 3480Sstevel@tonic-gate * either side. Does not use zero as first pos. 3490Sstevel@tonic-gate * 3500Sstevel@tonic-gate * DEVICE_LEN = length of "device" + 1 character. 3510Sstevel@tonic-gate */ 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate #define DISK_LEN 11 3540Sstevel@tonic-gate #define DISK_ERROR_LEN 16 3550Sstevel@tonic-gate #define DEVICE_LEN 7 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate /*ARGSUSED*/ 3580Sstevel@tonic-gate static void 3590Sstevel@tonic-gate show_disk_name(void *v1, void *v2, void *data) 3600Sstevel@tonic-gate { 3610Sstevel@tonic-gate struct iodev_snapshot *dev = (struct iodev_snapshot *)v2; 3620Sstevel@tonic-gate size_t slen; 3630Sstevel@tonic-gate char *name; 3640Sstevel@tonic-gate char fbuf[SMALL_SCRATCH_BUFLEN]; 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate if (dev == NULL) 3670Sstevel@tonic-gate return; 3680Sstevel@tonic-gate 3692907Scth name = do_conversions ? dev->is_pretty : dev->is_name; 3702907Scth name = name ? name : dev->is_name; 3712907Scth 3720Sstevel@tonic-gate if (!do_raw) { 3730Sstevel@tonic-gate uint_t width; 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate slen = strlen(name); 3760Sstevel@tonic-gate /* 3770Sstevel@tonic-gate * The length is less 3780Sstevel@tonic-gate * than the section 3790Sstevel@tonic-gate * which will be displayed 3800Sstevel@tonic-gate * on the next line. 3810Sstevel@tonic-gate * Center the entry. 3820Sstevel@tonic-gate */ 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate width = (DISK_LEN + 1)/2 + (slen / 2); 3850Sstevel@tonic-gate (void) snprintf(fbuf, sizeof (fbuf), 3860Sstevel@tonic-gate "%*s", width, name); 3870Sstevel@tonic-gate name = fbuf; 3882723Scth push_out("%-13.13s ", name); 3890Sstevel@tonic-gate } else { 3900Sstevel@tonic-gate push_out(name); 3910Sstevel@tonic-gate } 3920Sstevel@tonic-gate } 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate /*ARGSUSED*/ 3950Sstevel@tonic-gate static void 3960Sstevel@tonic-gate show_disk_header(void *v1, void *v2, void *data) 3970Sstevel@tonic-gate { 3980Sstevel@tonic-gate push_out(disk_header); 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate /* 4020Sstevel@tonic-gate * Write out a two line header. What is written out depends on the flags 4030Sstevel@tonic-gate * selected but in the worst case consists of a tty header, a disk header 4040Sstevel@tonic-gate * providing information for 4 disks and a cpu header. 4050Sstevel@tonic-gate * 4060Sstevel@tonic-gate * The tty header consists of the word "tty" on the first line above the 4070Sstevel@tonic-gate * words "tin tout" on the next line. If present the tty portion consumes 4080Sstevel@tonic-gate * the first 10 characters of each line since "tin tout" is surrounded 4090Sstevel@tonic-gate * by single spaces. 4100Sstevel@tonic-gate * 4110Sstevel@tonic-gate * Each of the disk sections is a 14 character "block" in which the name of 4120Sstevel@tonic-gate * the disk is centered in the first 12 characters of the first line. 4130Sstevel@tonic-gate * 4140Sstevel@tonic-gate * The cpu section is an 11 character block with "cpu" centered over the 4150Sstevel@tonic-gate * section. 4160Sstevel@tonic-gate * 4170Sstevel@tonic-gate * The worst case should look as follows: 4180Sstevel@tonic-gate * 4190Sstevel@tonic-gate * 0---------1--------2---------3---------4---------5---------6---------7------- 4200Sstevel@tonic-gate * tty sd0 sd1 sd2 sd3 cpu 4210Sstevel@tonic-gate * tin tout kps tps serv kps tps serv kps tps serv kps tps serv us sy wt id 4220Sstevel@tonic-gate * NNN NNNN NNN NNN NNNN NNN NNN NNNN NNN NNN NNNN NNN NNN NNNN NN NN NN NN 4230Sstevel@tonic-gate * 4240Sstevel@tonic-gate * When -D is specified, the disk header looks as follows (worst case): 4250Sstevel@tonic-gate * 4260Sstevel@tonic-gate * 0---------1--------2---------3---------4---------5---------6---------7------- 4270Sstevel@tonic-gate * tty sd0 sd1 sd2 sd3 cpu 4280Sstevel@tonic-gate * tin tout rps wps util rps wps util rps wps util rps wps util us sy wt id 4290Sstevel@tonic-gate * NNN NNNN NNN NNN NNNN NNN NNN NNNN NNN NNN NNNN NNN NNN NNNN NN NN NN NN 4300Sstevel@tonic-gate */ 4310Sstevel@tonic-gate static void 4320Sstevel@tonic-gate printhdr(int sig) 4330Sstevel@tonic-gate { 4340Sstevel@tonic-gate /* 4350Sstevel@tonic-gate * If we're here because a signal fired, reenable the 4360Sstevel@tonic-gate * signal. 4370Sstevel@tonic-gate */ 4380Sstevel@tonic-gate if (sig) 4390Sstevel@tonic-gate (void) signal(SIGCONT, printhdr); 4405461Stc35445 if (sig == SIGCONT) 4415461Stc35445 caught_cont = 1; 4420Sstevel@tonic-gate /* 4430Sstevel@tonic-gate * Horizontal mode headers 4440Sstevel@tonic-gate * 4450Sstevel@tonic-gate * First line 4460Sstevel@tonic-gate */ 4470Sstevel@tonic-gate if (do_tty) 4480Sstevel@tonic-gate print_tty_hdr1(); 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate if (do_disk & DISK_NORMAL) { 4510Sstevel@tonic-gate (void) snapshot_walk(SNAP_IODEVS, NULL, newss, 4520Sstevel@tonic-gate show_disk_name, NULL); 4530Sstevel@tonic-gate } 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate if (do_cpu) 4560Sstevel@tonic-gate print_cpu_hdr1(); 4570Sstevel@tonic-gate do_newline(); 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate /* 4600Sstevel@tonic-gate * Second line 4610Sstevel@tonic-gate */ 4620Sstevel@tonic-gate if (do_tty) 4630Sstevel@tonic-gate print_tty_hdr2(); 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate if (do_disk & DISK_NORMAL) { 4660Sstevel@tonic-gate (void) snapshot_walk(SNAP_IODEVS, NULL, newss, 4670Sstevel@tonic-gate show_disk_header, NULL); 4680Sstevel@tonic-gate } 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate if (do_cpu) 4710Sstevel@tonic-gate print_cpu_hdr2(); 4720Sstevel@tonic-gate do_newline(); 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate tohdr = REPRINT; 4750Sstevel@tonic-gate } 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate /* 4780Sstevel@tonic-gate * Write out the extended header centered over the core information. 4790Sstevel@tonic-gate */ 4800Sstevel@tonic-gate static void 4810Sstevel@tonic-gate write_core_header(void) 4820Sstevel@tonic-gate { 4830Sstevel@tonic-gate char *edev = "extended device statistics"; 4840Sstevel@tonic-gate uint_t lead_space_ct; 4850Sstevel@tonic-gate uint_t follow_space_ct; 4860Sstevel@tonic-gate size_t edevlen; 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate if (do_raw == 0) { 4890Sstevel@tonic-gate /* 4900Sstevel@tonic-gate * The things we do to look nice... 4910Sstevel@tonic-gate * 4920Sstevel@tonic-gate * Center the core output header. Make sure we have the 4930Sstevel@tonic-gate * right number of trailing spaces for follow-on headers 4940Sstevel@tonic-gate * (i.e., cpu and/or tty and/or errors). 4950Sstevel@tonic-gate */ 4960Sstevel@tonic-gate edevlen = strlen(edev); 4970Sstevel@tonic-gate lead_space_ct = dh_len - edevlen; 4980Sstevel@tonic-gate lead_space_ct /= 2; 4990Sstevel@tonic-gate if (lead_space_ct > 0) { 5000Sstevel@tonic-gate follow_space_ct = dh_len - (lead_space_ct + edevlen); 5010Sstevel@tonic-gate if (do_disk & DISK_ERRORS) 5020Sstevel@tonic-gate follow_space_ct -= DISK_ERROR_LEN; 5030Sstevel@tonic-gate if ((do_disk & DISK_EXTENDED) && do_conversions) 5040Sstevel@tonic-gate follow_space_ct -= DEVICE_LEN; 5050Sstevel@tonic-gate 5060Sstevel@tonic-gate push_out("%1$*2$.*2$s%3$s%4$*5$.*5$s", one_blank, 5070Sstevel@tonic-gate lead_space_ct, edev, one_blank, follow_space_ct); 5080Sstevel@tonic-gate } else 5090Sstevel@tonic-gate push_out("%56s", edev); 5100Sstevel@tonic-gate } else 5110Sstevel@tonic-gate push_out(edev); 5120Sstevel@tonic-gate } 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate /* 5150Sstevel@tonic-gate * In extended mode headers, we don't want to reprint the header on 5160Sstevel@tonic-gate * signals as they are printed every time anyways. 5170Sstevel@tonic-gate */ 5180Sstevel@tonic-gate static void 5190Sstevel@tonic-gate printxhdr(void) 5200Sstevel@tonic-gate { 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate /* 5230Sstevel@tonic-gate * Vertical mode headers 5240Sstevel@tonic-gate */ 5250Sstevel@tonic-gate if (do_disk & DISK_EXTENDED) 5260Sstevel@tonic-gate setup(write_core_header); 5270Sstevel@tonic-gate if (do_disk & DISK_ERRORS) 5280Sstevel@tonic-gate setup(print_err_hdr); 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate if (do_conversions) { 5310Sstevel@tonic-gate setup(do_newline); 5320Sstevel@tonic-gate if (do_disk & (DISK_EXTENDED | DISK_ERRORS)) 5330Sstevel@tonic-gate setup(print_disk_header); 5340Sstevel@tonic-gate setup(do_newline); 5350Sstevel@tonic-gate } else { 5360Sstevel@tonic-gate if (do_tty) 5370Sstevel@tonic-gate setup(print_tty_hdr1); 5380Sstevel@tonic-gate if (do_cpu) 5390Sstevel@tonic-gate setup(print_cpu_hdr1); 5400Sstevel@tonic-gate setup(do_newline); 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate if (do_disk & (DISK_EXTENDED | DISK_ERRORS)) 5430Sstevel@tonic-gate setup(print_disk_header); 5440Sstevel@tonic-gate if (do_tty) 5450Sstevel@tonic-gate setup(print_tty_hdr2); 5460Sstevel@tonic-gate if (do_cpu) 5470Sstevel@tonic-gate setup(print_cpu_hdr2); 5480Sstevel@tonic-gate setup(do_newline); 5490Sstevel@tonic-gate } 5500Sstevel@tonic-gate } 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate /* 5530Sstevel@tonic-gate * Write out a line for this disk - note that show_disk writes out 5540Sstevel@tonic-gate * full lines or blocks for each selected disk. 5550Sstevel@tonic-gate */ 5560Sstevel@tonic-gate static void 5570Sstevel@tonic-gate show_disk(void *v1, void *v2, void *data) 5580Sstevel@tonic-gate { 5590Sstevel@tonic-gate struct iodev_snapshot *old = (struct iodev_snapshot *)v1; 5600Sstevel@tonic-gate struct iodev_snapshot *new = (struct iodev_snapshot *)v2; 5610Sstevel@tonic-gate int *count = (int *)data; 5620Sstevel@tonic-gate double rps, wps, tps, mtps, krps, kwps, kps, avw, avr, w_pct, r_pct; 5630Sstevel@tonic-gate double wserv, rserv, serv; 5640Sstevel@tonic-gate double iosize; /* kb/sec or MB/sec */ 5650Sstevel@tonic-gate double etime, hr_etime; 5660Sstevel@tonic-gate char *disk_name; 5670Sstevel@tonic-gate u_longlong_t ldeltas; 5680Sstevel@tonic-gate uint_t udeltas; 5690Sstevel@tonic-gate uint64_t t_delta; 5700Sstevel@tonic-gate uint64_t w_delta; 5710Sstevel@tonic-gate uint64_t r_delta; 5720Sstevel@tonic-gate int doit = 1; 5730Sstevel@tonic-gate int i; 5740Sstevel@tonic-gate uint_t toterrs; 5750Sstevel@tonic-gate char *fstr; 5760Sstevel@tonic-gate 5770Sstevel@tonic-gate if (new == NULL) 5780Sstevel@tonic-gate return; 5790Sstevel@tonic-gate 5800Sstevel@tonic-gate switch (show_disk_mode) { 5810Sstevel@tonic-gate case SHOW_FIRST_ONLY: 5820Sstevel@tonic-gate if (count != NULL && *count) 5830Sstevel@tonic-gate return; 5840Sstevel@tonic-gate break; 5850Sstevel@tonic-gate 5860Sstevel@tonic-gate case SHOW_SECOND_ONWARDS: 5870Sstevel@tonic-gate if (count != NULL && !*count) { 5880Sstevel@tonic-gate (*count)++; 5890Sstevel@tonic-gate return; 5900Sstevel@tonic-gate } 5910Sstevel@tonic-gate break; 5920Sstevel@tonic-gate 5930Sstevel@tonic-gate default: 5940Sstevel@tonic-gate break; 5950Sstevel@tonic-gate } 5960Sstevel@tonic-gate 5972907Scth disk_name = do_conversions ? new->is_pretty : new->is_name; 5982907Scth disk_name = disk_name ? disk_name : new->is_name; 5990Sstevel@tonic-gate 6000Sstevel@tonic-gate /* 6010Sstevel@tonic-gate * Only do if we want IO stats - Avoids errors traveling this 6020Sstevel@tonic-gate * section if that's all we want to see. 6030Sstevel@tonic-gate */ 6040Sstevel@tonic-gate if (do_disk & DISK_IO_MASK) { 6050Sstevel@tonic-gate if (old) { 6060Sstevel@tonic-gate t_delta = hrtime_delta(old->is_snaptime, 6070Sstevel@tonic-gate new->is_snaptime); 6080Sstevel@tonic-gate } else { 6090Sstevel@tonic-gate t_delta = hrtime_delta(new->is_crtime, 6100Sstevel@tonic-gate new->is_snaptime); 6110Sstevel@tonic-gate } 6120Sstevel@tonic-gate 6132907Scth if (new->is_nr_children) { 6142907Scth if (new->is_type == IODEV_CONTROLLER) { 6152907Scth t_delta /= new->is_nr_children; 6162907Scth } else if ((new->is_type == IODEV_IOPATH_LT) || 6172907Scth (new->is_type == IODEV_IOPATH_LI)) { 6182907Scth /* synthetic path */ 6192907Scth if (!old) { 6202907Scth t_delta = new->is_crtime; 6212907Scth } 6222907Scth t_delta /= new->is_nr_children; 6232907Scth } 6242907Scth } 6250Sstevel@tonic-gate 6260Sstevel@tonic-gate hr_etime = (double)t_delta; 6270Sstevel@tonic-gate if (hr_etime == 0.0) 6280Sstevel@tonic-gate hr_etime = (double)NANOSEC; 6290Sstevel@tonic-gate etime = hr_etime / (double)NANOSEC; 6300Sstevel@tonic-gate 6310Sstevel@tonic-gate /* reads per second */ 6320Sstevel@tonic-gate udeltas = u32_delta(old ? old->is_stats.reads : 0, 6330Sstevel@tonic-gate new->is_stats.reads); 6340Sstevel@tonic-gate rps = (double)udeltas; 6350Sstevel@tonic-gate rps /= etime; 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate /* writes per second */ 6380Sstevel@tonic-gate udeltas = u32_delta(old ? old->is_stats.writes : 0, 6390Sstevel@tonic-gate new->is_stats.writes); 6400Sstevel@tonic-gate wps = (double)udeltas; 6410Sstevel@tonic-gate wps /= etime; 6420Sstevel@tonic-gate 6430Sstevel@tonic-gate tps = rps + wps; 6440Sstevel@tonic-gate /* transactions per second */ 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate /* 6470Sstevel@tonic-gate * report throughput as either kb/sec or MB/sec 6480Sstevel@tonic-gate */ 6490Sstevel@tonic-gate 6500Sstevel@tonic-gate if (!do_megabytes) 6510Sstevel@tonic-gate iosize = 1024.0; 6520Sstevel@tonic-gate else 6530Sstevel@tonic-gate iosize = 1048576.0; 6540Sstevel@tonic-gate 6550Sstevel@tonic-gate ldeltas = ull_delta(old ? old->is_stats.nread : 0, 6560Sstevel@tonic-gate new->is_stats.nread); 6570Sstevel@tonic-gate if (ldeltas) { 6580Sstevel@tonic-gate krps = (double)ldeltas; 6590Sstevel@tonic-gate krps /= etime; 6600Sstevel@tonic-gate krps /= iosize; 6610Sstevel@tonic-gate } else 6620Sstevel@tonic-gate krps = 0.0; 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate ldeltas = ull_delta(old ? old->is_stats.nwritten : 0, 6650Sstevel@tonic-gate new->is_stats.nwritten); 6660Sstevel@tonic-gate if (ldeltas) { 6670Sstevel@tonic-gate kwps = (double)ldeltas; 6680Sstevel@tonic-gate kwps /= etime; 6690Sstevel@tonic-gate kwps /= iosize; 6700Sstevel@tonic-gate } else 6710Sstevel@tonic-gate kwps = 0.0; 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate /* 6740Sstevel@tonic-gate * Blocks transferred per second 6750Sstevel@tonic-gate */ 6760Sstevel@tonic-gate kps = krps + kwps; 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate /* 679207Spetede * Average number of wait transactions waiting 6800Sstevel@tonic-gate */ 6810Sstevel@tonic-gate w_delta = hrtime_delta((u_longlong_t) 6820Sstevel@tonic-gate (old ? old->is_stats.wlentime : 0), 6830Sstevel@tonic-gate new->is_stats.wlentime); 6840Sstevel@tonic-gate if (w_delta) { 6850Sstevel@tonic-gate avw = (double)w_delta; 6860Sstevel@tonic-gate avw /= hr_etime; 6870Sstevel@tonic-gate } else 6880Sstevel@tonic-gate avw = 0.0; 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate /* 691207Spetede * Average number of run transactions waiting 6920Sstevel@tonic-gate */ 6930Sstevel@tonic-gate r_delta = hrtime_delta(old ? old->is_stats.rlentime : 0, 6940Sstevel@tonic-gate new->is_stats.rlentime); 6950Sstevel@tonic-gate if (r_delta) { 6960Sstevel@tonic-gate avr = (double)r_delta; 6970Sstevel@tonic-gate avr /= hr_etime; 6980Sstevel@tonic-gate } else 6990Sstevel@tonic-gate avr = 0.0; 7000Sstevel@tonic-gate 7010Sstevel@tonic-gate /* 7020Sstevel@tonic-gate * Average wait service time in milliseconds 7030Sstevel@tonic-gate */ 7040Sstevel@tonic-gate if (tps > 0.0 && (avw != 0.0 || avr != 0.0)) { 7050Sstevel@tonic-gate mtps = 1000.0 / tps; 7060Sstevel@tonic-gate if (avw != 0.0) 7070Sstevel@tonic-gate wserv = avw * mtps; 7080Sstevel@tonic-gate else 7090Sstevel@tonic-gate wserv = 0.0; 7100Sstevel@tonic-gate 7110Sstevel@tonic-gate if (avr != 0.0) 7120Sstevel@tonic-gate rserv = avr * mtps; 7130Sstevel@tonic-gate else 7140Sstevel@tonic-gate rserv = 0.0; 7150Sstevel@tonic-gate serv = rserv + wserv; 7160Sstevel@tonic-gate } else { 7170Sstevel@tonic-gate rserv = 0.0; 7180Sstevel@tonic-gate wserv = 0.0; 7190Sstevel@tonic-gate serv = 0.0; 7200Sstevel@tonic-gate } 7210Sstevel@tonic-gate 7220Sstevel@tonic-gate /* % of time there is a transaction waiting for service */ 7230Sstevel@tonic-gate t_delta = hrtime_delta(old ? old->is_stats.wtime : 0, 7240Sstevel@tonic-gate new->is_stats.wtime); 7250Sstevel@tonic-gate if (t_delta) { 7260Sstevel@tonic-gate w_pct = (double)t_delta; 7270Sstevel@tonic-gate w_pct /= hr_etime; 7280Sstevel@tonic-gate w_pct *= 100.0; 7290Sstevel@tonic-gate 7300Sstevel@tonic-gate /* 7310Sstevel@tonic-gate * Average the wait queue utilization over the 7320Sstevel@tonic-gate * the controller's devices, if this is a controller. 7330Sstevel@tonic-gate */ 7340Sstevel@tonic-gate if (new->is_type == IODEV_CONTROLLER) 7350Sstevel@tonic-gate w_pct /= new->is_nr_children; 7360Sstevel@tonic-gate } else 7370Sstevel@tonic-gate w_pct = 0.0; 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate /* % of time there is a transaction running */ 7400Sstevel@tonic-gate t_delta = hrtime_delta(old ? old->is_stats.rtime : 0, 7410Sstevel@tonic-gate new->is_stats.rtime); 7420Sstevel@tonic-gate if (t_delta) { 7430Sstevel@tonic-gate r_pct = (double)t_delta; 7440Sstevel@tonic-gate r_pct /= hr_etime; 7450Sstevel@tonic-gate r_pct *= 100.0; 7460Sstevel@tonic-gate 7470Sstevel@tonic-gate /* 7480Sstevel@tonic-gate * Average the percent busy over the controller's 7490Sstevel@tonic-gate * devices, if this is a controller. 7500Sstevel@tonic-gate */ 7510Sstevel@tonic-gate if (new->is_type == IODEV_CONTROLLER) 7520Sstevel@tonic-gate w_pct /= new->is_nr_children; 7530Sstevel@tonic-gate } else { 7540Sstevel@tonic-gate r_pct = 0.0; 7550Sstevel@tonic-gate } 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate /* % of time there is a transaction running */ 7580Sstevel@tonic-gate if (do_interval) { 7590Sstevel@tonic-gate rps *= etime; 7600Sstevel@tonic-gate wps *= etime; 7610Sstevel@tonic-gate tps *= etime; 7620Sstevel@tonic-gate krps *= etime; 7630Sstevel@tonic-gate kwps *= etime; 7640Sstevel@tonic-gate kps *= etime; 7650Sstevel@tonic-gate } 7660Sstevel@tonic-gate } 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate if (do_disk & (DISK_EXTENDED | DISK_ERRORS)) { 7690Sstevel@tonic-gate if ((!do_conversions) && ((suppress_zero == 0) || 7700Sstevel@tonic-gate ((do_disk & DISK_EXTENDED) == 0))) { 7712907Scth if (do_raw == 0) { 7722907Scth push_out("%-*.*s", 7732907Scth iodevs_nl, iodevs_nl, disk_name); 7742907Scth } else { 7750Sstevel@tonic-gate push_out(disk_name); 7762907Scth } 7770Sstevel@tonic-gate } 7780Sstevel@tonic-gate } 7790Sstevel@tonic-gate 7800Sstevel@tonic-gate switch (do_disk & DISK_IO_MASK) { 7815957Swroche case DISK_OLD: 7820Sstevel@tonic-gate if (do_raw == 0) 7830Sstevel@tonic-gate fstr = "%3.0f %3.0f %4.0f "; 7840Sstevel@tonic-gate else 7850Sstevel@tonic-gate fstr = "%.0f,%.0f,%.0f"; 7860Sstevel@tonic-gate push_out(fstr, kps, tps, serv); 7870Sstevel@tonic-gate break; 7885957Swroche case DISK_NEW: 7890Sstevel@tonic-gate if (do_raw == 0) 7900Sstevel@tonic-gate fstr = "%3.0f %3.0f %4.1f "; 7910Sstevel@tonic-gate else 7920Sstevel@tonic-gate fstr = "%.0f,%.0f,%.1f"; 7930Sstevel@tonic-gate push_out(fstr, rps, wps, r_pct); 7940Sstevel@tonic-gate break; 7955957Swroche case DISK_EXTENDED: 7960Sstevel@tonic-gate if (suppress_zero) { 7970Sstevel@tonic-gate if (fzero(rps) && fzero(wps) && fzero(krps) && 7980Sstevel@tonic-gate fzero(kwps) && fzero(avw) && fzero(avr) && 7992907Scth fzero(serv) && fzero(w_pct) && fzero(r_pct)) { 8000Sstevel@tonic-gate doit = 0; 8012907Scth } else if (do_conversions == 0) { 8022907Scth if (do_raw == 0) { 8032907Scth push_out("%-*.*s", 8042907Scth iodevs_nl, iodevs_nl, disk_name); 8052907Scth } else { 8060Sstevel@tonic-gate push_out(disk_name); 8072907Scth } 8080Sstevel@tonic-gate } 8090Sstevel@tonic-gate } 8100Sstevel@tonic-gate if (doit) { 8110Sstevel@tonic-gate if (!do_conversions) { 8120Sstevel@tonic-gate if (do_raw == 0) { 8130Sstevel@tonic-gate fstr = " %6.1f %6.1f %6.1f %6.1f " 8145957Swroche "%4.1f %4.1f %6.1f %3.0f " 8155957Swroche "%3.0f "; 8160Sstevel@tonic-gate } else { 8170Sstevel@tonic-gate fstr = "%.1f,%.1f,%.1f,%.1f,%.1f,%.1f," 8185957Swroche "%.1f,%.0f,%.0f"; 8190Sstevel@tonic-gate } 8200Sstevel@tonic-gate push_out(fstr, rps, wps, krps, kwps, avw, avr, 8210Sstevel@tonic-gate serv, w_pct, r_pct); 8220Sstevel@tonic-gate } else { 8230Sstevel@tonic-gate if (do_raw == 0) { 8240Sstevel@tonic-gate fstr = " %6.1f %6.1f %6.1f %6.1f " 8255957Swroche "%4.1f %4.1f %6.1f %6.1f " 8265957Swroche "%3.0f %3.0f "; 8270Sstevel@tonic-gate } else { 8280Sstevel@tonic-gate fstr = "%.1f,%.1f,%.1f,%.1f,%.1f,%.1f," 8295957Swroche "%.1f,%.1f,%.0f,%.0f"; 8300Sstevel@tonic-gate } 8310Sstevel@tonic-gate push_out(fstr, rps, wps, krps, kwps, avw, avr, 8320Sstevel@tonic-gate wserv, rserv, w_pct, r_pct); 8330Sstevel@tonic-gate } 8340Sstevel@tonic-gate } 8350Sstevel@tonic-gate break; 8360Sstevel@tonic-gate } 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate if (do_disk & DISK_ERRORS) { 8390Sstevel@tonic-gate if ((do_disk == DISK_ERRORS)) { 8400Sstevel@tonic-gate if (do_raw == 0) 8410Sstevel@tonic-gate push_out(two_blanks); 8420Sstevel@tonic-gate } 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate if (new->is_errors.ks_data) { 8450Sstevel@tonic-gate kstat_named_t *knp; 8460Sstevel@tonic-gate char *efstr; 8470Sstevel@tonic-gate 8480Sstevel@tonic-gate if (do_raw == 0) 8490Sstevel@tonic-gate efstr = "%3u "; 8500Sstevel@tonic-gate else 8510Sstevel@tonic-gate efstr = "%u"; 8520Sstevel@tonic-gate toterrs = 0; 8530Sstevel@tonic-gate knp = KSTAT_NAMED_PTR(&new->is_errors); 8540Sstevel@tonic-gate for (i = 0; i < 3; i++) { 8550Sstevel@tonic-gate switch (knp[i].data_type) { 8560Sstevel@tonic-gate case KSTAT_DATA_ULONG: 8570Sstevel@tonic-gate push_out(efstr, 8580Sstevel@tonic-gate knp[i].value.ui32); 8590Sstevel@tonic-gate toterrs += knp[i].value.ui32; 8600Sstevel@tonic-gate break; 8610Sstevel@tonic-gate case KSTAT_DATA_ULONGLONG: 8620Sstevel@tonic-gate /* 8630Sstevel@tonic-gate * We're only set up to 8640Sstevel@tonic-gate * write out the low 8650Sstevel@tonic-gate * order 32-bits so 8660Sstevel@tonic-gate * just grab that. 8670Sstevel@tonic-gate */ 8680Sstevel@tonic-gate push_out(efstr, 8690Sstevel@tonic-gate knp[i].value.ui32); 8700Sstevel@tonic-gate toterrs += knp[i].value.ui32; 8710Sstevel@tonic-gate break; 8720Sstevel@tonic-gate default: 8730Sstevel@tonic-gate break; 8740Sstevel@tonic-gate } 8750Sstevel@tonic-gate } 8760Sstevel@tonic-gate push_out(efstr, toterrs); 8770Sstevel@tonic-gate } else { 8780Sstevel@tonic-gate if (do_raw == 0) 8790Sstevel@tonic-gate push_out(" 0 0 0 0 "); 8800Sstevel@tonic-gate else 8810Sstevel@tonic-gate push_out("0,0,0,0"); 8820Sstevel@tonic-gate } 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate } 8850Sstevel@tonic-gate 8860Sstevel@tonic-gate if (suppress_zero == 0 || doit == 1) { 8870Sstevel@tonic-gate if ((do_disk & (DISK_EXTENDED | DISK_ERRORS)) && 8885957Swroche do_conversions) { 8890Sstevel@tonic-gate push_out("%s", disk_name); 8900Sstevel@tonic-gate if (show_mountpts && new->is_dname) { 8910Sstevel@tonic-gate mnt_t *mount_pt; 8920Sstevel@tonic-gate char *lu; 893*6266Swroche char *dnlu; 8940Sstevel@tonic-gate char lub[SMALL_SCRATCH_BUFLEN]; 8950Sstevel@tonic-gate 8960Sstevel@tonic-gate lu = strrchr(new->is_dname, '/'); 8970Sstevel@tonic-gate if (lu) { 898*6266Swroche /* only the part after a possible '/' */ 899*6266Swroche dnlu = strrchr(disk_name, '/'); 900*6266Swroche if (dnlu != NULL && 901*6266Swroche strcmp(dnlu, lu) == 0) 9020Sstevel@tonic-gate lu = new->is_dname; 9030Sstevel@tonic-gate else { 9040Sstevel@tonic-gate *lu = 0; 9050Sstevel@tonic-gate (void) strcpy(lub, 9060Sstevel@tonic-gate new->is_dname); 9070Sstevel@tonic-gate *lu = '/'; 9080Sstevel@tonic-gate (void) strcat(lub, "/"); 9090Sstevel@tonic-gate (void) strcat(lub, 9100Sstevel@tonic-gate disk_name); 9110Sstevel@tonic-gate lu = lub; 9120Sstevel@tonic-gate } 9130Sstevel@tonic-gate } else 9140Sstevel@tonic-gate lu = disk_name; 9150Sstevel@tonic-gate mount_pt = lookup_mntent_byname(lu); 9160Sstevel@tonic-gate if (mount_pt) { 9170Sstevel@tonic-gate if (do_raw == 0) 9180Sstevel@tonic-gate push_out(" (%s)", 9190Sstevel@tonic-gate mount_pt->mount_point); 9200Sstevel@tonic-gate else 9210Sstevel@tonic-gate push_out("(%s)", 9220Sstevel@tonic-gate mount_pt->mount_point); 9230Sstevel@tonic-gate } 9240Sstevel@tonic-gate } 9250Sstevel@tonic-gate } 9260Sstevel@tonic-gate } 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate if ((do_disk & PRINT_VERTICAL) && show_disk_mode != SHOW_FIRST_ONLY) 9290Sstevel@tonic-gate do_newline(); 9300Sstevel@tonic-gate 9310Sstevel@tonic-gate if (count != NULL) 9320Sstevel@tonic-gate (*count)++; 9330Sstevel@tonic-gate } 9340Sstevel@tonic-gate 9350Sstevel@tonic-gate static void 9360Sstevel@tonic-gate usage(void) 9370Sstevel@tonic-gate { 9380Sstevel@tonic-gate (void) fprintf(stderr, 9392907Scth "Usage: iostat [-cCdDeEiImMnpPrstxXYz] " 9400Sstevel@tonic-gate " [-l n] [-T d|u] [disk ...] [interval [count]]\n" 9410Sstevel@tonic-gate "\t\t-c: report percentage of time system has spent\n" 9420Sstevel@tonic-gate "\t\t\tin user/system/wait/idle mode\n" 9430Sstevel@tonic-gate "\t\t-C: report disk statistics by controller\n" 9440Sstevel@tonic-gate "\t\t-d: display disk Kb/sec, transfers/sec, avg. \n" 9450Sstevel@tonic-gate "\t\t\tservice time in milliseconds \n" 9460Sstevel@tonic-gate "\t\t-D: display disk reads/sec, writes/sec, \n" 9470Sstevel@tonic-gate "\t\t\tpercentage disk utilization \n" 9480Sstevel@tonic-gate "\t\t-e: report device error summary statistics\n" 9490Sstevel@tonic-gate "\t\t-E: report extended device error statistics\n" 9500Sstevel@tonic-gate "\t\t-i: show device IDs for -E output\n" 9510Sstevel@tonic-gate "\t\t-I: report the counts in each interval,\n" 9520Sstevel@tonic-gate "\t\t\tinstead of rates, where applicable\n" 9530Sstevel@tonic-gate "\t\t-l n: Limit the number of disks to n\n" 9540Sstevel@tonic-gate "\t\t-m: Display mount points (most useful with -p)\n" 9550Sstevel@tonic-gate "\t\t-M: Display data throughput in MB/sec " 9560Sstevel@tonic-gate "instead of Kb/sec\n" 9570Sstevel@tonic-gate "\t\t-n: convert device names to cXdYtZ format\n" 9580Sstevel@tonic-gate "\t\t-p: report per-partition disk statistics\n" 9590Sstevel@tonic-gate "\t\t-P: report per-partition disk statistics only,\n" 9600Sstevel@tonic-gate "\t\t\tno per-device disk statistics\n" 9610Sstevel@tonic-gate "\t\t-r: Display data in comma separated format\n" 9620Sstevel@tonic-gate "\t\t-s: Suppress state change messages\n" 9630Sstevel@tonic-gate "\t\t-T d|u Display a timestamp in date (d) or unix " 9640Sstevel@tonic-gate "time_t (u)\n" 9650Sstevel@tonic-gate "\t\t-t: display chars read/written to terminals\n" 9660Sstevel@tonic-gate "\t\t-x: display extended disk statistics\n" 9670Sstevel@tonic-gate "\t\t-X: display I/O path statistics\n" 9682907Scth "\t\t-Y: display I/O path (I/T/L) statistics\n" 9690Sstevel@tonic-gate "\t\t-z: Suppress entries with all zero values\n"); 9700Sstevel@tonic-gate exit(1); 9710Sstevel@tonic-gate } 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate /*ARGSUSED*/ 9740Sstevel@tonic-gate static void 9750Sstevel@tonic-gate show_disk_errors(void *v1, void *v2, void *d) 9760Sstevel@tonic-gate { 9770Sstevel@tonic-gate struct iodev_snapshot *disk = (struct iodev_snapshot *)v2; 9780Sstevel@tonic-gate kstat_named_t *knp; 9790Sstevel@tonic-gate size_t col; 9800Sstevel@tonic-gate int i, len; 9812907Scth char *dev_name; 9820Sstevel@tonic-gate 9830Sstevel@tonic-gate if (disk->is_errors.ks_ndata == 0) 9840Sstevel@tonic-gate return; 9850Sstevel@tonic-gate if (disk->is_type == IODEV_CONTROLLER) 9860Sstevel@tonic-gate return; 9870Sstevel@tonic-gate 9882907Scth dev_name = do_conversions ? disk->is_pretty : disk->is_name; 9892907Scth dev_name = dev_name ? dev_name : disk->is_name; 9900Sstevel@tonic-gate 9910Sstevel@tonic-gate len = strlen(dev_name); 9920Sstevel@tonic-gate if (len > 20) 9930Sstevel@tonic-gate push_out("%s ", dev_name); 9940Sstevel@tonic-gate else if (len > 16) 9950Sstevel@tonic-gate push_out("%-20.20s ", dev_name); 9960Sstevel@tonic-gate else { 9970Sstevel@tonic-gate if (do_conversions) 9980Sstevel@tonic-gate push_out("%-16.16s ", dev_name); 9990Sstevel@tonic-gate else 10000Sstevel@tonic-gate push_out("%-9.9s ", dev_name); 10010Sstevel@tonic-gate } 10020Sstevel@tonic-gate col = 0; 10030Sstevel@tonic-gate 10040Sstevel@tonic-gate knp = KSTAT_NAMED_PTR(&disk->is_errors); 10050Sstevel@tonic-gate for (i = 0; i < disk->is_errors.ks_ndata; i++) { 10060Sstevel@tonic-gate /* skip kstats that the driver did not kstat_named_init */ 10070Sstevel@tonic-gate if (knp[i].name[0] == 0) 10080Sstevel@tonic-gate continue; 10090Sstevel@tonic-gate 10100Sstevel@tonic-gate col += strlen(knp[i].name); 10110Sstevel@tonic-gate 10120Sstevel@tonic-gate switch (knp[i].data_type) { 10130Sstevel@tonic-gate case KSTAT_DATA_CHAR: 10140Sstevel@tonic-gate if ((strcmp(knp[i].name, "Serial No") == 0) && 10150Sstevel@tonic-gate do_devid) { 10160Sstevel@tonic-gate if (disk->is_devid) { 10170Sstevel@tonic-gate push_out("Device Id: %s ", 10180Sstevel@tonic-gate disk->is_devid); 10190Sstevel@tonic-gate col += strlen(disk->is_devid); 10200Sstevel@tonic-gate } else 10210Sstevel@tonic-gate push_out("Device Id: "); 10220Sstevel@tonic-gate } else { 10230Sstevel@tonic-gate push_out("%s: %-.16s ", knp[i].name, 10240Sstevel@tonic-gate &knp[i].value.c[0]); 10250Sstevel@tonic-gate col += strlen(&knp[i].value.c[0]); 10260Sstevel@tonic-gate } 10270Sstevel@tonic-gate break; 10280Sstevel@tonic-gate case KSTAT_DATA_ULONG: 10290Sstevel@tonic-gate push_out("%s: %u ", knp[i].name, 10300Sstevel@tonic-gate knp[i].value.ui32); 10310Sstevel@tonic-gate col += 4; 10320Sstevel@tonic-gate break; 10330Sstevel@tonic-gate case KSTAT_DATA_ULONGLONG: 10340Sstevel@tonic-gate if (strcmp(knp[i].name, "Size") == 0) { 10350Sstevel@tonic-gate push_out("%s: %2.2fGB <%llu bytes>\n", 10360Sstevel@tonic-gate knp[i].name, 10370Sstevel@tonic-gate (float)knp[i].value.ui64 / 10380Sstevel@tonic-gate DISK_GIGABYTE, 10390Sstevel@tonic-gate knp[i].value.ui64); 10400Sstevel@tonic-gate col = 0; 10410Sstevel@tonic-gate break; 10420Sstevel@tonic-gate } 10430Sstevel@tonic-gate push_out("%s: %u ", knp[i].name, 10440Sstevel@tonic-gate knp[i].value.ui32); 10450Sstevel@tonic-gate col += 4; 10460Sstevel@tonic-gate break; 10470Sstevel@tonic-gate } 10480Sstevel@tonic-gate if ((col >= 62) || (i == 2)) { 10490Sstevel@tonic-gate do_newline(); 10500Sstevel@tonic-gate col = 0; 10510Sstevel@tonic-gate } 10520Sstevel@tonic-gate } 10530Sstevel@tonic-gate if (col > 0) { 10540Sstevel@tonic-gate do_newline(); 10550Sstevel@tonic-gate } 10560Sstevel@tonic-gate do_newline(); 10570Sstevel@tonic-gate } 10580Sstevel@tonic-gate 10590Sstevel@tonic-gate void 10600Sstevel@tonic-gate do_args(int argc, char **argv) 10610Sstevel@tonic-gate { 10620Sstevel@tonic-gate int c; 10630Sstevel@tonic-gate int errflg = 0; 10640Sstevel@tonic-gate extern char *optarg; 10650Sstevel@tonic-gate extern int optind; 10660Sstevel@tonic-gate 10672907Scth while ((c = getopt(argc, argv, "tdDxXYCciIpPnmMeEszrT:l:")) != EOF) 10680Sstevel@tonic-gate switch (c) { 10690Sstevel@tonic-gate case 't': 10700Sstevel@tonic-gate do_tty++; 10710Sstevel@tonic-gate break; 10720Sstevel@tonic-gate case 'd': 10730Sstevel@tonic-gate do_disk |= DISK_OLD; 10740Sstevel@tonic-gate break; 10750Sstevel@tonic-gate case 'D': 10760Sstevel@tonic-gate do_disk |= DISK_NEW; 10770Sstevel@tonic-gate break; 10780Sstevel@tonic-gate case 'x': 10790Sstevel@tonic-gate do_disk |= DISK_EXTENDED; 10800Sstevel@tonic-gate break; 10810Sstevel@tonic-gate case 'X': 10822907Scth if (do_disk & DISK_IOPATH_LTI) 10832907Scth errflg++; /* -Y already used */ 10842907Scth else 10852907Scth do_disk |= DISK_IOPATH_LI; 10862907Scth break; 10872907Scth case 'Y': 10882907Scth if (do_disk & DISK_IOPATH_LI) 10892907Scth errflg++; /* -X already used */ 10902907Scth else 10912907Scth do_disk |= DISK_IOPATH_LTI; 10920Sstevel@tonic-gate break; 10930Sstevel@tonic-gate case 'C': 10940Sstevel@tonic-gate do_controller++; 10950Sstevel@tonic-gate break; 10960Sstevel@tonic-gate case 'c': 10970Sstevel@tonic-gate do_cpu++; 10980Sstevel@tonic-gate break; 10990Sstevel@tonic-gate case 'I': 11000Sstevel@tonic-gate do_interval++; 11010Sstevel@tonic-gate break; 11020Sstevel@tonic-gate case 'p': 11030Sstevel@tonic-gate do_partitions++; 11040Sstevel@tonic-gate break; 11050Sstevel@tonic-gate case 'P': 11060Sstevel@tonic-gate do_partitions_only++; 11070Sstevel@tonic-gate break; 11080Sstevel@tonic-gate case 'n': 11090Sstevel@tonic-gate do_conversions++; 11100Sstevel@tonic-gate break; 11110Sstevel@tonic-gate case 'M': 11120Sstevel@tonic-gate do_megabytes++; 11130Sstevel@tonic-gate break; 11140Sstevel@tonic-gate case 'e': 11150Sstevel@tonic-gate do_disk |= DISK_ERRORS; 11160Sstevel@tonic-gate break; 11170Sstevel@tonic-gate case 'E': 11180Sstevel@tonic-gate do_disk |= DISK_EXTENDED_ERRORS; 11190Sstevel@tonic-gate break; 11200Sstevel@tonic-gate case 'i': 11210Sstevel@tonic-gate do_devid = 1; 11220Sstevel@tonic-gate break; 11230Sstevel@tonic-gate case 's': 11240Sstevel@tonic-gate suppress_state = 1; 11250Sstevel@tonic-gate break; 11260Sstevel@tonic-gate case 'z': 11270Sstevel@tonic-gate suppress_zero = 1; 11280Sstevel@tonic-gate break; 11290Sstevel@tonic-gate case 'm': 11300Sstevel@tonic-gate show_mountpts = 1; 11310Sstevel@tonic-gate break; 11320Sstevel@tonic-gate case 'T': 11330Sstevel@tonic-gate if (optarg) { 11340Sstevel@tonic-gate if (*optarg == 'u') 11350Sstevel@tonic-gate do_timestamp = UDATE; 11360Sstevel@tonic-gate else if (*optarg == 'd') 11370Sstevel@tonic-gate do_timestamp = CDATE; 11380Sstevel@tonic-gate else 11390Sstevel@tonic-gate errflg++; 11400Sstevel@tonic-gate } else 11410Sstevel@tonic-gate errflg++; 11420Sstevel@tonic-gate break; 11430Sstevel@tonic-gate case 'r': 11440Sstevel@tonic-gate do_raw = 1; 11450Sstevel@tonic-gate break; 11460Sstevel@tonic-gate case 'l': 11470Sstevel@tonic-gate df.if_max_iodevs = safe_strtoi(optarg, "invalid limit"); 11480Sstevel@tonic-gate if (df.if_max_iodevs < 1) 11490Sstevel@tonic-gate usage(); 11500Sstevel@tonic-gate break; 11510Sstevel@tonic-gate case '?': 11520Sstevel@tonic-gate errflg++; 11530Sstevel@tonic-gate } 11540Sstevel@tonic-gate 11550Sstevel@tonic-gate if ((do_disk & DISK_OLD) && (do_disk & DISK_NEW)) { 11560Sstevel@tonic-gate (void) fprintf(stderr, "-d and -D are incompatible.\n"); 11570Sstevel@tonic-gate usage(); 11580Sstevel@tonic-gate } 11590Sstevel@tonic-gate 11600Sstevel@tonic-gate if (errflg) { 11610Sstevel@tonic-gate usage(); 11620Sstevel@tonic-gate } 11632907Scth 11640Sstevel@tonic-gate /* if no output classes explicity specified, use defaults */ 11650Sstevel@tonic-gate if (do_tty == 0 && do_disk == 0 && do_cpu == 0) 11660Sstevel@tonic-gate do_tty = do_cpu = 1, do_disk = DISK_OLD; 11670Sstevel@tonic-gate 11680Sstevel@tonic-gate /* 11692907Scth * multi-path options (-X, -Y) without a specific vertical 11702907Scth * output format (-x, -e, -E) imply extended -x format 11712907Scth */ 11722907Scth if ((do_disk & (DISK_IOPATH_LI | DISK_IOPATH_LTI)) && 11732907Scth !(do_disk & PRINT_VERTICAL)) 11742907Scth do_disk |= DISK_EXTENDED; 11752907Scth 11762907Scth /* 11770Sstevel@tonic-gate * If conflicting options take the preferred 11780Sstevel@tonic-gate * -D and -x result in -x 11790Sstevel@tonic-gate * -d or -D and -e or -E gives only whatever -d or -D was specified 11800Sstevel@tonic-gate */ 11810Sstevel@tonic-gate if ((do_disk & DISK_EXTENDED) && (do_disk & DISK_NORMAL)) 11820Sstevel@tonic-gate do_disk &= ~DISK_NORMAL; 11830Sstevel@tonic-gate if ((do_disk & DISK_NORMAL) && (do_disk & DISK_ERROR_MASK)) 11840Sstevel@tonic-gate do_disk &= ~DISK_ERROR_MASK; 11850Sstevel@tonic-gate 11860Sstevel@tonic-gate /* nfs, tape, always shown */ 11870Sstevel@tonic-gate df.if_allowed_types = IODEV_NFS | IODEV_TAPE; 11880Sstevel@tonic-gate 11890Sstevel@tonic-gate /* 11900Sstevel@tonic-gate * If limit == 0 then no command line limit was set, else if any of 11910Sstevel@tonic-gate * the flags that cause unlimited disks were not set, 11920Sstevel@tonic-gate * use the default of 4 11930Sstevel@tonic-gate */ 11940Sstevel@tonic-gate if (df.if_max_iodevs == 0) { 11950Sstevel@tonic-gate df.if_max_iodevs = DEFAULT_LIMIT; 11960Sstevel@tonic-gate df.if_skip_floppy = 1; 11970Sstevel@tonic-gate if (do_disk & (DISK_EXTENDED | DISK_ERRORS | 11980Sstevel@tonic-gate DISK_EXTENDED_ERRORS)) { 11990Sstevel@tonic-gate df.if_max_iodevs = UNLIMITED_IODEVS; 12000Sstevel@tonic-gate df.if_skip_floppy = 0; 12010Sstevel@tonic-gate } 12020Sstevel@tonic-gate } 12030Sstevel@tonic-gate if (do_disk) { 12040Sstevel@tonic-gate size_t count = 0; 12050Sstevel@tonic-gate size_t i = optind; 12060Sstevel@tonic-gate 12070Sstevel@tonic-gate while (i < argc && !isdigit(argv[i][0])) { 12080Sstevel@tonic-gate count++; 12090Sstevel@tonic-gate i++; 12100Sstevel@tonic-gate } 12110Sstevel@tonic-gate 12120Sstevel@tonic-gate /* 12130Sstevel@tonic-gate * "Note: disks explicitly requested 12140Sstevel@tonic-gate * are not subject to this disk limit" 12150Sstevel@tonic-gate */ 12162907Scth if ((count > df.if_max_iodevs) || 12172907Scth (count && (df.if_max_iodevs == UNLIMITED_IODEVS))) 12180Sstevel@tonic-gate df.if_max_iodevs = count; 12192907Scth 12200Sstevel@tonic-gate df.if_names = safe_alloc(count * sizeof (char *)); 12210Sstevel@tonic-gate (void) memset(df.if_names, 0, count * sizeof (char *)); 12220Sstevel@tonic-gate 12232907Scth df.if_nr_names = 0; 12240Sstevel@tonic-gate while (optind < argc && !isdigit(argv[optind][0])) 12250Sstevel@tonic-gate df.if_names[df.if_nr_names++] = argv[optind++]; 12260Sstevel@tonic-gate } 12270Sstevel@tonic-gate if (optind < argc) { 12280Sstevel@tonic-gate interval = safe_strtoi(argv[optind], "invalid interval"); 12290Sstevel@tonic-gate if (interval < 1) 12300Sstevel@tonic-gate fail(0, "invalid interval"); 12310Sstevel@tonic-gate optind++; 12320Sstevel@tonic-gate 12330Sstevel@tonic-gate if (optind < argc) { 12340Sstevel@tonic-gate iter = safe_strtoi(argv[optind], "invalid count"); 12350Sstevel@tonic-gate if (iter < 1) 12360Sstevel@tonic-gate fail(0, "invalid count"); 12370Sstevel@tonic-gate optind++; 12380Sstevel@tonic-gate } 12390Sstevel@tonic-gate } 12400Sstevel@tonic-gate if (interval == 0) 12410Sstevel@tonic-gate iter = 1; 12420Sstevel@tonic-gate if (optind < argc) 12430Sstevel@tonic-gate usage(); 12440Sstevel@tonic-gate } 12450Sstevel@tonic-gate 12460Sstevel@tonic-gate /* 12470Sstevel@tonic-gate * Driver for doing the extended header formatting. Will produce 12480Sstevel@tonic-gate * the function stack needed to output an extended header based 12490Sstevel@tonic-gate * on the options selected. 12500Sstevel@tonic-gate */ 12510Sstevel@tonic-gate 12520Sstevel@tonic-gate void 12530Sstevel@tonic-gate do_format(void) 12540Sstevel@tonic-gate { 12550Sstevel@tonic-gate char header[SMALL_SCRATCH_BUFLEN]; 12560Sstevel@tonic-gate char ch; 12570Sstevel@tonic-gate char iosz; 12580Sstevel@tonic-gate const char *fstr; 12590Sstevel@tonic-gate 12600Sstevel@tonic-gate disk_header[0] = 0; 12610Sstevel@tonic-gate ch = (do_interval ? 'i' : 's'); 12620Sstevel@tonic-gate iosz = (do_megabytes ? 'M' : 'k'); 12630Sstevel@tonic-gate if (do_disk & DISK_ERRORS) { 12640Sstevel@tonic-gate if (do_raw == 0) { 12650Sstevel@tonic-gate (void) sprintf(header, "s/w h/w trn tot "); 12660Sstevel@tonic-gate } else 12670Sstevel@tonic-gate (void) sprintf(header, "s/w,h/w,trn,tot"); 12680Sstevel@tonic-gate } else 12690Sstevel@tonic-gate *header = NULL; 12700Sstevel@tonic-gate switch (do_disk & DISK_IO_MASK) { 12710Sstevel@tonic-gate case DISK_OLD: 12720Sstevel@tonic-gate if (do_raw == 0) 12730Sstevel@tonic-gate fstr = "%cp%c tp%c serv "; 12740Sstevel@tonic-gate else 12750Sstevel@tonic-gate fstr = "%cp%c,tp%c,serv"; 12760Sstevel@tonic-gate (void) snprintf(disk_header, sizeof (disk_header), 12770Sstevel@tonic-gate fstr, iosz, ch, ch); 12780Sstevel@tonic-gate break; 12790Sstevel@tonic-gate case DISK_NEW: 12800Sstevel@tonic-gate if (do_raw == 0) 12810Sstevel@tonic-gate fstr = "rp%c wp%c util "; 12820Sstevel@tonic-gate else 12830Sstevel@tonic-gate fstr = "%rp%c,wp%c,util"; 12840Sstevel@tonic-gate (void) snprintf(disk_header, sizeof (disk_header), 12850Sstevel@tonic-gate fstr, ch, ch); 12860Sstevel@tonic-gate break; 12870Sstevel@tonic-gate case DISK_EXTENDED: 12882907Scth /* This is -x option */ 12890Sstevel@tonic-gate if (!do_conversions) { 12902907Scth /* without -n option */ 12912907Scth if (do_raw == 0) { 12922907Scth /* without -r option */ 12932907Scth (void) snprintf(disk_header, 12942907Scth sizeof (disk_header), 12952907Scth "%-*.*s r/%c w/%c " 12960Sstevel@tonic-gate "%cr/%c %cw/%c wait actv " 12972907Scth "svc_t %%%%w %%%%b %s", 12982907Scth iodevs_nl, iodevs_nl, "device", 12992907Scth ch, ch, iosz, ch, iosz, ch, header); 13002907Scth } else { 13012907Scth /* with -r option */ 13022907Scth (void) snprintf(disk_header, 13032907Scth sizeof (disk_header), 13042907Scth "device,r/%c,w/%c,%cr/%c,%cw/%c," 13052907Scth "wait,actv,svc_t,%%%%w," 13062907Scth "%%%%b,%s", 13072907Scth ch, ch, iosz, ch, iosz, ch, header); 13082907Scth } 13090Sstevel@tonic-gate } else { 13102907Scth /* with -n option */ 13110Sstevel@tonic-gate if (do_raw == 0) { 13120Sstevel@tonic-gate fstr = " r/%c w/%c %cr/%c " 13130Sstevel@tonic-gate "%cw/%c wait actv wsvc_t asvc_t " 13140Sstevel@tonic-gate "%%%%w %%%%b %sdevice"; 13150Sstevel@tonic-gate } else { 13160Sstevel@tonic-gate fstr = "r/%c,w/%c,%cr/%c,%cw/%c," 13170Sstevel@tonic-gate "wait,actv,wsvc_t,asvc_t," 13180Sstevel@tonic-gate "%%%%w,%%%%b,%sdevice"; 13190Sstevel@tonic-gate } 13200Sstevel@tonic-gate (void) snprintf(disk_header, 13210Sstevel@tonic-gate sizeof (disk_header), 13220Sstevel@tonic-gate fstr, ch, ch, iosz, ch, iosz, 13230Sstevel@tonic-gate ch, header); 13240Sstevel@tonic-gate } 13250Sstevel@tonic-gate break; 13260Sstevel@tonic-gate default: 13270Sstevel@tonic-gate break; 13280Sstevel@tonic-gate } 13292723Scth 13302723Scth /* do DISK_ERRORS header (already added above for DISK_EXTENDED) */ 13312723Scth if ((do_disk & DISK_ERRORS) && 13322723Scth ((do_disk & DISK_IO_MASK) != DISK_EXTENDED)) { 13330Sstevel@tonic-gate if (!do_conversions) { 13342907Scth if (do_raw == 0) 13352907Scth (void) snprintf(disk_header, 13362907Scth sizeof (disk_header), "%-*.*s %s", 13372907Scth iodevs_nl, iodevs_nl, "device", header); 13382907Scth else 13392907Scth (void) snprintf(disk_header, 13402907Scth sizeof (disk_header), "device,%s", header); 13410Sstevel@tonic-gate } else { 13420Sstevel@tonic-gate if (do_raw == 0) { 13430Sstevel@tonic-gate (void) snprintf(disk_header, 13440Sstevel@tonic-gate sizeof (disk_header), 13452723Scth " %sdevice", header); 13462723Scth } else { 13472723Scth (void) snprintf(disk_header, 13482723Scth sizeof (disk_header), 13492723Scth "%s,device", header); 13502723Scth } 13510Sstevel@tonic-gate } 13520Sstevel@tonic-gate } else { 13530Sstevel@tonic-gate /* 13540Sstevel@tonic-gate * Need to subtract two characters for the % escape in 13550Sstevel@tonic-gate * the string. 13560Sstevel@tonic-gate */ 13570Sstevel@tonic-gate dh_len = strlen(disk_header) - 2; 13580Sstevel@tonic-gate } 13590Sstevel@tonic-gate 13600Sstevel@tonic-gate if (do_timestamp) 13610Sstevel@tonic-gate setup(print_timestamp); 13620Sstevel@tonic-gate 13630Sstevel@tonic-gate /* 13640Sstevel@tonic-gate * -n *and* (-E *or* -e *or* -x) 13650Sstevel@tonic-gate */ 13660Sstevel@tonic-gate if (do_conversions && (do_disk & PRINT_VERTICAL)) { 13670Sstevel@tonic-gate if (do_tty) 13680Sstevel@tonic-gate setup(print_tty_hdr1); 13690Sstevel@tonic-gate if (do_cpu) 13700Sstevel@tonic-gate setup(print_cpu_hdr1); 13710Sstevel@tonic-gate if (do_tty || do_cpu) 13720Sstevel@tonic-gate setup(do_newline); 13730Sstevel@tonic-gate if (do_tty) 13740Sstevel@tonic-gate setup(print_tty_hdr2); 13750Sstevel@tonic-gate if (do_cpu) 13760Sstevel@tonic-gate setup(print_cpu_hdr2); 13770Sstevel@tonic-gate if (do_tty || do_cpu) 13780Sstevel@tonic-gate setup(do_newline); 13790Sstevel@tonic-gate if (do_tty) 13800Sstevel@tonic-gate setup(print_tty_data); 13810Sstevel@tonic-gate if (do_cpu) 13820Sstevel@tonic-gate setup(print_cpu_data); 13830Sstevel@tonic-gate if (do_tty || do_cpu) 13840Sstevel@tonic-gate setup(do_newline); 13850Sstevel@tonic-gate printxhdr(); 13860Sstevel@tonic-gate 13870Sstevel@tonic-gate setup(show_all_disks); 13880Sstevel@tonic-gate } else { 13890Sstevel@tonic-gate /* 13900Sstevel@tonic-gate * These unholy gymnastics are necessary to place CPU/tty 13910Sstevel@tonic-gate * data to the right of the disks/errors for the first 13920Sstevel@tonic-gate * line in vertical mode. 13930Sstevel@tonic-gate */ 13940Sstevel@tonic-gate if (do_disk & PRINT_VERTICAL) { 13950Sstevel@tonic-gate printxhdr(); 13960Sstevel@tonic-gate 13970Sstevel@tonic-gate setup(show_first_disk); 13980Sstevel@tonic-gate if (do_tty) 13990Sstevel@tonic-gate setup(print_tty_data); 14000Sstevel@tonic-gate if (do_cpu) 14010Sstevel@tonic-gate setup(print_cpu_data); 14020Sstevel@tonic-gate setup(do_newline); 14030Sstevel@tonic-gate 14040Sstevel@tonic-gate setup(show_other_disks); 14050Sstevel@tonic-gate } else { 14060Sstevel@tonic-gate setup(hdrout); 14070Sstevel@tonic-gate if (do_tty) 14080Sstevel@tonic-gate setup(print_tty_data); 14090Sstevel@tonic-gate setup(show_all_disks); 14100Sstevel@tonic-gate if (do_cpu) 14110Sstevel@tonic-gate setup(print_cpu_data); 14120Sstevel@tonic-gate } 14130Sstevel@tonic-gate 14140Sstevel@tonic-gate setup(do_newline); 14150Sstevel@tonic-gate } 14160Sstevel@tonic-gate if (do_disk & DISK_EXTENDED_ERRORS) 14170Sstevel@tonic-gate setup(disk_errors); 14180Sstevel@tonic-gate } 14190Sstevel@tonic-gate 14200Sstevel@tonic-gate /* 14210Sstevel@tonic-gate * Add a new function to the list of functions 14220Sstevel@tonic-gate * for this invocation. Once on the stack the 14230Sstevel@tonic-gate * function is never removed nor does its place 14240Sstevel@tonic-gate * change. 14250Sstevel@tonic-gate */ 14260Sstevel@tonic-gate void 14270Sstevel@tonic-gate setup(void (*nfunc)(void)) 14280Sstevel@tonic-gate { 14290Sstevel@tonic-gate format_t *tmp; 14300Sstevel@tonic-gate 14310Sstevel@tonic-gate tmp = safe_alloc(sizeof (format_t)); 14320Sstevel@tonic-gate tmp->nfunc = nfunc; 14330Sstevel@tonic-gate tmp->next = 0; 14340Sstevel@tonic-gate if (formatter_end) 14350Sstevel@tonic-gate formatter_end->next = tmp; 14360Sstevel@tonic-gate else 14370Sstevel@tonic-gate formatter_list = tmp; 14380Sstevel@tonic-gate formatter_end = tmp; 14390Sstevel@tonic-gate 14400Sstevel@tonic-gate } 14410Sstevel@tonic-gate 14420Sstevel@tonic-gate /* 14430Sstevel@tonic-gate * The functions after this comment are devoted to printing 14440Sstevel@tonic-gate * various parts of the header. They are selected based on the 14450Sstevel@tonic-gate * options provided when the program was invoked. The functions 14460Sstevel@tonic-gate * are either directly invoked in printhdr() or are indirectly 14470Sstevel@tonic-gate * invoked by being placed on the list of functions used when 14480Sstevel@tonic-gate * extended headers are used. 14490Sstevel@tonic-gate */ 14500Sstevel@tonic-gate void 14510Sstevel@tonic-gate print_tty_hdr1(void) 14520Sstevel@tonic-gate { 14530Sstevel@tonic-gate char *fstr; 14540Sstevel@tonic-gate char *dstr; 14550Sstevel@tonic-gate 14560Sstevel@tonic-gate if (do_raw == 0) { 14570Sstevel@tonic-gate fstr = "%10.10s"; 14580Sstevel@tonic-gate dstr = "tty "; 14590Sstevel@tonic-gate } else { 14600Sstevel@tonic-gate fstr = "%s"; 14610Sstevel@tonic-gate dstr = "tty"; 14620Sstevel@tonic-gate } 14630Sstevel@tonic-gate push_out(fstr, dstr); 14640Sstevel@tonic-gate } 14650Sstevel@tonic-gate 14660Sstevel@tonic-gate void 14670Sstevel@tonic-gate print_tty_hdr2(void) 14680Sstevel@tonic-gate { 14690Sstevel@tonic-gate if (do_raw == 0) 14700Sstevel@tonic-gate push_out("%-10.10s", " tin tout"); 14710Sstevel@tonic-gate else 14720Sstevel@tonic-gate push_out("tin,tout"); 14730Sstevel@tonic-gate } 14740Sstevel@tonic-gate 14750Sstevel@tonic-gate void 14760Sstevel@tonic-gate print_cpu_hdr1(void) 14770Sstevel@tonic-gate { 14780Sstevel@tonic-gate char *dstr; 14790Sstevel@tonic-gate 14800Sstevel@tonic-gate if (do_raw == 0) 14810Sstevel@tonic-gate dstr = " cpu"; 14820Sstevel@tonic-gate else 14830Sstevel@tonic-gate dstr = "cpu"; 14840Sstevel@tonic-gate push_out(dstr); 14850Sstevel@tonic-gate } 14860Sstevel@tonic-gate 14870Sstevel@tonic-gate void 14880Sstevel@tonic-gate print_cpu_hdr2(void) 14890Sstevel@tonic-gate { 14900Sstevel@tonic-gate char *dstr; 14910Sstevel@tonic-gate 14920Sstevel@tonic-gate if (do_raw == 0) 14930Sstevel@tonic-gate dstr = " us sy wt id"; 14940Sstevel@tonic-gate else 14950Sstevel@tonic-gate dstr = "us,sy,wt,id"; 14960Sstevel@tonic-gate push_out(dstr); 14970Sstevel@tonic-gate } 14980Sstevel@tonic-gate 14990Sstevel@tonic-gate /* 15000Sstevel@tonic-gate * Assumption is that tty data is always first - no need for raw mode leading 15010Sstevel@tonic-gate * comma. 15020Sstevel@tonic-gate */ 15030Sstevel@tonic-gate void 15040Sstevel@tonic-gate print_tty_data(void) 15050Sstevel@tonic-gate { 15060Sstevel@tonic-gate char *fstr; 15070Sstevel@tonic-gate uint64_t deltas; 15080Sstevel@tonic-gate double raw; 15090Sstevel@tonic-gate double outch; 15100Sstevel@tonic-gate kstat_t *oldks = NULL; 15110Sstevel@tonic-gate 15120Sstevel@tonic-gate if (oldss) 15130Sstevel@tonic-gate oldks = &oldss->s_sys.ss_agg_sys; 15140Sstevel@tonic-gate 15150Sstevel@tonic-gate if (do_raw == 0) 15160Sstevel@tonic-gate fstr = " %3.0f %4.0f "; 15170Sstevel@tonic-gate else 15180Sstevel@tonic-gate fstr = "%.0f,%.0f"; 15190Sstevel@tonic-gate deltas = kstat_delta(oldks, &newss->s_sys.ss_agg_sys, "rawch"); 15200Sstevel@tonic-gate raw = deltas; 15210Sstevel@tonic-gate raw /= getime; 15220Sstevel@tonic-gate deltas = kstat_delta(oldks, &newss->s_sys.ss_agg_sys, "outch"); 15230Sstevel@tonic-gate outch = deltas; 15240Sstevel@tonic-gate outch /= getime; 15250Sstevel@tonic-gate push_out(fstr, raw, outch); 15260Sstevel@tonic-gate } 15270Sstevel@tonic-gate 15280Sstevel@tonic-gate /* 15290Sstevel@tonic-gate * Write out CPU data 15300Sstevel@tonic-gate */ 15310Sstevel@tonic-gate void 15320Sstevel@tonic-gate print_cpu_data(void) 15330Sstevel@tonic-gate { 15340Sstevel@tonic-gate char *fstr; 15350Sstevel@tonic-gate uint64_t idle; 15360Sstevel@tonic-gate uint64_t user; 15370Sstevel@tonic-gate uint64_t kern; 15380Sstevel@tonic-gate uint64_t wait; 15390Sstevel@tonic-gate kstat_t *oldks = NULL; 15400Sstevel@tonic-gate 15410Sstevel@tonic-gate if (oldss) 15420Sstevel@tonic-gate oldks = &oldss->s_sys.ss_agg_sys; 15430Sstevel@tonic-gate 15440Sstevel@tonic-gate if (do_raw == 0) 15450Sstevel@tonic-gate fstr = " %2.0f %2.0f %2.0f %2.0f"; 15460Sstevel@tonic-gate else 15470Sstevel@tonic-gate fstr = "%.0f,%.0f,%.0f,%.0f"; 15480Sstevel@tonic-gate 15490Sstevel@tonic-gate idle = kstat_delta(oldks, &newss->s_sys.ss_agg_sys, "cpu_ticks_idle"); 15500Sstevel@tonic-gate user = kstat_delta(oldks, &newss->s_sys.ss_agg_sys, "cpu_ticks_user"); 15510Sstevel@tonic-gate kern = kstat_delta(oldks, &newss->s_sys.ss_agg_sys, "cpu_ticks_kernel"); 15520Sstevel@tonic-gate wait = kstat_delta(oldks, &newss->s_sys.ss_agg_sys, "cpu_ticks_wait"); 15530Sstevel@tonic-gate push_out(fstr, user * percent, kern * percent, 15545957Swroche wait * percent, idle * percent); 15550Sstevel@tonic-gate } 15560Sstevel@tonic-gate 15570Sstevel@tonic-gate /* 15580Sstevel@tonic-gate * Emit the appropriate header. 15590Sstevel@tonic-gate */ 15600Sstevel@tonic-gate void 15610Sstevel@tonic-gate hdrout(void) 15620Sstevel@tonic-gate { 15630Sstevel@tonic-gate if (do_raw == 0) { 15640Sstevel@tonic-gate if (--tohdr == 0) 15650Sstevel@tonic-gate printhdr(0); 15660Sstevel@tonic-gate } else if (hdr_out == 0) { 15670Sstevel@tonic-gate printhdr(0); 15680Sstevel@tonic-gate hdr_out = 1; 15690Sstevel@tonic-gate } 15700Sstevel@tonic-gate } 15710Sstevel@tonic-gate 15720Sstevel@tonic-gate /* 15730Sstevel@tonic-gate * Write out disk errors when -E is specified. 15740Sstevel@tonic-gate */ 15750Sstevel@tonic-gate void 15760Sstevel@tonic-gate disk_errors(void) 15770Sstevel@tonic-gate { 15780Sstevel@tonic-gate (void) snapshot_walk(SNAP_IODEVS, oldss, newss, show_disk_errors, NULL); 15790Sstevel@tonic-gate } 15800Sstevel@tonic-gate 15810Sstevel@tonic-gate void 15820Sstevel@tonic-gate show_first_disk(void) 15830Sstevel@tonic-gate { 15840Sstevel@tonic-gate int count = 0; 15850Sstevel@tonic-gate 15860Sstevel@tonic-gate show_disk_mode = SHOW_FIRST_ONLY; 15870Sstevel@tonic-gate 15880Sstevel@tonic-gate (void) snapshot_walk(SNAP_IODEVS, oldss, newss, show_disk, &count); 15890Sstevel@tonic-gate } 15900Sstevel@tonic-gate 15910Sstevel@tonic-gate void 15920Sstevel@tonic-gate show_other_disks(void) 15930Sstevel@tonic-gate { 15940Sstevel@tonic-gate int count = 0; 15950Sstevel@tonic-gate 15960Sstevel@tonic-gate show_disk_mode = SHOW_SECOND_ONWARDS; 15970Sstevel@tonic-gate 15980Sstevel@tonic-gate (void) snapshot_walk(SNAP_IODEVS, oldss, newss, show_disk, &count); 15990Sstevel@tonic-gate } 16000Sstevel@tonic-gate 16010Sstevel@tonic-gate void 16020Sstevel@tonic-gate show_all_disks(void) 16030Sstevel@tonic-gate { 16040Sstevel@tonic-gate int count = 0; 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate show_disk_mode = SHOW_ALL; 16070Sstevel@tonic-gate 16080Sstevel@tonic-gate (void) snapshot_walk(SNAP_IODEVS, oldss, newss, show_disk, &count); 16090Sstevel@tonic-gate } 16100Sstevel@tonic-gate 16110Sstevel@tonic-gate /* 16120Sstevel@tonic-gate * Write a newline out and clear the lineout flag. 16130Sstevel@tonic-gate */ 16140Sstevel@tonic-gate static void 16150Sstevel@tonic-gate do_newline(void) 16160Sstevel@tonic-gate { 16170Sstevel@tonic-gate if (lineout) { 16180Sstevel@tonic-gate (void) putchar('\n'); 16190Sstevel@tonic-gate lineout = 0; 16200Sstevel@tonic-gate } 16210Sstevel@tonic-gate } 16220Sstevel@tonic-gate 16230Sstevel@tonic-gate /* 16240Sstevel@tonic-gate * Generalized printf function that determines what extra 16250Sstevel@tonic-gate * to print out if we're in raw mode. At this time we 16260Sstevel@tonic-gate * don't care about errors. 16270Sstevel@tonic-gate */ 16280Sstevel@tonic-gate static void 16290Sstevel@tonic-gate push_out(const char *message, ...) 16300Sstevel@tonic-gate { 16310Sstevel@tonic-gate va_list args; 16320Sstevel@tonic-gate 16330Sstevel@tonic-gate va_start(args, message); 16340Sstevel@tonic-gate if (do_raw && lineout == 1) 16350Sstevel@tonic-gate (void) putchar(','); 16360Sstevel@tonic-gate (void) vprintf(message, args); 16370Sstevel@tonic-gate va_end(args); 16380Sstevel@tonic-gate lineout = 1; 16390Sstevel@tonic-gate } 16400Sstevel@tonic-gate 16410Sstevel@tonic-gate /* 16420Sstevel@tonic-gate * Emit the header string when -e is specified. 16430Sstevel@tonic-gate */ 16440Sstevel@tonic-gate static void 16450Sstevel@tonic-gate print_err_hdr(void) 16460Sstevel@tonic-gate { 16470Sstevel@tonic-gate char obuf[SMALL_SCRATCH_BUFLEN]; 16480Sstevel@tonic-gate 16492723Scth if (do_raw) { 16502723Scth push_out("errors"); 16512723Scth return; 16522723Scth } 16532723Scth 16540Sstevel@tonic-gate if (do_conversions == 0) { 16550Sstevel@tonic-gate if (!(do_disk & DISK_EXTENDED)) { 16560Sstevel@tonic-gate (void) snprintf(obuf, sizeof (obuf), 16570Sstevel@tonic-gate "%11s", one_blank); 16580Sstevel@tonic-gate push_out(obuf); 16590Sstevel@tonic-gate } 16600Sstevel@tonic-gate } else if (do_disk == DISK_ERRORS) 16610Sstevel@tonic-gate push_out(two_blanks); 16620Sstevel@tonic-gate else 16630Sstevel@tonic-gate push_out(one_blank); 16640Sstevel@tonic-gate push_out("---- errors --- "); 16650Sstevel@tonic-gate } 16660Sstevel@tonic-gate 16670Sstevel@tonic-gate /* 16680Sstevel@tonic-gate * Emit the header string when -e is specified. 16690Sstevel@tonic-gate */ 16700Sstevel@tonic-gate static void 16710Sstevel@tonic-gate print_disk_header(void) 16720Sstevel@tonic-gate { 16730Sstevel@tonic-gate push_out(disk_header); 16740Sstevel@tonic-gate } 16750Sstevel@tonic-gate 16760Sstevel@tonic-gate /* 16770Sstevel@tonic-gate * Write out a timestamp. Format is all that goes out on 16780Sstevel@tonic-gate * the line so no use of push_out. 16790Sstevel@tonic-gate * 16800Sstevel@tonic-gate * Write out as decimal reprentation of time_t value 16810Sstevel@tonic-gate * (-T u was specified) or the string returned from 16820Sstevel@tonic-gate * ctime() (-T d was specified). 16830Sstevel@tonic-gate */ 16840Sstevel@tonic-gate static void 16850Sstevel@tonic-gate print_timestamp(void) 16860Sstevel@tonic-gate { 16870Sstevel@tonic-gate time_t t; 16880Sstevel@tonic-gate 16890Sstevel@tonic-gate if (time(&t) != -1) { 16900Sstevel@tonic-gate if (do_timestamp == UDATE) { 16910Sstevel@tonic-gate (void) printf("%ld\n", t); 16920Sstevel@tonic-gate } else if (do_timestamp == CDATE) { 16930Sstevel@tonic-gate char *cpt; 16940Sstevel@tonic-gate 16950Sstevel@tonic-gate cpt = ctime(&t); 16960Sstevel@tonic-gate if (cpt) { 16970Sstevel@tonic-gate (void) fputs(cpt, stdout); 16980Sstevel@tonic-gate } 16990Sstevel@tonic-gate } 17000Sstevel@tonic-gate } 17010Sstevel@tonic-gate } 17020Sstevel@tonic-gate 17030Sstevel@tonic-gate /* 17040Sstevel@tonic-gate * No, UINTMAX_MAX isn't the right thing here since 17050Sstevel@tonic-gate * it is #defined to be either INT32_MAX or INT64_MAX 17060Sstevel@tonic-gate * depending on the whether _LP64 is defined. 17070Sstevel@tonic-gate * 17080Sstevel@tonic-gate * We want to handle the odd future case of having 17090Sstevel@tonic-gate * ulonglong_t be more than 64 bits but we have 17100Sstevel@tonic-gate * no nice #define MAX value we can drop in place 17110Sstevel@tonic-gate * without having to change this code in the future. 17120Sstevel@tonic-gate */ 17130Sstevel@tonic-gate 17140Sstevel@tonic-gate u_longlong_t 17150Sstevel@tonic-gate ull_delta(u_longlong_t old, u_longlong_t new) 17160Sstevel@tonic-gate { 17170Sstevel@tonic-gate if (new >= old) 17180Sstevel@tonic-gate return (new - old); 17190Sstevel@tonic-gate else 17200Sstevel@tonic-gate return ((UINT64_MAX - old) + new + 1); 17210Sstevel@tonic-gate } 17220Sstevel@tonic-gate 17230Sstevel@tonic-gate /* 17240Sstevel@tonic-gate * Take the difference of an unsigned 32 17250Sstevel@tonic-gate * bit int attempting to cater for 17260Sstevel@tonic-gate * overflow. 17270Sstevel@tonic-gate */ 17280Sstevel@tonic-gate uint_t 17290Sstevel@tonic-gate u32_delta(uint_t old, uint_t new) 17300Sstevel@tonic-gate { 17310Sstevel@tonic-gate if (new >= old) 17320Sstevel@tonic-gate return (new - old); 17330Sstevel@tonic-gate else 17340Sstevel@tonic-gate return ((UINT32_MAX - old) + new + 1); 17350Sstevel@tonic-gate } 17360Sstevel@tonic-gate 17370Sstevel@tonic-gate /* 17380Sstevel@tonic-gate * This is exactly what is needed for standard iostat output, 17390Sstevel@tonic-gate * but make sure to use it only for that 17400Sstevel@tonic-gate */ 17410Sstevel@tonic-gate #define EPSILON (0.1) 17420Sstevel@tonic-gate static int 17430Sstevel@tonic-gate fzero(double value) 17440Sstevel@tonic-gate { 17450Sstevel@tonic-gate return (value >= 0.0 && value < EPSILON); 17460Sstevel@tonic-gate } 17470Sstevel@tonic-gate 17480Sstevel@tonic-gate static int 17490Sstevel@tonic-gate safe_strtoi(char const *val, char *errmsg) 17500Sstevel@tonic-gate { 17510Sstevel@tonic-gate char *end; 17520Sstevel@tonic-gate long tmp; 17530Sstevel@tonic-gate 17540Sstevel@tonic-gate errno = 0; 17550Sstevel@tonic-gate tmp = strtol(val, &end, 10); 17560Sstevel@tonic-gate if (*end != '\0' || errno) 17570Sstevel@tonic-gate fail(0, "%s %s", errmsg, val); 17580Sstevel@tonic-gate return ((int)tmp); 17590Sstevel@tonic-gate } 1760