vmstat.c (81a4459b5f06bf6e531285c5a4c8ef390657aabb) | vmstat.c (8d2fbde5040bc61a6c4685c0b8db2289834bc353) |
---|---|
1/*- 2 * Copyright (c) 1983, 1989, 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94"; 37#endif 38static const char rcsid[] = | 1/*- 2 * Copyright (c) 1983, 1989, 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94"; 37#endif 38static const char rcsid[] = |
39 "$Id: vmstat.c,v 1.25 1998/06/09 04:17:29 imp Exp $"; | 39 "$Id: vmstat.c,v 1.26 1998/07/06 22:08:00 bde Exp $"; |
40#endif /* not lint */ 41 42/* 43 * Cursed vmstat -- from Robert Elz. 44 */ 45 46#include <sys/param.h> | 40#endif /* not lint */ 41 42/* 43 * Cursed vmstat -- from Robert Elz. 44 */ 45 46#include <sys/param.h> |
47#include <sys/dkstat.h> | |
48#include <sys/buf.h> 49#include <sys/stat.h> 50#include <sys/time.h> 51#include <sys/proc.h> 52#include <sys/uio.h> 53#include <sys/namei.h> 54#include <sys/sysctl.h> | 47#include <sys/buf.h> 48#include <sys/stat.h> 49#include <sys/time.h> 50#include <sys/proc.h> 51#include <sys/uio.h> 52#include <sys/namei.h> 53#include <sys/sysctl.h> |
54#include <sys/dkstat.h> |
|
55#include <sys/vmmeter.h> 56 57#include <vm/vm_param.h> 58 59#include <ctype.h> 60#include <err.h> 61#include <nlist.h> 62#include <paths.h> 63#include <signal.h> 64#include <stdlib.h> 65#include <string.h> 66#include <time.h> 67#include <unistd.h> 68#include <utmp.h> | 55#include <sys/vmmeter.h> 56 57#include <vm/vm_param.h> 58 59#include <ctype.h> 60#include <err.h> 61#include <nlist.h> 62#include <paths.h> 63#include <signal.h> 64#include <stdlib.h> 65#include <string.h> 66#include <time.h> 67#include <unistd.h> 68#include <utmp.h> |
69#include <devstat.h> |
|
69#include "systat.h" 70#include "extern.h" 71 72static struct Info { 73 long time[CPUSTATES]; 74 struct vmmeter Cnt; 75 struct vmtotal Total; | 70#include "systat.h" 71#include "extern.h" 72 73static struct Info { 74 long time[CPUSTATES]; 75 struct vmmeter Cnt; 76 struct vmtotal Total; |
76 long *dk_time; 77 long *dk_wds; 78 long *dk_seek; 79 long *dk_xfer; 80 int dk_busy; | |
81 struct nchstats nchstats; 82 long nchcount; 83 long *intrcnt; 84 int bufspace; 85 int desiredvnodes; 86 long numvnodes; 87 long freevnodes; 88} s, s1, s2, z; 89 | 77 struct nchstats nchstats; 78 long nchcount; 79 long *intrcnt; 80 int bufspace; 81 int desiredvnodes; 82 long numvnodes; 83 long freevnodes; 84} s, s1, s2, z; 85 |
86struct statinfo cur, last, run; 87 |
|
90#define cnt s.Cnt 91#define oldcnt s1.Cnt 92#define total s.Total 93#define nchtotal s.nchstats 94#define oldnchtotal s1.nchstats 95 96static enum state { BOOT, TIME, RUN } state = TIME; 97 98static void allocinfo __P((struct Info *)); 99static void copyinfo __P((struct Info *, struct Info *)); 100static float cputime __P((int)); | 88#define cnt s.Cnt 89#define oldcnt s1.Cnt 90#define total s.Total 91#define nchtotal s.nchstats 92#define oldnchtotal s1.nchstats 93 94static enum state { BOOT, TIME, RUN } state = TIME; 95 96static void allocinfo __P((struct Info *)); 97static void copyinfo __P((struct Info *, struct Info *)); 98static float cputime __P((int)); |
101static void dinfo __P((int, int)); | 99static void dinfo __P((int, int, struct statinfo *, struct statinfo *)); |
102static void getinfo __P((struct Info *, enum state)); 103static void putint __P((int, int, int, int)); 104static void putfloat __P((double, int, int, int, int, int)); | 100static void getinfo __P((struct Info *, enum state)); 101static void putint __P((int, int, int, int)); 102static void putfloat __P((double, int, int, int, int, int)); |
103static void putlongdouble __P((long double, int, int, int, int, int)); |
|
105static int ucount __P((void)); 106 107static int ncpu; 108static int ut; 109static char buf[26]; 110static time_t t; 111static double etime; 112static int nintr; --- 29 unchanged lines hidden (view full) --- 142 143static struct nlist namelist[] = { 144#define X_CPTIME 0 145 { "_cp_time" }, 146#define X_CNT 1 147 { "_cnt" }, 148#define X_BUFFERSPACE 2 149 { "_bufspace" }, | 104static int ucount __P((void)); 105 106static int ncpu; 107static int ut; 108static char buf[26]; 109static time_t t; 110static double etime; 111static int nintr; --- 29 unchanged lines hidden (view full) --- 141 142static struct nlist namelist[] = { 143#define X_CPTIME 0 144 { "_cp_time" }, 145#define X_CNT 1 146 { "_cnt" }, 147#define X_BUFFERSPACE 2 148 { "_bufspace" }, |
150#define X_DK_BUSY 3 151 { "_dk_busy" }, 152#define X_DK_TIME 4 153 { "_dk_time" }, 154#define X_DK_XFER 5 155 { "_dk_xfer" }, 156#define X_DK_WDS 6 157 { "_dk_wds" }, 158#define X_DK_SEEK 7 159 { "_dk_seek" }, 160#define X_NCHSTATS 8 | 149#define X_NCHSTATS 3 |
161 { "_nchstats" }, | 150 { "_nchstats" }, |
162#define X_INTRNAMES 9 | 151#define X_INTRNAMES 4 |
163 { "_intrnames" }, | 152 { "_intrnames" }, |
164#define X_EINTRNAMES 10 | 153#define X_EINTRNAMES 5 |
165 { "_eintrnames" }, | 154 { "_eintrnames" }, |
166#define X_INTRCNT 11 | 155#define X_INTRCNT 6 |
167 { "_intrcnt" }, | 156 { "_intrcnt" }, |
168#define X_EINTRCNT 12 | 157#define X_EINTRCNT 7 |
169 { "_eintrcnt" }, | 158 { "_eintrcnt" }, |
170#define X_DESIREDVNODES 13 | 159#define X_DESIREDVNODES 8 |
171 { "_desiredvnodes" }, | 160 { "_desiredvnodes" }, |
172#define X_NUMVNODES 14 | 161#define X_NUMVNODES 9 |
173 { "_numvnodes" }, | 162 { "_numvnodes" }, |
174#define X_FREEVNODES 15 | 163#define X_FREEVNODES 10 |
175 { "_freevnodes" }, 176 { "" }, 177}; 178 179/* 180 * These constants define where the major pieces are laid out 181 */ 182#define STATROW 0 /* uses 1 row and 68 cols */ --- 12 unchanged lines hidden (view full) --- 195#define VMSTATCOL 48 196#define GRAPHROW 10 /* uses 3 rows and 51 cols */ 197#define GRAPHCOL 0 198#define NAMEIROW 14 /* uses 3 rows and 38 cols */ 199#define NAMEICOL 0 200#define DISKROW 18 /* uses 5 rows and 50 cols (for 9 drives) */ 201#define DISKCOL 0 202 | 164 { "_freevnodes" }, 165 { "" }, 166}; 167 168/* 169 * These constants define where the major pieces are laid out 170 */ 171#define STATROW 0 /* uses 1 row and 68 cols */ --- 12 unchanged lines hidden (view full) --- 184#define VMSTATCOL 48 185#define GRAPHROW 10 /* uses 3 rows and 51 cols */ 186#define GRAPHCOL 0 187#define NAMEIROW 14 /* uses 3 rows and 38 cols */ 188#define NAMEICOL 0 189#define DISKROW 18 /* uses 5 rows and 50 cols (for 9 drives) */ 190#define DISKCOL 0 191 |
203#define DRIVESPACE 9 /* max # for space */ | 192#define DRIVESPACE 7 /* max # for space */ |
204 | 193 |
205#if DK_NDRIVE > DRIVESPACE | |
206#define MAXDRIVES DRIVESPACE /* max # to display */ | 194#define MAXDRIVES DRIVESPACE /* max # to display */ |
207#else 208#define MAXDRIVES DK_NDRIVE /* max # to display */ 209#endif | |
210 211int 212initkre() 213{ 214 char *intrnamebuf, *cp; 215 int i; 216 static int once = 0; 217 218 if (namelist[0].n_type == 0) { 219 if (kvm_nlist(kd, namelist)) { 220 nlisterr(namelist); 221 return(0); 222 } 223 if (namelist[0].n_type == 0) { 224 error("No namelist"); 225 return(0); 226 } 227 } | 195 196int 197initkre() 198{ 199 char *intrnamebuf, *cp; 200 int i; 201 static int once = 0; 202 203 if (namelist[0].n_type == 0) { 204 if (kvm_nlist(kd, namelist)) { 205 nlisterr(namelist); 206 return(0); 207 } 208 if (namelist[0].n_type == 0) { 209 error("No namelist"); 210 return(0); 211 } 212 } |
228 if (! dkinit()) | 213 214 if (num_devices = getnumdevs() < 0) { 215 warnx("%s", devstat_errbuf); |
229 return(0); | 216 return(0); |
230 if (dk_ndrive && !once) { 231#define allocate(e, t) \ 232 s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \ 233 s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \ 234 s2./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \ 235 z./**/e = (t *)calloc(dk_ndrive, sizeof (t)); 236 allocate(dk_time, long); 237 allocate(dk_wds, long); 238 allocate(dk_seek, long); 239 allocate(dk_xfer, long); 240 once = 1; 241#undef allocate | |
242 } | 217 } |
218 219 cur.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); 220 last.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); 221 run.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); 222 bzero(cur.dinfo, sizeof(struct devinfo)); 223 bzero(last.dinfo, sizeof(struct devinfo)); 224 bzero(run.dinfo, sizeof(struct devinfo)); 225 226 if (dsinit(MAXDRIVES, &cur, &last, &run) != 1) 227 return(0); 228 |
|
243 if (nintr == 0) { 244 nintr = (namelist[X_EINTRCNT].n_value - 245 namelist[X_INTRCNT].n_value) / sizeof (long); 246 intrloc = calloc(nintr, sizeof (long)); 247 intrname = calloc(nintr, sizeof (long)); 248 intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value - 249 namelist[X_INTRNAMES].n_value); 250 if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) { --- 85 unchanged lines hidden (view full) --- 336 mvprintw(PROCSROW, PROCSCOL, "Proc:r p d s w"); 337 mvprintw(GRAPHROW + 1, GRAPHCOL, 338 "| | | | | | | | | | |"); 339 340 mvprintw(NAMEIROW, NAMEICOL, "Namei Name-cache Dir-cache"); 341 mvprintw(NAMEIROW + 1, NAMEICOL, 342 " Calls hits %% hits %%"); 343 mvprintw(DISKROW, DISKCOL, "Discs"); | 229 if (nintr == 0) { 230 nintr = (namelist[X_EINTRCNT].n_value - 231 namelist[X_INTRCNT].n_value) / sizeof (long); 232 intrloc = calloc(nintr, sizeof (long)); 233 intrname = calloc(nintr, sizeof (long)); 234 intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value - 235 namelist[X_INTRNAMES].n_value); 236 if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) { --- 85 unchanged lines hidden (view full) --- 322 mvprintw(PROCSROW, PROCSCOL, "Proc:r p d s w"); 323 mvprintw(GRAPHROW + 1, GRAPHCOL, 324 "| | | | | | | | | | |"); 325 326 mvprintw(NAMEIROW, NAMEICOL, "Namei Name-cache Dir-cache"); 327 mvprintw(NAMEIROW + 1, NAMEICOL, 328 " Calls hits %% hits %%"); 329 mvprintw(DISKROW, DISKCOL, "Discs"); |
344 mvprintw(DISKROW + 1, DISKCOL, "seeks"); 345 mvprintw(DISKROW + 2, DISKCOL, "xfers"); 346 mvprintw(DISKROW + 3, DISKCOL, " blks"); 347 mvprintw(DISKROW + 4, DISKCOL, " msps"); | 330 mvprintw(DISKROW + 1, DISKCOL, "KB/t"); 331 mvprintw(DISKROW + 2, DISKCOL, "tps"); 332 mvprintw(DISKROW + 3, DISKCOL, "MB/s"); 333 /* 334 * For now, we don't support a fourth disk statistic. So there's 335 * no point in providing a label for it. If someone can think of a 336 * fourth useful disk statistic, there is room to add it. 337 */ 338 /* mvprintw(DISKROW + 4, DISKCOL, " msps"); */ |
348 j = 0; | 339 j = 0; |
349 for (i = 0; i < dk_ndrive && j < MAXDRIVES; i++) 350 if (dk_select[i]) { 351 mvprintw(DISKROW, DISKCOL + 5 + 5 * j, 352 " %4.4s", dr_name[j]); | 340 for (i = 0; i < num_devices && j < MAXDRIVES; i++) 341 if (dev_select[i].selected) { 342 char tmpstr[80]; 343 sprintf(tmpstr, "%s%d", dev_select[i].device_name, 344 dev_select[i].unit_number); 345 mvprintw(DISKROW, DISKCOL + 5 + 6 * j, 346 " %5.5s", tmpstr); |
353 j++; 354 } 355 for (i = 0; i < nintr; i++) { 356 if (intrloc[i] == 0) 357 continue; 358 mvprintw(intrloc[i], INTSCOL + 9, "%-10.10s", intrname[i]); 359 } 360} 361 362#define X(fld) {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;} | 347 j++; 348 } 349 for (i = 0; i < nintr; i++) { 350 if (intrloc[i] == 0) 351 continue; 352 mvprintw(intrloc[i], INTSCOL + 9, "%-10.10s", intrname[i]); 353 } 354} 355 356#define X(fld) {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;} |
357#define Q(fld) {t=cur.fld[i]; cur.fld[i]-=last.fld[i]; if(state==TIME) last.fld[i]=t;} |
|
363#define Y(fld) {t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;} 364#define Z(fld) {t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \ 365 if(state == TIME) s1.nchstats.fld = t;} 366#define PUTRATE(fld, l, c, w) \ 367 Y(fld); \ 368 putint((int)((float)s.fld/etime + 0.5), l, c, w) 369#define MAXFAIL 5 370 --- 4 unchanged lines hidden (view full) --- 375void 376showkre() 377{ 378 float f1, f2; 379 int psiz, inttotal; 380 int i, l, c; 381 static int failcnt = 0; 382 | 358#define Y(fld) {t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;} 359#define Z(fld) {t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \ 360 if(state == TIME) s1.nchstats.fld = t;} 361#define PUTRATE(fld, l, c, w) \ 362 Y(fld); \ 363 putint((int)((float)s.fld/etime + 0.5), l, c, w) 364#define MAXFAIL 5 365 --- 4 unchanged lines hidden (view full) --- 370void 371showkre() 372{ 373 float f1, f2; 374 int psiz, inttotal; 375 int i, l, c; 376 static int failcnt = 0; 377 |
383 for (i = 0; i < dk_ndrive; i++) { 384 X(dk_xfer); X(dk_seek); X(dk_wds); X(dk_time); 385 } | |
386 etime = 0; 387 for(i = 0; i < CPUSTATES; i++) { 388 X(time); | 378 etime = 0; 379 for(i = 0; i < CPUSTATES; i++) { 380 X(time); |
381 Q(cp_time); |
|
389 etime += s.time[i]; 390 } 391 if (etime < 5.0) { /* < 5 ticks - ignore this trash */ 392 if (failcnt++ >= MAXFAIL) { 393 clear(); 394 mvprintw(2, 10, "The alternate system clock has died!"); 395 mvprintw(3, 10, "Reverting to ``pigs'' display."); 396 move(CMDLINE, 0); --- 94 unchanged lines hidden (view full) --- 491 PUTRATE(Cnt.v_swappgsout, PAGEROW + 3, PAGECOL + 22, 5); 492 PUTRATE(Cnt.v_swtch, GENSTATROW + 1, GENSTATCOL, 5); 493 PUTRATE(Cnt.v_trap, GENSTATROW + 1, GENSTATCOL + 5, 5); 494 PUTRATE(Cnt.v_syscall, GENSTATROW + 1, GENSTATCOL + 10, 5); 495 PUTRATE(Cnt.v_intr, GENSTATROW + 1, GENSTATCOL + 15, 5); 496 PUTRATE(Cnt.v_soft, GENSTATROW + 1, GENSTATCOL + 20, 5); 497 PUTRATE(Cnt.v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 5); 498 mvprintw(DISKROW, DISKCOL + 5, " "); | 382 etime += s.time[i]; 383 } 384 if (etime < 5.0) { /* < 5 ticks - ignore this trash */ 385 if (failcnt++ >= MAXFAIL) { 386 clear(); 387 mvprintw(2, 10, "The alternate system clock has died!"); 388 mvprintw(3, 10, "Reverting to ``pigs'' display."); 389 move(CMDLINE, 0); --- 94 unchanged lines hidden (view full) --- 484 PUTRATE(Cnt.v_swappgsout, PAGEROW + 3, PAGECOL + 22, 5); 485 PUTRATE(Cnt.v_swtch, GENSTATROW + 1, GENSTATCOL, 5); 486 PUTRATE(Cnt.v_trap, GENSTATROW + 1, GENSTATCOL + 5, 5); 487 PUTRATE(Cnt.v_syscall, GENSTATROW + 1, GENSTATCOL + 10, 5); 488 PUTRATE(Cnt.v_intr, GENSTATROW + 1, GENSTATCOL + 15, 5); 489 PUTRATE(Cnt.v_soft, GENSTATROW + 1, GENSTATCOL + 20, 5); 490 PUTRATE(Cnt.v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 5); 491 mvprintw(DISKROW, DISKCOL + 5, " "); |
499 for (i = 0, c = 0; i < dk_ndrive && c < MAXDRIVES; i++) 500 if (dk_select[i]) { 501 mvprintw(DISKROW, DISKCOL + 5 + 5 * c, 502 " %4.4s", dr_name[i]); 503 dinfo(i, ++c); | 492 for (i = 0, c = 0; i < num_devices && c < MAXDRIVES; i++) 493 if (dev_select[i].selected) { 494 char tmpstr[80]; 495 sprintf(tmpstr, "%s%d", dev_select[i].device_name, 496 dev_select[i].unit_number); 497 mvprintw(DISKROW, DISKCOL + 5 + 6 * c, 498 " %5.5s", tmpstr); 499 switch(state) { 500 case TIME: 501 dinfo(i, ++c, &cur, &last); 502 break; 503 case RUN: 504 dinfo(i, ++c, &cur, &run); 505 break; 506 case BOOT: 507 dinfo(i, ++c, &cur, NULL); 508 break; 509 } |
504 } 505 putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9); 506 putint((nchtotal.ncs_goodhits + nchtotal.ncs_neghits), 507 NAMEIROW + 2, NAMEICOL + 9, 9); 508#define nz(x) ((x) ? (x) : 1) 509 putfloat((nchtotal.ncs_goodhits+nchtotal.ncs_neghits) * 510 100.0 / nz(s.nchcount), 511 NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1); 512 putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 23, 9); 513 putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount), 514 NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1); 515#undef nz 516} 517 518int 519cmdkre(cmd, args) 520 char *cmd, *args; 521{ | 510 } 511 putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9); 512 putint((nchtotal.ncs_goodhits + nchtotal.ncs_neghits), 513 NAMEIROW + 2, NAMEICOL + 9, 9); 514#define nz(x) ((x) ? (x) : 1) 515 putfloat((nchtotal.ncs_goodhits+nchtotal.ncs_neghits) * 516 100.0 / nz(s.nchcount), 517 NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1); 518 putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 23, 9); 519 putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount), 520 NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1); 521#undef nz 522} 523 524int 525cmdkre(cmd, args) 526 char *cmd, *args; 527{ |
528 int retval; |
|
522 523 if (prefix(cmd, "run")) { | 529 530 if (prefix(cmd, "run")) { |
531 retval = 1; |
|
524 copyinfo(&s2, &s1); | 532 copyinfo(&s2, &s1); |
533 switch (getdevs(&run)) { 534 case -1: 535 errx(1, "%s", devstat_errbuf); 536 break; 537 case 1: 538 num_devices = run.dinfo->numdevs; 539 generation = run.dinfo->generation; 540 retval = dscmd("refresh", NULL, MAXDRIVES, &cur); 541 if (retval == 2) 542 labelkre(); 543 break; 544 default: 545 break; 546 } |
|
525 state = RUN; | 547 state = RUN; |
526 return (1); | 548 return (retval); |
527 } 528 if (prefix(cmd, "boot")) { 529 state = BOOT; 530 copyinfo(&z, &s1); 531 return (1); 532 } 533 if (prefix(cmd, "time")) { 534 state = TIME; 535 return (1); 536 } 537 if (prefix(cmd, "zero")) { | 549 } 550 if (prefix(cmd, "boot")) { 551 state = BOOT; 552 copyinfo(&z, &s1); 553 return (1); 554 } 555 if (prefix(cmd, "time")) { 556 state = TIME; 557 return (1); 558 } 559 if (prefix(cmd, "zero")) { |
538 if (state == RUN) | 560 retval = 1; 561 if (state == RUN) { |
539 getinfo(&s1, RUN); | 562 getinfo(&s1, RUN); |
540 return (1); | 563 switch (getdevs(&run)) { 564 case -1: 565 errx(1, "%s", devstat_errbuf); 566 break; 567 case 1: 568 num_devices = run.dinfo->numdevs; 569 generation = run.dinfo->generation; 570 retval = dscmd("refresh",NULL, MAXDRIVES, &cur); 571 if (retval == 2) 572 labelkre(); 573 break; 574 default: 575 break; 576 } 577 } 578 return (retval); |
541 } | 579 } |
542 return (dkcmd(cmd, args)); | 580 retval = dscmd(cmd, args, MAXDRIVES, &cur); 581 582 if (retval == 2) 583 labelkre(); 584 585 return(retval); |
543} 544 545/* calculate number of users on the system */ 546static int 547ucount() 548{ 549 register int nusers = 0; 550 --- 61 unchanged lines hidden (view full) --- 612 while (--w >= 0) 613 addch('*'); 614 return; 615 } 616 addstr(b); 617} 618 619static void | 586} 587 588/* calculate number of users on the system */ 589static int 590ucount() 591{ 592 register int nusers = 0; 593 --- 61 unchanged lines hidden (view full) --- 655 while (--w >= 0) 656 addch('*'); 657 return; 658 } 659 addstr(b); 660} 661 662static void |
663putlongdouble(f, l, c, w, d, nz) 664 long double f; 665 int l, c, w, d, nz; 666{ 667 char b[128]; 668 669 move(l, c); 670 if (nz && f == 0.0) { 671 while (--w >= 0) 672 addch(' '); 673 return; 674 } 675 sprintf(b, "%*.*Lf", w, d, f); 676 if (strlen(b) > w) { 677 while (--w >= 0) 678 addch('*'); 679 return; 680 } 681 addstr(b); 682} 683 684static void |
|
620getinfo(s, st) 621 struct Info *s; 622 enum state st; 623{ | 685getinfo(s, st) 686 struct Info *s; 687 enum state st; 688{ |
689 struct devinfo *tmp_dinfo; |
|
624 int mib[2], size; 625 extern int errno; 626 627 NREAD(X_CPTIME, s->time, sizeof s->time); | 690 int mib[2], size; 691 extern int errno; 692 693 NREAD(X_CPTIME, s->time, sizeof s->time); |
694 NREAD(X_CPTIME, cur.cp_time, sizeof(cur.cp_time)); |
|
628 NREAD(X_CNT, &s->Cnt, sizeof s->Cnt); 629 NREAD(X_BUFFERSPACE, &s->bufspace, sizeof(s->bufspace)); 630 NREAD(X_DESIREDVNODES, &s->desiredvnodes, sizeof(s->desiredvnodes)); 631 NREAD(X_NUMVNODES, &s->numvnodes, LONG); 632 NREAD(X_FREEVNODES, &s->freevnodes, LONG); | 695 NREAD(X_CNT, &s->Cnt, sizeof s->Cnt); 696 NREAD(X_BUFFERSPACE, &s->bufspace, sizeof(s->bufspace)); 697 NREAD(X_DESIREDVNODES, &s->desiredvnodes, sizeof(s->desiredvnodes)); 698 NREAD(X_NUMVNODES, &s->numvnodes, LONG); 699 NREAD(X_FREEVNODES, &s->freevnodes, LONG); |
633 NREAD(X_DK_BUSY, &s->dk_busy, sizeof(s->dk_busy)); 634 NREAD(X_DK_TIME, s->dk_time, dk_ndrive * LONG); 635 NREAD(X_DK_XFER, s->dk_xfer, dk_ndrive * LONG); 636 NREAD(X_DK_WDS, s->dk_wds, dk_ndrive * LONG); 637 NREAD(X_DK_SEEK, s->dk_seek, dk_ndrive * LONG); | |
638 NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats); 639 NREAD(X_INTRCNT, s->intrcnt, nintr * LONG); 640 size = sizeof(s->Total); 641 mib[0] = CTL_VM; 642 mib[1] = VM_METER; 643 if (sysctl(mib, 2, &s->Total, &size, NULL, 0) < 0) { 644 error("Can't get kernel info: %s\n", strerror(errno)); 645 bzero(&s->Total, sizeof(s->Total)); 646 } 647 size = sizeof(ncpu); 648 if (sysctlbyname("hw.ncpu", &ncpu, &size, NULL, 0) < 0) 649 ncpu = 1; | 700 NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats); 701 NREAD(X_INTRCNT, s->intrcnt, nintr * LONG); 702 size = sizeof(s->Total); 703 mib[0] = CTL_VM; 704 mib[1] = VM_METER; 705 if (sysctl(mib, 2, &s->Total, &size, NULL, 0) < 0) { 706 error("Can't get kernel info: %s\n", strerror(errno)); 707 bzero(&s->Total, sizeof(s->Total)); 708 } 709 size = sizeof(ncpu); 710 if (sysctlbyname("hw.ncpu", &ncpu, &size, NULL, 0) < 0) 711 ncpu = 1; |
712 713 tmp_dinfo = last.dinfo; 714 last.dinfo = cur.dinfo; 715 cur.dinfo = tmp_dinfo; 716 717 last.busy_time = cur.busy_time; 718 switch (getdevs(&cur)) { 719 case -1: 720 errx(1, "%s", devstat_errbuf); 721 break; 722 case 1: 723 num_devices = cur.dinfo->numdevs; 724 generation = cur.dinfo->generation; 725 cmdkre("refresh", NULL); 726 break; 727 default: 728 break; 729 } |
|
650} 651 652static void 653allocinfo(s) 654 struct Info *s; 655{ 656 657 s->intrcnt = (long *) calloc(nintr, sizeof(long)); 658 if (s->intrcnt == NULL) 659 errx(2, "out of memory"); 660} 661 662static void 663copyinfo(from, to) 664 register struct Info *from, *to; 665{ | 730} 731 732static void 733allocinfo(s) 734 struct Info *s; 735{ 736 737 s->intrcnt = (long *) calloc(nintr, sizeof(long)); 738 if (s->intrcnt == NULL) 739 errx(2, "out of memory"); 740} 741 742static void 743copyinfo(from, to) 744 register struct Info *from, *to; 745{ |
666 long *time, *wds, *seek, *xfer; | |
667 long *intrcnt; | 746 long *intrcnt; |
747 struct devinfo tmp_dinfo; |
|
668 669 /* 670 * time, wds, seek, and xfer are malloc'd so we have to 671 * save the pointers before the structure copy and then 672 * copy by hand. 673 */ | 748 749 /* 750 * time, wds, seek, and xfer are malloc'd so we have to 751 * save the pointers before the structure copy and then 752 * copy by hand. 753 */ |
674 time = to->dk_time; wds = to->dk_wds; seek = to->dk_seek; 675 xfer = to->dk_xfer; intrcnt = to->intrcnt; | 754 intrcnt = to->intrcnt; |
676 *to = *from; | 755 *to = *from; |
677 bcopy(from->dk_time, to->dk_time = time, dk_ndrive * sizeof (long)); 678 bcopy(from->dk_wds, to->dk_wds = wds, dk_ndrive * sizeof (long)); 679 bcopy(from->dk_seek, to->dk_seek = seek, dk_ndrive * sizeof (long)); 680 bcopy(from->dk_xfer, to->dk_xfer = xfer, dk_ndrive * sizeof (long)); | 756 |
681 bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int)); 682} 683 684static void | 757 bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int)); 758} 759 760static void |
685dinfo(dn, c) | 761dinfo(dn, c, now, then) |
686 int dn, c; | 762 int dn, c; |
763 struct statinfo *now, *then; |
|
687{ | 764{ |
688 double words, atime, itime, xtime; | 765 long double transfers_per_second; 766 long double kb_per_transfer, mb_per_second; 767 long double busy_seconds; 768 int di; |
689 | 769 |
690 c = DISKCOL + c * 5; 691 atime = s.dk_time[dn]; 692 atime /= hertz; 693 words = s.dk_wds[dn]*32.0; /* number of words transferred */ 694 xtime = dk_mspw[dn]*words; /* transfer time */ 695 itime = atime - xtime; /* time not transferring */ 696 if (xtime < 0) 697 itime += xtime, xtime = 0; 698 if (itime < 0) 699 xtime += itime, itime = 0; 700 putint((int)((float)s.dk_seek[dn]/etime+0.5), DISKROW + 1, c, 5); 701 putint((int)((float)s.dk_xfer[dn]/etime+0.5), DISKROW + 2, c, 5); 702 putint((int)(words/etime/512.0 + 0.5), DISKROW + 3, c, 5); 703 if (s.dk_seek[dn]) 704 putfloat(itime*1000.0/s.dk_seek[dn], DISKROW + 4, c, 5, 1, 1); 705 else 706 putint(0, DISKROW + 4, c, 5); | 770 di = dev_select[dn].position; 771 772 busy_seconds = compute_etime(now->busy_time, then ? 773 then->busy_time : 774 then->dinfo->devices[di].dev_creation_time); 775 776 if (compute_stats(&now->dinfo->devices[di], then ? 777 &then->dinfo->devices[di] : NULL, busy_seconds, 778 NULL, NULL, NULL, 779 &kb_per_transfer, &transfers_per_second, 780 &mb_per_second, NULL, NULL) != 0) 781 errx(1, "%s", devstat_errbuf); 782 783 c = DISKCOL + c * 6; 784 putlongdouble(kb_per_transfer, DISKROW + 1, c, 5, 2, 0); 785 putlongdouble(transfers_per_second, DISKROW + 2, c, 5, 0, 0); 786 putlongdouble(mb_per_second, DISKROW + 3, c, 5, 2, 0); |
707} | 787} |