[BACK]Return to mbufs.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / systat

Annotation of src/usr.bin/systat/mbufs.c, Revision 1.5

1.5     ! ericj       1: /*     $OpenBSD: mbufs.c,v 1.4 1997/12/19 09:03:32 deraadt Exp $       */
1.1       deraadt     2: /*     $NetBSD: mbufs.c,v 1.2 1995/01/20 08:52:02 jtc Exp $    */
                      3:
                      4: /*-
                      5:  * Copyright (c) 1980, 1992, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *     This product includes software developed by the University of
                     19:  *     California, Berkeley and its contributors.
                     20:  * 4. Neither the name of the University nor the names of its contributors
                     21:  *    may be used to endorse or promote products derived from this software
                     22:  *    without specific prior written permission.
                     23:  *
                     24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     34:  * SUCH DAMAGE.
                     35:  */
                     36:
                     37: #ifndef lint
                     38: #if 0
                     39: static char sccsid[] = "@(#)mbufs.c    8.1 (Berkeley) 6/6/93";
                     40: #endif
1.5     ! ericj      41: static char rcsid[] = "$OpenBSD: mbufs.c,v 1.4 1997/12/19 09:03:32 deraadt Exp $";
1.1       deraadt    42: #endif /* not lint */
                     43:
                     44: #include <sys/param.h>
                     45: #include <sys/types.h>
                     46: #include <sys/mbuf.h>
                     47:
                     48: #include <stdlib.h>
                     49: #include <string.h>
                     50: #include <nlist.h>
                     51: #include <paths.h>
                     52: #include "systat.h"
                     53: #include "extern.h"
                     54:
                     55: static struct mbstat *mb;
                     56:
                     57: char *mtnames[] = {
                     58:        "free",
                     59:        "data",
                     60:        "headers",
                     61:        "sockets",
                     62:        "pcbs",
                     63:        "routes",
                     64:        "hosts",
                     65:        "arps",
                     66:        "socknames",
                     67:        "zombies",
                     68:        "sockopts",
                     69:        "frags",
                     70:        "rights",
                     71:        "ifaddrs",
                     72: };
                     73:
                     74: #define        NNAMES  (sizeof (mtnames) / sizeof (mtnames[0]))
                     75:
                     76: WINDOW *
                     77: openmbufs()
                     78: {
                     79:        return (subwin(stdscr, LINES-5-1, 0, 5, 0));
                     80: }
                     81:
                     82: void
                     83: closembufs(w)
                     84:        WINDOW *w;
                     85: {
                     86:        if (w == NULL)
                     87:                return;
                     88:        wclear(w);
                     89:        wrefresh(w);
                     90:        delwin(w);
                     91: }
                     92:
                     93: void
                     94: labelmbufs()
                     95: {
                     96:        wmove(wnd, 0, 0); wclrtoeol(wnd);
                     97:        mvwaddstr(wnd, 0, 10,
                     98:            "/0   /5   /10  /15  /20  /25  /30  /35  /40  /45  /50  /55  /60");
                     99: }
                    100:
                    101: void
                    102: showmbufs()
                    103: {
                    104:        register int i, j, max, index;
1.4       deraadt   105:        char buf[13];
1.1       deraadt   106:
                    107:        if (mb == 0)
                    108:                return;
1.2       mickey    109:        for (j = 0; j < wnd->_maxy; j++) {
1.1       deraadt   110:                max = 0, index = -1;
1.2       mickey    111:                for (i = 0; i < wnd->_maxy; i++)
1.1       deraadt   112:                        if (mb->m_mtypes[i] > max) {
                    113:                                max = mb->m_mtypes[i];
                    114:                                index = i;
                    115:                        }
                    116:                if (max == 0)
                    117:                        break;
                    118:                if (j > NNAMES)
                    119:                        mvwprintw(wnd, 1+j, 0, "%10d", index);
                    120:                else
                    121:                        mvwprintw(wnd, 1+j, 0, "%-10.10s", mtnames[index]);
                    122:                wmove(wnd, 1 + j, 10);
                    123:                if (max > 60) {
1.4       deraadt   124:                        snprintf(buf, sizeof buf, " %d", max);
1.1       deraadt   125:                        max = 60;
                    126:                        while (max--)
                    127:                                waddch(wnd, 'X');
                    128:                        waddstr(wnd, buf);
                    129:                } else {
                    130:                        while (max--)
                    131:                                waddch(wnd, 'X');
                    132:                        wclrtoeol(wnd);
                    133:                }
                    134:                mb->m_mtypes[index] = 0;
                    135:        }
                    136:        wmove(wnd, 1+j, 0); wclrtobot(wnd);
                    137: }
                    138:
                    139: static struct nlist namelist[] = {
                    140: #define        X_MBSTAT        0
                    141:        { "_mbstat" },
                    142:        { "" }
                    143: };
                    144:
                    145: int
                    146: initmbufs()
                    147: {
1.5     ! ericj     148:        int ret;
        !           149:
1.1       deraadt   150:        if (namelist[X_MBSTAT].n_type == 0) {
1.5     ! ericj     151:                if ((ret = kvm_nlist(kd, namelist)) == -1)
        !           152:                        errx(1, "%s", kvm_geterr(kd));
        !           153:                else if (ret)
1.1       deraadt   154:                        nlisterr(namelist);
                    155:                if (namelist[X_MBSTAT].n_type == 0) {
                    156:                        error("namelist on %s failed", _PATH_UNIX);
                    157:                        return(0);
                    158:                }
                    159:        }
                    160:        if (mb == 0)
                    161:                mb = (struct mbstat *)calloc(1, sizeof (*mb));
                    162:        return(1);
                    163: }
                    164:
                    165: void
                    166: fetchmbufs()
                    167: {
                    168:        if (namelist[X_MBSTAT].n_type == 0)
                    169:                return;
                    170:        NREAD(X_MBSTAT, mb, sizeof (*mb));
                    171: }