📄 perfmon.c
字号:
else { timeout.tv_usec = 0; timeout.tv_sec += 1; } break; case 'F': /* faster sec timeout */ if (timeout.tv_sec >= SEC_INC) timeout.tv_sec -= SEC_INC; break; case 'S': /* slower sec timeout */ timeout.tv_sec += SEC_INC; break; case 'R': /* reset */ timeout.tv_sec = SEC_INC; timeout.tv_usec = USEC_INC; num_of_val = 0; redisplay(); break; case 'q': case 'Q': quit = -1; (void)gfxsw_selectdone(gfx_local); break; case 'h': case 'H': case '?': /* Help */ (void)printf("%s\n%s\n%s\n%s\n%s\n%s\n", "'s' slower usec timeout", "'f' faster usec timeout", "'S' slower sec timeout", "'F' faster sec timeout", "'R' reset timeout and display", "'q' or 'Q' quit"); /* * Don't reset timeout */ return; default: (void)gfxsw_inputinterrupts(gfx_local, &event); } } *ibits = *obits = *ebits = 0; timeleft = timeout; *timer = &timeleft;}int total_disk_transfers(){ register int i, total_xfers = 0; for(i=0; i < DK_NDRIVE; i++) total_xfers += s.xfer[i]; return(total_xfers/etime);}copy_cpu_stats(stat) int *stat[CPUSTATES-1];{ register int i; for(i=0; i<CPUSTATES; i++) { float f = stat1(i); if (i == 0) { /* US+NI */ i++; f += stat1(i); } if (stat[i-1] != 0) *stat[i-1] = f; }}collect_stats(){ off_t ifnetaddr = (long)nl[N_IFNET].n_value; /* ************* \/ vmstat \/ *************** */ register int i; (void)lseek(mf, (long)nl[X_CPTIME].n_value, 0); (void)read(mf, (char *)(LINT_CAST(s.time)), sizeof s.time); (void)lseek(mf, (long)nl[X_DKXFER].n_value, 0); (void)read(mf, (char *)(LINT_CAST(s.xfer)), sizeof s.xfer); if (nintv != 1) { steal((long)nl[X_SUM].n_value, rate); } else { steal((long)nl[X_RATE].n_value, rate); } steal((long)nl[X_TOTAL].n_value, total); osum = sum; steal((long)nl[X_SUM].n_value, sum); steal((long)nl[X_DEFICIT].n_value, deficit); etime = 0; for (i=0; i < DK_NDRIVE; i++) { t = s.xfer[i]; s.xfer[i] -= s1.xfer[i]; s1.xfer[i] = t; } for (i=0; i < CPUSTATES; i++) { t = s.time[i]; s.time[i] -= s1.time[i]; s1.time[i] = t; etime += s.time[i]; } if(etime == 0.) etime = 1.;#ifdef notdef (void)printf("%2d%2d%2d", total.t_rq, total.t_dw+total.t_pw, total.t_sw); (void)printf("%6d%5d", pgtok(total.t_avm), pgtok(total.t_free)); (void)printf("%4d%3d", swflag ? sum.v_swpin-osum.v_swpin : (rate.v_pgrec - (rate.v_xsfrec+rate.v_xifrec))/nintv, swflag ? sum.v_swpout-osum.v_swpout : (rate.v_xsfrec+rate.v_xifrec)/nintv); (void)printf("%4d", pgtok(rate.v_pgpgin)/nintv); (void)printf("%4d%4d%4d%4d", pgtok(rate.v_pgpgout)/nintv, pgtok(rate.v_dfree)/nintv, pgtok(deficit), rate.v_scan/nintv);#endif etime /= 60.;#ifdef notdef (void)printf("%4d%4d", (rate.v_intr/nintv), rate.v_syscall/nintv); (void)printf("%4d", rate.v_swtch/nintv);#endif nintv = 1; /* ************** ^ vmstat ^ **************** */ /* *********** \/ netstat/if.c \/ ************* */ if (nl[N_IFNET].n_value != 0) { struct ifnet ifnet; steal((long)nl[N_IFNET].n_value, ifnetaddr); old_packets = packets; packets.input = packets.output = packets.collisions = 0; while (ifnetaddr) { steal(ifnetaddr, ifnet); packets.input += ifnet.if_ipackets; packets.output += ifnet.if_opackets; packets.collisions += ifnet.if_collisions; ifnetaddr = (off_t) ifnet.if_next; } } /* ************ ^ netstat/if.c ^ ************** */}#define YORIGIN_FOR_STAT(num) \ (((num)*rect.r_height)/num_stats)#define YMIDPOINT_FOR_STAT(num) \ (((num)*rect.r_height+rect.r_height/2)/num_stats)#define Y_FOR_STAT_VAL(stat, num_of_val) \ YORIGIN_FOR_STAT(stat)+5+height_of_stat - min(height_of_stat, ( \ height_of_stat*( \ stats[stat].value[num_of_val]-stats[stat].min_val)/( \ stats[stat].max_val-stats[stat].min_val)))display_dividers(pw, clear_first) struct pixwin *pw; int clear_first;{ register int i, stat; struct rect div_rect; div_rect.r_left = graph_x_offset; div_rect.r_width = rect.r_width-graph_x_offset; div_rect.r_height = 5; FORALLSTATS(stat) { register int y_origin_of_stat = YORIGIN_FOR_STAT(stat); if (stat == 0) continue; div_rect.r_top = y_origin_of_stat-2; (void)pw_lock(pw, &div_rect); if (clear_first) (void)pw_writebackground(pw, div_rect.r_left, div_rect.r_top, div_rect.r_width, div_rect.r_height, PIX_CLR); /* Draw the horizontal line and then add the tick marks */ (void)pw_vector(pw, div_rect.r_left, y_origin_of_stat, rect.r_width, y_origin_of_stat, PIX_SRC, -1); for (i = 0; i < num_of_val; i++) { if (do_time[i]) (void)pw_vector(pw, graph_x_offset+i, div_rect.r_top, graph_x_offset+i, y_origin_of_stat+2, PIX_SRC, -1); } (void)pw_unlock(pw); }}redisplay(){ register int height_of_stat, stat; (void)win_getsize(gfx->gfx_windowfd, &rect); (void)pw_writebackground(gfx->gfx_pixwin, 0, 0, rect.r_width, rect.r_height, PIX_CLR); display_dividers(gfx->gfx_pixwin, 0); height_of_stat = YORIGIN_FOR_STAT(1) - YORIGIN_FOR_STAT(0) - 10; FORALLSTATS(stat) { register int font_height = (font->pf_defaultsize.y)+2; register int y_origin_of_stat = YORIGIN_FOR_STAT(stat); struct pr_size text_size; char temp[10]; (void)pw_text(gfx->gfx_pixwin, 0, YMIDPOINT_FOR_STAT(stat), PIX_SRC, font, stats[stat].label); (void)pw_text(gfx->gfx_pixwin, 0, YMIDPOINT_FOR_STAT(stat)+font_height, PIX_SRC, font, stats[stat].label2); (void)sprintf(temp, "%d", stats[stat].max_val); text_size = pf_textwidth(strlen(temp), font, temp); (void)pw_text(gfx->gfx_pixwin, graph_x_offset-5-text_size.x, y_origin_of_stat-3+font_height, PIX_SRC, font, temp); (void)sprintf(temp, "%d", stats[stat].min_val); text_size = pf_textwidth(strlen(temp), font, temp); (void)pw_text(gfx->gfx_pixwin, graph_x_offset-5-text_size.x, y_origin_of_stat+8+height_of_stat, PIX_SRC, font, temp); } if (num_of_val > 0) FORALLSTATS(stat) { redisplay_stat_values( gfx->gfx_pixwin, height_of_stat, stat, 0, num_of_val); }}redisplay_stat_values(pw, height_of_stat, stat, start, stop_plus_one) struct pixwin *pw; int height_of_stat, stat, start, stop_plus_one;{ int j, newY; (void)pw_lock(pw, &rect); newY = Y_FOR_STAT_VAL(stat, start); for (j = start; j < stop_plus_one; ) { int jcopy = j, oldY = newY; do { newY = Y_FOR_STAT_VAL(stat, j); j++; } while ((oldY == newY) && (j < stop_plus_one)); if (j > jcopy+1) (void)pw_vector(pw, graph_x_offset+jcopy, oldY, graph_x_offset+j-2, oldY, PIX_SRC, 1); (void)pw_vector(pw, graph_x_offset+j-2, oldY, graph_x_offset+j-1, newY, PIX_SRC, 1); } (void)pw_unlock(pw);}set_clipping_equal_fixup(pw) struct pixwin *pw;{ int screenX, screenY; struct rect screenrect; screenrect = rect; (void)win_getscreenposition( pw->pw_clipdata->pwcd_windowfd, &screenX, &screenY); screenrect.r_left = screenX; screenrect.r_top = screenY; (void)rl_free(&pw->pw_clipdata->pwcd_clipping); pw->pw_clipdata->pwcd_clipping = pw->pw_fixup; pw->pw_fixup = rl_null; (void)_pw_setclippers(pw, &screenrect);}int next_display(pw) struct pixwin *pw;{ int new_cycle = 0, stat, height_of_stat; height_of_stat = YORIGIN_FOR_STAT(1) - YORIGIN_FOR_STAT(0) - 10; FORALLSTATS(stat) { int newY, oldY; newY = Y_FOR_STAT_VAL(stat, num_of_val); if (num_of_val == 0) oldY = newY; else oldY = Y_FOR_STAT_VAL(stat, num_of_val-1); (void)pw_vector(pw, graph_x_offset+num_of_val, oldY, graph_x_offset+num_of_val+1, newY, PIX_SRC, 1); if ((stat != 0) && do_time[num_of_val]) { int y_origin_of_stat = YORIGIN_FOR_STAT(stat); (void)pw_vector(pw, graph_x_offset+num_of_val, y_origin_of_stat-2, graph_x_offset+num_of_val, y_origin_of_stat+2, PIX_SRC, -1); } } if (++num_of_val >= NUM_VALS_PER || num_of_val >= rect.r_width-graph_x_offset) { if (shift_left_on_new_cycle) { int num_shift_left = (rect.r_width-graph_x_offset)/2; int width = (rect.r_width-graph_x_offset) - num_shift_left; register int j; for (j = num_shift_left; j < num_of_val; j++) do_time[j-num_shift_left] = do_time[j]; FORALLSTATS(stat) { int ys = YORIGIN_FOR_STAT(stat)+5; for (j = num_shift_left; j < num_of_val; j++) stats[stat].value[j-num_shift_left] = stats[stat].value[j]; (void)pw_copy(pw, graph_x_offset, ys, width, height_of_stat+1, PIX_SRC, pw, graph_x_offset+num_shift_left, ys); if (!rl_empty(&pw->pw_fixup)) { set_clipping_equal_fixup(pw); (void)pw_writebackground( pw, 0, 0, rect.r_width, rect.r_height, PIX_SRC); redisplay_stat_values( pw, height_of_stat, stat, 0, num_of_val-num_shift_left-1); (void)pw_exposed(pw); } (void)pw_writebackground( pw, graph_x_offset+num_shift_left, ys, width, height_of_stat+1, PIX_SRC); } num_of_val -= num_shift_left+1; display_dividers(pw, 1); } else { num_of_val = 0; } new_cycle = -1; } return(new_cycle);}int get_namelist(kernel_name, memory_name) char *kernel_name, *memory_name;{ /* ************* \/ vmstat \/ *************** */ time_t now; time_t boottime; register int i; int nintv_local; nlist(kernel_name, nl); if(nl[0].n_type == 0) { (void)fprintf(stderr, "no %s namelist\n", kernel_name); exit(1); } mf = open(memory_name, 0); if (mf < 0) { (void)fprintf(stderr, "cannot open %s\n", memory_name); exit(1); } steal((long)nl[X_FIRSTFREE].n_value, firstfree); steal((long)nl[X_MAXFREE].n_value, maxfree); steal((long)nl[X_BOOTTIME].n_value, boottime); steal((long)nl[X_HZ].n_value, hz); for (i = 0; i < DK_NDRIVE; i++) { (void)strcpy(dr_name[i], "xx"); dr_unit[i] = i; } read_names(); (void)time(&now); nintv_local = now - boottime; if (nintv_local <= 0 || nintv_local > 60*60*24*365*10) { (void)fprintf(stderr, "Time makes no sense... namelist must be wrong.\n"); exit(1); } /* ************** ^ vmstat ^ **************** */ return(nintv_local);} /* ************* \/ vmstat \/ *************** */doublestat1(row){ double tt; register i; tt = 0; for(i=0; i<CPUSTATES; i++) tt += s.time[i]; if(tt == 0.) tt = 1.; return(s.time[row]*100./tt);}read_names(){ struct mb_device mdev; register struct mb_device *mp; struct mb_driver mdrv; short two_char; char *cp = (char *) &two_char; mp = (struct mb_device *) nl[X_MBDINIT].n_value; if (mp == 0) { (void)fprintf(stderr, "vmstat: Disk init info not in namelist\n"); exit(1); } for (;;) { steal(mp++, mdev); if (mdev.md_driver == 0) break; if (mdev.md_dk < 0 || mdev.md_alive == 0) continue; steal(mdev.md_driver, mdrv); steal(mdrv.mdr_dname, two_char); (void)sprintf(dr_name[mdev.md_dk], "%c%c", cp[0], cp[1]); dr_unit[mdev.md_dk] = mdev.md_unit; }} /* ************** ^ vmstat ^ **************** */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -