Index: head/usr.bin/vmstat/Makefile =================================================================== --- head/usr.bin/vmstat/Makefile +++ head/usr.bin/vmstat/Makefile @@ -5,6 +5,6 @@ MAN= vmstat.8 LIBADD= devstat kvm memstat xo util -WARNS?= 1 +WARNS?= 6 .include Index: head/usr.bin/vmstat/vmstat.c =================================================================== --- head/usr.bin/vmstat/vmstat.c +++ head/usr.bin/vmstat/vmstat.c @@ -85,50 +85,38 @@ static char da[] = "da"; +enum x_stats { X_SUM, X_HZ, X_STATHZ, X_NCHSTATS, X_INTRNAMES, X_SINTRNAMES, + X_INTRCNT, X_SINTRCNT, X_DEFICIT, X_REC, X_PGIN, X_XSTATS }; + static struct nlist namelist[] = { -#define X_SUM 0 - { "_vm_cnt" }, -#define X_HZ 1 - { "_hz" }, -#define X_STATHZ 2 - { "_stathz" }, -#define X_NCHSTATS 3 - { "_nchstats" }, -#define X_INTRNAMES 4 - { "_intrnames" }, -#define X_SINTRNAMES 5 - { "_sintrnames" }, -#define X_INTRCNT 6 - { "_intrcnt" }, -#define X_SINTRCNT 7 - { "_sintrcnt" }, + [X_SUM] = { .n_name = "_vm_cnt", }, + [X_HZ] = { .n_name = "_hz", }, + [X_STATHZ] = { .n_name = "_stathz", }, + [X_NCHSTATS] = { .n_name = "_nchstats", }, + [X_INTRNAMES] = { .n_name = "_intrnames", }, + [X_SINTRNAMES] = { .n_name = "_sintrnames", }, + [X_INTRCNT] = { .n_name = "_intrcnt", }, + [X_SINTRCNT] = { .n_name = "_sintrcnt", }, #ifdef notyet -#define X_DEFICIT XXX - { "_deficit" }, -#define X_REC XXX - { "_rectime" }, -#define X_PGIN XXX - { "_pgintime" }, -#define X_XSTATS XXX - { "_xstats" }, -#define X_END XXX -#else -#define X_END 8 + [X_DEFICIT] = { .n_name = "_deficit", }, + [X_REC] = { .n_name = "_rectime", }, + [X_PGIN] = { .n_name = "_pgintime", }, + [X_XSTATS] = { .n_name = "_xstats", }, #endif - { "" }, + { .n_name = NULL, }, }; -static struct statinfo cur, last; -static int num_devices, maxshowdevs; -static long generation; -static struct device_selection *dev_select; -static int num_selected; static struct devstat_match *matches; -static int num_matches = 0; -static int num_devices_specified, num_selections; -static long select_generation; -static char **specified_devices; +static struct device_selection *dev_select; +static struct statinfo cur, last; static devstat_select_mode select_mode; +static size_t size_cp_times; +static long *cur_cp_times, *last_cp_times; +static long generation, select_generation; +static int hz, hdrcnt, maxshowdevs; +static int num_devices, num_devices_specified; +static int num_matches, num_selected, num_selections; +static char **specified_devices; static struct __vmmeter { uint64_t v_swtch; @@ -183,7 +171,7 @@ } sum, osum; #define VMSTAT_DEFAULT_LINES 20 /* Default number of `winlines'. */ -volatile sig_atomic_t wresized; /* Tty resized, when non-zero. */ +static volatile sig_atomic_t wresized; /* Tty resized when non-zero. */ static int winlines = VMSTAT_DEFAULT_LINES; /* Current number of tty rows. */ static int aflag; @@ -191,7 +179,7 @@ static int Pflag; static int hflag; -static kvm_t *kd; +static kvm_t *kd; #define FORKSTAT 0x01 #define INTRSTAT 0x02 @@ -199,11 +187,11 @@ #define SUMSTAT 0x08 #define TIMESTAT 0x10 #define VMSTAT 0x20 -#define ZMEMSTAT 0x40 +#define ZMEMSTAT 0x40 #define OBJSTAT 0x80 static void cpustats(void); -static void pcpustats(int, u_long, int); +static void pcpustats(u_long, int); static void devstats(void); static void doforkst(void); static void dointr(unsigned int, int); @@ -214,7 +202,6 @@ static void domemstat_zone(void); static void kread(int, void *, size_t); static void kreado(int, void *, size_t, size_t); -static char *kgetstr(const char *); static void needhdr(int); static void needresize(int); static void doresize(void); @@ -224,16 +211,15 @@ static long pct(long, long); static long long getuptime(void); -static char **getdrivedata(char **); +static char **getdrivedata(char **); int main(int argc, char *argv[]) { - int c, todo; - unsigned int interval; + char *bp, *buf, *memf, *nlistf; float f; - int reps; - char *memf, *nlistf; + int bufsize, c, len, reps, todo; + unsigned int interval; char errbuf[_POSIX2_LINE_MAX]; memf = nlistf = NULL; @@ -243,7 +229,7 @@ argc = xo_parse_args(argc, argv); if (argc < 0) - return argc; + return (argc); while ((c = getopt(argc, argv, "ac:fhHiM:mN:n:oPp:stw:z")) != -1) { switch (c) { @@ -282,13 +268,14 @@ maxshowdevs = atoi(optarg); if (maxshowdevs < 0) xo_errx(1, "number of devices %d is < 0", - maxshowdevs); + maxshowdevs); break; case 'o': todo |= OBJSTAT; break; case 'p': - if (devstat_buildmatch(optarg, &matches, &num_matches) != 0) + if (devstat_buildmatch(optarg, &matches, &num_matches) + != 0) xo_errx(1, "%s", devstat_errbuf); break; case 's': @@ -298,7 +285,8 @@ #ifdef notyet todo |= TIMESTAT; #else - xo_errx(EX_USAGE, "sorry, -t is not (re)implemented yet"); + xo_errx(EX_USAGE, + "sorry, -t is not (re)implemented yet"); #endif break; case 'w': @@ -330,10 +318,10 @@ retry_nlist: if (kd != NULL && (c = kvm_nlist(kd, namelist)) != 0) { if (c > 0) { - int bufsize = 0, len = 0; - char *buf, *bp; + bufsize = 0, len = 0; + /* - * 'cnt' was renamed to 'vm_cnt'. If 'vm_cnt' is not + * 'cnt' was renamed to 'vm_cnt'. If 'vm_cnt' is not * found try looking up older 'cnt' symbol. * */ if (namelist[X_SUM].n_type == 0 && @@ -341,9 +329,11 @@ namelist[X_SUM].n_name = "_cnt"; goto retry_nlist; } + for (c = 0; c < (int)(nitems(namelist)); c++) if (namelist[c].n_type == 0) - bufsize += strlen(namelist[c].n_name) + 1; + bufsize += strlen(namelist[c].n_name) + + 1; bufsize += len + 1; buf = bp = alloca(bufsize); @@ -428,6 +418,7 @@ static char ** getdrivedata(char **argv) { + if ((num_devices = devstat_getnumdevs(NULL)) < 0) xo_errx(1, "%s", devstat_errbuf); @@ -440,20 +431,19 @@ num_devices = cur.dinfo->numdevs; generation = cur.dinfo->generation; - specified_devices = (char **)malloc(sizeof(char *)); + specified_devices = malloc(sizeof(char *)); for (num_devices_specified = 0; *argv; ++argv) { if (isdigit(**argv)) break; num_devices_specified++; - specified_devices = (char **)realloc(specified_devices, - sizeof(char *) * - num_devices_specified); + specified_devices = realloc(specified_devices, + sizeof(char *) * num_devices_specified); specified_devices[num_devices_specified - 1] = *argv; } dev_select = NULL; if (nflag == 0 && maxshowdevs < num_devices_specified) - maxshowdevs = num_devices_specified; + maxshowdevs = num_devices_specified; /* * People are generally only interested in disk statistics when @@ -468,7 +458,6 @@ if ((num_devices_specified == 0) && (num_matches == 0)) { if (devstat_buildmatch(da, &matches, &num_matches) != 0) xo_errx(1, "%s", devstat_errbuf); - select_mode = DS_SELECT_ADD; } else select_mode = DS_SELECT_ONLY; @@ -479,10 +468,10 @@ * or 1. If we get back -1, though, there is an error. */ if (devstat_selectdevs(&dev_select, &num_selected, &num_selections, - &select_generation, generation, cur.dinfo->devices, - num_devices, matches, num_matches, specified_devices, - num_devices_specified, select_mode, - maxshowdevs, 0) == -1) + &select_generation, generation, cur.dinfo->devices, + num_devices, matches, num_matches, specified_devices, + num_devices_specified, select_mode, + maxshowdevs, 0) == -1) xo_errx(1, "%s", devstat_errbuf); return(argv); @@ -495,19 +484,16 @@ struct timespec sp; (void)clock_gettime(CLOCK_UPTIME, &sp); - return((long long)sp.tv_sec * 1000000000LL + sp.tv_nsec); } static void fill_vmmeter(struct __vmmeter *vmmp) { - struct pcpu **pcpu; - int maxcpu, i; + struct vmmeter vm_cnt; + size_t size; if (kd != NULL) { - struct vmmeter vm_cnt; - kread(X_SUM, &vm_cnt, sizeof(vm_cnt)); #define GET_COUNTER(name) \ vmmp->name = kvm_counter_u64_fetch(kd, (u_long)vm_cnt.name) @@ -542,8 +528,6 @@ GET_COUNTER(v_kthreadpages); #undef GET_COUNTER } else { - size_t size; - #define GET_VM_STATS(cat, name) do { \ size = sizeof(vmmp->name); \ mysysctl("vm.stats." #cat "." #name, &vmmp->name, &size); \ @@ -607,11 +591,13 @@ static void fill_vmtotal(struct vmtotal *vmtp) { + size_t size; + if (kd != NULL) { /* XXX fill vmtp */ xo_errx(1, "not implemented"); } else { - size_t size = sizeof(*vmtp); + size = sizeof(*vmtp); mysysctl("vm.vmtotal", vmtp, &size); if (size != sizeof(*vmtp)) xo_errx(1, "vm.total size mismatch"); @@ -622,14 +608,10 @@ static int getcpuinfo(u_long *maskp, int *maxidp) { - int maxcpu; - int maxid; - int ncpus; - int i, j; - int empty; - size_t size; long *times; u_long mask; + size_t size; + int empty, i, j, maxcpu, maxid, ncpus; if (kd != NULL) xo_errx(1, "not implemented"); @@ -667,8 +649,8 @@ static void prthuman(const char *name, uint64_t val, int size) { - char buf[10]; int flags; + char buf[10]; char fmt[128]; snprintf(fmt, sizeof(fmt), "{:%s/%%*s}", name); @@ -681,28 +663,23 @@ xo_emit(fmt, size, buf); } -static int hz, hdrcnt; - -static long *cur_cp_times; -static long *last_cp_times; -static size_t size_cp_times; - static void dovmstat(unsigned int interval, int reps) { + struct clockinfo clockrate; struct vmtotal total; - time_t uptime, halfuptime; struct devinfo *tmp_dinfo; - size_t size; - int ncpus, maxid; u_long cpumask; - int rate_adj; + size_t size; + time_t uptime, halfuptime; + int ncpus, maxid, rate_adj, retval; uptime = getuptime() / 1000000000LL; halfuptime = uptime / 2; rate_adj = 1; ncpus = 1; maxid = 0; + cpumask = 0; /* * If the user stops the program (control-Z) and then resumes it, @@ -731,8 +708,6 @@ if (!hz) kread(X_HZ, &hz, sizeof(hz)); } else { - struct clockinfo clockrate; - size = sizeof(clockrate); mysysctl("kern.clockrate", &clockrate, &size); if (size != sizeof(clockrate)) @@ -781,19 +756,17 @@ case -1: xo_errx(1, "%s", devstat_errbuf); break; - case 1: { - int retval; - + case 1: num_devices = cur.dinfo->numdevs; generation = cur.dinfo->generation; retval = devstat_selectdevs(&dev_select, &num_selected, - &num_selections, &select_generation, - generation, cur.dinfo->devices, - num_devices, matches, num_matches, - specified_devices, - num_devices_specified, select_mode, - maxshowdevs, 0); + &num_selections, &select_generation, + generation, cur.dinfo->devices, + num_devices, matches, num_matches, + specified_devices, + num_devices_specified, select_mode, + maxshowdevs, 0); switch (retval) { case -1: xo_errx(1, "%s", devstat_errbuf); @@ -804,7 +777,7 @@ default: break; } - } + break; default: break; } @@ -813,8 +786,8 @@ fill_vmtotal(&total); xo_open_container("processes"); xo_emit("{:runnable/%1d} {:waiting/%ld} " - "{:swapped-out/%ld}", - total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw); + "{:swapped-out/%ld}", total.t_rq - 1, total.t_dw + + total.t_pw, total.t_sw); xo_close_container("processes"); xo_open_container("memory"); #define vmstat_pgtok(a) ((uintmax_t)(a) * (sum.v_page_size >> 10)) @@ -822,28 +795,29 @@ if (hflag) { xo_emit(""); prthuman("available-memory", - total.t_avm * (uint64_t)sum.v_page_size, 5); + total.t_avm * (uint64_t)sum.v_page_size, 5); xo_emit(" "); prthuman("free-memory", - total.t_free * (uint64_t)sum.v_page_size, 5); + total.t_free * (uint64_t)sum.v_page_size, 5); xo_emit(" "); } else { xo_emit(" "); xo_emit("{:available-memory/%7ju}", - vmstat_pgtok(total.t_avm)); + vmstat_pgtok(total.t_avm)); xo_emit(" "); xo_emit("{:free-memory/%7ju}", - vmstat_pgtok(total.t_free)); + vmstat_pgtok(total.t_free)); xo_emit(" "); } xo_emit("{:total-page-faults/%5lu} ", - (unsigned long)rate(sum.v_vm_faults - - osum.v_vm_faults)); + (unsigned long)rate(sum.v_vm_faults - + osum.v_vm_faults)); xo_close_container("memory"); xo_open_container("paging-rates"); xo_emit("{:page-reactivated/%3lu} ", - (unsigned long)rate(sum.v_reactivated - osum.v_reactivated)); + (unsigned long)rate(sum.v_reactivated - + osum.v_reactivated)); xo_emit("{:paged-in/%3lu} ", (unsigned long)rate(sum.v_swapin + sum.v_vnodein - (osum.v_swapin + osum.v_vnodein))); @@ -859,13 +833,13 @@ devstats(); xo_open_container("fault-rates"); xo_emit("{:interrupts/%4lu} {:system-calls/%5lu} " - "{:context-switches/%5u}", + "{:context-switches/%5lu}", (unsigned long)rate(sum.v_intr - osum.v_intr), (unsigned long)rate(sum.v_syscall - osum.v_syscall), (unsigned long)rate(sum.v_swtch - osum.v_swtch)); xo_close_container("fault-rates"); if (Pflag) - pcpustats(ncpus, cpumask, maxid); + pcpustats(cpumask, maxid); else cpustats(); xo_emit("\n"); @@ -893,13 +867,12 @@ int i, num_shown; num_shown = MIN(num_selected, maxshowdevs); - if (hflag) { + if (hflag) xo_emit("{T:procs} {T:memory} {T:/page%*s}", 19, ""); - } else { + else xo_emit("{T:procs} {T:memory} {T:/page%*s}", 19, ""); - } if (num_shown > 1) - xo_emit(" {T:/disks %*s}", num_shown * 4 - 7, ""); + xo_emit(" {T:/disks %*s}", num_shown * 4 - 7, ""); else if (num_shown == 1) xo_emit(" {T:disks}"); xo_emit(" {T:faults} "); @@ -912,16 +885,18 @@ } else xo_emit(" {T:cpu}\n"); if (hflag) { - xo_emit("{T:r} {T:b} {T:w} {T:avm} {T:fre} {T:flt} {T:re} {T:pi} {T:po} {T:fr} {T:sr} "); + xo_emit("{T:r} {T:b} {T:w} {T:avm} {T:fre} {T:flt} {T:re}" + " {T:pi} {T:po} {T:fr} {T:sr} "); } else { - xo_emit("{T:r} {T:b} {T:w} {T:avm} {T:fre} {T:flt} {T:re} {T:pi} {T:po} {T:fr} {T:sr} "); + xo_emit("{T:r} {T:b} {T:w} {T:avm} {T:fre} {T:flt} " + "{T:re} {T:pi} {T:po} {T:fr} {T:sr} "); } for (i = 0; i < num_devices; i++) - if ((dev_select[i].selected) - && (dev_select[i].selected <= maxshowdevs)) + if ((dev_select[i].selected) && + (dev_select[i].selected <= maxshowdevs)) xo_emit("{T:/%c%c%d} ", dev_select[i].device_name[0], - dev_select[i].device_name[1], - dev_select[i].unit_number); + dev_select[i].device_name[1], + dev_select[i].unit_number); xo_emit(" {T:in} {T:sy} {T:cs}"); if (Pflag) { for (i = 0; i <= maxid; i++) { @@ -952,7 +927,7 @@ * prepended to the next output. */ void -needresize(int signo) +needresize(int signo __unused) { wresized = 1; @@ -965,8 +940,8 @@ void doresize(void) { - int status; struct winsize w; + int status; for (;;) { status = ioctl(fileno(stdout), TIOCGWINSZ, &w); @@ -997,13 +972,13 @@ kread(X_PGIN, &pgintime, sizeof(pgintime)); kread(X_SUM, &sum, sizeof(sum)); xo_emit("{:page-reclaims/%u} {N:reclaims}, " - "{:reclaim-time/%u} {N:total time (usec)}\n", + "{:reclaim-time/%u} {N:total time (usec)}\n", sum.v_pgrec, rectime); xo_emit("{L:average}: {:reclaim-average/%u} {N:usec \\/ reclaim}\n", - rectime / sum.v_pgrec); + rectime / sum.v_pgrec); xo_emit("\n"); xo_emit("{:page-ins/%u} {N:page ins}, " - "{:page-in-time/%u} {N:total time (msec)}\n", + "{:page-in-time/%u} {N:total time (msec)}\n", sum.v_pgin, pgintime / 10); xo_emit("{L:average}: {:average/%8.1f} {N:msec \\/ page in}\n", pgintime / (sum.v_pgin * 10.0)); @@ -1027,93 +1002,94 @@ dosum(void) { struct nchstats lnchstats; + size_t size; long nchtotal; fill_vmmeter(&sum); xo_open_container("summary-statistics"); xo_emit("{:context-switches/%9u} {N:cpu context switches}\n", - sum.v_swtch); + sum.v_swtch); xo_emit("{:interrupts/%9u} {N:device interrupts}\n", - sum.v_intr); + sum.v_intr); xo_emit("{:software-interrupts/%9u} {N:software interrupts}\n", - sum.v_soft); + sum.v_soft); xo_emit("{:traps/%9u} {N:traps}\n", sum.v_trap); xo_emit("{:system-calls/%9u} {N:system calls}\n", - sum.v_syscall); + sum.v_syscall); xo_emit("{:kernel-threads/%9u} {N:kernel threads created}\n", - sum.v_kthreads); + sum.v_kthreads); xo_emit("{:forks/%9u} {N: fork() calls}\n", sum.v_forks); xo_emit("{:vforks/%9u} {N:vfork() calls}\n", - sum.v_vforks); + sum.v_vforks); xo_emit("{:rforks/%9u} {N:rfork() calls}\n", - sum.v_rforks); + sum.v_rforks); xo_emit("{:swap-ins/%9u} {N:swap pager pageins}\n", - sum.v_swapin); + sum.v_swapin); xo_emit("{:swap-in-pages/%9u} {N:swap pager pages paged in}\n", - sum.v_swappgsin); + sum.v_swappgsin); xo_emit("{:swap-outs/%9u} {N:swap pager pageouts}\n", - sum.v_swapout); + sum.v_swapout); xo_emit("{:swap-out-pages/%9u} {N:swap pager pages paged out}\n", - sum.v_swappgsout); + sum.v_swappgsout); xo_emit("{:vnode-page-ins/%9u} {N:vnode pager pageins}\n", - sum.v_vnodein); + sum.v_vnodein); xo_emit("{:vnode-page-in-pages/%9u} {N:vnode pager pages paged in}\n", - sum.v_vnodepgsin); + sum.v_vnodepgsin); xo_emit("{:vnode-page-outs/%9u} {N:vnode pager pageouts}\n", - sum.v_vnodeout); + sum.v_vnodeout); xo_emit("{:vnode-page-out-pages/%9u} {N:vnode pager pages paged out}\n", - sum.v_vnodepgsout); + sum.v_vnodepgsout); xo_emit("{:page-daemon-wakeups/%9u} {N:page daemon wakeups}\n", - sum.v_pdwakeups); - xo_emit("{:page-daemon-pages/%9u} {N:pages examined by the page daemon}\n", - sum.v_pdpages); - xo_emit("{:page-reclamation-shortfalls/%9u} {N:clean page reclamation shortfalls}\n", - sum.v_pdshortfalls); + sum.v_pdwakeups); + xo_emit("{:page-daemon-pages/%9u} {N:pages examined by the page" + "daemon}\n", sum.v_pdpages); + xo_emit("{:page-reclamation-shortfalls/%9u} {N:clean page reclamation" + "shortfalls}\n", sum.v_pdshortfalls); xo_emit("{:reactivated/%9u} {N:pages reactivated by the page daemon}\n", - sum.v_reactivated); + sum.v_reactivated); xo_emit("{:copy-on-write-faults/%9u} {N:copy-on-write faults}\n", - sum.v_cow_faults); - xo_emit("{:copy-on-write-optimized-faults/%9u} {N:copy-on-write optimized faults}\n", - sum.v_cow_optim); + sum.v_cow_faults); + xo_emit("{:copy-on-write-optimized-faults/%9u} {N:copy-on-write" + "optimized faults}\n", sum.v_cow_optim); xo_emit("{:zero-fill-pages/%9u} {N:zero fill pages zeroed}\n", - sum.v_zfod); + sum.v_zfod); xo_emit("{:zero-fill-prezeroed/%9u} {N:zero fill pages prezeroed}\n", - sum.v_ozfod); + sum.v_ozfod); xo_emit("{:intransit-blocking/%9u} {N:intransit blocking page faults}\n", - sum.v_intrans); + sum.v_intrans); xo_emit("{:total-faults/%9u} {N:total VM faults taken}\n", - sum.v_vm_faults); + sum.v_vm_faults); xo_emit("{:faults-requiring-io/%9u} {N:page faults requiring I\\/O}\n", - sum.v_io_faults); - xo_emit("{:faults-from-thread-creation/%9u} {N:pages affected by kernel thread creation}\n", - sum.v_kthreadpages); + sum.v_io_faults); + xo_emit("{:faults-from-thread-creation/%9u} {N:pages affected by" + "kernel thread creation}\n", sum.v_kthreadpages); xo_emit("{:faults-from-fork/%9u} {N:pages affected by fork}()\n", - sum.v_forkpages); + sum.v_forkpages); xo_emit("{:faults-from-vfork/%9u} {N:pages affected by vfork}()\n", - sum.v_vforkpages); + sum.v_vforkpages); xo_emit("{:pages-rfork/%9u} {N:pages affected by rfork}()\n", - sum.v_rforkpages); + sum.v_rforkpages); xo_emit("{:pages-freed/%9u} {N:pages freed}\n", - sum.v_tfree); + sum.v_tfree); xo_emit("{:pages-freed-by-daemon/%9u} {N:pages freed by daemon}\n", - sum.v_dfree); + sum.v_dfree); xo_emit("{:pages-freed-on-exit/%9u} {N:pages freed by exiting processes}\n", - sum.v_pfree); + sum.v_pfree); xo_emit("{:active-pages/%9u} {N:pages active}\n", - sum.v_active_count); + sum.v_active_count); xo_emit("{:inactive-pages/%9u} {N:pages inactive}\n", - sum.v_inactive_count); + sum.v_inactive_count); xo_emit("{:laundry-pages/%9u} {N:pages in the laundry queue}\n", - sum.v_laundry_count); + sum.v_laundry_count); xo_emit("{:wired-pages/%9u} {N:pages wired down}\n", - sum.v_wire_count); + sum.v_wire_count); xo_emit("{:free-pages/%9u} {N:pages free}\n", - sum.v_free_count); + sum.v_free_count); xo_emit("{:bytes-per-page/%9u} {N:bytes per page}\n", sum.v_page_size); if (kd != NULL) { kread(X_NCHSTATS, &lnchstats, sizeof(lnchstats)); } else { - size_t size = sizeof(lnchstats); + size = sizeof(lnchstats); mysysctl("vfs.cache.nchstats", &lnchstats, &size); if (size != sizeof(lnchstats)) xo_errx(1, "vfs.cache.nchstats size mismatch"); @@ -1122,17 +1098,17 @@ lnchstats.ncs_badhits + lnchstats.ncs_falsehits + lnchstats.ncs_miss + lnchstats.ncs_long; xo_emit("{:total-name-lookups/%9ld} {N:total name lookups}\n", - nchtotal); + nchtotal); xo_emit("{P:/%9s} {N:cache hits} " - "({:positive-cache-hits/%ld}% pos + " - "{:negative-cache-hits/%ld}% {N:neg}) " - "system {:cache-hit-percent/%ld}% per-directory\n", + "({:positive-cache-hits/%ld}% pos + " + "{:negative-cache-hits/%ld}% {N:neg}) " + "system {:cache-hit-percent/%ld}% per-directory\n", "", PCT(lnchstats.ncs_goodhits, nchtotal), PCT(lnchstats.ncs_neghits, nchtotal), PCT(lnchstats.ncs_pass2, nchtotal)); xo_emit("{P:/%9s} {L:deletions} {:deletions/%ld}%, " - "{L:falsehits} {:false-hits/%ld}%, " - "{L:toolong} {:too-long/%ld}%\n", "", + "{L:falsehits} {:false-hits/%ld}%, " + "{L:toolong} {:too-long/%ld}%\n", "", PCT(lnchstats.ncs_badhits, nchtotal), PCT(lnchstats.ncs_falsehits, nchtotal), PCT(lnchstats.ncs_long, nchtotal)); @@ -1142,20 +1118,21 @@ static void doforkst(void) { + fill_vmmeter(&sum); xo_open_container("fork-statistics"); xo_emit("{:fork/%u} {N:forks}, {:fork-pages/%u} {N:pages}, " - "{L:average} {:fork-average/%.2f}\n", + "{L:average} {:fork-average/%.2f}\n", sum.v_forks, sum.v_forkpages, sum.v_forks == 0 ? 0.0 : (double)sum.v_forkpages / sum.v_forks); xo_emit("{:vfork/%u} {N:vforks}, {:vfork-pages/%u} {N:pages}, " - "{L:average} {:vfork-average/%.2f}\n", + "{L:average} {:vfork-average/%.2f}\n", sum.v_vforks, sum.v_vforkpages, sum.v_vforks == 0 ? 0.0 : (double)sum.v_vforkpages / sum.v_vforks); xo_emit("{:rfork/%u} {N:rforks}, {:rfork-pages/%u} {N:pages}, " - "{L:average} {:rfork-average/%.2f}\n", + "{L:average} {:rfork-average/%.2f}\n", sum.v_rforks, sum.v_rforkpages, sum.v_rforks == 0 ? 0.0 : (double)sum.v_rforkpages / sum.v_rforks); @@ -1165,10 +1142,9 @@ static void devstats(void) { - int dn, state; - long double transfers_per_second; - long double busy_seconds; + long double busy_seconds, transfers_per_second; long tmp; + int di, dn, state; for (state = 0; state < CPUSTATES; ++state) { tmp = cur.cp_time[state]; @@ -1180,10 +1156,8 @@ xo_open_list("device"); for (dn = 0; dn < num_devices; dn++) { - int di; - - if ((dev_select[dn].selected == 0) - || (dev_select[dn].selected > maxshowdevs)) + if (dev_select[dn].selected == 0 || + dev_select[dn].selected > maxshowdevs) continue; di = dev_select[dn].position; @@ -1196,24 +1170,24 @@ xo_open_instance("device"); xo_emit("{ekq:name/%c%c%d}{:transfers/%3.0Lf} ", - dev_select[dn].device_name[0], - dev_select[dn].device_name[1], - dev_select[dn].unit_number, - transfers_per_second); + dev_select[dn].device_name[0], + dev_select[dn].device_name[1], + dev_select[dn].unit_number, + transfers_per_second); xo_close_instance("device"); } xo_close_list("device"); } static void -percent(const char *name, double pct, int *over) +percent(const char *name, double pctv, int *over) { + int l; char buf[10]; char fmt[128]; - int l; snprintf(fmt, sizeof(fmt), " {:%s/%%*s}", name); - l = snprintf(buf, sizeof(buf), "%.0f", pct); + l = snprintf(buf, sizeof(buf), "%.0f", pctv); if (l == 1 && *over) { xo_emit(fmt, 1, buf); (*over)--; @@ -1226,8 +1200,8 @@ static void cpustats(void) { - int state, over; double lpct, total; + int state, over; total = 0; for (state = 0; state < CPUSTATES; ++state) @@ -1238,19 +1212,20 @@ lpct = 0.0; over = 0; xo_open_container("cpu-statistics"); - percent("user", (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * lpct, &over); - percent("system", (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * lpct, &over); + percent("user", (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * lpct, + &over); + percent("system", (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * lpct, + &over); percent("idle", cur.cp_time[CP_IDLE] * lpct, &over); xo_close_container("cpu-statistics"); } static void -pcpustats(int ncpus, u_long cpumask, int maxid) +pcpustats(u_long cpumask, int maxid) { - int state, i; double lpct, total; long tmp; - int over; + int i, over, state; /* devstats does this for cp_time */ for (i = 0; i <= maxid; i++) { @@ -1279,11 +1254,11 @@ else lpct = 0.0; percent("user", (cur_cp_times[i * CPUSTATES + CP_USER] + - cur_cp_times[i * CPUSTATES + CP_NICE]) * lpct, &over); + cur_cp_times[i * CPUSTATES + CP_NICE]) * lpct, &over); percent("system", (cur_cp_times[i * CPUSTATES + CP_SYS] + - cur_cp_times[i * CPUSTATES + CP_INTR]) * lpct, &over); + cur_cp_times[i * CPUSTATES + CP_INTR]) * lpct, &over); percent("idle", cur_cp_times[i * CPUSTATES + CP_IDLE] * lpct, - &over); + &over); xo_close_instance("cpu"); } xo_close_list("cpu"); @@ -1314,12 +1289,12 @@ static void print_intrcnts(unsigned long *intrcnts, unsigned long *old_intrcnts, - char *intrnames, unsigned int nintr, - size_t istrnamlen, long long period_ms) + char *intrnames, unsigned int nintr, size_t istrnamlen, long long period_ms) { unsigned long *intrcnt, *old_intrcnt; + char *intrname; uint64_t inttotal, old_inttotal, total_count, total_rate; - char* intrname; + unsigned long count, rate; unsigned int i; inttotal = 0; @@ -1328,15 +1303,12 @@ xo_open_list("interrupt"); for (i = 0, intrcnt=intrcnts, old_intrcnt=old_intrcnts; i < nintr; i++) { if (intrname[0] != '\0' && (*intrcnt != 0 || aflag)) { - unsigned long count, rate; - count = *intrcnt - *old_intrcnt; rate = (count * 1000 + period_ms / 2) / period_ms; xo_open_instance("interrupt"); xo_emit("{d:name/%-*s}{ket:name/%s} " "{:total/%20lu} {:rate/%10lu}\n", - (int)istrnamlen, intrname, - intrname, count, rate); + (int)istrnamlen, intrname, intrname, count, rate); xo_close_instance("interrupt"); } intrname += strlen(intrname) + 1; @@ -1346,20 +1318,21 @@ total_count = inttotal - old_inttotal; total_rate = (total_count * 1000 + period_ms / 2) / period_ms; xo_close_list("interrupt"); - xo_emit("{L:/%-*s} {:total-interrupts/%20" PRIu64 "} " - "{:total-rate/%10" PRIu64 "}\n", (int)istrnamlen, - "Total", total_count, total_rate); + xo_emit("{L:/%-*s} {:total-interrupts/%20ju} " + "{:total-rate/%10ju}\n", (int)istrnamlen, + "Total", (uintmax_t)total_count, (uintmax_t)total_rate); } static void dointr(unsigned int interval, int reps) { - unsigned long *intrcnts; - long long uptime, period_ms; - unsigned long *old_intrcnts = NULL; + unsigned long *intrcnts, *old_intrcnts; + char *intrname, *intrnames; + long long period_ms, old_uptime, uptime; size_t clen, inamlen, istrnamlen; - char *intrnames, *intrname; + unsigned int nintr; + old_intrcnts = NULL; uptime = getuptime(); /* Get the names of each interrupt source */ @@ -1387,7 +1360,7 @@ intrname += strlen(intrname) + 1; } xo_emit("{T:/%-*s} {T:/%20s} {T:/%10s}\n", - (int)istrnamlen, "interrupt", "total", "rate"); + (int)istrnamlen, "interrupt", "total", "rate"); /* * Loop reps times printing differential interrupt counts. If reps is @@ -1397,9 +1370,6 @@ period_ms = uptime / 1000000; while(1) { - unsigned int nintr; - long long old_uptime; - nintr = read_intrcnts(&intrcnts); /* * Initialize old_intrcnts to 0 for the first pass, so @@ -1459,7 +1429,7 @@ } xo_open_container("malloc-statistics"); xo_emit("{T:/%13s} {T:/%5s} {T:/%6s} {T:/%7s} {T:/%8s} {T:Size(s)}\n", - "Type", "InUse", "MemUse", "HighUse", "Requests"); + "Type", "InUse", "MemUse", "HighUse", "Requests"); xo_open_list("memory"); for (mtp = memstat_mtl_first(mtlp); mtp != NULL; mtp = memstat_mtl_next(mtp)) { @@ -1467,12 +1437,12 @@ memstat_get_count(mtp) == 0) continue; xo_open_instance("memory"); - xo_emit("{k:type/%13s/%s} {:in-use/%5" PRIu64 "} " - "{:memory-use/%5" PRIu64 "}{U:K} {:high-use/%7s} " - "{:requests/%8" PRIu64 "} ", - memstat_get_name(mtp), memstat_get_count(mtp), - (memstat_get_bytes(mtp) + 1023) / 1024, "-", - memstat_get_numallocs(mtp)); + xo_emit("{k:type/%13s/%s} {:in-use/%5ju} " + "{:memory-use/%5ju}{U:K} {:high-use/%7s} " + "{:requests/%8ju} ", + memstat_get_name(mtp), (uintmax_t)memstat_get_count(mtp), + ((uintmax_t)memstat_get_bytes(mtp) + 1023) / 1024, "-", + (uintmax_t)memstat_get_numallocs(mtp)); first = 1; xo_open_list("size"); for (i = 0; i < 32; i++) { @@ -1497,8 +1467,8 @@ { struct memory_type_list *mtlp; struct memory_type *mtp; - char name[MEMTYPE_MAXNAME + 1]; int error; + char name[MEMTYPE_MAXNAME + 1]; mtlp = memstat_mtl_alloc(); if (mtlp == NULL) { @@ -1524,23 +1494,26 @@ } xo_open_container("memory-zone-statistics"); xo_emit("{T:/%-20s} {T:/%6s} {T:/%6s} {T:/%8s} {T:/%8s} {T:/%8s} " - "{T:/%4s} {T:/%4s}\n\n", "ITEM", "SIZE", - "LIMIT", "USED", "FREE", "REQ", "FAIL", "SLEEP"); + "{T:/%4s} {T:/%4s}\n\n", "ITEM", "SIZE", + "LIMIT", "USED", "FREE", "REQ", "FAIL", "SLEEP"); xo_open_list("zone"); for (mtp = memstat_mtl_first(mtlp); mtp != NULL; mtp = memstat_mtl_next(mtp)) { strlcpy(name, memstat_get_name(mtp), MEMTYPE_MAXNAME); strcat(name, ":"); xo_open_instance("zone"); - xo_emit("{d:name/%-20s}{ke:name/%s} {:size/%6" PRIu64 "}, " - "{:limit/%6" PRIu64 "},{:used/%8" PRIu64 "}," - "{:free/%8" PRIu64 "},{:requests/%8" PRIu64 "}," - "{:fail/%4" PRIu64 "},{:sleep/%4" PRIu64 "}\n", name, - memstat_get_name(mtp), - memstat_get_size(mtp), memstat_get_countlimit(mtp), - memstat_get_count(mtp), memstat_get_free(mtp), - memstat_get_numallocs(mtp), memstat_get_failures(mtp), - memstat_get_sleeps(mtp)); + xo_emit("{d:name/%-20s}{ke:name/%s} {:size/%6ju}, " + "{:limit/%6ju},{:used/%8ju}," + "{:free/%8ju},{:requests/%8ju}," + "{:fail/%4ju},{:sleep/%4ju}\n", name, + memstat_get_name(mtp), + (uintmax_t)memstat_get_size(mtp), + (uintmax_t)memstat_get_countlimit(mtp), + (uintmax_t)memstat_get_count(mtp), + (uintmax_t)memstat_get_free(mtp), + (uintmax_t)memstat_get_numallocs(mtp), + (uintmax_t)memstat_get_failures(mtp), + (uintmax_t)memstat_get_sleeps(mtp)); xo_close_instance("zone"); } memstat_mtl_free(mtlp); @@ -1671,7 +1644,7 @@ return; } xo_emit("{T:RES/%5s} {T:ACT/%5s} {T:INACT/%5s} {T:REF/%3s} {T:SHD/%3s} " - "{T:CM/%3s} {T:TP/%2s} {T:PATH/%s}\n"); + "{T:CM/%3s} {T:TP/%2s} {T:PATH/%s}\n"); xo_open_list("object"); for (i = 0; i < cnt; i++) display_object(&kvo[i]); @@ -1705,34 +1678,16 @@ static void kread(int nlx, void *addr, size_t size) { + kreado(nlx, addr, size, 0); } -static char * -kgetstr(const char *strp) -{ - int n = 0, size = 1; - char *ret = NULL; - - do { - if (size == n + 1) { - ret = realloc(ret, size); - if (ret == NULL) - xo_err(1, "%s: realloc", __func__); - size *= 2; - } - if (kvm_read(kd, (u_long)strp + n, &ret[n], 1) != 1) - xo_errx(1, "%s: %s", __func__, kvm_geterr(kd)); - } while (ret[n++] != '\0'); - return (ret); -} - static void usage(void) { xo_error("%s%s", - "usage: vmstat [-afHhimoPsz] [-M core [-N system]] [-c count] [-n devs]\n", - " [-p type,if,pass] [-w wait] [disks] [wait [count]]\n"); + "usage: vmstat [-afHhimoPsz] [-M core [-N system]] [-c count] [-n devs]\n", + " [-p type,if,pass] [-w wait] [disks] [wait [count]]\n"); xo_finish(); exit(1); }