diff options
author | Andrey V. Elsukov <ae@FreeBSD.org> | 2013-07-09 09:43:03 +0000 |
---|---|---|
committer | Andrey V. Elsukov <ae@FreeBSD.org> | 2013-07-09 09:43:03 +0000 |
commit | 5da0521fcea9b7bf34635529187eddf4cfca1cba (patch) | |
tree | ae9cc37d3d61216f4f205b4e2bf561b5cf5ea330 /usr.bin | |
parent | 7daad711df788ed9ff68f2ca151f5f625cb1dcb0 (diff) | |
download | src-5da0521fcea9b7bf34635529187eddf4cfca1cba.tar.gz src-5da0521fcea9b7bf34635529187eddf4cfca1cba.zip |
Use new macros to implement ipstat and tcpstat using PCPU counters.
Change interface of kread_counters() similar ot kread() in the netstat(1).
Notes
Notes:
svn path=/head/; revision=253083
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/netstat/inet.c | 18 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 16 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 2 |
3 files changed, 16 insertions, 20 deletions
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index c898775d4593..1df1bfa665f2 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -603,13 +603,8 @@ tcp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) warn("sysctl: net.inet.tcp.stats"); return; } - } else { - u_long tcpstat_p[sizeof(struct tcpstat)/sizeof(uint64_t)]; - - kread(off, &tcpstat_p, sizeof(tcpstat_p)); - kread_counters(tcpstat_p, (uint64_t *)&tcpstat, - sizeof(struct tcpstat)/sizeof(uint64_t)); - } + } else + kread_counters(off, &tcpstat, len); printf ("%s:\n", name); @@ -863,13 +858,8 @@ ip_stats(u_long off, const char *name, int af1 __unused, int proto __unused) warn("sysctl: net.inet.ip.stats"); return; } - } else { - u_long ipstat_p[sizeof(struct ipstat)/sizeof(uint64_t)]; - - kread(off, &ipstat_p, sizeof(ipstat_p)); - kread_counters(ipstat_p, (uint64_t *)&ipstat, - sizeof(struct ipstat)/sizeof(uint64_t)); - } + } else + kread_counters(off, &ipstat, len); printf("%s:\n", name); diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index ce4ff9508c65..d9c8334afaf1 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -147,11 +147,11 @@ static struct nlist nl[] = { #define N_IPCOMPSTAT 37 { .n_name = "_ipcompstat" }, #define N_TCPSTAT 38 - { .n_name = "_tcpstatp" }, + { .n_name = "_tcpstat" }, #define N_UDPSTAT 39 { .n_name = "_udpstat" }, #define N_IPSTAT 40 - { .n_name = "_ipstatp" }, + { .n_name = "_ipstat" }, #define N_ICMPSTAT 41 { .n_name = "_icmpstat" }, #define N_IGMPSTAT 42 @@ -753,15 +753,21 @@ kread(u_long addr, void *buf, size_t size) * Read an array of N counters in kernel memory into array of N uint64_t's. */ int -kread_counters(u_long *addr, uint64_t *rval, size_t count) +kread_counters(u_long addr, void *buf, size_t size) { + uint64_t *c = buf; if (kvmd_init() < 0) return (-1); - for (u_int i = 0; i < count; i++, addr++, rval++) - *rval = kvm_counter_u64_fetch(kvmd, *addr); + if (kread(addr, buf, size) < 0) + return (-1); + while (size != 0) { + *c = kvm_counter_u64_fetch(kvmd, *c); + size -= sizeof(*c); + c++; + } return (0); } diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index 32bea795b5ac..318fcbedfadb 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -60,7 +60,7 @@ extern int af; /* address family */ extern int live; /* true if we are examining a live system */ int kread(u_long addr, void *buf, size_t size); -int kread_counters(u_long *addr, uint64_t *rval, size_t count); +int kread_counters(u_long addr, void *buf, size_t size); const char *plural(uintmax_t); const char *plurales(uintmax_t); const char *pluralies(uintmax_t); |