summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluigi <luigi@FreeBSD.org>2001-10-10 17:52:04 +0000
committerluigi <luigi@FreeBSD.org>2001-10-10 17:52:04 +0000
commit2aa1af93379067670e8df4817172e697f6192d8b (patch)
tree3e97f66ad01ef8cfb94b5c2a30ba7d10553f9cb3
parent229c3ac7c37b6aa4c4077e0903ab2f95e835aace (diff)
downloadFreeBSD-src-2aa1af93379067670e8df4817172e697f6192d8b.zip
FreeBSD-src-2aa1af93379067670e8df4817172e697f6192d8b.tar.gz
Add a -d flag to show deltas as opposed to cumulative counters
in interface statistics. Most useful when used with the -w flag e.g. ns -i -w 1 -d
-rw-r--r--release/picobsd/tinyware/ns/ns.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/release/picobsd/tinyware/ns/ns.c b/release/picobsd/tinyware/ns/ns.c
index f2ee7cc..64c4054 100644
--- a/release/picobsd/tinyware/ns/ns.c
+++ b/release/picobsd/tinyware/ns/ns.c
@@ -70,6 +70,7 @@ int rflag = 0;
int sflag = 0;
int pflag = 0;
int wflag = 0; /* repeat every wait seconds */
+int delta = 0 ;
extern char *optarg;
extern int optind;
@@ -259,6 +260,10 @@ print_routing(char *proto)
struct rt_metrics rm;
char fbuf[50];
+ /* keep a copy of statistics here for future use */
+ static unsigned *base_stats = NULL ;
+ static unsigned base_len = 0 ;
+
/* Get the routing table */
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
@@ -321,6 +326,16 @@ print_routing(char *proto)
printf("Name Mtu Network Address "
"Ipkts Ierrs Opkts Oerrs Coll\n");
}
+ /* scan the list and store base values */
+ i = 0 ;
+ for (next = if_buf; next < lim; next += ifm->ifm_msglen) {
+ ifm = (struct if_msghdr *)next;
+ i++ ;
+ }
+ if (base_stats == NULL || i != base_len) {
+ base_stats = calloc(i*5, sizeof(unsigned));
+ base_len = i ;
+ }
i = 0;
for (next = if_buf; next < lim; next += ifm->ifm_msglen) {
ifm = (struct if_msghdr *)next;
@@ -330,6 +345,7 @@ print_routing(char *proto)
sa = if_table[i];
if (iflag && sa->sa_family == AF_LINK) {
struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
+ unsigned *bp = &base_stats[i*5];
printf("%-4s %-5d <Link> ",
sock_ntop(if_table[i], if_table[i]->sa_len),
@@ -342,11 +358,18 @@ print_routing(char *proto)
} else
printf(" ");
printf("%9d%6d%9d%6d%6d\n",
- ifm->ifm_data.ifi_ipackets,
- ifm->ifm_data.ifi_ierrors,
- ifm->ifm_data.ifi_opackets,
- ifm->ifm_data.ifi_oerrors,
- ifm->ifm_data.ifi_collisions);
+ ifm->ifm_data.ifi_ipackets - bp[0],
+ ifm->ifm_data.ifi_ierrors - bp[1],
+ ifm->ifm_data.ifi_opackets - bp[2],
+ ifm->ifm_data.ifi_oerrors - bp[3],
+ ifm->ifm_data.ifi_collisions -bp[4]);
+ if (delta > 0) {
+ bp[0] = ifm->ifm_data.ifi_ipackets ;
+ bp[1] = ifm->ifm_data.ifi_ierrors ;
+ bp[2] = ifm->ifm_data.ifi_opackets ;
+ bp[3] = ifm->ifm_data.ifi_oerrors ;
+ bp[4] = ifm->ifm_data.ifi_collisions ;
+ }
}
i++;
}
@@ -720,8 +743,11 @@ main(int argc, char *argv[])
progname = argv[0];
- while ((c = getopt(argc, argv, "inrsp:w:")) != -1) {
+ while ((c = getopt(argc, argv, "dinrsp:w:")) != -1) {
switch (c) {
+ case 'd': /* print deltas in stats every w seconds */
+ delta++ ;
+ break;
case 'w':
wflag = atoi(optarg);
break;
OpenPOWER on IntegriCloud