mbufs.c revision 8874
1327952Sdim/*- 2259701Sdim * Copyright (c) 1980, 1992, 1993 3353358Sdim * The Regents of the University of California. All rights reserved. 4353358Sdim * 5353358Sdim * Redistribution and use in source and binary forms, with or without 6259701Sdim * modification, are permitted provided that the following conditions 7259701Sdim * are met: 8327952Sdim * 1. Redistributions of source code must retain the above copyright 9259701Sdim * notice, this list of conditions and the following disclaimer. 10341825Sdim * 2. Redistributions in binary form must reproduce the above copyright 11259701Sdim * notice, this list of conditions and the following disclaimer in the 12259701Sdim * documentation and/or other materials provided with the distribution. 13327952Sdim * 3. All advertising materials mentioning features or use of this software 14259701Sdim * must display the following acknowledgement: 15259701Sdim * This product includes software developed by the University of 16280031Sdim * California, Berkeley and its contributors. 17280031Sdim * 4. Neither the name of the University nor the names of its contributors 18259701Sdim * may be used to endorse or promote products derived from this software 19259701Sdim * without specific prior written permission. 20259701Sdim * 21259701Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22276479Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23259701Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24314564Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25314564Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26314564Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27259701Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28259701Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29259701Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30259701Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31259701Sdim * SUCH DAMAGE. 32276479Sdim */ 33314564Sdim 34276479Sdim#ifndef lint 35276479Sdimstatic char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) 6/6/93"; 36327952Sdim#endif /* not lint */ 37314564Sdim 38327952Sdim#include <sys/param.h> 39276479Sdim#include <sys/types.h> 40276479Sdim#include <sys/mbuf.h> 41314564Sdim 42280031Sdim#include <stdlib.h> 43280031Sdim#include <string.h> 44280031Sdim#include <nlist.h> 45280031Sdim#include <paths.h> 46276479Sdim#include "systat.h" 47314564Sdim#include "extern.h" 48314564Sdim 49314564Sdimstatic struct mbstat *mb; 50314564Sdim 51341825Sdimchar *mtnames[] = { 52276479Sdim "free", 53276479Sdim "data", 54341825Sdim "headers", 55276479Sdim "sockets", 56276479Sdim "pcbs", 57341825Sdim "routes", 58280031Sdim "hosts", 59280031Sdim "arps", 60280031Sdim "socknames", 61280031Sdim "zombies", 62280031Sdim "sockopts", 63276479Sdim "frags", 64276479Sdim "rights", 65259701Sdim "ifaddrs", 66259701Sdim}; 67314564Sdim 68314564Sdim#define NNAMES (sizeof (mtnames) / sizeof (mtnames[0])) 69341825Sdim 70259701SdimWINDOW * 71276479Sdimopenmbufs() 72276479Sdim{ 73276479Sdim return (subwin(stdscr, LINES-5-1, 0, 5, 0)); 74276479Sdim} 75341825Sdim 76259701Sdimvoid 77276479Sdimclosembufs(w) 78280031Sdim WINDOW *w; 79280031Sdim{ 80280031Sdim if (w == NULL) 81280031Sdim return; 82280031Sdim wclear(w); 83280031Sdim wrefresh(w); 84280031Sdim delwin(w); 85280031Sdim} 86341825Sdim 87280031Sdimvoid 88259701Sdimlabelmbufs() 89280031Sdim{ 90276479Sdim wmove(wnd, 0, 0); wclrtoeol(wnd); 91280031Sdim mvwaddstr(wnd, 0, 10, 92280031Sdim "/0 /5 /10 /15 /20 /25 /30 /35 /40 /45 /50 /55 /60"); 93280031Sdim} 94280031Sdim 95276479Sdimvoid 96280031Sdimshowmbufs() 97276479Sdim{ 98341825Sdim register int i, j, max, index; 99276479Sdim char buf[10]; 100276479Sdim 101276479Sdim if (mb == 0) 102259701Sdim return; 103259701Sdim for (j = 0; j < wnd->maxy; j++) { 104259701Sdim max = 0, index = -1; 105259701Sdim for (i = 0; i < wnd->maxy; i++) 106259701Sdim if (mb->m_mtypes[i] > max) { 107259701Sdim max = mb->m_mtypes[i]; 108259701Sdim index = i; 109259701Sdim } 110276479Sdim if (max == 0) 111276479Sdim break; 112276479Sdim if (j > NNAMES) 113276479Sdim mvwprintw(wnd, 1+j, 0, "%10d", index); 114296417Sdim else 115259701Sdim mvwprintw(wnd, 1+j, 0, "%-10.10s", mtnames[index]); 116259701Sdim wmove(wnd, 1 + j, 10); 117259701Sdim if (max > 60) { 118341825Sdim sprintf(buf, " %d", max); 119259701Sdim max = 60; 120259701Sdim while (max--) 121259701Sdim waddch(wnd, 'X'); 122259701Sdim waddstr(wnd, buf); 123259701Sdim } else { 124276479Sdim while (max--) 125296417Sdim waddch(wnd, 'X'); 126259701Sdim wclrtoeol(wnd); 127259701Sdim } 128259701Sdim mb->m_mtypes[index] = 0; 129259701Sdim } 130259701Sdim wmove(wnd, 1+j, 0); wclrtobot(wnd); 131327952Sdim} 132327952Sdim 133327952Sdimstatic struct nlist namelist[] = { 134259701Sdim#define X_MBSTAT 0 135314564Sdim { "_mbstat" }, 136 { "" } 137}; 138 139int 140initmbufs() 141{ 142 if (namelist[X_MBSTAT].n_type == 0) { 143 if (kvm_nlist(kd, namelist)) { 144 nlisterr(namelist); 145 return(0); 146 } 147 if (namelist[X_MBSTAT].n_type == 0) { 148 error("namelist on %s failed", getbootfile()); 149 return(0); 150 } 151 } 152 if (mb == 0) 153 mb = (struct mbstat *)calloc(1, sizeof (*mb)); 154 return(1); 155} 156 157void 158fetchmbufs() 159{ 160 if (namelist[X_MBSTAT].n_type == 0) 161 return; 162 NREAD(X_MBSTAT, mb, sizeof (*mb)); 163} 164