diff options
Diffstat (limited to 'freebsd/usr.bin/netstat/mbuf.c')
-rw-r--r-- | freebsd/usr.bin/netstat/mbuf.c | 189 |
1 files changed, 115 insertions, 74 deletions
diff --git a/freebsd/usr.bin/netstat/mbuf.c b/freebsd/usr.bin/netstat/mbuf.c index a005d167..81f57292 100644 --- a/freebsd/usr.bin/netstat/mbuf.c +++ b/freebsd/usr.bin/netstat/mbuf.c @@ -1,5 +1,9 @@ #include <machine/rtems-bsd-user-space.h> +#ifdef __rtems__ +#include "rtems-bsd-netstat-namespace.h" +#endif /* __rtems__ */ + /*- * Copyright (c) 1983, 1988, 1993 * The Regents of the University of California. @@ -41,12 +45,16 @@ static char sccsid[] = "@(#)mbuf.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #endif +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); #include <rtems/bsd/sys/param.h> #include <sys/mbuf.h> #include <sys/protosw.h> +#include <sys/sf_buf.h> #include <sys/socket.h> #include <sys/socketvar.h> #include <sys/sysctl.h> @@ -57,8 +65,13 @@ __FBSDID("$FreeBSD$"); #include <stdint.h> #include <stdio.h> #include <stdlib.h> +#include <stdbool.h> #include <string.h> +#include <libxo/xo.h> #include "netstat.h" +#ifdef __rtems__ +#include "rtems-bsd-netstat-mbuf-data.h" +#endif /* __rtems__ */ /* * Print mbuf statistics. @@ -70,26 +83,26 @@ mbpr(void *kvmd, u_long mbaddr) struct memory_type *mtp; uintmax_t mbuf_count, mbuf_bytes, mbuf_free, mbuf_failures, mbuf_size; uintmax_t mbuf_sleeps; - uintmax_t cluster_count, cluster_bytes, cluster_limit, cluster_free; + uintmax_t cluster_count, cluster_limit, cluster_free; uintmax_t cluster_failures, cluster_size, cluster_sleeps; uintmax_t packet_count, packet_bytes, packet_free, packet_failures; uintmax_t packet_sleeps; - uintmax_t tag_count, tag_bytes; - uintmax_t jumbop_count, jumbop_bytes, jumbop_limit, jumbop_free; + uintmax_t tag_bytes; + uintmax_t jumbop_count, jumbop_limit, jumbop_free; uintmax_t jumbop_failures, jumbop_sleeps, jumbop_size; - uintmax_t jumbo9_count, jumbo9_bytes, jumbo9_limit, jumbo9_free; + uintmax_t jumbo9_count, jumbo9_limit, jumbo9_free; uintmax_t jumbo9_failures, jumbo9_sleeps, jumbo9_size; - uintmax_t jumbo16_count, jumbo16_bytes, jumbo16_limit, jumbo16_free; + uintmax_t jumbo16_count, jumbo16_limit, jumbo16_free; uintmax_t jumbo16_failures, jumbo16_sleeps, jumbo16_size; uintmax_t bytes_inuse, bytes_incache, bytes_total; int nsfbufs, nsfbufspeak, nsfbufsused; - struct mbstat mbstat; + struct sfstat sfstat; size_t mlen; int error; mtlp = memstat_mtl_alloc(); if (mtlp == NULL) { - warn("memstat_mtl_alloc"); + xo_warn("memstat_mtl_alloc"); return; } @@ -99,7 +112,7 @@ mbpr(void *kvmd, u_long mbaddr) */ if (live) { if (memstat_sysctl_all(mtlp, 0) < 0) { - warnx("memstat_sysctl_all: %s", + xo_warnx("memstat_sysctl_all: %s", memstat_strerror(memstat_mtl_geterror(mtlp))); goto out; } @@ -108,10 +121,10 @@ mbpr(void *kvmd, u_long mbaddr) if (memstat_kvm_all(mtlp, kvmd) < 0) { error = memstat_mtl_geterror(mtlp); if (error == MEMSTAT_ERROR_KVM) - warnx("memstat_kvm_all: %s", + xo_warnx("memstat_kvm_all: %s", kvm_geterr(kvmd)); else - warnx("memstat_kvm_all: %s", + xo_warnx("memstat_kvm_all: %s", memstat_strerror(error)); goto out; } @@ -123,7 +136,7 @@ mbpr(void *kvmd, u_long mbaddr) mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_MEM_NAME); if (mtp == NULL) { - warnx("memstat_mtl_find: zone %s not found", MBUF_MEM_NAME); + xo_warnx("memstat_mtl_find: zone %s not found", MBUF_MEM_NAME); goto out; } mbuf_count = memstat_get_count(mtp); @@ -135,7 +148,7 @@ mbpr(void *kvmd, u_long mbaddr) mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_PACKET_MEM_NAME); if (mtp == NULL) { - warnx("memstat_mtl_find: zone %s not found", + xo_warnx("memstat_mtl_find: zone %s not found", MBUF_PACKET_MEM_NAME); goto out; } @@ -147,12 +160,11 @@ mbpr(void *kvmd, u_long mbaddr) mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_CLUSTER_MEM_NAME); if (mtp == NULL) { - warnx("memstat_mtl_find: zone %s not found", + xo_warnx("memstat_mtl_find: zone %s not found", MBUF_CLUSTER_MEM_NAME); goto out; } cluster_count = memstat_get_count(mtp); - cluster_bytes = memstat_get_bytes(mtp); cluster_limit = memstat_get_countlimit(mtp); cluster_free = memstat_get_free(mtp); cluster_failures = memstat_get_failures(mtp); @@ -162,25 +174,22 @@ mbpr(void *kvmd, u_long mbaddr) #ifndef __rtems__ mtp = memstat_mtl_find(mtlp, ALLOCATOR_MALLOC, MBUF_TAG_MEM_NAME); if (mtp == NULL) { - warnx("memstat_mtl_find: malloc type %s not found", + xo_warnx("memstat_mtl_find: malloc type %s not found", MBUF_TAG_MEM_NAME); goto out; } - tag_count = memstat_get_count(mtp); tag_bytes = memstat_get_bytes(mtp); #else /* __rtems__ */ - tag_count = 0; tag_bytes = 0; #endif /* __rtems__ */ mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBOP_MEM_NAME); if (mtp == NULL) { - warnx("memstat_mtl_find: zone %s not found", + xo_warnx("memstat_mtl_find: zone %s not found", MBUF_JUMBOP_MEM_NAME); goto out; } jumbop_count = memstat_get_count(mtp); - jumbop_bytes = memstat_get_bytes(mtp); jumbop_limit = memstat_get_countlimit(mtp); jumbop_free = memstat_get_free(mtp); jumbop_failures = memstat_get_failures(mtp); @@ -189,12 +198,11 @@ mbpr(void *kvmd, u_long mbaddr) mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBO9_MEM_NAME); if (mtp == NULL) { - warnx("memstat_mtl_find: zone %s not found", + xo_warnx("memstat_mtl_find: zone %s not found", MBUF_JUMBO9_MEM_NAME); goto out; } jumbo9_count = memstat_get_count(mtp); - jumbo9_bytes = memstat_get_bytes(mtp); jumbo9_limit = memstat_get_countlimit(mtp); jumbo9_free = memstat_get_free(mtp); jumbo9_failures = memstat_get_failures(mtp); @@ -203,48 +211,55 @@ mbpr(void *kvmd, u_long mbaddr) mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBO16_MEM_NAME); if (mtp == NULL) { - warnx("memstat_mtl_find: zone %s not found", + xo_warnx("memstat_mtl_find: zone %s not found", MBUF_JUMBO16_MEM_NAME); goto out; } jumbo16_count = memstat_get_count(mtp); - jumbo16_bytes = memstat_get_bytes(mtp); jumbo16_limit = memstat_get_countlimit(mtp); jumbo16_free = memstat_get_free(mtp); jumbo16_failures = memstat_get_failures(mtp); jumbo16_sleeps = memstat_get_sleeps(mtp); jumbo16_size = memstat_get_size(mtp); - printf("%ju/%ju/%ju mbufs in use (current/cache/total)\n", + xo_open_container("mbuf-statistics"); + + xo_emit("{:mbuf-current/%ju}/{:mbuf-cache/%ju}/{:mbuf-total/%ju} " + "{N:mbufs in use (current\\/cache\\/total)}\n", mbuf_count + packet_count, mbuf_free + packet_free, mbuf_count + packet_count + mbuf_free + packet_free); - printf("%ju/%ju/%ju/%ju mbuf clusters in use " - "(current/cache/total/max)\n", + xo_emit("{:cluster-current/%ju}/{:cluster-cache/%ju}/" + "{:cluster-total/%ju}/{:cluster-max/%ju} " + "{N:mbuf clusters in use (current\\/cache\\/total\\/max)}\n", cluster_count - packet_free, cluster_free + packet_free, cluster_count + cluster_free, cluster_limit); - printf("%ju/%ju mbuf+clusters out of packet secondary zone in use " - "(current/cache)\n", + xo_emit("{:packet-count/%ju}/{:packet-free/%ju} " + "{N:mbuf+clusters out of packet secondary zone in use " + "(current\\/cache)}\n", packet_count, packet_free); - printf("%ju/%ju/%ju/%ju %juk (page size) jumbo clusters in use " - "(current/cache/total/max)\n", + xo_emit("{:jumbo-count/%ju}/{:jumbo-cache/%ju}/{:jumbo-total/%ju}/" + "{:jumbo-max/%ju} {:jumbo-page-size/%ju}{U:k} {N:(page size)} " + "{N:jumbo clusters in use (current\\/cache\\/total\\/max)}\n", jumbop_count, jumbop_free, jumbop_count + jumbop_free, jumbop_limit, jumbop_size / 1024); - printf("%ju/%ju/%ju/%ju 9k jumbo clusters in use " - "(current/cache/total/max)\n", + xo_emit("{:jumbo9-count/%ju}/{:jumbo9-cache/%ju}/" + "{:jumbo9-total/%ju}/{:jumbo9-max/%ju} " + "{N:9k jumbo clusters in use (current\\/cache\\/total\\/max)}\n", jumbo9_count, jumbo9_free, jumbo9_count + jumbo9_free, jumbo9_limit); - printf("%ju/%ju/%ju/%ju 16k jumbo clusters in use " - "(current/cache/total/max)\n", + xo_emit("{:jumbo16-count/%ju}/{:jumbo16-cache/%ju}/" + "{:jumbo16-total/%ju}/{:jumbo16-limit/%ju} " + "{N:16k jumbo clusters in use (current\\/cache\\/total\\/max)}\n", jumbo16_count, jumbo16_free, jumbo16_count + jumbo16_free, jumbo16_limit); #if 0 - printf("%ju mbuf tags in use\n", tag_count); + xo_emit("{:tag-count/%ju} {N:mbuf tags in use}\n", tag_count); #endif /*- @@ -292,48 +307,74 @@ mbpr(void *kvmd, u_long mbaddr) */ bytes_total = bytes_inuse + bytes_incache; - printf("%juK/%juK/%juK bytes allocated to network " - "(current/cache/total)\n", bytes_inuse / 1024, - bytes_incache / 1024, bytes_total / 1024); + xo_emit("{:bytes-in-use/%ju}{U:K}/{:bytes-in-cache/%ju}{U:K}/" + "{:bytes-total/%ju}{U:K} " + "{N:bytes allocated to network (current\\/cache\\/total)}\n", + bytes_inuse / 1024, bytes_incache / 1024, bytes_total / 1024); - printf("%ju/%ju/%ju requests for mbufs denied (mbufs/clusters/" - "mbuf+clusters)\n", mbuf_failures, cluster_failures, - packet_failures); - printf("%ju/%ju/%ju requests for mbufs delayed (mbufs/clusters/" - "mbuf+clusters)\n", mbuf_sleeps, cluster_sleeps, - packet_sleeps); + xo_emit("{:mbuf-failures/%ju}/{:cluster-failures/%ju}/" + "{:packet-failures/%ju} {N:requests for mbufs denied " + "(mbufs\\/clusters\\/mbuf+clusters)}\n", + mbuf_failures, cluster_failures, packet_failures); + xo_emit("{:mbuf-sleeps/%ju}/{:cluster-sleeps/%ju}/{:packet-sleeps/%ju} " + "{N:requests for mbufs delayed " + "(mbufs\\/clusters\\/mbuf+clusters)}\n", + mbuf_sleeps, cluster_sleeps, packet_sleeps); - printf("%ju/%ju/%ju requests for jumbo clusters delayed " - "(%juk/9k/16k)\n", jumbop_sleeps, jumbo9_sleeps, - jumbo16_sleeps, jumbop_size / 1024); - printf("%ju/%ju/%ju requests for jumbo clusters denied " - "(%juk/9k/16k)\n", jumbop_failures, jumbo9_failures, - jumbo16_failures, jumbop_size / 1024); + xo_emit("{:jumbop-sleeps/%ju}/{:jumbo9-sleeps/%ju}/" + "{:jumbo16-sleeps/%ju} {N:/requests for jumbo clusters delayed " + "(%juk\\/9k\\/16k)}\n", + jumbop_sleeps, jumbo9_sleeps, jumbo16_sleeps, jumbop_size / 1024); + xo_emit("{:jumbop-failures/%ju}/{:jumbo9-failures/%ju}/" + "{:jumbo16-failures/%ju} {N:/requests for jumbo clusters denied " + "(%juk\\/9k\\/16k)}\n", + jumbop_failures, jumbo9_failures, jumbo16_failures, + jumbop_size / 1024); - if (live) { - mlen = sizeof(nsfbufs); - if (!sysctlbyname("kern.ipc.nsfbufs", &nsfbufs, &mlen, NULL, - 0) && - !sysctlbyname("kern.ipc.nsfbufsused", &nsfbufsused, - &mlen, NULL, 0) && - !sysctlbyname("kern.ipc.nsfbufspeak", &nsfbufspeak, - &mlen, NULL, 0)) - printf("%d/%d/%d sfbufs in use (current/peak/max)\n", - nsfbufsused, nsfbufspeak, nsfbufs); - mlen = sizeof(mbstat); - if (sysctlbyname("kern.ipc.mbstat", &mbstat, &mlen, NULL, 0)) { - warn("kern.ipc.mbstat"); - goto out; - } - } else { - if (kread(mbaddr, (char *)&mbstat, sizeof mbstat) != 0) - goto out; - } - printf("%lu requests for sfbufs denied\n", mbstat.sf_allocfail); - printf("%lu requests for sfbufs delayed\n", mbstat.sf_allocwait); - printf("%lu requests for I/O initiated by sendfile\n", - mbstat.sf_iocnt); - printf("%lu calls to protocol drain routines\n", mbstat.m_drain); + mlen = sizeof(nsfbufs); + if (live && + sysctlbyname("kern.ipc.nsfbufs", &nsfbufs, &mlen, NULL, 0) == 0 && + sysctlbyname("kern.ipc.nsfbufsused", &nsfbufsused, &mlen, + NULL, 0) == 0 && + sysctlbyname("kern.ipc.nsfbufspeak", &nsfbufspeak, &mlen, + NULL, 0) == 0) + xo_emit("{:nsfbufs-current/%d}/{:nsfbufs-peak/%d}/" + "{:nsfbufs/%d} " + "{N:sfbufs in use (current\\/peak\\/max)}\n", + nsfbufsused, nsfbufspeak, nsfbufs); + + if (fetch_stats("kern.ipc.sfstat", mbaddr, &sfstat, sizeof(sfstat), + kread_counters) != 0) + goto out; + + xo_emit("{:sendfile-syscalls/%ju} {N:sendfile syscalls}\n", + (uintmax_t)sfstat.sf_syscalls); + xo_emit("{:sendfile-no-io/%ju} " + "{N:sendfile syscalls completed without I\\/O request}\n", + (uintmax_t)sfstat.sf_noiocnt); + xo_emit("{:sendfile-io-count/%ju} " + "{N:requests for I\\/O initiated by sendfile}\n", + (uintmax_t)sfstat.sf_iocnt); + xo_emit("{:sendfile-pages-sent/%ju} " + "{N:pages read by sendfile as part of a request}\n", + (uintmax_t)sfstat.sf_pages_read); + xo_emit("{:sendfile-pages-valid/%ju} " + "{N:pages were valid at time of a sendfile request}\n", + (uintmax_t)sfstat.sf_pages_valid); + xo_emit("{:sendfile-requested-readahead/%ju} " + "{N:pages were requested for read ahead by applications}\n", + (uintmax_t)sfstat.sf_rhpages_requested); + xo_emit("{:sendfile-readahead/%ju} " + "{N:pages were read ahead by sendfile}\n", + (uintmax_t)sfstat.sf_rhpages_read); + xo_emit("{:sendfile-busy-encounters/%ju} " + "{N:times sendfile encountered an already busy page}\n", + (uintmax_t)sfstat.sf_busy); + xo_emit("{:sfbufs-alloc-failed/%ju} {N:requests for sfbufs denied}\n", + (uintmax_t)sfstat.sf_allocfail); + xo_emit("{:sfbufs-alloc-wait/%ju} {N:requests for sfbufs delayed}\n", + (uintmax_t)sfstat.sf_allocwait); out: + xo_close_container("mbuf-statistics"); memstat_mtl_free(mtlp); } |