--- cci/usr/src/usr.bin/iostat.c 2019/07/28 12:24:19 1.1 +++ cci/usr/src/usr.bin/iostat.c 2019/07/28 12:25:28 1.1.1.2 @@ -9,6 +9,7 @@ #include #include #include +#include #include struct nlist nli[] = { @@ -40,8 +41,11 @@ struct nlist nli[] = { #define X_NVDDRV 12 { 0 }, }; +#define PART 16 /* 16 drives displayed in one mounted set */ +#define MAX_PART ((int)((DK_NDRIVE+(PART-1))/PART)) char dr_name[DK_NDRIVE][10]; +int dr_win[DK_NDRIVE]; fs_tab *vdinfo,*vdinfo_save; long name; @@ -49,7 +53,7 @@ long name; struct { int dk_busy; - long cp_time[CPUSTATES]; + long cp_time[CPUSTATES]; long dk_time[DK_NDRIVE]; long dk_wds[DK_NDRIVE]; long dk_seek[DK_NDRIVE]; @@ -72,7 +76,7 @@ struct float syste[CPUSTE]; float bps[DK_NDRIVE]; float tps[DK_NDRIVE]; - float msps[DK_NDRIVE]; + float mspt[DK_NDRIVE]; } rec[MAXRPT]; int mf; @@ -82,8 +86,13 @@ int count,repcnt, iter; double etime; extern char *malloc(); +int wno; +jmp_buf jb; +int timer(); +int max_win, recurflg; main(argc, argv) +int argc; char *argv[]; { extern char *ctime(); @@ -92,13 +101,22 @@ char *argv[]; int j, totrep; double f1, f2; long t; - int beg_i, end_i,head,hd; + int beg_i, end_i,head[MAX_PART],hd; int tohdr = 1; int die(); int dietty(); int ptoutput(); int shiftarray(); int TERM; + /* addition variables for windowing implementation */ + WINDOW *win[MAX_PART], *window, *newwin(); + register w; + int w_sv; + int deft=0; + int brkflg; + int wsleep, wrnd; + int sleeptime; + char ch; TERM = isatty(1); nlist(UNIX, nli); @@ -111,14 +129,12 @@ char *argv[]; printf("cannot open /dev/kmem\n"); exit(1); } - while (argc>1&&argv[1][0]=='-') { - argc--; - argv++; - } lseek(mf, (long)nli[X_DK_MSPW].n_value, 0); read(mf, s.dk_mspw, sizeof s.dk_mspw); - for (i = 0; i < DK_NDRIVE; i++) - sprintf (dr_name[i],"??%x",i); + for (i = 0; i < DK_NDRIVE; i++){ + sprintf (dr_name[i],"?%x",i); + dr_win[i] = -1; + } lseek(mf, (long)nli[X_NVDDRV].n_value, 0); read(mf, &nodktyp, sizeof nodktyp); vdinfo = (fs_tab *)malloc(nodktyp*sizeof(fs_tab)); @@ -133,11 +149,60 @@ char *argv[]; } vdinfo = vdinfo_save; read_names(); + max_win=wno+1; + argc--, argv++; + while (argc>0 && argv[0][0]=='-') { + char *cp= *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 'r': + if(TERM && max_win > 0 ) + recurflg++; + break; + + default: + fprintf(stderr,"usage:iostat"); + 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," [interval] [count] \n"); + exit(1); + } + + } totrep = 1; - if(argc > 2) + if(argc > 1) totrep = atoi(argv[2]); - if (argc ==2) + if (argc ==1) totrep = -1; iter = 0; if ((totrep < 0) || (totrep > MAXRPT)) @@ -147,16 +212,22 @@ char *argv[]; if (TERM){ initscr(); signal(SIGINT,dietty); + signal(SIGBUS,dietty); + signal(SIGALRM, timer); nonl(); crmode(); noecho(); leaveok(stdscr, TRUE); scrollok(stdscr,FALSE); + for(w=0; w < max_win; w++){ + win[w]=newwin(NLINES,NCOLS,0,0); + } } else signal(SIGINT,die); loop: - head = 4; + for (w=0; w < max_win; w++) + head[w] = 4; end_i = 0; hd=0; lseek(mf, (long)nli[X_DK_BUSY].n_value, 0); @@ -187,6 +258,7 @@ loop: t = s.tk_nout; s.tk_nout -= s1.tk_nout; s1.tk_nout = t; etime = 0; for(i=0; i1){ + 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); } else if ((count >= MAXRPT) &&( (count % MAXRPT ) == 0)) @@ -262,28 +356,34 @@ prt_loop: } iter = MAXRPT-1; } -/* - - if (count >= MAXRPT) { - for(i = 0; i < (MAXRPT-1); i ++){ - rec[i].tin = rec[i+1].tin; - rec[i].tout = rec[i+1].tout; - for(j=0; j < CPUSTATES; j++) - rec[i].syste[j] = rec[i+1].syste[j]; - for(j=0; j< DK_NDRIVE; j++){ - rec[i].bps[j] =rec[i+1].bps[j]; - rec[i].tps[j] =rec[i+1].tps[j]; - rec[i].msps[j] =rec[i+1].msps[j]; - } - } - iter = MAXRPT -1; - } -*/ - if (totrep != 0 ){ - if(argc > 1) { - sleep(atoi(argv[1])); - goto loop; + if(argc > 0) { + sleeptime=atoi(argv[0]); + if (TERM){ + w_sv=deft; + 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) @@ -293,17 +393,10 @@ prt_loop: } stats(dn,cnt) + int dn, cnt; { register i; double atime, words, xtime, itime; -/* - if (s.dk_mspw[dn] == 0.0) { - rec[cnt].bps[dn] = 0.0; - rec[cnt].tps[dn] = 0.0; - rec[cnt].msps[dn] = 0.0; - return; - } -*/ atime = s.dk_time[dn]; atime /= (float) hz; words = s.dk_wds[dn]*32.0; /* number of words transferred */ @@ -313,22 +406,23 @@ stats(dn,cnt) itime += xtime, xtime = 0; if (itime < 0) xtime += itime, itime = 0; - rec[cnt].bps[dn] = words/512/etime; + rec[cnt].bps[dn] = words/512.0/etime; rec[cnt].tps[dn] = s.dk_xfer[dn]/etime; - rec[cnt].msps[dn] = s.dk_seek[dn] ? itime*1000./s.dk_seek[dn] : 0.0; + rec[cnt].mspt[dn] = s.dk_seek[dn] ? (itime*1000./s.dk_seek[dn])+8.0 : 0.0; } stat1(o,ict) + int o,ict; { register i; - double time; + float time; time = 0; for(i=0; i=PART){ + wcnt=0; + wno++; + } + if(wno > MAX_PART){ + fprintf(stderr, "iostat : maximum mounted disk set 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() @@ -381,7 +488,7 @@ die() dietty() { signal(SIGINT, SIG_IGN); - mvcur(0,COLS-1, LINES-1,0); + mvcur(0,NCOLS-1, NLINES-1,0); endwin(); exit(0); } @@ -412,7 +519,7 @@ int doneflg,head,end_i,beg_i; end_i = i; for (i = beg_i; i <= end_i; i++) if(dr_name[i][0] != '?') - printf(" bps tps msps"); + printf(" bps tps mspt"); printf ("\n"); for(i = 0; i < reptot; i++){ if (head == 5){ @@ -425,7 +532,7 @@ int doneflg,head,end_i,beg_i; for (j = beg_i; j <= end_i; j++) if (dr_name[j][0] != '?'){ printf("%4.0f%4.0f %5.1f", rec[i].bps[j], - rec[i].tps[j],rec[i].msps[j]); + rec[i].tps[j],rec[i].mspt[j]); } printf ("\n"); } @@ -446,6 +553,52 @@ register j; for(j=0; j< DK_NDRIVE; j++){ rec[srtary].bps[j] =rec[srtary+offset].bps[j]; rec[srtary].tps[j] =rec[srtary+offset].tps[j]; - rec[srtary].msps[j] =rec[srtary+offset].msps[j]; + rec[srtary].mspt[j] =rec[srtary+offset].mspt[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++; + } + 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); +}