sbm

simple bandwidth monitor
git clone git://git.2f30.org/sbm
Log | Files | Refs | LICENSE

commit 599b2293f0435b849393f5579610cd7da6cc1ae2
parent bc55bf1d7a442eb2454b172ee5212c31e018ba07
Author: sin <sin@2f30.org>
Date:   Tue, 23 Feb 2016 10:03:04 +0000

No need to impose a max sampling frequency

The minimum sampling period is 1 ms because the delay argument for
the program is an integer and specified in milliseconds.

Diffstat:
Msbm.1 | 3+--
Msbm.c | 22+++++++++++-----------
2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/sbm.1 b/sbm.1 @@ -23,8 +23,7 @@ is 0, it will loop forever. This is the default. .It Fl d Ar delay Sample interface statistics every .Ar delay -ms. The default delay is 1000 ms and the minimum delay -is 100 ms. +ms. The default delay is 1000 ms. .It Fl i Ar interface Monitor the selected .Ar interface . diff --git a/sbm.c b/sbm.c @@ -40,8 +40,6 @@ #include "arg.h" -#define SAMPLINGPERIOD (100) /* sampling period in ms */ - char *argv0; void @@ -214,6 +212,16 @@ tv2ms(struct timeval *tv) return (tv->tv_sec * 1000) + ((tv->tv_usec + 500) / 1000); } +int +msleep(struct timeval *tv) +{ + struct timespec ts; + + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * 1000; + return nanosleep(&ts, NULL); +} + void loop(char *ifname, long count, struct timeval *delay) { @@ -227,16 +235,10 @@ loop(char *ifname, long count, struct timeval *delay) getmonotime(&old); sample(ifname, &oldrxbytes, &oldtxbytes, &oldrxpps, &oldtxpps); for (;;) { - /* - * This is the minimum sampling period that is supported and - * is always less than or equal to the given delay. - */ - usleep(SAMPLINGPERIOD * 1000); + msleep(delay); sample(ifname, &rxbytes, &txbytes, &rxpps, &txpps); getmonotime(&now); timersub(&now, &old, &diff); - if (timercmp(&diff, delay, <)) - continue; getmonotime(&old); diffrxbits = (rxbytes - oldrxbytes) * 8; difftxbits = (txbytes - oldtxbytes) * 8; @@ -279,8 +281,6 @@ main(int argc, char *argv[]) delay = strtol(EARGF(usage()), &end, 10); if (*end != '\0' || errno) errx(1, "invalid delay"); - if (delay < SAMPLINGPERIOD) - errx(1, "minimum delay is %d ms", SAMPLINGPERIOD); break; case 'i': strncpy(ifname, EARGF(usage()), sizeof(ifname));