2 * Copyright (c) 2003 Poul-Henning Kamp
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the authors may not be used to endorse or promote
14 * products derived from this software without specific prior written
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 #include <sys/resource.h>
48 #include <sys/devicestat.h>
50 static int flag_a, flag_c, flag_d;
51 static int flag_I = 500000;
53 static void usage(void);
56 main(int argc, char **argv)
59 struct devstat *gsp, *gsq;
62 struct timespec tp, tq;
72 while ((i = getopt(argc, argv, "adcI:")) != -1) {
85 i = strtoul(optarg, &p, 0);
86 if (p == optarg || errno == EINVAL ||
88 errx(1, "Invalid argument to -I");
89 } else if (!strcmp(p, "s"))
91 else if (!strcmp(p, "ms"))
93 else if (!strcmp(p, "us"))
107 i = geom_gettree(&gmp);
109 err(1, "geom_gettree = %d", i);
110 error = geom_stats_open();
112 err(1, "geom_stats_open()");
114 sq = geom_stats_snapshot_get();
116 err(1, "geom_stats_snapshot()");
119 use_default_colors();
120 pair_content(0, &cf, &cb);
121 init_pair(1, COLOR_GREEN, cb);
122 init_pair(2, COLOR_MAGENTA, cb);
123 init_pair(3, COLOR_RED, cb);
128 intrflush(stdscr, FALSE);
129 keypad(stdscr, TRUE);
130 geom_stats_snapshot_timestamp(sq, &tq);
131 for (quit = 0; !quit;) {
132 sp = geom_stats_snapshot_get();
134 err(1, "geom_stats_snapshot()");
135 geom_stats_snapshot_timestamp(sp, &tp);
136 dt = tp.tv_sec - tq.tv_sec;
137 dt += (tp.tv_nsec - tq.tv_nsec) * 1e-9;
140 geom_stats_snapshot_reset(sp);
141 geom_stats_snapshot_reset(sq);
143 printw("dT: %5.3f flag_I %dus sizeof %d i %d\n",
144 dt, flag_I, sizeof(*gsp), i);
145 printw(" L(q) ops/s ");
146 printw(" r/s kBps ms/r ");
147 printw(" w/s kBps ms/w ");
149 printw(" d/s kBps ms/d ");
150 printw("%%busy Name\n");
152 gsp = geom_stats_snapshot_next(sp);
153 gsq = geom_stats_snapshot_next(sq);
154 if (gsp == NULL || gsq == NULL)
158 gid = geom_lookupid(&gmp, gsp->id);
160 geom_deletetree(&gmp);
161 i = geom_gettree(&gmp);
163 err(1, "geom_gettree = %d", i);
164 gid = geom_lookupid(&gmp, gsp->id);
168 if (gid != NULL && gid->lg_what == ISCONSUMER &&
171 if (gsp->sequence0 != gsp->sequence1) {
175 devstat_compute_statistics(gsp, gsq, dt,
176 DSM_QUEUE_LENGTH, &u64,
177 DSM_TRANSFERS_PER_SECOND, &ld[0],
179 DSM_TRANSFERS_PER_SECOND_READ, &ld[1],
180 DSM_MB_PER_SECOND_READ, &ld[2],
181 DSM_MS_PER_TRANSACTION_READ, &ld[3],
183 DSM_TRANSFERS_PER_SECOND_WRITE, &ld[4],
184 DSM_MB_PER_SECOND_WRITE, &ld[5],
185 DSM_MS_PER_TRANSACTION_WRITE, &ld[6],
187 DSM_BUSY_PCT, &ld[7],
188 DSM_TRANSFERS_PER_SECOND_FREE, &ld[8],
189 DSM_MB_PER_SECOND_FREE, &ld[9],
190 DSM_MS_PER_TRANSACTION_FREE, &ld[10],
193 if (flag_a && ld[7] < 0.1) {
198 printw(" %4ju", (uintmax_t)u64);
199 printw(" %6.0f", (double)ld[0]);
200 printw(" %6.0f", (double)ld[1]);
201 printw(" %6.0f", (double)ld[2] * 1024);
202 printw(" %6.1f", (double)ld[3]);
203 printw(" %6.0f", (double)ld[4]);
204 printw(" %6.0f", (double)ld[5] * 1024);
205 printw(" %6.1f", (double)ld[6]);
208 printw(" %6.0f", (double)ld[8]);
209 printw(" %6.0f", (double)ld[9] * 1024);
210 printw(" %6.1f", (double)ld[10]);
219 attron(COLOR_PAIR(i));
220 printw(" %6.1lf", (double)ld[7]);
221 attroff(COLOR_PAIR(i));
225 } else if (gid->lg_what == ISPROVIDER) {
227 printw(" %s", pp->lg_name);
228 } else if (gid->lg_what == ISCONSUMER) {
231 cp->lg_geom->lg_class->lg_name,
232 cp->lg_geom->lg_name,
233 cp->lg_provider->lg_name);
239 geom_stats_snapshot_free(sp);
271 fprintf(stderr, "usage: gstat [-acd] [-I interval]\n");