vmstat.c (22694ebad57c49178f28bcc781d8ee9eb5868dd8) | vmstat.c (8d2fbde5040bc61a6c4685c0b8db2289834bc353) |
---|---|
1/* 2 * Copyright (c) 1980, 1986, 1991, 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 --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93"; 43#endif 44static const char rcsid[] = | 1/* 2 * Copyright (c) 1980, 1986, 1991, 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 --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93"; 43#endif 44static const char rcsid[] = |
45 "$Id: vmstat.c,v 1.23 1998/03/07 23:40:23 dyson Exp $"; | 45 "$Id: vmstat.c,v 1.24 1998/07/06 21:01:54 bde Exp $"; |
46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/time.h> 50#include <sys/proc.h> 51#include <sys/dkstat.h> 52#include <sys/buf.h> 53#include <sys/uio.h> --- 15 unchanged lines hidden (view full) --- 69#include <nlist.h> 70#include <paths.h> 71#include <stdio.h> 72#include <stdlib.h> 73#include <string.h> 74#include <sysexits.h> 75#include <time.h> 76#include <unistd.h> | 46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/time.h> 50#include <sys/proc.h> 51#include <sys/dkstat.h> 52#include <sys/buf.h> 53#include <sys/uio.h> --- 15 unchanged lines hidden (view full) --- 69#include <nlist.h> 70#include <paths.h> 71#include <stdio.h> 72#include <stdlib.h> 73#include <string.h> 74#include <sysexits.h> 75#include <time.h> 76#include <unistd.h> |
77#include <devstat.h> |
|
77 78struct nlist namelist[] = { 79#define X_CPTIME 0 80 { "_cp_time" }, | 78 79struct nlist namelist[] = { 80#define X_CPTIME 0 81 { "_cp_time" }, |
81#define X_DK_NDRIVE 1 82 { "_dk_ndrive" }, 83#define X_SUM 2 | 82#define X_SUM 1 |
84 { "_cnt" }, | 83 { "_cnt" }, |
85#define X_BOOTTIME 3 | 84#define X_BOOTTIME 2 |
86 { "_boottime" }, | 85 { "_boottime" }, |
87#define X_DKXFER 4 88 { "_dk_xfer" }, 89#define X_HZ 5 | 86#define X_HZ 3 |
90 { "_hz" }, | 87 { "_hz" }, |
91#define X_STATHZ 6 | 88#define X_STATHZ 4 |
92 { "_stathz" }, | 89 { "_stathz" }, |
93#define X_NCHSTATS 7 | 90#define X_NCHSTATS 5 |
94 { "_nchstats" }, | 91 { "_nchstats" }, |
95#define X_INTRNAMES 8 | 92#define X_INTRNAMES 6 |
96 { "_intrnames" }, | 93 { "_intrnames" }, |
97#define X_EINTRNAMES 9 | 94#define X_EINTRNAMES 7 |
98 { "_eintrnames" }, | 95 { "_eintrnames" }, |
99#define X_INTRCNT 10 | 96#define X_INTRCNT 8 |
100 { "_intrcnt" }, | 97 { "_intrcnt" }, |
101#define X_EINTRCNT 11 | 98#define X_EINTRCNT 9 |
102 { "_eintrcnt" }, | 99 { "_eintrcnt" }, |
103#define X_KMEMSTATISTICS 12 | 100#define X_KMEMSTATISTICS 10 |
104 { "_kmemstatistics" }, | 101 { "_kmemstatistics" }, |
105#define X_KMEMBUCKETS 13 | 102#define X_KMEMBUCKETS 11 |
106 { "_bucket" }, 107#ifdef notyet | 103 { "_bucket" }, 104#ifdef notyet |
108#define X_DEFICIT 14 | 105#define X_DEFICIT 12 |
109 { "_deficit" }, | 106 { "_deficit" }, |
110#define X_FORKSTAT 15 | 107#define X_FORKSTAT 13 |
111 { "_forkstat" }, | 108 { "_forkstat" }, |
112#define X_REC 16 | 109#define X_REC 14 |
113 { "_rectime" }, | 110 { "_rectime" }, |
114#define X_PGIN 17 | 111#define X_PGIN 15 |
115 { "_pgintime" }, | 112 { "_pgintime" }, |
116#define X_XSTATS 18 | 113#define X_XSTATS 16 |
117 { "_xstats" }, | 114 { "_xstats" }, |
118#define X_END 19 | 115#define X_END 17 |
119#else 120#define X_END 14 121#endif 122#if defined(hp300) || defined(luna68k) 123#define X_HPDINIT (X_END) 124 { "_hp_dinit" }, 125#endif | 116#else 117#define X_END 14 118#endif 119#if defined(hp300) || defined(luna68k) 120#define X_HPDINIT (X_END) 121 { "_hp_dinit" }, 122#endif |
126#if defined(i386) 127#define X_DK_NAMES (X_END) 128 { "_dk_names" }, 129#endif | |
130#ifdef mips 131#define X_SCSI_DINIT (X_END) 132 { "_scsi_dinit" }, 133#endif 134#ifdef tahoe 135#define X_VBDINIT (X_END) 136 { "_vbdinit" }, 137#define X_CKEYSTATS (X_END+1) --- 5 unchanged lines hidden (view full) --- 143#define X_MBDINIT (X_END) 144 { "_mbdinit" }, 145#define X_UBDINIT (X_END+1) 146 { "_ubdinit" }, 147#endif 148 { "" }, 149}; 150 | 123#ifdef mips 124#define X_SCSI_DINIT (X_END) 125 { "_scsi_dinit" }, 126#endif 127#ifdef tahoe 128#define X_VBDINIT (X_END) 129 { "_vbdinit" }, 130#define X_CKEYSTATS (X_END+1) --- 5 unchanged lines hidden (view full) --- 136#define X_MBDINIT (X_END) 137 { "_mbdinit" }, 138#define X_UBDINIT (X_END+1) 139 { "_ubdinit" }, 140#endif 141 { "" }, 142}; 143 |
151struct _disk { 152 long time[CPUSTATES]; 153 long *xfer; 154} cur, last; | 144struct statinfo cur, last; 145int num_devices, maxshowdevs, generation; 146struct device_selection *dev_select; 147int num_selected; 148struct devstat_match *matches; 149int num_matches = 0; 150int num_devices_specified, num_selections, select_generation; 151char **specified_devices; 152devstat_select_mode select_mode; |
155 156struct vmmeter sum, osum; | 153 154struct vmmeter sum, osum; |
157char **dr_name; 158int *dr_select, dk_ndrive, ndrives; | |
159 160int winlines = 20; 161 162kvm_t *kd; 163 164#define FORKSTAT 0x01 165#define INTRSTAT 0x02 166#define MEMSTAT 0x04 167#define SUMSTAT 0x08 168#define TIMESTAT 0x10 169#define VMSTAT 0x20 170 | 155 156int winlines = 20; 157 158kvm_t *kd; 159 160#define FORKSTAT 0x01 161#define INTRSTAT 0x02 162#define MEMSTAT 0x04 163#define SUMSTAT 0x08 164#define TIMESTAT 0x10 165#define VMSTAT 0x20 166 |
171#include "names.c" /* disk names -- machine dependent */ 172 173void cpustats(), dkstats(), dointr(), domem(), dosum(); | 167void cpustats(), dointr(), domem(), dosum(); |
174void dovmstat(), kread(), usage(); 175#ifdef notyet 176void dotimes(), doforkst(); 177#endif 178void printhdr __P((void)); | 168void dovmstat(), kread(), usage(); 169#ifdef notyet 170void dotimes(), doforkst(); 171#endif 172void printhdr __P((void)); |
173static void devstats(); |
|
179 180int 181main(argc, argv) 182 register int argc; 183 register char **argv; 184{ 185 register int c, todo; 186 u_int interval; 187 int reps; 188 char *memf, *nlistf; 189 char errbuf[_POSIX2_LINE_MAX]; | 174 175int 176main(argc, argv) 177 register int argc; 178 register char **argv; 179{ 180 register int c, todo; 181 u_int interval; 182 int reps; 183 char *memf, *nlistf; 184 char errbuf[_POSIX2_LINE_MAX]; |
185 char *err_str; |
|
190 191 memf = nlistf = NULL; 192 interval = reps = todo = 0; | 186 187 memf = nlistf = NULL; 188 interval = reps = todo = 0; |
193 while ((c = getopt(argc, argv, "c:fiM:mN:stw:")) != -1) { | 189 maxshowdevs = 3; 190 while ((c = getopt(argc, argv, "c:fiM:mN:n:p:stw:")) != -1) { |
194 switch (c) { 195 case 'c': 196 reps = atoi(optarg); 197 break; 198 case 'f': 199#ifdef notyet 200 todo |= FORKSTAT; 201#else --- 7 unchanged lines hidden (view full) --- 209 memf = optarg; 210 break; 211 case 'm': 212 todo |= MEMSTAT; 213 break; 214 case 'N': 215 nlistf = optarg; 216 break; | 191 switch (c) { 192 case 'c': 193 reps = atoi(optarg); 194 break; 195 case 'f': 196#ifdef notyet 197 todo |= FORKSTAT; 198#else --- 7 unchanged lines hidden (view full) --- 206 memf = optarg; 207 break; 208 case 'm': 209 todo |= MEMSTAT; 210 break; 211 case 'N': 212 nlistf = optarg; 213 break; |
214 case 'n': 215 maxshowdevs = atoi(optarg); 216 if (maxshowdevs < 0) 217 errx(1, "number of devices %d is < 0", 218 maxshowdevs); 219 break; 220 case 'p': 221 if (buildmatch(optarg, &matches, &num_matches) != 0) 222 errx(1, "%s", devstat_errbuf); 223 break; |
|
217 case 's': 218 todo |= SUMSTAT; 219 break; 220 case 't': 221#ifdef notyet 222 todo |= TIMESTAT; 223#else 224 errx(EX_USAGE, "sorry, -t is not (re)implemented yet"); --- 84 unchanged lines hidden (view full) --- 309 exit(0); 310} 311 312char ** 313getdrivedata(argv) 314 char **argv; 315{ 316 register int i; | 224 case 's': 225 todo |= SUMSTAT; 226 break; 227 case 't': 228#ifdef notyet 229 todo |= TIMESTAT; 230#else 231 errx(EX_USAGE, "sorry, -t is not (re)implemented yet"); --- 84 unchanged lines hidden (view full) --- 316 exit(0); 317} 318 319char ** 320getdrivedata(argv) 321 char **argv; 322{ 323 register int i; |
317 register char **cp; | |
318 char buf[30]; 319 | 324 char buf[30]; 325 |
320 kread(X_DK_NDRIVE, &dk_ndrive, sizeof(dk_ndrive)); 321 if (dk_ndrive < 0) 322 errx(1, "dk_ndrive %d", dk_ndrive); 323 dr_select = calloc((size_t)dk_ndrive, sizeof(int)); 324 dr_name = calloc((size_t)dk_ndrive, sizeof(char *)); 325 for (i = 0; i < dk_ndrive; i++) 326 dr_name[i] = NULL; 327 cur.xfer = calloc((size_t)dk_ndrive, sizeof(long)); 328 last.xfer = calloc((size_t)dk_ndrive, sizeof(long)); 329 if (!read_names()) 330 exit (1); 331 for (i = 0; i < dk_ndrive; i++) 332 if (dr_name[i] == NULL) { 333 (void)sprintf(buf, "??%d", i); 334 dr_name[i] = strdup(buf); 335 } | 326 if ((num_devices = getnumdevs()) < 0) 327 errx(1, "%s", devstat_errbuf); |
336 | 328 |
337 /* 338 * Choose drives to be displayed. Priority goes to (in order) drives 339 * supplied as arguments, default drives. If everything isn't filled 340 * in and there are drives not taken care of, display the first few 341 * that fit. 342 */ 343#define BACKWARD_COMPATIBILITY 344 for (ndrives = 0; *argv; ++argv) { 345#ifdef BACKWARD_COMPATIBILITY | 329 cur.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); 330 last.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); 331 bzero(cur.dinfo, sizeof(struct devinfo)); 332 bzero(last.dinfo, sizeof(struct devinfo)); 333 334 if (getdevs(&cur) == -1) 335 errx(1, "%s", devstat_errbuf); 336 337 num_devices = cur.dinfo->numdevs; 338 generation = cur.dinfo->generation; 339 340 specified_devices = (char **)malloc(sizeof(char *)); 341 for (num_devices_specified = 0; *argv; ++argv) { |
346 if (isdigit(**argv)) 347 break; | 342 if (isdigit(**argv)) 343 break; |
348#endif 349 for (i = 0; i < dk_ndrive; i++) { 350 if (strcmp(dr_name[i], *argv)) 351 continue; 352 dr_select[i] = 1; 353 ++ndrives; 354 break; 355 } | 344 num_devices_specified++; 345 specified_devices = (char **)realloc(specified_devices, 346 sizeof(char *) * 347 num_devices_specified); 348 specified_devices[num_devices_specified - 1] = *argv; |
356 } | 349 } |
357 for (i = 0; i < dk_ndrive && ndrives < 4; i++) { 358 if (dr_select[i]) 359 continue; 360 for (cp = defdrives; *cp; cp++) 361 if (strcmp(dr_name[i], *cp) == 0) { 362 dr_select[i] = 1; 363 ++ndrives; 364 break; 365 } 366 } 367 for (i = 0; i < dk_ndrive && ndrives < 4; i++) { 368 if (dr_select[i]) 369 continue; 370 dr_select[i] = 1; 371 ++ndrives; 372 } | 350 dev_select = NULL; 351 352 /* 353 * People are generally only interested in disk statistics when 354 * they're running vmstat. So, that's what we're going to give 355 * them if they don't specify anything by default. We'll also give 356 * them any other random devices in the system so that we get to 357 * maxshowdevs devices, if that many devices exist. If the user 358 * specifies devices on the command line, either through a pattern 359 * match or by naming them explicitly, we will give the user only 360 * those devices. 361 */ 362 if ((num_devices_specified == 0) && (num_matches == 0)) { 363 if (buildmatch("da", &matches, &num_matches) != 0) 364 errx(1, "%s", devstat_errbuf); 365 366 select_mode = DS_SELECT_ADD; 367 } else 368 select_mode = DS_SELECT_ONLY; 369 370 /* 371 * At this point, selectdevs will almost surely indicate that the 372 * device list has changed, so we don't look for return values of 0 373 * or 1. If we get back -1, though, there is an error. 374 */ 375 if (selectdevs(&dev_select, &num_selected, &num_selections, 376 &select_generation, generation, cur.dinfo->devices, 377 num_devices, matches, num_matches, specified_devices, 378 num_devices_specified, select_mode, 379 maxshowdevs, 0) == -1) 380 errx(1, "%s", devstat_errbuf); 381 |
373 return(argv); 374} 375 376long 377getuptime() 378{ 379 static time_t now, boottime; 380 time_t uptime; --- 11 unchanged lines hidden (view full) --- 392 393void 394dovmstat(interval, reps) 395 u_int interval; 396 int reps; 397{ 398 struct vmtotal total; 399 time_t uptime, halfuptime; | 382 return(argv); 383} 384 385long 386getuptime() 387{ 388 static time_t now, boottime; 389 time_t uptime; --- 11 unchanged lines hidden (view full) --- 401 402void 403dovmstat(interval, reps) 404 u_int interval; 405 int reps; 406{ 407 struct vmtotal total; 408 time_t uptime, halfuptime; |
409 struct devinfo *tmp_dinfo; |
|
400 void needhdr(); 401 int mib[2], size; 402 403 uptime = getuptime(); 404 halfuptime = uptime / 2; 405 (void)signal(SIGCONT, needhdr); 406 407 if (namelist[X_STATHZ].n_type != 0 && namelist[X_STATHZ].n_value != 0) 408 kread(X_STATHZ, &hz, sizeof(hz)); 409 if (!hz) 410 kread(X_HZ, &hz, sizeof(hz)); 411 | 410 void needhdr(); 411 int mib[2], size; 412 413 uptime = getuptime(); 414 halfuptime = uptime / 2; 415 (void)signal(SIGCONT, needhdr); 416 417 if (namelist[X_STATHZ].n_type != 0 && namelist[X_STATHZ].n_value != 0) 418 kread(X_STATHZ, &hz, sizeof(hz)); 419 if (!hz) 420 kread(X_HZ, &hz, sizeof(hz)); 421 |
422 /* 423 * Make sure that the userland devstat version matches the kernel 424 * devstat version. If not, exit and print a message informing 425 * the user of his mistake. 426 */ 427 if (checkversion() < 0) 428 errx(1, "%s", devstat_errbuf); 429 |
|
412 for (hdrcnt = 1;;) { 413 if (!--hdrcnt) 414 printhdr(); | 430 for (hdrcnt = 1;;) { 431 if (!--hdrcnt) 432 printhdr(); |
415 kread(X_CPTIME, cur.time, sizeof(cur.time)); 416 kread(X_DKXFER, cur.xfer, sizeof(*cur.xfer) * dk_ndrive); | 433 kread(X_CPTIME, cur.cp_time, sizeof(cur.cp_time)); 434 435 tmp_dinfo = last.dinfo; 436 last.dinfo = cur.dinfo; 437 cur.dinfo = tmp_dinfo; 438 last.busy_time = cur.busy_time; 439 440 /* 441 * Here what we want to do is refresh our device stats. 442 * getdevs() returns 1 when the device list has changed. 443 * If the device list has changed, we want to go through 444 * the selection process again, in case a device that we 445 * were previously displaying has gone away. 446 */ 447 switch (getdevs(&cur)) { 448 case -1: 449 errx(1, "%s", devstat_errbuf); 450 break; 451 case 1: { 452 int retval; 453 454 num_devices = cur.dinfo->numdevs; 455 generation = cur.dinfo->generation; 456 457 retval = selectdevs(&dev_select, &num_selected, 458 &num_selections, &select_generation, 459 generation, cur.dinfo->devices, 460 num_devices, matches, num_matches, 461 specified_devices, 462 num_devices_specified, select_mode, 463 maxshowdevs, 0); 464 switch (retval) { 465 case -1: 466 errx(1, "%s", devstat_errbuf); 467 break; 468 case 1: 469 printhdr(); 470 break; 471 default: 472 break; 473 } 474 } 475 default: 476 break; 477 } 478 |
417 kread(X_SUM, &sum, sizeof(sum)); 418 size = sizeof(total); 419 mib[0] = CTL_VM; 420 mib[1] = VM_METER; 421 if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) { 422 printf("Can't get kerninfo: %s\n", strerror(errno)); 423 bzero(&total, sizeof(total)); 424 } --- 12 unchanged lines hidden (view full) --- 437 (osum.v_swapin + osum.v_vnodein))); 438 (void)printf("%3lu ", 439 (u_long)rate(sum.v_swapout + sum.v_vnodeout - 440 (osum.v_swapout + osum.v_vnodeout))); 441 (void)printf("%3lu ", 442 (u_long)rate(sum.v_tfree - osum.v_tfree)); 443 (void)printf("%3lu ", 444 (u_long)rate(sum.v_pdpages - osum.v_pdpages)); | 479 kread(X_SUM, &sum, sizeof(sum)); 480 size = sizeof(total); 481 mib[0] = CTL_VM; 482 mib[1] = VM_METER; 483 if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) { 484 printf("Can't get kerninfo: %s\n", strerror(errno)); 485 bzero(&total, sizeof(total)); 486 } --- 12 unchanged lines hidden (view full) --- 499 (osum.v_swapin + osum.v_vnodein))); 500 (void)printf("%3lu ", 501 (u_long)rate(sum.v_swapout + sum.v_vnodeout - 502 (osum.v_swapout + osum.v_vnodeout))); 503 (void)printf("%3lu ", 504 (u_long)rate(sum.v_tfree - osum.v_tfree)); 505 (void)printf("%3lu ", 506 (u_long)rate(sum.v_pdpages - osum.v_pdpages)); |
445 dkstats(); | 507 devstats(); |
446 (void)printf("%4lu %4lu %3lu ", 447 (u_long)rate(sum.v_intr - osum.v_intr), 448 (u_long)rate(sum.v_syscall - osum.v_syscall), 449 (u_long)rate(sum.v_swtch - osum.v_swtch)); 450 cpustats(); 451 (void)printf("\n"); 452 (void)fflush(stdout); 453 if (reps >= 0 && --reps <= 0) --- 12 unchanged lines hidden (view full) --- 466 } 467} 468 469void 470printhdr() 471{ 472 register int i; 473 | 508 (void)printf("%4lu %4lu %3lu ", 509 (u_long)rate(sum.v_intr - osum.v_intr), 510 (u_long)rate(sum.v_syscall - osum.v_syscall), 511 (u_long)rate(sum.v_swtch - osum.v_swtch)); 512 cpustats(); 513 (void)printf("\n"); 514 (void)fflush(stdout); 515 if (reps >= 0 && --reps <= 0) --- 12 unchanged lines hidden (view full) --- 528 } 529} 530 531void 532printhdr() 533{ 534 register int i; 535 |
474 (void)printf(" procs memory page%*s", 20, ""); 475 if (ndrives > 1) | 536 (void)printf(" procs memory page%*s", 19, ""); 537 if (num_selected > 1) |
476 (void)printf("disks %*s faults cpu\n", | 538 (void)printf("disks %*s faults cpu\n", |
477 ndrives * 3 - 6, ""); | 539 ((num_selected < maxshowdevs) ? num_selected : 540 maxshowdevs ) * 4 - 7, ""); 541 else if (num_selected == 1) 542 (void)printf("disk faults cpu\n"); |
478 else | 543 else |
479 (void)printf("%*s faults cpu\n", ndrives * 3, ""); | 544 (void)printf("%*s faults cpu\n", num_selected * 4, ""); 545 |
480 (void)printf(" r b w avm fre flt re pi po fr sr "); | 546 (void)printf(" r b w avm fre flt re pi po fr sr "); |
481 for (i = 0; i < dk_ndrive; i++) 482 if (dr_select[i]) 483 (void)printf("%c%c ", dr_name[i][0], 484 dr_name[i][strlen(dr_name[i]) - 1]); | 547 for (i = 0; i < num_devices; i++) 548 if ((dev_select[i].selected) 549 && (dev_select[i].selected <= maxshowdevs)) 550 (void)printf("%c%c%d ", dev_select[i].device_name[0], 551 dev_select[i].device_name[1], 552 dev_select[i].unit_number); |
485 (void)printf(" in sy cs us sy id\n"); 486 hdrcnt = winlines - 2; 487} 488 489/* 490 * Force a header to be prepended to the next output. 491 */ 492void --- 126 unchanged lines hidden (view full) --- 619 kread(X_FORKSTAT, &fks, sizeof(struct forkstat)); 620 (void)printf("%d forks, %d pages, average %.2f\n", 621 fks.cntfork, fks.sizfork, (double)fks.sizfork / fks.cntfork); 622 (void)printf("%d vforks, %d pages, average %.2f\n", 623 fks.cntvfork, fks.sizvfork, (double)fks.sizvfork / fks.cntvfork); 624} 625#endif 626 | 553 (void)printf(" in sy cs us sy id\n"); 554 hdrcnt = winlines - 2; 555} 556 557/* 558 * Force a header to be prepended to the next output. 559 */ 560void --- 126 unchanged lines hidden (view full) --- 687 kread(X_FORKSTAT, &fks, sizeof(struct forkstat)); 688 (void)printf("%d forks, %d pages, average %.2f\n", 689 fks.cntfork, fks.sizfork, (double)fks.sizfork / fks.cntfork); 690 (void)printf("%d vforks, %d pages, average %.2f\n", 691 fks.cntvfork, fks.sizvfork, (double)fks.sizvfork / fks.cntvfork); 692} 693#endif 694 |
627void 628dkstats() | 695static void 696devstats() |
629{ 630 register int dn, state; | 697{ 698 register int dn, state; |
631 double etime; | 699 long double transfers_per_second; 700 long double busy_seconds; |
632 long tmp; | 701 long tmp; |
633 634 for (dn = 0; dn < dk_ndrive; ++dn) { 635 tmp = cur.xfer[dn]; 636 cur.xfer[dn] -= last.xfer[dn]; 637 last.xfer[dn] = tmp; 638 } 639 etime = 0; | 702 |
640 for (state = 0; state < CPUSTATES; ++state) { | 703 for (state = 0; state < CPUSTATES; ++state) { |
641 tmp = cur.time[state]; 642 cur.time[state] -= last.time[state]; 643 last.time[state] = tmp; 644 etime += cur.time[state]; | 704 tmp = cur.cp_time[state]; 705 cur.cp_time[state] -= last.cp_time[state]; 706 last.cp_time[state] = tmp; |
645 } | 707 } |
646 if (etime == 0) 647 etime = 1; 648 etime /= hz; 649 for (dn = 0; dn < dk_ndrive; ++dn) { 650 if (!dr_select[dn]) | 708 709 busy_seconds = compute_etime(cur.busy_time, last.busy_time); 710 711 for (dn = 0; dn < num_devices; dn++) { 712 int di; 713 714 if ((dev_select[dn].selected == 0) 715 || (dev_select[dn].selected > maxshowdevs)) |
651 continue; | 716 continue; |
652 (void)printf("%2.0f ", cur.xfer[dn] / etime); | 717 718 di = dev_select[dn].position; 719 720 if (compute_stats(&cur.dinfo->devices[di], 721 &last.dinfo->devices[di], busy_seconds, 722 NULL, NULL, NULL, 723 NULL, &transfers_per_second, NULL, 724 NULL, NULL) != 0) 725 errx(1, "%s", devstat_errbuf); 726 727 printf("%3.0Lf ", transfers_per_second); |
653 } 654} 655 656void 657cpustats() 658{ 659 register int state; 660 double pct, total; 661 662 total = 0; 663 for (state = 0; state < CPUSTATES; ++state) | 728 } 729} 730 731void 732cpustats() 733{ 734 register int state; 735 double pct, total; 736 737 total = 0; 738 for (state = 0; state < CPUSTATES; ++state) |
664 total += cur.time[state]; | 739 total += cur.cp_time[state]; |
665 if (total) 666 pct = 100 / total; 667 else 668 pct = 0; | 740 if (total) 741 pct = 100 / total; 742 else 743 pct = 0; |
669 (void)printf("%2.0f ", (cur.time[CP_USER] + cur.time[CP_NICE]) * pct); 670 (void)printf("%2.0f ", (cur.time[CP_SYS] + cur.time[CP_INTR]) * pct); 671 (void)printf("%2.0f", cur.time[CP_IDLE] * pct); | 744 (void)printf("%2.0f ", (cur.cp_time[CP_USER] + 745 cur.cp_time[CP_NICE]) * pct); 746 (void)printf("%2.0f ", (cur.cp_time[CP_SYS] + 747 cur.cp_time[CP_INTR]) * pct); 748 (void)printf("%2.0f", cur.cp_time[CP_IDLE] * pct); |
672} 673 674void 675dointr() 676{ 677 register long *intrcnt, inttotal, uptime; 678 register int nintr, inamlen; 679 register char *intrname; --- 169 unchanged lines hidden --- | 749} 750 751void 752dointr() 753{ 754 register long *intrcnt, inttotal, uptime; 755 register int nintr, inamlen; 756 register char *intrname; --- 169 unchanged lines hidden --- |