X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/852c70640426119d3090e5ea154c3a6be80ec96b..b5eefd1e5ec8f5441559bbdf4e3f44e0fba9a1a2:/usr/src/usr.bin/systat/pigs.c diff --git a/usr/src/usr.bin/systat/pigs.c b/usr/src/usr.bin/systat/pigs.c index a496efdaaa..1ce24cc072 100644 --- a/usr/src/usr.bin/systat/pigs.c +++ b/usr/src/usr.bin/systat/pigs.c @@ -1,8 +1,39 @@ #ifndef lint -static char sccsid[] = "@(#)pigs.c 1.2 (Lucasfilm) %G%"; +static char sccsid[] = "@(#)pigs.c 1.7 (Berkeley) %G%"; #endif #include "systat.h" +#include +#include +#include +#include +#include +#include +#include + +WINDOW * +openpigs() +{ + + return (subwin(stdscr, LINES-5-1, 0, 5, 0)); +} + +closepigs(w) + WINDOW *w; +{ + + if (w == NULL) + return; + wclear(w); + wrefresh(w); + delwin(w); +} + +int maxind; +int factor; +float total; +struct passwd *getpwuid(); +char pidname[30]; showpigs() { @@ -14,6 +45,8 @@ showpigs() register struct users *knptr; char *getpname(), *pnamp; + if (pt == NULL) + return; /* Accumulate the percent of cpu per user. */ ptptr = pt; numprocs = 0; @@ -39,8 +72,10 @@ showpigs() total = 1.0; factor = 50.0/total; - /* Find the top ten by executing a "bubble pass" ten times. */ - y = numprocs + 1 < 15 ? numprocs + 1 : 15; + /* Find the top few by executing a "bubble pass" ten times. */ + y = numprocs + 1; + if (y > wnd->_maxy-1) + y = wnd->_maxy-1; for (i = 0; i < y; i++) { ptptr = &pt[i]; max = -10000.0; @@ -58,11 +93,11 @@ showpigs() pt[maxind] = temppt; } } - - /* Display the top fifteen. */ - y = 4; + y = 1; ptptr = pt; - i = numprocs+1 < 15 ? numprocs+1 : 15; + i = numprocs + 1; + if (i > wnd->_maxy-1) + i = wnd->_maxy-1; for (; i > 0 && ptptr->pt_pctcpu > 0.01; i--) { /* Find the user's name. */ knptr = known; @@ -89,64 +124,50 @@ showpigs() wmove(wnd, y, 0); wclrtoeol(wnd); mvwaddstr(wnd, y, 0, namp); - sprintf(pidname, "%8.8s", pnamp); - mvwaddstr(wnd, y, 6, pidname); - wmove(wnd, y++, 15); + sprintf(pidname, "%10.10s", pnamp); + mvwaddstr(wnd, y, 9, pidname); + wmove(wnd, y++, 20); for (j = ptptr->pt_pctcpu*factor + 0.5; j > 0; j--) waddch(wnd, 'X'); ptptr++; } - - while (y < 19) { - wmove(wnd, y++, 0); - wclrtoeol(wnd); - } -} - -openpigs() -{ - - kmemf = "/dev/kmem"; - kmem = open(kmemf, 0); - if (kmem < 0) { - perror(kmemf); - exit(1); - } - memf = "/dev/mem"; - mem = open(memf, 0); - if (mem < 0) { - perror(memf); - exit(1); - } - swapf = "/dev/drum"; - swap = open(swapf, 0); - if (swap < 0) { - perror(swapf); - exit(1); - } + wmove(wnd, y, 0); wclrtobot(wnd); } -/* these don't belong here */ +static struct nlist nlst[] = { #define X_PROC 0 + { "_proc" }, #define X_NPROC 1 -#define X_USRPTMAP 4 -#define X_USRPT 5 - -struct proc *kprocp; + { "_nproc" }, +#define X_USRPTMAP 2 + { "_Usrptmap" }, +#define X_USRPT 3 + { "_usrpt" }, + { "" } +}; initpigs() { + if (nlst[X_PROC].n_type == 0) { + nlist("/vmunix", nlst); + if (nlst[X_PROC].n_type == 0) { + error("namelist on /vmunix failed"); + return; + } + } if (procp == NULL) { procp = getw(nlst[X_PROC].n_value); nproc = getw(nlst[X_NPROC].n_value); - kprocp = (struct proc *)malloc(sizeof (*kprocp) * nproc); } + if (kprocp == NULL) + kprocp = (struct proc *)calloc(nproc, sizeof (struct proc)); if (usrpt != NULL) return; usrpt = (struct pte *)nlst[X_USRPT].n_value; Usrptma = (struct pte *)nlst[X_USRPTMAP].n_value; - pt = (struct p_times *)malloc(nproc * sizeof (struct p_times)); + if (pt == NULL) + pt = (struct p_times *)calloc(nproc, sizeof (struct p_times)); } fetchpigs() @@ -156,6 +177,18 @@ fetchpigs() register float time; register struct proc *pp; + if (nlst[X_PROC].n_type == 0) + return; + if (kprocp == NULL) { + kprocp = (struct proc *)calloc(nproc, sizeof (struct proc)); + if (kprocp == NULL) + return; + } + if (pt == NULL) { + pt = (struct p_times *)calloc(nproc, sizeof (struct p_times)); + if (pt == NULL) + return; + } prt = pt; lseek(kmem, procp, L_SET); read(kmem, kprocp, sizeof (struct proc) * nproc); @@ -176,8 +209,7 @@ fetchpigs() labelpigs() { - move(5, 0); - clrtoeol(); - mvaddstr(5, 20, + wmove(wnd, 0, 0); wclrtoeol(wnd); + mvwaddstr(wnd, 0, 20, "/0 /10 /20 /30 /40 /50 /60 /70 /80 /90 /100"); }