Date: Wed, 31 Jan 2007 15:58:30 GMT From: "Christian S.J. Peron" <csjp@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 113771 for review Message-ID: <200701311558.l0VFwUVH041527@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=113771 Change 113771 by csjp@csjp_rnd01 on 2007/01/31 15:57:57 Use some of the new stats and implement a -s which gives us extended statistics. Affected files ... .. //depot/projects/zcopybpf/src/usr.sbin/netstat/bpf.c#2 edit .. //depot/projects/zcopybpf/src/usr.sbin/netstat/main.c#2 edit .. //depot/projects/zcopybpf/src/usr.sbin/netstat/netstat.h#2 edit Differences ... ==== //depot/projects/zcopybpf/src/usr.sbin/netstat/bpf.c#2 (text+ko) ==== @@ -82,31 +82,82 @@ *flagbuf++ = '\0'; } -void -bpf_stats(char *ifname) +static int +bpf_get_stats(int *size, struct xbpf_d **bdp) { - struct xbpf_d *d, *bd; - char *pname, flagbuf[12]; - size_t size; + struct xbpf_d *bd; + size_t s; - if (sysctlbyname("net.bpf.stats", NULL, &size, + if (sysctlbyname("net.bpf.stats", NULL, &s, NULL, 0) < 0) { warn("net.bpf.stats"); - return; + return (-1); } - if (size == 0) - return; - bd = malloc(size); + if (s == 0) + return (-1); + bd = malloc(s); if (bd == NULL) { warn("malloc failed"); - return; + return (-1); } - if (sysctlbyname("net.bpf.stats", bd, &size, + if (sysctlbyname("net.bpf.stats", bd, &s, NULL, 0) < 0) { warn("net.bpf.stats"); free(bd); + return (-1); + } + *bdp = bd; + *size = s; + return (0); +} + +void +bpf_stats_extended(char *ifname) +{ + struct xbpf_d *d, *bd; + int size; + char *pname; + + if (bpf_get_stats(&size, &bd) < 0) return; + for (d = &bd[0]; d < &bd[size / sizeof(*d)]; d++) { + if (ifname && strcmp(ifname, d->bd_ifname) != 0) + continue; + pname = bpf_pidname(d->bd_pid); + (void) printf("%s: pid %d on %s:\n", pname, bd->bd_pid, + d->bd_ifname); + (void) printf( + "\t%lu packets received\n" + "\t%lu packets matched receive filter\n" + "\t%lu packets dropped\n" + "\t%d current hold buffer size\n" + "\t%d current store buffer size\n" + "\t%lu packets written\n" + "\t%lu packets matched write filter\n" + "\t%lu packet writes failed\n" + "\t%lu zero copy operations\n", + d->bd_rcount, + d->bd_fcount, + d->bd_dcount, + d->bd_hlen, + d->bd_slen, + d->bd_wcount, + d->bd_wfcount, + d->bd_wdcount, + d->bd_zcopy); + free(pname); } +} + +void +bpf_stats(char *ifname) +{ + char *pname, flagbuf[12]; + struct xbpf_d *d, *bd; + int size; + + if (bpf_get_stats(&size, &bd) < 0) + return; printf("%5s %6s %6s %9s %9s %9s %5s %5s %s\n", "Pid", "Netif", "Flags", "Recv", "Drop", "Match", "Sblen", "Hblen", "Command"); ==== //depot/projects/zcopybpf/src/usr.sbin/netstat/main.c#2 (text+ko) ==== @@ -459,7 +459,10 @@ setgid(getgid()); if (Bflag) { - bpf_stats(interface); + if (sflag) + bpf_stats_extended(interface); + else + bpf_stats(interface); exit(0); } if (mflag) { ==== //depot/projects/zcopybpf/src/usr.sbin/netstat/netstat.h#2 (text+ko) ==== @@ -158,3 +158,4 @@ void mroutepr(u_long, u_long); void mrt_stats(u_long); void bpf_stats(char *); +void bpf_stats_extended(char *);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200701311558.l0VFwUVH041527>