2003-03-20 20:48:41 +00:00
|
|
|
/*-
|
2017-11-27 15:37:16 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2003-03-20 20:48:41 +00:00
|
|
|
* Copyright (c) 2003 Poul-Henning Kamp
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The names of the authors may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2006-05-20 19:17:47 +00:00
|
|
|
#include <sys/devicestat.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <curses.h>
|
|
|
|
#include <devstat.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <histedit.h>
|
|
|
|
#include <libgeom.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <regex.h>
|
2003-03-20 20:48:41 +00:00
|
|
|
#include <stdint.h>
|
2006-05-20 19:17:47 +00:00
|
|
|
#include <stdio.h>
|
2003-03-20 20:48:41 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-05-20 19:17:47 +00:00
|
|
|
#include <sysexits.h>
|
2003-03-20 20:48:41 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2016-11-09 07:31:39 +00:00
|
|
|
static int flag_a, flag_b, flag_B, flag_c, flag_d, flag_o, flag_p, flag_s;
|
2007-03-29 07:23:49 +00:00
|
|
|
static int flag_I = 1000000;
|
2003-03-20 20:48:41 +00:00
|
|
|
|
2008-10-07 10:25:27 +00:00
|
|
|
#define PRINTMSG(...) do { \
|
2016-11-09 07:31:39 +00:00
|
|
|
if ((flag_b && !loop) || (flag_B)) \
|
2008-10-07 10:25:27 +00:00
|
|
|
printf(__VA_ARGS__); \
|
|
|
|
else if (!flag_b) \
|
|
|
|
printw(__VA_ARGS__); \
|
|
|
|
} while(0)
|
|
|
|
|
2003-03-22 09:39:52 +00:00
|
|
|
static void usage(void);
|
|
|
|
|
2006-05-20 19:17:47 +00:00
|
|
|
static const char*
|
|
|
|
el_prompt(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
return ("Filter: ");
|
|
|
|
}
|
|
|
|
|
2003-03-20 20:48:41 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int error, i, quit;
|
2008-10-07 10:25:27 +00:00
|
|
|
int curx, cury, maxx, maxy, line_len, loop, max_flen;
|
2003-03-20 20:48:41 +00:00
|
|
|
struct devstat *gsp, *gsq;
|
|
|
|
void *sp, *sq;
|
|
|
|
double dt;
|
|
|
|
struct timespec tp, tq;
|
|
|
|
struct gmesh gmp;
|
|
|
|
struct gprovider *pp;
|
2004-05-16 22:08:17 +00:00
|
|
|
struct gconsumer *cp;
|
2003-03-20 20:48:41 +00:00
|
|
|
struct gident *gid;
|
2006-05-20 19:17:47 +00:00
|
|
|
regex_t f_re, tmp_f_re;
|
2003-03-20 20:48:41 +00:00
|
|
|
short cf, cb;
|
|
|
|
char *p;
|
2006-05-20 19:17:47 +00:00
|
|
|
char f_s[100], pf_s[100], tmp_f_s[100];
|
|
|
|
const char *line;
|
2016-11-09 07:31:39 +00:00
|
|
|
long double ld[16];
|
2003-03-20 20:48:41 +00:00
|
|
|
uint64_t u64;
|
2006-05-20 19:17:47 +00:00
|
|
|
EditLine *el;
|
|
|
|
History *hist;
|
|
|
|
HistEvent hist_ev;
|
2003-03-20 20:48:41 +00:00
|
|
|
|
2008-10-07 10:25:27 +00:00
|
|
|
hist = NULL;
|
|
|
|
el = NULL;
|
|
|
|
maxx = -1;
|
|
|
|
curx = -1;
|
|
|
|
loop = 1;
|
2009-03-12 13:17:46 +00:00
|
|
|
/* Turn on batch mode if output is not tty. */
|
|
|
|
if (!isatty(fileno(stdout)))
|
|
|
|
flag_b = 1;
|
|
|
|
|
2006-05-20 19:17:47 +00:00
|
|
|
f_s[0] = '\0';
|
2016-11-09 07:31:39 +00:00
|
|
|
while ((i = getopt(argc, argv, "abBdcf:I:ops")) != -1) {
|
2003-03-20 20:48:41 +00:00
|
|
|
switch (i) {
|
2004-10-10 16:13:11 +00:00
|
|
|
case 'a':
|
|
|
|
flag_a = 1;
|
|
|
|
break;
|
2008-10-07 10:25:27 +00:00
|
|
|
case 'b':
|
|
|
|
flag_b = 1;
|
|
|
|
break;
|
2016-11-09 07:31:39 +00:00
|
|
|
case 'B':
|
|
|
|
flag_B = 1;
|
|
|
|
flag_b = 1;
|
|
|
|
break;
|
2003-03-20 20:48:41 +00:00
|
|
|
case 'c':
|
2003-03-22 09:47:02 +00:00
|
|
|
flag_c = 1;
|
2003-03-20 20:48:41 +00:00
|
|
|
break;
|
2004-02-15 09:34:08 +00:00
|
|
|
case 'd':
|
|
|
|
flag_d = 1;
|
|
|
|
break;
|
2006-05-20 19:17:47 +00:00
|
|
|
case 'f':
|
|
|
|
if (strlen(optarg) > sizeof(f_s) - 1)
|
|
|
|
errx(EX_USAGE, "Filter string too long");
|
|
|
|
if (regcomp(&f_re, optarg, REG_EXTENDED) != 0)
|
|
|
|
errx(EX_USAGE,
|
|
|
|
"Invalid filter - see re_format(7)");
|
2015-09-11 06:52:57 +00:00
|
|
|
strlcpy(f_s, optarg, sizeof(f_s));
|
2006-05-20 19:17:47 +00:00
|
|
|
break;
|
2014-05-17 15:26:08 +00:00
|
|
|
case 'o':
|
|
|
|
flag_o = 1;
|
|
|
|
break;
|
2003-03-20 20:48:41 +00:00
|
|
|
case 'I':
|
|
|
|
p = NULL;
|
|
|
|
i = strtoul(optarg, &p, 0);
|
2003-03-22 09:23:29 +00:00
|
|
|
if (p == optarg || errno == EINVAL ||
|
|
|
|
errno == ERANGE) {
|
2003-03-20 20:48:41 +00:00
|
|
|
errx(1, "Invalid argument to -I");
|
|
|
|
} else if (!strcmp(p, "s"))
|
|
|
|
i *= 1000000;
|
|
|
|
else if (!strcmp(p, "ms"))
|
|
|
|
i *= 1000;
|
|
|
|
else if (!strcmp(p, "us"))
|
|
|
|
i *= 1;
|
|
|
|
flag_I = i;
|
|
|
|
break;
|
2014-07-03 21:48:19 +00:00
|
|
|
case 'p':
|
|
|
|
flag_p = 1;
|
|
|
|
break;
|
2016-11-09 07:31:39 +00:00
|
|
|
case 's':
|
|
|
|
flag_s = 1;
|
|
|
|
break;
|
2003-03-20 20:48:41 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
2003-03-22 09:39:52 +00:00
|
|
|
usage();
|
2003-03-20 20:48:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
if (argc != 0)
|
2003-03-22 09:39:52 +00:00
|
|
|
usage();
|
2003-03-20 20:48:41 +00:00
|
|
|
|
|
|
|
i = geom_gettree(&gmp);
|
|
|
|
if (i != 0)
|
|
|
|
err(1, "geom_gettree = %d", i);
|
|
|
|
error = geom_stats_open();
|
|
|
|
if (error)
|
|
|
|
err(1, "geom_stats_open()");
|
|
|
|
sq = NULL;
|
|
|
|
sq = geom_stats_snapshot_get();
|
|
|
|
if (sq == NULL)
|
|
|
|
err(1, "geom_stats_snapshot()");
|
2008-10-07 10:25:27 +00:00
|
|
|
if (!flag_b) {
|
|
|
|
/* Setup libedit */
|
|
|
|
hist = history_init();
|
|
|
|
if (hist == NULL)
|
|
|
|
err(EX_SOFTWARE, "history_init()");
|
|
|
|
history(hist, &hist_ev, H_SETSIZE, 100);
|
|
|
|
el = el_init("gstat", stdin, stdout, stderr);
|
|
|
|
if (el == NULL)
|
|
|
|
err(EX_SOFTWARE, "el_init");
|
|
|
|
el_set(el, EL_EDITOR, "emacs");
|
|
|
|
el_set(el, EL_SIGNAL, 1);
|
|
|
|
el_set(el, EL_HIST, history, hist);
|
|
|
|
el_set(el, EL_PROMPT, el_prompt);
|
|
|
|
if (f_s[0] != '\0')
|
|
|
|
history(hist, &hist_ev, H_ENTER, f_s);
|
2016-06-23 23:13:14 +00:00
|
|
|
/* Setup curses */
|
|
|
|
initscr();
|
|
|
|
start_color();
|
|
|
|
use_default_colors();
|
|
|
|
pair_content(0, &cf, &cb);
|
|
|
|
init_pair(1, COLOR_GREEN, cb);
|
|
|
|
init_pair(2, COLOR_MAGENTA, cb);
|
|
|
|
init_pair(3, COLOR_RED, cb);
|
|
|
|
cbreak();
|
|
|
|
noecho();
|
|
|
|
nonl();
|
|
|
|
nodelay(stdscr, 1);
|
|
|
|
intrflush(stdscr, FALSE);
|
|
|
|
keypad(stdscr, TRUE);
|
2008-10-07 10:25:27 +00:00
|
|
|
}
|
2003-03-20 20:48:41 +00:00
|
|
|
geom_stats_snapshot_timestamp(sq, &tq);
|
|
|
|
for (quit = 0; !quit;) {
|
|
|
|
sp = geom_stats_snapshot_get();
|
|
|
|
if (sp == NULL)
|
|
|
|
err(1, "geom_stats_snapshot()");
|
|
|
|
geom_stats_snapshot_timestamp(sp, &tp);
|
|
|
|
dt = tp.tv_sec - tq.tv_sec;
|
|
|
|
dt += (tp.tv_nsec - tq.tv_nsec) * 1e-9;
|
|
|
|
tq = tp;
|
|
|
|
|
|
|
|
geom_stats_snapshot_reset(sp);
|
|
|
|
geom_stats_snapshot_reset(sq);
|
2016-11-09 07:31:39 +00:00
|
|
|
if (!flag_b)
|
|
|
|
move(0,0);
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG("dT: %5.3fs w: %.3fs", dt, (float)flag_I / 1000000);
|
2006-05-20 19:17:47 +00:00
|
|
|
if (f_s[0] != '\0') {
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" filter: ");
|
|
|
|
if (!flag_b) {
|
|
|
|
getyx(stdscr, cury, curx);
|
|
|
|
getmaxyx(stdscr, maxy, maxx);
|
|
|
|
}
|
2015-09-11 06:52:57 +00:00
|
|
|
strlcpy(pf_s, f_s, sizeof(pf_s));
|
2006-05-20 19:17:47 +00:00
|
|
|
max_flen = maxx - curx - 1;
|
|
|
|
if ((int)strlen(f_s) > max_flen && max_flen >= 0) {
|
|
|
|
if (max_flen > 3)
|
|
|
|
pf_s[max_flen - 3] = '.';
|
|
|
|
if (max_flen > 2)
|
|
|
|
pf_s[max_flen - 2] = '.';
|
|
|
|
if (max_flen > 1)
|
|
|
|
pf_s[max_flen - 1] = '.';
|
|
|
|
pf_s[max_flen] = '\0';
|
|
|
|
}
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG("%s", pf_s);
|
2006-05-20 19:17:47 +00:00
|
|
|
}
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG("\n");
|
|
|
|
PRINTMSG(" L(q) ops/s ");
|
2016-11-09 07:31:39 +00:00
|
|
|
if (flag_s) {
|
|
|
|
PRINTMSG(" r/s kB kBps ms/r ");
|
|
|
|
PRINTMSG(" w/s kB kBps ms/w ");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRINTMSG(" r/s kBps ms/r ");
|
|
|
|
PRINTMSG(" w/s kBps ms/w ");
|
|
|
|
}
|
|
|
|
if (flag_d) {
|
|
|
|
if (flag_s)
|
|
|
|
PRINTMSG(" d/s kB kBps ms/d ");
|
|
|
|
else
|
|
|
|
PRINTMSG(" d/s kBps ms/d ");
|
|
|
|
}
|
2014-05-17 15:26:08 +00:00
|
|
|
if (flag_o)
|
|
|
|
PRINTMSG(" o/s ms/o ");
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG("%%busy Name\n");
|
2003-03-20 20:48:41 +00:00
|
|
|
for (;;) {
|
|
|
|
gsp = geom_stats_snapshot_next(sp);
|
|
|
|
gsq = geom_stats_snapshot_next(sq);
|
|
|
|
if (gsp == NULL || gsq == NULL)
|
|
|
|
break;
|
|
|
|
if (gsp->id == NULL)
|
|
|
|
continue;
|
|
|
|
gid = geom_lookupid(&gmp, gsp->id);
|
|
|
|
if (gid == NULL) {
|
|
|
|
geom_deletetree(&gmp);
|
|
|
|
i = geom_gettree(&gmp);
|
|
|
|
if (i != 0)
|
|
|
|
err(1, "geom_gettree = %d", i);
|
|
|
|
gid = geom_lookupid(&gmp, gsp->id);
|
|
|
|
}
|
|
|
|
if (gid == NULL)
|
|
|
|
continue;
|
2006-05-20 19:17:47 +00:00
|
|
|
if (gid->lg_what == ISCONSUMER && !flag_c)
|
|
|
|
continue;
|
2014-07-03 21:48:19 +00:00
|
|
|
if (flag_p && gid->lg_what == ISPROVIDER &&
|
|
|
|
((struct gprovider *)(gid->lg_ptr))->lg_geom->lg_rank != 1)
|
|
|
|
continue;
|
2006-05-20 19:17:47 +00:00
|
|
|
/* Do not print past end of window */
|
2008-10-07 10:25:27 +00:00
|
|
|
if (!flag_b) {
|
|
|
|
getyx(stdscr, cury, curx);
|
|
|
|
if (curx > 0)
|
|
|
|
continue;
|
|
|
|
}
|
2006-05-20 19:17:47 +00:00
|
|
|
if ((gid->lg_what == ISPROVIDER
|
|
|
|
|| gid->lg_what == ISCONSUMER) && f_s[0] != '\0') {
|
|
|
|
pp = gid->lg_ptr;
|
|
|
|
if ((regexec(&f_re, pp->lg_name, 0, NULL, 0)
|
|
|
|
!= 0))
|
|
|
|
continue;
|
|
|
|
}
|
2003-03-20 20:48:41 +00:00
|
|
|
if (gsp->sequence0 != gsp->sequence1) {
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG("*\n");
|
2003-03-20 20:48:41 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
devstat_compute_statistics(gsp, gsq, dt,
|
|
|
|
DSM_QUEUE_LENGTH, &u64,
|
|
|
|
DSM_TRANSFERS_PER_SECOND, &ld[0],
|
2004-02-15 09:34:08 +00:00
|
|
|
|
2003-03-20 20:48:41 +00:00
|
|
|
DSM_TRANSFERS_PER_SECOND_READ, &ld[1],
|
|
|
|
DSM_MB_PER_SECOND_READ, &ld[2],
|
|
|
|
DSM_MS_PER_TRANSACTION_READ, &ld[3],
|
2004-02-15 09:34:08 +00:00
|
|
|
|
2003-03-20 20:48:41 +00:00
|
|
|
DSM_TRANSFERS_PER_SECOND_WRITE, &ld[4],
|
|
|
|
DSM_MB_PER_SECOND_WRITE, &ld[5],
|
|
|
|
DSM_MS_PER_TRANSACTION_WRITE, &ld[6],
|
2004-02-15 09:34:08 +00:00
|
|
|
|
2003-03-20 20:48:41 +00:00
|
|
|
DSM_BUSY_PCT, &ld[7],
|
2014-05-17 15:26:08 +00:00
|
|
|
|
2004-02-15 09:34:08 +00:00
|
|
|
DSM_TRANSFERS_PER_SECOND_FREE, &ld[8],
|
|
|
|
DSM_MB_PER_SECOND_FREE, &ld[9],
|
|
|
|
DSM_MS_PER_TRANSACTION_FREE, &ld[10],
|
2014-05-17 15:26:08 +00:00
|
|
|
|
|
|
|
DSM_TRANSFERS_PER_SECOND_OTHER, &ld[11],
|
|
|
|
DSM_MS_PER_TRANSACTION_OTHER, &ld[12],
|
|
|
|
|
2016-11-09 07:31:39 +00:00
|
|
|
DSM_KB_PER_TRANSFER_READ, &ld[13],
|
|
|
|
DSM_KB_PER_TRANSFER_WRITE, &ld[14],
|
|
|
|
DSM_KB_PER_TRANSFER_FREE, &ld[15],
|
|
|
|
|
2003-03-20 20:48:41 +00:00
|
|
|
DSM_NONE);
|
|
|
|
|
2004-10-10 16:13:11 +00:00
|
|
|
if (flag_a && ld[7] < 0.1) {
|
|
|
|
*gsq = *gsp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %4ju", (uintmax_t)u64);
|
|
|
|
PRINTMSG(" %6.0f", (double)ld[0]);
|
|
|
|
PRINTMSG(" %6.0f", (double)ld[1]);
|
2016-11-09 07:31:39 +00:00
|
|
|
if (flag_s)
|
|
|
|
PRINTMSG(" %6.0f", (double)ld[13]);
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %6.0f", (double)ld[2] * 1024);
|
2008-01-06 12:12:44 +00:00
|
|
|
if (ld[3] > 1e3)
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %6.0f", (double)ld[3]);
|
2008-01-06 12:12:44 +00:00
|
|
|
else
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %6.1f", (double)ld[3]);
|
|
|
|
PRINTMSG(" %6.0f", (double)ld[4]);
|
2016-11-09 07:31:39 +00:00
|
|
|
if (flag_s)
|
|
|
|
PRINTMSG(" %6.0f", (double)ld[14]);
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %6.0f", (double)ld[5] * 1024);
|
2008-01-06 12:12:44 +00:00
|
|
|
if (ld[6] > 1e3)
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %6.0f", (double)ld[6]);
|
2008-01-06 12:12:44 +00:00
|
|
|
else
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %6.1f", (double)ld[6]);
|
2003-03-20 20:48:41 +00:00
|
|
|
|
2004-02-15 09:34:08 +00:00
|
|
|
if (flag_d) {
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %6.0f", (double)ld[8]);
|
2016-11-09 07:31:39 +00:00
|
|
|
if (flag_s)
|
|
|
|
PRINTMSG(" %6.0f", (double)ld[15]);
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %6.0f", (double)ld[9] * 1024);
|
2008-01-06 12:12:44 +00:00
|
|
|
if (ld[10] > 1e3)
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %6.0f", (double)ld[10]);
|
2008-01-06 12:12:44 +00:00
|
|
|
else
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %6.1f", (double)ld[10]);
|
2004-02-15 09:34:08 +00:00
|
|
|
}
|
|
|
|
|
2014-05-17 15:26:08 +00:00
|
|
|
if (flag_o) {
|
|
|
|
PRINTMSG(" %6.0f", (double)ld[11]);
|
|
|
|
if (ld[12] > 1e3)
|
|
|
|
PRINTMSG(" %6.0f", (double)ld[12]);
|
|
|
|
else
|
|
|
|
PRINTMSG(" %6.1f", (double)ld[12]);
|
|
|
|
}
|
|
|
|
|
2003-03-20 20:48:41 +00:00
|
|
|
if (ld[7] > 80)
|
|
|
|
i = 3;
|
|
|
|
else if (ld[7] > 50)
|
|
|
|
i = 2;
|
|
|
|
else
|
|
|
|
i = 1;
|
2008-10-07 10:25:27 +00:00
|
|
|
if (!flag_b)
|
|
|
|
attron(COLOR_PAIR(i));
|
|
|
|
PRINTMSG(" %6.1lf", (double)ld[7]);
|
2009-03-12 13:17:46 +00:00
|
|
|
if (!flag_b) {
|
2008-10-07 10:25:27 +00:00
|
|
|
attroff(COLOR_PAIR(i));
|
2009-03-12 13:17:46 +00:00
|
|
|
PRINTMSG("|");
|
|
|
|
} else
|
|
|
|
PRINTMSG(" ");
|
2003-03-20 20:48:41 +00:00
|
|
|
if (gid == NULL) {
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" ??");
|
2004-03-09 21:14:18 +00:00
|
|
|
} else if (gid->lg_what == ISPROVIDER) {
|
|
|
|
pp = gid->lg_ptr;
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %s", pp->lg_name);
|
2004-03-09 21:14:18 +00:00
|
|
|
} else if (gid->lg_what == ISCONSUMER) {
|
|
|
|
cp = gid->lg_ptr;
|
2008-10-07 10:25:27 +00:00
|
|
|
PRINTMSG(" %s/%s/%s",
|
2004-03-09 21:14:18 +00:00
|
|
|
cp->lg_geom->lg_class->lg_name,
|
|
|
|
cp->lg_geom->lg_name,
|
|
|
|
cp->lg_provider->lg_name);
|
2003-03-20 20:48:41 +00:00
|
|
|
}
|
2008-10-07 10:25:27 +00:00
|
|
|
if (!flag_b)
|
|
|
|
clrtoeol();
|
|
|
|
PRINTMSG("\n");
|
2003-03-20 20:48:41 +00:00
|
|
|
*gsq = *gsp;
|
|
|
|
}
|
|
|
|
geom_stats_snapshot_free(sp);
|
2008-10-07 10:25:27 +00:00
|
|
|
if (flag_b) {
|
|
|
|
/* We loop extra to make sure we get the information. */
|
|
|
|
if (!loop)
|
|
|
|
break;
|
2016-11-09 07:31:39 +00:00
|
|
|
if (!flag_B)
|
|
|
|
loop = 0;
|
|
|
|
else
|
|
|
|
fflush(stdout);
|
2008-10-07 10:25:27 +00:00
|
|
|
usleep(flag_I);
|
|
|
|
continue;
|
|
|
|
}
|
2006-05-20 19:17:47 +00:00
|
|
|
getyx(stdscr, cury, curx);
|
|
|
|
getmaxyx(stdscr, maxy, maxx);
|
2003-03-20 20:48:41 +00:00
|
|
|
clrtobot();
|
2006-05-20 19:17:47 +00:00
|
|
|
if (maxy - 1 <= cury)
|
|
|
|
move(maxy - 1, 0);
|
2003-03-20 20:48:41 +00:00
|
|
|
refresh();
|
|
|
|
usleep(flag_I);
|
2006-05-20 19:17:47 +00:00
|
|
|
while((i = getch()) != ERR) {
|
|
|
|
switch (i) {
|
|
|
|
case '>':
|
|
|
|
flag_I *= 2;
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
flag_I /= 2;
|
|
|
|
if (flag_I < 1000)
|
|
|
|
flag_I = 1000;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
flag_c = !flag_c;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
move(0,0);
|
|
|
|
clrtoeol();
|
|
|
|
refresh();
|
|
|
|
line = el_gets(el, &line_len);
|
|
|
|
if (line == NULL)
|
|
|
|
err(1, "el_gets");
|
|
|
|
if (line_len > 1)
|
|
|
|
history(hist, &hist_ev, H_ENTER, line);
|
2015-09-11 06:52:57 +00:00
|
|
|
strlcpy(tmp_f_s, line, sizeof(f_s));
|
2006-05-20 19:17:47 +00:00
|
|
|
if ((p = strchr(tmp_f_s, '\n')) != NULL)
|
|
|
|
*p = '\0';
|
|
|
|
/*
|
2016-06-23 23:13:14 +00:00
|
|
|
* Fix the terminal. We messed up
|
2006-05-20 19:17:47 +00:00
|
|
|
* curses idea of the screen by using
|
|
|
|
* libedit.
|
|
|
|
*/
|
|
|
|
clear();
|
|
|
|
refresh();
|
2016-06-23 23:13:14 +00:00
|
|
|
cbreak();
|
|
|
|
noecho();
|
|
|
|
nonl();
|
2006-05-20 19:17:47 +00:00
|
|
|
if (regcomp(&tmp_f_re, tmp_f_s, REG_EXTENDED)
|
|
|
|
!= 0) {
|
|
|
|
move(0, 0);
|
|
|
|
printw("Invalid filter");
|
|
|
|
refresh();
|
|
|
|
sleep(1);
|
|
|
|
} else {
|
2015-09-11 06:52:57 +00:00
|
|
|
strlcpy(f_s, tmp_f_s, sizeof(f_s));
|
2006-05-20 19:17:47 +00:00
|
|
|
f_re = tmp_f_re;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
f_s[0] = '\0';
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
quit = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-03-20 20:48:41 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-21 09:34:23 +00:00
|
|
|
|
2008-10-07 10:25:27 +00:00
|
|
|
if (!flag_b) {
|
|
|
|
el_end(el);
|
2016-06-23 23:13:14 +00:00
|
|
|
endwin();
|
2008-10-07 10:25:27 +00:00
|
|
|
}
|
2006-05-20 19:17:47 +00:00
|
|
|
exit(EX_OK);
|
2003-03-20 20:48:41 +00:00
|
|
|
}
|
2003-03-22 09:39:52 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2016-11-09 07:31:39 +00:00
|
|
|
fprintf(stderr, "usage: gstat [-abBcdps] [-f filter] [-I interval]\n");
|
2006-05-20 19:17:47 +00:00
|
|
|
exit(EX_USAGE);
|
2003-03-22 09:39:52 +00:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|