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
   6:  * provided that this notice is preserved and that due credit is given
   7:  * to the University of California at Berkeley. The name of the University
   8:  * may not be used to endorse or promote products derived from this
   9:  * software without specific prior written permission. This software
  10:  * is provided ``as is'' without express or implied warranty.
  11:  */
  12: 
  13: #if defined(DOSCCS) && !defined(lint)
  14: static char sccsid[] = "@(#)mbuf.c	5.3.1 (2.11BSD GTE) 1/1/94";
  15: #endif
  16: 
  17: #include <stdio.h>
  18: #include <sys/param.h>
  19: #include <sys/mbuf.h>
  20: #define YES 1
  21: typedef int bool;
  22: 
  23: struct  mbstat mbstat;
  24: extern  int kmem;
  25: 
  26: static struct mbtypes {
  27:     int mt_type;
  28:     char    *mt_name;
  29: } mbtypes[] = {
  30:     { MT_DATA,  "data" },
  31:     { MT_HEADER,    "packet headers" },
  32:     { MT_SOCKET,    "socket structures" },
  33:     { MT_PCB,   "protocol control blocks" },
  34:     { MT_RTABLE,    "routing table entries" },
  35:     { MT_HTABLE,    "IMP host table entries" },
  36:     { MT_ATABLE,    "address resolution tables" },
  37:     { MT_FTABLE,    "fragment reassembly queue headers" },
  38:     { MT_SONAME,    "socket names and addresses" },
  39:     { MT_ZOMBIE,    "zombie process information" },
  40:     { MT_SOOPTS,    "socket options" },
  41:     { MT_RIGHTS,    "access rights" },
  42:     { MT_IFADDR,    "interface addresses" },
  43:     { 0, 0 }
  44: };
  45: 
  46: int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short);
  47: bool seen[NMBTYPES];        /* "have we seen this type yet?" */
  48: 
  49: #ifdef pdp11
  50: #define klseek slseek
  51: #endif
  52: 
  53: /*
  54:  * Print mbuf statistics.
  55:  */
  56: mbpr(mbaddr)
  57:     off_t mbaddr;
  58: {
  59:     register int totmbufs;
  60:     long totmem, totfree;
  61:     register int i;
  62:     register struct mbtypes *mp;
  63: 
  64:     if (nmbtypes != NMBTYPES) {
  65:         fprintf(stderr, "unexpected change to mbstat; check source\n");
  66:         return;
  67:     }
  68:     if (mbaddr == 0) {
  69:         printf("mbstat: symbol not in namelist\n");
  70:         return;
  71:     }
  72:     klseek(kmem, mbaddr, 0);
  73:     if (read(kmem, (char *)&mbstat, sizeof (mbstat)) != sizeof (mbstat)) {
  74:         printf("mbstat: bad read\n");
  75:         return;
  76:     }
  77:     printf("%u/%u mbufs in use:\n",
  78:         mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE], mbstat.m_mbufs);
  79:     totmbufs = 0;
  80:     for (mp = mbtypes; mp->mt_name; mp++)
  81:         if (mbstat.m_mtypes[mp->mt_type]) {
  82:             seen[mp->mt_type] = YES;
  83:             printf("\t%u mbufs allocated to %s\n",
  84:                 mbstat.m_mtypes[mp->mt_type], mp->mt_name);
  85:             totmbufs += mbstat.m_mtypes[mp->mt_type];
  86:         }
  87:     seen[MT_FREE] = YES;
  88:     for (i = 0; i < nmbtypes; i++)
  89:         if (!seen[i] && mbstat.m_mtypes[i]) {
  90:             printf("\t%u mbufs allocated to <mbuf type %d>\n",
  91:                 mbstat.m_mtypes[i], i);
  92:             totmbufs += mbstat.m_mtypes[i];
  93:         }
  94:     if (totmbufs != mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE])
  95:         printf("*** %u mbufs missing ***\n",
  96:             (mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) - totmbufs);
  97:     printf("%u/%u mapped pages in use\n",
  98:         mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters);
  99:     printf("%u interface pages allocated\n", mbstat.m_space);
 100:     totmem = mbstat.m_mbufs * MSIZE + mbstat.m_clusters * CLBYTES +
 101:         mbstat.m_space * CLBYTES;
 102:     totfree = mbstat.m_mtypes[MT_FREE]*MSIZE + mbstat.m_clfree * CLBYTES;
 103:     printf("%lu Kbytes allocated to network (%ld%% in use)\n",
 104:         totmem / 1024, (totmem - totfree) * 100 / totmem);
 105:     printf("%u requests for memory denied\n", mbstat.m_drops);
 106:     printf("%u requests for memory delayed\n", mbstat.m_wait);
 107:     printf("%u calls to protocol drain routines\n", mbstat.m_drain);
 108: }

Defined functions

mbpr defined in line 56; never used

Defined variables

mbstat defined in line 23; used 29 times
mbtypes defined in line 29; used 1 times
  • in line 80
nmbtypes defined in line 46; used 2 times
sccsid defined in line 14; never used
seen defined in line 47; used 3 times

Defined struct's

mbtypes defined in line 26; used 2 times
  • in line 62(2)

Defined typedef's

bool defined in line 21; used 1 times
  • in line 47

Defined macros

YES defined in line 20; used 2 times
klseek defined in line 50; used 1 times
  • in line 72
Last modified: 1994-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3229
Valid CSS Valid XHTML 1.0 Strict