Restore old netstat -m output.

A new flag '-c' can be used to ask for the cache stats.
This commit is contained in:
Alfred Perlstein 2003-12-23 13:24:03 +00:00
parent 8592d7a760
commit dbe0253a8b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=123764
4 changed files with 76 additions and 31 deletions

View File

@ -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]");

View File

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

View File

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

View File

@ -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 */