Annotation of 43BSDReno/usr.bin/netstat/mbuf.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983, 1988 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted provided
                      6:  * that: (1) source distributions retain this entire copyright notice and
                      7:  * comment, and (2) distributions including binaries display the following
                      8:  * acknowledgement:  ``This product includes software developed by the
                      9:  * University of California, Berkeley and its contributors'' in the
                     10:  * documentation or other materials provided with the distribution and in
                     11:  * all advertising materials mentioning features or use of this software.
                     12:  * Neither the name of the University nor the names of its contributors may
                     13:  * be used to endorse or promote products derived from this software without
                     14:  * specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     16:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     17:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)mbuf.c     5.9 (Berkeley) 6/18/90";
                     22: #endif /* not lint */
                     23: 
                     24: #include <stdio.h>
                     25: #include <sys/param.h>
                     26: #include <sys/mbuf.h>
                     27: #define        YES     1
                     28: typedef int bool;
                     29: 
                     30: struct mbstat mbstat;
                     31: 
                     32: static struct mbtypes {
                     33:        int     mt_type;
                     34:        char    *mt_name;
                     35: } mbtypes[] = {
                     36:        { MT_DATA,      "data" },
                     37:        { MT_OOBDATA,   "oob data" },
                     38:        { MT_CONTROL,   "ancillary data" },
                     39:        { MT_HEADER,    "packet headers" },
                     40:        { MT_SOCKET,    "socket structures" },                  /* XXX */
                     41:        { MT_PCB,       "protocol control blocks" },            /* XXX */
                     42:        { MT_RTABLE,    "routing table entries" },              /* XXX */
                     43:        { MT_HTABLE,    "IMP host table entries" },             /* XXX */
                     44:        { MT_ATABLE,    "address resolution tables" },
                     45:        { MT_FTABLE,    "fragment reassembly queue headers" },  /* XXX */
                     46:        { MT_SONAME,    "socket names and addresses" },
                     47:        { MT_SOOPTS,    "socket options" },
                     48:        { MT_RIGHTS,    "access rights" },
                     49:        { MT_IFADDR,    "interface addresses" },                /* XXX */
                     50:        { 0, 0 }
                     51: };
                     52: 
                     53: int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short);
                     54: bool seen[256];                        /* "have we seen this type yet?" */
                     55: 
                     56: /*
                     57:  * Print mbuf statistics.
                     58:  */
                     59: mbpr(mbaddr)
                     60:        off_t mbaddr;
                     61: {
                     62:        register int totmem, totfree, totmbufs;
                     63:        register int i;
                     64:        register struct mbtypes *mp;
                     65: 
                     66:        if (nmbtypes != 256) {
                     67:                fprintf(stderr, "unexpected change to mbstat; check source\n");
                     68:                return;
                     69:        }
                     70:        if (mbaddr == 0) {
                     71:                printf("mbstat: symbol not in namelist\n");
                     72:                return;
                     73:        }
                     74:        if (kvm_read(mbaddr, (char *)&mbstat, sizeof (mbstat))
                     75:                                                != sizeof (mbstat)) {
                     76:                printf("mbstat: bad read\n");
                     77:                return;
                     78:        }
                     79:        totmbufs = 0;
                     80:        for (mp = mbtypes; mp->mt_name; mp++)
                     81:                totmbufs += mbstat.m_mtypes[mp->mt_type];
                     82:        printf("%u mbufs in use:\n", totmbufs);
                     83:        for (mp = mbtypes; mp->mt_name; mp++)
                     84:                if (mbstat.m_mtypes[mp->mt_type]) {
                     85:                        seen[mp->mt_type] = YES;
                     86:                        printf("\t%u mbufs allocated to %s\n",
                     87:                            mbstat.m_mtypes[mp->mt_type], mp->mt_name);
                     88:                }
                     89:        seen[MT_FREE] = YES;
                     90:        for (i = 0; i < nmbtypes; i++)
                     91:                if (!seen[i] && mbstat.m_mtypes[i]) {
                     92:                        printf("\t%u mbufs allocated to <mbuf type %d>\n",
                     93:                            mbstat.m_mtypes[i], i);
                     94:                }
                     95:        printf("%u/%u mapped pages in use\n",
                     96:                mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters);
                     97:        totmem = totmbufs * MSIZE + mbstat.m_clusters * CLBYTES;
                     98:        totfree = mbstat.m_clfree * CLBYTES;
                     99:        printf("%u Kbytes allocated to network (%d%% in use)\n",
                    100:                totmem / 1024, (totmem - totfree) * 100 / totmem);
                    101:        printf("%u requests for memory denied\n", mbstat.m_drops);
                    102:        printf("%u requests for memory delayed\n", mbstat.m_wait);
                    103:        printf("%u calls to protocol drain routines\n", mbstat.m_drain);
                    104: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.