summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2003-12-23 13:24:03 +0000
committeralfred <alfred@FreeBSD.org>2003-12-23 13:24:03 +0000
commitabd1027a01880a215e2c2f5c955c21a22e7424bd (patch)
tree5fe04b13890d4637e842156dc35025c641bdfc1f /usr.bin
parentfe692735bff0c4124372fb220744c13ca13657f2 (diff)
downloadFreeBSD-src-abd1027a01880a215e2c2f5c955c21a22e7424bd.zip
FreeBSD-src-abd1027a01880a215e2c2f5c955c21a22e7424bd.tar.gz
Restore old netstat -m output.
A new flag '-c' can be used to ask for the cache stats.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/main.c14
-rw-r--r--usr.bin/netstat/mbuf.c88
-rw-r--r--usr.bin/netstat/netstat.14
-rw-r--r--usr.bin/netstat/netstat.h1
4 files changed, 76 insertions, 31 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 145f740..6d70371 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -256,6 +256,7 @@ static char *nlistf = NULL, *memf = NULL;
int Aflag; /* show addresses of protocol control block */
int aflag; /* show all sockets (including servers) */
int bflag; /* show i/f total bytes in/out */
+int cflag; /* show mbuf cache information */
int dflag; /* show i/f dropped packets */
int gflag; /* show group (multicast) routing or stats */
int iflag; /* show interfaces */
@@ -285,7 +286,7 @@ main(int argc, char *argv[])
af = AF_UNSPEC;
- while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rSstuWw:z")) != -1)
+ while ((ch = getopt(argc, argv, "Aabcdf:gI:iLlM:mN:np:rSstuWw:z")) != -1)
switch(ch) {
case 'A':
Aflag = 1;
@@ -296,6 +297,9 @@ main(int argc, char *argv[])
case 'b':
bflag = 1;
break;
+ case 'c':
+ cflag = 1;
+ break;
case 'd':
dflag = 1;
break;
@@ -421,6 +425,10 @@ main(int argc, char *argv[])
if (nlistf != NULL || memf != NULL)
setgid(getgid());
+ if (cflag && !mflag) {
+ (void)fprintf(stderr, "-c only valid with -m\n");
+ usage();
+ }
if (mflag) {
if (memf != NULL) {
if (kread(0, 0, 0) == 0)
@@ -686,8 +694,8 @@ usage(void)
" netstat -s [-s] [-z] [-f protocol_family | -p protocol] [-M core]",
" netstat -i | -I interface -s [-f protocol_family | -p protocol]\n"
" [-M core] [-N system]",
-" netstat -m [-M core] [-N system]",
-" netstat -r [-AanW] [-f address_family] [-M core] [-N system]",
+" netstat -m [-c] [-M core] [-N system]",
+" netstat -r [-AenW] [-f address_family] [-M core] [-N system]",
" netstat -rs [-s] [-M core] [-N system]",
" netstat -g [-W] [-f address_family] [-M core] [-N system]",
" netstat -gs [-s] [-f address_family] [-M core] [-N system]");
diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c
index 4da47cd..24d7c79 100644
--- a/usr.bin/netstat/mbuf.c
+++ b/usr.bin/netstat/mbuf.c
@@ -101,7 +101,7 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
{
int i, j, nmbufs, nmbclusters, page_size, num_objs;
u_int mbuf_hiwm, clust_hiwm, mbuf_lowm, clust_lowm;
- u_long totspace[2], totused[2], totnum, totfree;
+ u_long totspace[2], totused[2], gentotnum, gentotfree, totnum, totfree;
short nmbtypes;
size_t mlen;
long *mbtypes = NULL;
@@ -229,21 +229,14 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
#define MCLBYTES (mbstat->m_mclbytes)
#define GENLST (num_objs - 1)
- printf("mbuf usage:\n");
totnum = mbpstat[GENLST]->mb_mbbucks * mbstat->m_mbperbuck;
totfree = mbpstat[GENLST]->mb_mbfree;
- printf("\tGEN cache:\t%lu/%lu (in use/in pool)\n",
- totnum - totfree, totnum);
for (j = 1; j < nmbtypes; j++)
mbtypes[j] += mbpstat[GENLST]->mb_mbtypes[j];
totspace[0] = mbpstat[GENLST]->mb_mbbucks * mbstat->m_mbperbuck * MSIZE;
for (i = 0; i < (num_objs - 1); i++) {
if (mbpstat[i]->mb_active == 0)
continue;
- printf("\tCPU #%d cache:\t%lu/%lu (in use/in pool)\n", i,
- (mbpstat[i]->mb_mbbucks * mbstat->m_mbperbuck -
- mbpstat[i]->mb_mbfree),
- (mbpstat[i]->mb_mbbucks * mbstat->m_mbperbuck));
totspace[0] += mbpstat[i]->mb_mbbucks*mbstat->m_mbperbuck*MSIZE;
totnum += mbpstat[i]->mb_mbbucks * mbstat->m_mbperbuck;
totfree += mbpstat[i]->mb_mbfree;
@@ -251,13 +244,35 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
mbtypes[j] += mbpstat[i]->mb_mbtypes[j];
}
totused[0] = totnum - totfree;
- printf("\tTotal:\t\t%lu/%lu (in use/in pool)\n", totused[0], totnum);
- printf("\tMbuf cache high watermark: %d\n", mbuf_hiwm);
+ if (cflag) {
+ printf("mbuf usage:\n"
+ "\tTotal:\t\t%lu/%lu/%d (in use/in pool/max)\n",
+ totused[0], totnum, nmbufs);
+ gentotnum = mbpstat[GENLST]->mb_mbbucks * mbstat->m_mbperbuck;
+ gentotfree = mbpstat[GENLST]->mb_mbfree;
+ printf("\tGEN cache:\t%lu/%lu (in use/in pool)\n",
+ gentotnum - gentotfree, gentotnum);
+ } else {
+ /* XXX: peak is now wrong. */
+ printf("%lu/%lu/%d (current/peak/max):\n",
+ totused[0], totused[0], nmbufs);
+ }
+
+ for (i = 0; cflag && i < (num_objs - 1); i++) {
+ if (mbpstat[i]->mb_active == 0)
+ continue;
+ printf("\tCPU #%d cache:\t%lu/%lu (in use/in pool)\n",
+ i,
+ (mbpstat[i]->mb_mbbucks * mbstat->m_mbperbuck -
+ mbpstat[i]->mb_mbfree),
+ (mbpstat[i]->mb_mbbucks * mbstat->m_mbperbuck));
+ }
+ if (cflag) {
+ printf("\tMbuf cache high watermark: %d\n", mbuf_hiwm);
#ifdef NOTYET
- printf("\tMbuf cache low watermark: %d\n", mbuf_lowm);
+ printf("\tMbuf cache low watermark: %d\n", mbuf_lowm);
#endif
- printf("\tMaximum possible: %d\n", nmbufs);
- printf("\tAllocated mbuf types:\n");
+ }
for (mp = mbtypenames; mp->mt_name; mp++) {
if (mbtypes[mp->mt_type]) {
seen[mp->mt_type] = YES;
@@ -270,36 +285,53 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
printf("\t %lu mbufs allocated to <mbuf type: %d>\n",
mbtypes[i], i);
}
- printf("\t%lu%% of mbuf map consumed\n", ((totspace[0] * 100) / (nmbufs
- * MSIZE)));
+ if (cflag)
+ printf("\t%lu%% of mbuf map consumed\n",
+ ((totspace[0] * 100) / (nmbufs * MSIZE)));
- printf("mbuf cluster usage:\n");
totnum = mbpstat[GENLST]->mb_clbucks * mbstat->m_clperbuck;
totfree = mbpstat[GENLST]->mb_clfree;
- printf("\tGEN cache:\t%lu/%lu (in use/in pool)\n",
- totnum - totfree, totnum);
totspace[1] = mbpstat[GENLST]->mb_clbucks*mbstat->m_clperbuck*MCLBYTES;
for (i = 0; i < (num_objs - 1); i++) {
if (mbpstat[i]->mb_active == 0)
continue;
- printf("\tCPU #%d cache:\t%lu/%lu (in use/in pool)\n", i,
- (mbpstat[i]->mb_clbucks * mbstat->m_clperbuck -
- mbpstat[i]->mb_clfree),
- (mbpstat[i]->mb_clbucks * mbstat->m_clperbuck));
totspace[1] += mbpstat[i]->mb_clbucks * mbstat->m_clperbuck
* MCLBYTES;
totnum += mbpstat[i]->mb_clbucks * mbstat->m_clperbuck;
totfree += mbpstat[i]->mb_clfree;
}
totused[1] = totnum - totfree;
- printf("\tTotal:\t\t%lu/%lu (in use/in pool)\n", totused[1], totnum);
- printf("\tCluster cache high watermark: %d\n", clust_hiwm);
+ if (cflag) {
+ printf("mbuf cluster usage:\n"
+ "\tTotal:\t\t%lu/%lu/%d (in use/in pool/max)\n",
+ totused[1], totnum, nmbclusters);
+ gentotnum = mbpstat[GENLST]->mb_clbucks * mbstat->m_clperbuck;
+ gentotfree = mbpstat[GENLST]->mb_clfree;
+ printf("\tGEN cache:\t%lu/%lu (in use/in pool)\n",
+ gentotnum - gentotfree, gentotnum);
+ } else {
+ /* XXX: peak is now wrong. */
+ printf("%lu/%lu/%d (current/peak/max):\n",
+ totused[1], totused[1], nmbclusters);
+ }
+ for (i = 0; cflag && i < (num_objs - 1); i++) {
+ if (mbpstat[i]->mb_active == 0)
+ continue;
+ printf("\tCPU #%d cache:\t%lu/%lu (in use/in pool)\n",
+ i,
+ (mbpstat[i]->mb_clbucks * mbstat->m_clperbuck -
+ mbpstat[i]->mb_clfree),
+ (mbpstat[i]->mb_clbucks * mbstat->m_clperbuck));
+ }
+ if (cflag) {
+ printf("\tCluster cache high watermark: %d\n", clust_hiwm);
#ifdef NOTYET
- printf("\tCluster cache low watermark: %d\n", clust_lowm);
+ printf("\tCluster cache low watermark: %d\n", clust_lowm);
#endif
- printf("\tMaximum possible: %d\n", nmbclusters);
- printf("\t%lu%% of cluster map consumed\n", ((totspace[1] * 100) /
- (nmbclusters * MCLBYTES)));
+ }
+ if (cflag)
+ printf("\t%lu%% of cluster map consumed\n",
+ ((totspace[1] * 100) / (nmbclusters * MCLBYTES)));
printf("%lu KBytes of wired memory reserved (%lu%% in use)\n",
(totspace[0] + totspace[1]) / 1024, ((totused[0] * MSIZE +
diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1
index 3071ad4..7b46d79 100644
--- a/usr.bin/netstat/netstat.1
+++ b/usr.bin/netstat/netstat.1
@@ -181,6 +181,7 @@ or for a single
.Bk -words
.Nm
.Fl m
+.Op Fl c
.Op Fl M Ar core
.Op Fl N Ar system
.Ek
@@ -188,6 +189,9 @@ or for a single
Show statistics recorded by the memory management routines
.Pq Xr mbuf 9 .
The network manages a private pool of memory buffers.
+The
+.Fl c
+option shows per-cpu statistics for caching.
.It Xo
.Bk -words
.Nm
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index ee00124..bade20a 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -39,6 +39,7 @@
extern int Aflag; /* show addresses of protocol control block */
extern int aflag; /* show all sockets (including servers) */
extern int bflag; /* show i/f total bytes in/out */
+extern int cflag; /* show mbuf cache information */
extern int dflag; /* show i/f dropped packets */
extern int gflag; /* show group (multicast) routing or stats */
extern int iflag; /* show interfaces */
OpenPOWER on IntegriCloud