diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2007-04-24 06:32:09 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2007-04-24 06:32:09 +0000 |
commit | 7851ca48b013029dbd218b5a3132fb2d02cd1ad5 (patch) | |
tree | 122f0fd37951a35696a288a53419ac0b972a3637 /usr.bin/systat | |
parent | f3d6e320d570b412b53697bbe0d09988db14f11c (diff) |
support non-integral refresh intervals, possibly as low as 0.1s.
this makes it more useful for real time display of fast changing stats
ok art deraadt
Diffstat (limited to 'usr.bin/systat')
-rw-r--r-- | usr.bin/systat/cmds.c | 18 | ||||
-rw-r--r-- | usr.bin/systat/extern.h | 4 | ||||
-rw-r--r-- | usr.bin/systat/main.c | 21 |
3 files changed, 22 insertions, 21 deletions
diff --git a/usr.bin/systat/cmds.c b/usr.bin/systat/cmds.c index 8e0d12e7afe..63f97a7bc50 100644 --- a/usr.bin/systat/cmds.c +++ b/usr.bin/systat/cmds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmds.c,v 1.14 2007/03/20 03:56:13 tedu Exp $ */ +/* $OpenBSD: cmds.c,v 1.15 2007/04/24 06:32:08 tedu Exp $ */ /* $NetBSD: cmds.c,v 1.4 1996/05/10 23:16:32 thorpej Exp $ */ /*- @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)cmds.c 8.2 (Berkeley) 4/29/95"; #endif -static char rcsid[] = "$OpenBSD: cmds.c,v 1.14 2007/03/20 03:56:13 tedu Exp $"; +static char rcsid[] = "$OpenBSD: cmds.c,v 1.15 2007/04/24 06:32:08 tedu Exp $"; #endif /* not lint */ #include <stdlib.h> @@ -50,7 +50,7 @@ command(char *cmd) { struct cmdtab *p; char *cp; - int interval; + double interval; sigset_t mask, omask; sigemptyset(&mask); @@ -93,16 +93,16 @@ command(char *cmd) clrtoeol(); goto done; } - interval = atoi(cmd); - if (interval <= 0 && + interval = strtod(cmd, NULL); + if (interval < 0.09 && (strcmp(cmd, "start") == 0 || strcmp(cmd, "interval") == 0)) { - interval = *cp ? atoi(cp) : naptime; - if (interval <= 0) { + interval = *cp ? strtod(cp, NULL) : naptime; + if (interval < 0.09) { error("%d: bad interval.", interval); goto done; } } - if (interval > 0) { + if (interval >= 0.09) { alarm(0); naptime = interval; display(); @@ -179,7 +179,7 @@ void status(void) { - error("Showing %s, refresh every %d seconds.", + error("Showing %s, refresh every %f seconds.", curcmd->c_name, naptime); } diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h index 7aae57315bf..f3f5732d475 100644 --- a/usr.bin/systat/extern.h +++ b/usr.bin/systat/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.17 2007/02/24 09:45:27 otto Exp $ */ +/* $OpenBSD: extern.h,v 1.18 2007/04/24 06:32:08 tedu Exp $ */ /* $NetBSD: extern.h,v 1.3 1996/05/10 23:16:34 thorpej Exp $ */ /*- @@ -48,7 +48,7 @@ extern int *dk_select; extern int CMDLINE; extern int dk_ndrive; extern int hz, stathz; -extern u_int naptime; +extern double naptime; extern int nhosts; extern int nports; extern int protos; diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c index 38ea76b7ec7..4210fc6326f 100644 --- a/usr.bin/systat/main.c +++ b/usr.bin/systat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.35 2007/02/25 18:21:24 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.36 2007/04/24 06:32:08 tedu Exp $ */ /* $NetBSD: main.c,v 1.8 1996/05/10 23:16:36 thorpej Exp $ */ /*- @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: main.c,v 1.35 2007/02/25 18:21:24 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.36 2007/04/24 06:32:08 tedu Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -67,7 +67,7 @@ kvm_t *kd; char *nlistf = NULL; char *memf = NULL; double avenrun[3]; -u_int naptime = 5; +double naptime = 5.0; int verbose = 1; /* to report kvm read errs */ int nflag = 0; int ut, hz, stathz; @@ -109,9 +109,10 @@ main(int argc, char *argv[]) nflag = 1; break; case 'w': - naptime = (u_int)strtonum(optarg, 1, 1000, &errstr); - if (errstr) - errx(1, "interval %s: %s", errstr, optarg); + + naptime = strtod(optarg, NULL); + if (naptime < 0.09 || naptime > 1000.0) + errx(1, "invalid interval: %s", optarg); break; default: usage(); @@ -121,9 +122,9 @@ main(int argc, char *argv[]) while (argc > 0) { if (isdigit(argv[0][0])) { - naptime = (u_int)strtonum(argv[0], 1, 1000, &errstr); - if (errstr) - naptime = 5; + naptime = strtod(argv[0], NULL); + if (naptime < 0.09 || naptime > 1000.0) + naptime = 5.0; } else { struct cmdtab *p; @@ -256,7 +257,7 @@ display(void) wrefresh(wnd); move(CMDLINE, 0); refresh(); - alarm(naptime); + ualarm(naptime * 1000000, 0); } void |