--- cci/usr/src/ucb/vmstat.c 2019/07/28 12:24:19 1.1 +++ cci/usr/src/ucb/vmstat.c 2019/07/28 12:29:18 1.1.1.2 @@ -11,8 +11,11 @@ static char *sccsid = "@(#)vmstat.c 4.11 #include #include #include +#include #include +#define PART 16 /* 16 drives displayed in one mounted set */ +#define MAX_PART ((int)((DK_NDRIVE+(PART-1))/PART)) struct nlist nli[] = { #define X_CPTIME 0 { "_cp_time" }, @@ -51,6 +54,7 @@ struct nlist nli[] = { #define UNIX "/vmunix" char dr_name[DK_NDRIVE][10]; +int dr_win[DK_NDRIVE]; double stat1(); int firstfree, maxfree; int hz; @@ -113,7 +117,11 @@ int id; */ } rec[MAXRPT]; +int wno; extern char *malloc(); +jmp_buf jb; +int recurflg; +int max_win; main(argc, argv) int argc; @@ -131,8 +139,17 @@ main(argc, argv) int ptoutput(); int shiftarray(); int dietty(); + int timer(); int TERM; time_t now; + /* addition variables for windowing implementation */ + WINDOW *win[MAX_PART], *window, *newwin(); + register w; + int w_sv; + int deft=0; + int wsleep, wrnd; + int sleeptime; + char ch; TERM = isatty(1); setbuf(stdout, _sobuf); @@ -146,6 +163,25 @@ main(argc, argv) printf("cannot open /dev/kmem\n"); exit(1); } + lseek(mf, (long)nli[X_NVDDRV].n_value, 0); + read(mf, &nodktyp, sizeof nodktyp); + vdinfo = (fs_tab *)malloc(nodktyp*sizeof(fs_tab)); + lseek(mf, (long)nli[X_VDST].n_value, 0); + read(mf, (char *)vdinfo, nodktyp*sizeof(fs_tab)); + vdinfo_save = vdinfo; + for (i = 0; i < nodktyp; vdinfo++, i++) { + name = (long)vdinfo->type_name; + vdinfo->type_name = malloc(3); + lseek(mf, (long)name, 0); + read(mf, vdinfo->type_name, 3); + } + vdinfo = vdinfo_save; + for (i = 0; i < DK_NDRIVE; i++){ + sprintf(dr_name[i],"?%x",i); + dr_win[i] = -1; + } + read_names(); + max_win=wno+1; iter = 0; argc--, argv++; while (argc>0 && argv[0][0]=='-') { @@ -153,11 +189,48 @@ main(argc, argv) argc--; while (*++cp) switch (*cp) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (TERM) + deft=(*cp)-'0'; + if (deft >= max_win) deft =0; + break; + + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + if (TERM) + deft=(*cp) -'A' +10; + if (deft >= max_win) deft =0; + break; + case 'f': + doforkst(); + exit(0); + + case 'r': + if(TERM) + if(max_win > 1) recurflg++; + break; + + case 's': + dosum(); + exit(0); + case 'S': swflag = 1 - swflag; break; - case 't': dotimes(); exit(0); @@ -169,16 +242,15 @@ main(argc, argv) write(mf, &z.Sum, sizeof z.Sum); exit(0); - case 'f': - doforkst(); - exit(0); - - case 's': - dosum(); - exit(0); - default: - fprintf(stderr, "usage: vmstat [ -fs ] [ interval ] [ count]\n"); + fprintf(stderr,"usage:vmstat "); + if(max_win > 0 ) + if(max_win <10) + fprintf(stderr,"[-[0-%x][r",max_win); + else if (max_win >=10 && max_win < 16) + fprintf(stderr,"[-[0-9A-%x][r",max_win); + else; + fprintf(stderr," fs] [interval] [count] \n"); exit(1); } } @@ -200,22 +272,6 @@ main(argc, argv) read(mf, &boottime, sizeof boottime); lseek(mf, (long)nli[X_HZ].n_value, 0); read(mf, &hz, sizeof hz); - lseek(mf, (long)nli[X_NVDDRV].n_value, 0); - read(mf, &nodktyp, sizeof nodktyp); - vdinfo = (fs_tab *)malloc(nodktyp*sizeof(fs_tab)); - lseek(mf, (long)nli[X_VDST].n_value, 0); - read(mf, (char *)vdinfo, nodktyp*sizeof(fs_tab)); - vdinfo_save = vdinfo; - for (i = 0; i < nodktyp; vdinfo++, i++) { - name = (long)vdinfo->type_name; - vdinfo->type_name = malloc(3); - lseek(mf, (long)name, 0); - read(mf, vdinfo->type_name, 3); - } - vdinfo = vdinfo_save; - for (i = 0; i < DK_NDRIVE; i++) - sprintf(dr_name[i],"??%x",i); - read_names(); time(&now); nintv = now - boottime; if (nintv <= 0 || nintv > 60*60*24*365*10) { @@ -225,11 +281,17 @@ main(argc, argv) if (TERM){ initscr(); signal(SIGINT,dietty); + signal(SIGBUS,dietty); + signal(SIGALRM, timer); nonl(); crmode(); noecho(); leaveok(stdscr,TRUE); - scrollok(stdscr,FALSE); + scrollok(stdscr,FALSE); + for(w=0; w < max_win; w++){ + win[w]=newwin(NLINES,NCOLS,0,0); + wmove(win[w],0,0); + } } else signal(SIGINT,die); @@ -309,34 +371,52 @@ loop: ptoutput(iter+1); if(TERM) { - printw("mem[avm fre] pag[%5s pi po fr de sr] fault[in sy cs] cpu[us sy id]\n", swflag ? "si so" : "re at"); - for(i=0; i < (iter+1); i++){ - printw("%7d%7d %4d%3d%4d%4d%4d%4d%4d %5d%4d%4d ", + for(w=0; w 1 ){ + wmove(win[w],NLINES-1,0); + wprintw(win[w],"More mounted disk set display: type [0-%x] to select or [r] to rotate" ,(max_win-1)); + } + wmove(win[w],0,0); + } + window=win[deft]; + touchwin(window); + wrefresh(window); } if (totrep > 0) totrep--; @@ -347,11 +427,34 @@ loop: } iter = MAXRPT-1; } - - if (totrep != 0){ + if (totrep != 0 ){ if(argc > 0) { - sleep(atoi(argv[0])); - goto loop; + w_sv=deft; + sleeptime=atoi(argv[0]); + if (TERM){ + if (recurflg){ + wrnd=(max_win-deft); + wsleep=(int)(sleeptime/(wrnd+1)); + if(wsleep < 1) recurflg=0; + else{ + for(w=0; w< wrnd; w++){ + w_sv=wtimed_ch(window,wsleep); + window=win[w+deft]; + touchwin(window); + wrefresh(window); + } + } + w_sv=wtimed_ch(window,sleeptime-(wrnd*wsleep)); + } + else { + w_sv=wtimed_ch(window,sleeptime); + } + if(w_sv >= 0 && w_sv < max_win) deft=w_sv; + if(recurflg && deft == max_win-1) recurflg=0; + } + else + sleep(sleeptime); + goto loop; } } if(TERM) @@ -466,6 +569,7 @@ read_names() struct vba_device udev, *up; struct vba_driver udrv; int unit, i; + int wcnt; up = (struct vba_device *) nli[X_VBDINIT].n_value; if (up == 0) @@ -474,6 +578,8 @@ read_names() exit(1); } vdinfo_save = vdinfo; + wno=0; + wcnt=0; for (;;) { steal(up++, udev); unit = (udev.ui_ctlr * 4) + udev.ui_slave; @@ -485,11 +591,21 @@ read_names() fprintf(stderr,"vmstat : disk type in unit %d not supported \n",unit); exit(1); } + if (wcnt >=PART){ + wcnt=0; + wno++; + } + if(wno > MAX_PART){ + fprintf(stderr, "vmstat : maximum partition of display exceeded \n"); + exit(1); + } vdinfo = vdinfo_save; for(i=0; i < udev.ui_type; i++) vdinfo++; dr_name[unit][0] = vdinfo->type_name[0]; - dr_name[unit][1] = vdinfo->type_name[1]; +/* dr_name[unit][1] = vdinfo->type_name[1]; */ + dr_win[unit]=wno; + wcnt++; } } die() @@ -509,7 +625,9 @@ die() dietty() { signal(SIGINT,SIG_IGN); - mvcur(0,COLS-1, LINES-1,0); + signal(SIGBUS,SIG_IGN); + signal(SIGSEGV,SIG_IGN); + mvcur(0,NCOLS-1, NLINES-1,0); endwin(); exit(0); } @@ -571,3 +689,49 @@ register j; for(j=0; j < (CPUSTATES-1); j++) rec[srtary].syste[j] = rec[srtary+offset].syste[j]; } +timer() +{ + signal(SIGALRM, timer); + longjmp(jb,1); +} + +int wtimed_ch(win, seconds) +WINDOW *win; +int seconds; +{ + int ch = '\0'; + int w; + int deft = -1; + + if(setjmp(jb) == 0) + { + do{ + alarm(seconds); + ch = wgetch(win); + if(ch == 'r') { + deft= -2; + recurflg=1; + } + w=ch-'0'; + if (w < max_win && w >=0) { + recurflg=0; + deft=w; + } + w=ch -'A' +10; + if (w < max_win && w >= 10){ + recurflg=0; + deft=w; + } + else ; + seconds = alarm(0); + + } while (ch != 'r'|| deft <0 ); + } + return(deft); +} + +terminate() /* SIGINT handler */ +{ + endwin(); + exit(0); +}