1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-04 09:09:56 +00:00

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
This commit is contained in:
Luigi Rizzo 2001-10-10 17:52:04 +00:00
parent 6eabd84580
commit ce28e3e9fe
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=84769

View File

@ -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;