FreeBSD Bugzilla – Attachment 200735 Details for
Bug 213310
[patch] systat -zarc to display disk activities like -vm
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
devstat on zarc and swap pages
systat-dev.patch (text/plain), 24.96 KB, created by
ota
on 2019-01-03 05:07:10 UTC
(
hide
)
Description:
devstat on zarc and swap pages
Filename:
MIME Type:
Creator:
ota
Created:
2019-01-03 05:07:10 UTC
Size:
24.96 KB
patch
obsolete
>Index: usr.bin/systat/devs.c >=================================================================== >--- usr.bin/systat/devs.c (revision 342672) >+++ usr.bin/systat/devs.c (working copy) >@@ -2,6 +2,7 @@ > * SPDX-License-Identifier: BSD-3-Clause > * > * Copyright (c) 1998 Kenneth D. Merry. >+ * 2015 Yoshihiro Ota > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without >@@ -69,7 +70,6 @@ > #include <sys/resource.h> > > #include <ctype.h> >-#include <devstat.h> > #include <err.h> > #include <stdlib.h> > #include <string.h> >@@ -84,6 +84,8 @@ > DS_MATCHTYPE_PATTERN > } last_match_type; > >+struct statinfo cur_dev, last_dev, run_dev; >+ > last_match_type last_type; > struct device_selection *dev_select; > long generation; >@@ -101,10 +103,8 @@ > int maxshowdevs, struct statinfo *s1); > > int >-dsinit(int maxshowdevs, struct statinfo *s1, struct statinfo *s2 __unused, >- struct statinfo *s3 __unused) >+dsinit(int maxshowdevs) > { >- > /* > * Make sure that the userland devstat version matches the kernel > * devstat version. If not, exit and print a message informing >@@ -113,6 +113,18 @@ > if (devstat_checkversion(NULL) < 0) > errx(1, "%s", devstat_errbuf); > >+ if( cur_dev.dinfo ) // init was alreay ran >+ return(1); >+ >+ if ((num_devices = devstat_getnumdevs(NULL)) < 0) { >+ warnx("%s", devstat_errbuf); >+ return(0); >+ } >+ >+ cur_dev.dinfo = calloc(1, sizeof(struct devinfo)); >+ last_dev.dinfo = calloc(1, sizeof(struct devinfo)); >+ run_dev.dinfo = calloc(1, sizeof(struct devinfo)); >+ > generation = 0; > num_devices = 0; > num_selected = 0; >@@ -120,11 +132,11 @@ > select_generation = 0; > last_type = DS_MATCHTYPE_NONE; > >- if (devstat_getdevs(NULL, s1) == -1) >+ if (devstat_getdevs(NULL, &cur_dev) == -1) > errx(1, "%s", devstat_errbuf); > >- num_devices = s1->dinfo->numdevs; >- generation = s1->dinfo->generation; >+ num_devices = cur_dev.dinfo->numdevs; >+ generation = cur_dev.dinfo->generation; > > dev_select = NULL; > >@@ -134,7 +146,7 @@ > * or 1. If we get back -1, though, there is an error. > */ > if (devstat_selectdevs(&dev_select, &num_selected, &num_selections, >- &select_generation, generation, s1->dinfo->devices, num_devices, >+ &select_generation, generation, cur_dev.dinfo->devices, num_devices, > NULL, 0, NULL, 0, DS_SELECT_ADD, maxshowdevs, 0) == -1) > errx(1, "%d %s", __LINE__, devstat_errbuf); > >@@ -141,6 +153,24 @@ > return(1); > } > >+ >+void >+dsgetinfo(struct statinfo* dev) >+{ >+ switch (devstat_getdevs(NULL, dev)) { >+ case -1: >+ errx(1, "%s", devstat_errbuf); >+ break; >+ case 1: >+ num_devices = dev->dinfo->numdevs; >+ generation = dev->dinfo->generation; >+ cmdkre("refresh", NULL); >+ break; >+ default: >+ break; >+ } >+} >+ > int > dscmd(const char *cmd, const char *args, int maxshowdevs, struct statinfo *s1) > { >@@ -321,3 +351,83 @@ > } > return(1); > } >+ >+ >+void >+dslabel(int maxdrives, int diskcol, int diskrow) >+{ >+ int i, j; >+ >+ mvprintw(diskrow, diskcol, "Disks"); >+ mvprintw(diskrow + 1, diskcol, "KB/t"); >+ mvprintw(diskrow + 2, diskcol, "tps"); >+ mvprintw(diskrow + 3, diskcol, "MB/s"); >+ mvprintw(diskrow + 4, diskcol, "%%busy"); >+ /* >+ * For now, we don't support a fourth disk statistic. So there's >+ * no point in providing a label for it. If someone can think of a >+ * fourth useful disk statistic, there is room to add it. >+ */ >+ /* mvprintw(diskrow + 4, diskcol, " msps"); */ >+ j = 0; >+ for (i = 0; i < num_devices && j < maxdrives; i++) >+ if (dev_select[i].selected) { >+ char tmpstr[80]; >+ sprintf(tmpstr, "%s%d", dev_select[i].device_name, >+ dev_select[i].unit_number); >+ mvprintw(diskrow, diskcol + 5 + 6 * j, >+ " %5.5s", tmpstr); >+ j++; >+ } >+} >+ >+static void >+dsshow2(int diskcol, int diskrow, int dn, int lc, struct statinfo *now, struct statinfo *then) >+{ >+ long double transfers_per_second; >+ long double kb_per_transfer, mb_per_second; >+ long double elapsed_time, device_busy; >+ int di; >+ >+ di = dev_select[dn].position; >+ >+ if (then != NULL) { >+ /* Calculate relative to previous sample */ >+ elapsed_time = now->snap_time - then->snap_time; >+ } else { >+ /* Calculate relative to device creation */ >+ elapsed_time = now->snap_time - devstat_compute_etime( >+ &now->dinfo->devices[di].creation_time, NULL); >+ } >+ >+ if (devstat_compute_statistics(&now->dinfo->devices[di], then ? >+ &then->dinfo->devices[di] : NULL, elapsed_time, >+ DSM_KB_PER_TRANSFER, &kb_per_transfer, >+ DSM_TRANSFERS_PER_SECOND, &transfers_per_second, >+ DSM_MB_PER_SECOND, &mb_per_second, >+ DSM_BUSY_PCT, &device_busy, >+ DSM_NONE) != 0) >+ errx(1, "%s", devstat_errbuf); >+ >+ lc = diskcol + lc * 6; >+ putlongdouble(kb_per_transfer, diskrow + 1, lc, 5, 2, 0); >+ putlongdouble(transfers_per_second, diskrow + 2, lc, 5, 0, 0); >+ putlongdouble(mb_per_second, diskrow + 3, lc, 5, 2, 0); >+ putlongdouble(device_busy, diskrow + 4, lc, 5, 0, 0); >+} >+ >+static void >+dsshow3(int diskcol, int diskrow, int dn, int lc, struct statinfo *now, struct statinfo *then) >+{ >+ dsshow2(diskcol, diskrow, dn, lc, now, then); >+} >+ >+void >+dsshow(int maxdrives, int diskcol, int diskrow, struct statinfo *now, struct statinfo *then) >+{ >+ int i, lc; >+ >+ for (i = 0, lc = 0; i < num_devices && lc < maxdrives; i++) >+ if (dev_select[i].selected) >+ dsshow3(diskcol, diskrow, i, ++lc, now, then); >+} >Index: usr.bin/systat/devs.h >=================================================================== >--- usr.bin/systat/devs.h (revision 342672) >+++ usr.bin/systat/devs.h (working copy) >@@ -2,6 +2,7 @@ > * SPDX-License-Identifier: BSD-2-Clause-FreeBSD > * > * Copyright (c) 1998 David E. O'Brien >+ * 2015 Yoshihiro Ota > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without >@@ -28,5 +29,18 @@ > * $FreeBSD$ > */ > >-int dsinit(int, struct statinfo *, struct statinfo *, struct statinfo *); >+#ifndef DEVS_H >+#define DEVS_H >+ >+#include <devstat.h> >+ >+int dsinit(int); >+void dsgetinfo(struct statinfo *); > int dscmd(const char *, const char *, int, struct statinfo *); >+ >+void dslabel(int, int, int); >+void dsshow(int, int, int, struct statinfo *, struct statinfo *); >+ >+extern struct statinfo cur_dev, last_dev, run_dev; >+ >+#endif >Index: usr.bin/systat/iostat.c >=================================================================== >--- usr.bin/systat/iostat.c (revision 342672) >+++ usr.bin/systat/iostat.c (working copy) >@@ -79,8 +79,6 @@ > #include "extern.h" > #include "devs.h" > >-struct statinfo cur, last; >- > static int linesperregion; > static double etime; > static int numbers = 0; /* default display bar graphs */ >@@ -111,17 +109,11 @@ > int > initiostat(void) > { >- if ((num_devices = devstat_getnumdevs(NULL)) < 0) >- return(0); >- >- cur.dinfo = calloc(1, sizeof(struct devinfo)); >- last.dinfo = calloc(1, sizeof(struct devinfo)); >- > /* > * This value for maxshowdevs (100) is bogus. I'm not sure exactly > * how to calculate it, though. > */ >- if (dsinit(100, &cur, &last, NULL) != 1) >+ if (dsinit(7) != 1) > return(0); > > return(1); >@@ -133,17 +125,17 @@ > struct devinfo *tmp_dinfo; > size_t len; > >- len = sizeof(cur.cp_time); >- if (sysctlbyname("kern.cp_time", &cur.cp_time, &len, NULL, 0) >- || len != sizeof(cur.cp_time)) { >+ len = sizeof(cur_dev.cp_time); >+ if (sysctlbyname("kern.cp_time", &cur_dev.cp_time, &len, NULL, 0) >+ || len != sizeof(cur_dev.cp_time)) { > perror("kern.cp_time"); > exit (1); > } >- tmp_dinfo = last.dinfo; >- last.dinfo = cur.dinfo; >- cur.dinfo = tmp_dinfo; >+ tmp_dinfo = last_dev.dinfo; >+ last_dev.dinfo = cur_dev.dinfo; >+ cur_dev.dinfo = tmp_dinfo; > >- last.snap_time = cur.snap_time; >+ last_dev.snap_time = cur_dev.snap_time; > > /* > * Here what we want to do is refresh our device stats. >@@ -152,7 +144,7 @@ > * the selection process again, in case a device that we > * were previously displaying has gone away. > */ >- switch (devstat_getdevs(NULL, &cur)) { >+ switch (devstat_getdevs(NULL, &cur_dev)) { > case -1: > errx(1, "%s", devstat_errbuf); > break; >@@ -162,8 +154,8 @@ > default: > break; > } >- num_devices = cur.dinfo->numdevs; >- generation = cur.dinfo->generation; >+ num_devices = cur_dev.dinfo->numdevs; >+ generation = cur_dev.dinfo->generation; > > } > >@@ -260,11 +252,11 @@ > long t; > int i, row, _col; > >-#define X(fld) t = cur.fld[i]; cur.fld[i] -= last.fld[i]; last.fld[i] = t >+#define X(fld) t = cur_dev.fld[i]; cur_dev.fld[i] -= last_dev.fld[i]; last_dev.fld[i] = t > etime = 0; > for(i = 0; i < CPUSTATES; i++) { > X(cp_time); >- etime += cur.cp_time[i]; >+ etime += cur_dev.cp_time[i]; > } > if (etime == 0.0) > etime = 1.0; >@@ -313,10 +305,10 @@ > > di = dev_select[dn].position; > >- busy_seconds = cur.snap_time - last.snap_time; >+ busy_seconds = cur_dev.snap_time - last_dev.snap_time; > >- if (devstat_compute_statistics(&cur.dinfo->devices[di], >- &last.dinfo->devices[di], busy_seconds, >+ if (devstat_compute_statistics(&cur_dev.dinfo->devices[di], >+ &last_dev.dinfo->devices[di], busy_seconds, > DSM_KB_PER_TRANSFER, &kb_per_transfer, > DSM_TRANSFERS_PER_SECOND, &transfers_per_second, > DSM_MB_PER_SECOND, &mb_per_second, DSM_NONE) != 0) >@@ -349,12 +341,12 @@ > > dtime = 0.0; > for (i = 0; i < CPUSTATES; i++) >- dtime += cur.cp_time[i]; >+ dtime += cur_dev.cp_time[i]; > if (dtime == 0.0) > dtime = 1.0; > wmove(wnd, row, INSET); > #define CPUSCALE 0.5 >- histogram(100.0 * cur.cp_time[o] / dtime, 50, CPUSCALE); >+ histogram(100.0 * cur_dev.cp_time[o] / dtime, 50, CPUSCALE); > } > > static void >@@ -388,7 +380,7 @@ > numbers = 1; > else if (prefix(cmd, "bars")) > numbers = 0; >- else if (!dscmd(cmd, args, 100, &cur)) >+ else if (!dscmd(cmd, args, 100, &cur_dev)) > return (0); > wclear(wnd); > labeliostat(); >Index: usr.bin/systat/swap.c >=================================================================== >--- usr.bin/systat/swap.c (revision 342672) >+++ usr.bin/systat/swap.c (working copy) >@@ -3,6 +3,7 @@ > * > * Copyright (c) 1980, 1992, 1993 > * The Regents of the University of California. All rights reserved. >+ * Copyright (c) 2017 Yoshihiro Ota > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions >@@ -55,6 +56,7 @@ > > #include "systat.h" > #include "extern.h" >+#include "devs.h" > > kvm_t *kd; > >@@ -63,7 +65,11 @@ > static int dlen, odlen; > static int hlen; > static int ulen, oulen; >+static int voffset = 2; >+ >+/* constants after booting */ > static int pagesize; >+static unsigned long swap_maxpages; > > WINDOW * > openswap(void) >@@ -91,6 +97,7 @@ > > static struct kvm_swap kvmsw[NSWAP]; > static int kvnsw, okvnsw; >+static int64_t swap_total; > > static void calclens(void); > >@@ -125,6 +132,7 @@ > > header = getbsize(&hlen, &blocksize); > pagesize = getpagesize(); >+ GETSYSCTL("vm.swap_maxpages", swap_maxpages); > > if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) { > error("systat: kvm_getswapinfo failed"); >@@ -137,6 +145,9 @@ > oulen = ulen; > > once = 1; >+ >+ dsinit(12); >+ > return (1); > } > >@@ -143,16 +154,25 @@ > void > fetchswap(void) > { >- > okvnsw = kvnsw; > if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) { > error("systat: kvm_getswapinfo failed"); > return; > } >+ GETSYSCTL("vm.swap_total", swap_total); > > odlen = dlen; > oulen = ulen; > calclens(); >+ >+ struct devinfo *tmp_dinfo; >+ >+ tmp_dinfo = last_dev.dinfo; >+ last_dev.dinfo = cur_dev.dinfo; >+ cur_dev.dinfo = tmp_dinfo; >+ >+ last_dev.snap_time = cur_dev.snap_time; >+ dsgetinfo( &cur_dev ); > } > > void >@@ -165,7 +185,10 @@ > > werase(wnd); > >- mvwprintw(wnd, 0, 0, "%*s%*s%*s %s", >+ mvwprintw(wnd, 0, 0, "swap_maxpages: %ld", swap_maxpages); >+ mvwprintw(wnd, 0, 40, "swap_total: %ld", swap_total / 1024); >+ >+ mvwprintw(wnd, voffset + 0, 0, "%*s%*s%*s %s", > -dlen, "Disk", hlen, header, ulen, "Used", > "/0% /10 /20 /30 /40 /50 /60 /70 /80 /90 /100"); > >@@ -176,8 +199,9 @@ > name = "Total"; > } else > name = kvmsw[i].ksw_devname; >- mvwprintw(wnd, i + 1, 0, "%*s", -dlen, name); >+ mvwprintw(wnd, voffset + i + 1, 0, "%*s", -dlen, name); > } >+ dslabel(12, 0, 18); > } > > void >@@ -198,7 +222,7 @@ > if (kvmsw[i].ksw_total == 0) { > mvwprintw( > wnd, >- i + 1, >+ voffset + i + 1, > dlen + hlen + ulen + 1, > "(swap not configured)" > ); >@@ -205,7 +229,7 @@ > continue; > } > >- wmove(wnd, i + 1, dlen); >+ wmove(wnd, voffset + i + 1, dlen); > > wprintw(wnd, "%*d", hlen, CONVERT(kvmsw[i].ksw_total)); > wprintw(wnd, "%*d", ulen, CONVERT(kvmsw[i].ksw_used)); >@@ -217,4 +241,5 @@ > waddch(wnd, 'X'); > wclrtoeol(wnd); > } >+ dsshow(12, 0, 18, &cur_dev, &last_dev); > } >Index: usr.bin/systat/systat.h >=================================================================== >--- usr.bin/systat/systat.h (revision 342672) >+++ usr.bin/systat/systat.h (working copy) >@@ -68,3 +68,7 @@ > #define NVAL(indx) namelist[(indx)].n_value > #define NPTR(indx) (void *)NVAL((indx)) > #define NREAD(indx, buf, len) kvm_ckread(NPTR((indx)), (buf), (len)) >+ >+extern void putint(int, int, int, int); >+extern void putfloat(double, int, int, int, int, int); >+extern void putlongdouble(long double, int, int, int, int, int); >Index: usr.bin/systat/vmstat.c >=================================================================== >--- usr.bin/systat/vmstat.c (revision 342672) >+++ usr.bin/systat/vmstat.c (working copy) >@@ -66,7 +66,6 @@ > #include <time.h> > #include <unistd.h> > #include <utmpx.h> >-#include <devstat.h> > #include "systat.h" > #include "extern.h" > #include "devs.h" >@@ -125,7 +124,6 @@ > static u_long kmem_size; > static u_int v_page_count; > >-struct statinfo cur, last, run; > > #define total s.Total > #define nchtotal s.nchstats >@@ -137,13 +135,9 @@ > static void allocinfo(struct Info *); > static void copyinfo(struct Info *, struct Info *); > static float cputime(int); >-static void dinfo(int, int, struct statinfo *, struct statinfo *); > static void do_putuint64(uint64_t, int, int, int, int); > static void getinfo(struct Info *); >-static void putint(int, int, int, int); > static void putuint64(uint64_t, int, int, int); >-static void putfloat(double, int, int, int, int, int); >-static void putlongdouble(long double, int, int, int, int, int); > static int ucount(void); > > static int ncpu; >@@ -209,18 +203,9 @@ > int i; > size_t sz; > >- if ((num_devices = devstat_getnumdevs(NULL)) < 0) { >- warnx("%s", devstat_errbuf); >+ if (dsinit(MAXDRIVES) != 1) > return(0); >- } > >- cur.dinfo = calloc(1, sizeof(struct devinfo)); >- last.dinfo = calloc(1, sizeof(struct devinfo)); >- run.dinfo = calloc(1, sizeof(struct devinfo)); >- >- if (dsinit(MAXDRIVES, &cur, &last, &run) != 1) >- return(0); >- > if (nintr == 0) { > if (sysctlbyname("hw.intrcnt", NULL, &sz, NULL, 0) == -1) { > error("sysctl(hw.intrcnt...) failed: %s", >@@ -318,7 +303,7 @@ > > clear(); > mvprintw(STATROW, STATCOL + 6, "users Load"); >- mvprintw(STATROW + 1, STATCOL + 3, "Mem usage: %%Phy %%Kmem"); >+ mvprintw(STATROW + 1, STATCOL + 3, "Mem usage: %%Phy %%Kmem %%VM"); > mvprintw(MEMROW, MEMCOL, "Mem: KB REAL VIRTUAL"); > mvprintw(MEMROW + 1, MEMCOL, " Tot Share Tot Share"); > mvprintw(MEMROW + 2, MEMCOL, "Act"); >@@ -371,27 +356,7 @@ > mvprintw(NAMEIROW, NAMEICOL, "Namei Name-cache Dir-cache"); > mvprintw(NAMEIROW + 1, NAMEICOL, > " Calls hits %% hits %%"); >- mvprintw(DISKROW, DISKCOL, "Disks"); >- mvprintw(DISKROW + 1, DISKCOL, "KB/t"); >- mvprintw(DISKROW + 2, DISKCOL, "tps"); >- mvprintw(DISKROW + 3, DISKCOL, "MB/s"); >- mvprintw(DISKROW + 4, DISKCOL, "%%busy"); >- /* >- * For now, we don't support a fourth disk statistic. So there's >- * no point in providing a label for it. If someone can think of a >- * fourth useful disk statistic, there is room to add it. >- */ >- /* mvprintw(DISKROW + 4, DISKCOL, " msps"); */ >- j = 0; >- for (i = 0; i < num_devices && j < MAXDRIVES; i++) >- if (dev_select[i].selected) { >- char tmpstr[80]; >- sprintf(tmpstr, "%s%d", dev_select[i].device_name, >- dev_select[i].unit_number); >- mvprintw(DISKROW, DISKCOL + 5 + 6 * j, >- " %5.5s", tmpstr); >- j++; >- } >+ dslabel(MAXDRIVES, DISKCOL, DISKROW); > > for (i = 0; i < nintr; i++) { > if (intrloc[i] == 0) >@@ -401,7 +366,7 @@ > } > > #define X(fld) {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;} >-#define Q(fld) {t=cur.fld[i]; cur.fld[i]-=last.fld[i]; if(state==TIME) last.fld[i]=t;} >+#define Q(fld) {t=cur_dev.fld[i]; cur_dev.fld[i]-=last_dev.fld[i]; if(state==TIME) last_dev.fld[i]=t;} > #define Y(fld) {t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;} > #define Z(fld) {t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \ > if(state == TIME) s1.nchstats.fld = t;} >@@ -494,6 +459,8 @@ > STATROW + 1, STATCOL + 15, 2, 0, 1); > putfloat(100.0 * s.v_kmem_map_size / kmem_size, > STATROW + 1, STATCOL + 22, 2, 0, 1); >+ putfloat(100.0 * total.t_avm / total.t_vm, >+ STATROW + 1, STATCOL + 30, 2, 0, 1); > > putuint64(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7); > putuint64(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7); >@@ -543,20 +510,17 @@ > PUTRATE(v_intr, GENSTATROW + 1, GENSTATCOL + 15, 4); > PUTRATE(v_soft, GENSTATROW + 1, GENSTATCOL + 20, 4); > PUTRATE(v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 4); >- for (i = 0, lc = 0; i < num_devices && lc < MAXDRIVES; i++) >- if (dev_select[i].selected) { >- switch(state) { >- case TIME: >- dinfo(i, ++lc, &cur, &last); >- break; >- case RUN: >- dinfo(i, ++lc, &cur, &run); >- break; >- case BOOT: >- dinfo(i, ++lc, &cur, NULL); >- break; >- } >- } >+ switch(state) { >+ case TIME: >+ dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, &last_dev); >+ break; >+ case RUN: >+ dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, &run_dev); >+ break; >+ case BOOT: >+ dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, NULL); >+ break; >+ } > putint(s.numdirtybuffers, VNSTATROW, VNSTATCOL, 7); > putint(s.desiredvnodes, VNSTATROW + 1, VNSTATCOL, 7); > putint(s.numvnodes, VNSTATROW + 2, VNSTATCOL, 7); >@@ -582,14 +546,14 @@ > if (prefix(cmd, "run")) { > retval = 1; > copyinfo(&s2, &s1); >- switch (devstat_getdevs(NULL, &run)) { >+ switch (devstat_getdevs(NULL, &run_dev)) { > case -1: > errx(1, "%s", devstat_errbuf); > break; > case 1: >- num_devices = run.dinfo->numdevs; >- generation = run.dinfo->generation; >- retval = dscmd("refresh", NULL, MAXDRIVES, &cur); >+ num_devices = run_dev.dinfo->numdevs; >+ generation = run_dev.dinfo->generation; >+ retval = dscmd("refresh", NULL, MAXDRIVES, &cur_dev); > if (retval == 2) > labelkre(); > break; >@@ -612,14 +576,14 @@ > retval = 1; > if (state == RUN) { > getinfo(&s1); >- switch (devstat_getdevs(NULL, &run)) { >+ switch (devstat_getdevs(NULL, &run_dev)) { > case -1: > errx(1, "%s", devstat_errbuf); > break; > case 1: >- num_devices = run.dinfo->numdevs; >- generation = run.dinfo->generation; >- retval = dscmd("refresh",NULL, MAXDRIVES, &cur); >+ num_devices = run_dev.dinfo->numdevs; >+ generation = run_dev.dinfo->generation; >+ retval = dscmd("refresh",NULL, MAXDRIVES, &cur_dev); > if (retval == 2) > labelkre(); > break; >@@ -629,7 +593,7 @@ > } > return (retval); > } >- retval = dscmd(cmd, args, MAXDRIVES, &cur); >+ retval = dscmd(cmd, args, MAXDRIVES, &cur_dev); > > if (retval == 2) > labelkre(); >@@ -667,7 +631,7 @@ > return (s.time[indx] * 100.0 / lt); > } > >-static void >+void > putint(int n, int l, int lc, int w) > { > >@@ -713,7 +677,7 @@ > addstr(b); > } > >-static void >+void > putfloat(double f, int l, int lc, int w, int d, int nz) > { > int snr; >@@ -745,7 +709,7 @@ > addstr(b); > } > >-static void >+void > putlongdouble(long double f, int l, int lc, int w, int d, int nz) > { > int snr; >@@ -785,7 +749,7 @@ > int mib[2]; > > GETSYSCTL("kern.cp_time", ls->time); >- GETSYSCTL("kern.cp_time", cur.cp_time); >+ GETSYSCTL("kern.cp_time", cur_dev.cp_time); > GETSYSCTL("vm.stats.sys.v_swtch", ls->v_swtch); > GETSYSCTL("vm.stats.sys.v_trap", ls->v_trap); > GETSYSCTL("vm.stats.sys.v_syscall", ls->v_syscall); >@@ -838,23 +802,12 @@ > size != sizeof(ncpu)) > ncpu = 1; > >- tmp_dinfo = last.dinfo; >- last.dinfo = cur.dinfo; >- cur.dinfo = tmp_dinfo; >+ tmp_dinfo = last_dev.dinfo; >+ last_dev.dinfo = cur_dev.dinfo; >+ cur_dev.dinfo = tmp_dinfo; > >- last.snap_time = cur.snap_time; >- switch (devstat_getdevs(NULL, &cur)) { >- case -1: >- errx(1, "%s", devstat_errbuf); >- break; >- case 1: >- num_devices = cur.dinfo->numdevs; >- generation = cur.dinfo->generation; >- cmdkre("refresh", NULL); >- break; >- default: >- break; >- } >+ last_dev.snap_time = cur_dev.snap_time; >+ dsgetinfo(&cur_dev); > } > > static void >@@ -881,38 +834,3 @@ > > bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int)); > } >- >-static void >-dinfo(int dn, int lc, struct statinfo *now, struct statinfo *then) >-{ >- long double transfers_per_second; >- long double kb_per_transfer, mb_per_second; >- long double elapsed_time, device_busy; >- int di; >- >- di = dev_select[dn].position; >- >- if (then != NULL) { >- /* Calculate relative to previous sample */ >- elapsed_time = now->snap_time - then->snap_time; >- } else { >- /* Calculate relative to device creation */ >- elapsed_time = now->snap_time - devstat_compute_etime( >- &now->dinfo->devices[di].creation_time, NULL); >- } >- >- if (devstat_compute_statistics(&now->dinfo->devices[di], then ? >- &then->dinfo->devices[di] : NULL, elapsed_time, >- DSM_KB_PER_TRANSFER, &kb_per_transfer, >- DSM_TRANSFERS_PER_SECOND, &transfers_per_second, >- DSM_MB_PER_SECOND, &mb_per_second, >- DSM_BUSY_PCT, &device_busy, >- DSM_NONE) != 0) >- errx(1, "%s", devstat_errbuf); >- >- lc = DISKCOL + lc * 6; >- putlongdouble(kb_per_transfer, DISKROW + 1, lc, 5, 2, 0); >- putlongdouble(transfers_per_second, DISKROW + 2, lc, 5, 0, 0); >- putlongdouble(mb_per_second, DISKROW + 3, lc, 5, 2, 0); >- putlongdouble(device_busy, DISKROW + 4, lc, 5, 0, 0); >-} >Index: usr.bin/systat/zarc.c >=================================================================== >--- usr.bin/systat/zarc.c (revision 342672) >+++ usr.bin/systat/zarc.c (working copy) >@@ -1,6 +1,5 @@ > /*- >- * Copyright (c) 2014 >- * The Regents of the University of California. All rights reserved. >+ * Copyright (c) 2014 - 2017 Yoshihiro Ota > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions >@@ -33,11 +32,14 @@ > #include <sys/types.h> > #include <sys/sysctl.h> > >+/* #include <stdlib.h> */ > #include <inttypes.h> > #include <string.h> >+#include <err.h> > > #include "systat.h" > #include "extern.h" >+#include "devs.h" > > struct zfield{ > uint64_t arcstats; >@@ -77,21 +79,23 @@ > void > labelzarc(void) > { >+ int row = 1; > wmove(wnd, 0, 0); wclrtoeol(wnd); > mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s", > "rate", "hits", "misses", "total hits", "total misses"); >-#define L(row, str) mvwprintw(wnd, row, 5, str); \ >+#define L(str) mvwprintw(wnd, row, 5, #str); \ > mvwprintw(wnd, row, 31, ":"); \ >- mvwprintw(wnd, row, 31+4, "%%") >- L(1, "arcstats"); >- L(2, "arcstats.demand_data"); >- L(3, "arcstats.demand_metadata"); >- L(4, "arcstats.prefetch_data"); >- L(5, "arcstats.prefetch_metadata"); >- L(6, "zfetchstats"); >- L(7, "arcstats.l2"); >- L(8, "vdev_cache_stats"); >+ mvwprintw(wnd, row, 31+4, "%%"); ++row >+ L(arcstats); >+ L(arcstats.demand_data); >+ L(arcstats.demand_metadata); >+ L(arcstats.prefetch_data); >+ L(arcstats.prefetch_metadata); >+ L(zfetchstats); >+ L(arcstats.l2); >+ L(vdev_cache_stats); > #undef L >+ dslabel(12, 0, 18); > } > > static int calc(uint64_t hits, uint64_t misses) >@@ -131,6 +135,7 @@ > void > showzarc(void) > { >+ int row = 1; > struct zarcstats delta, rate; > > memset(&delta, 0, sizeof delta); >@@ -138,34 +143,37 @@ > > domode(&delta, &rate); > >-#define DO(stat, row, col, fmt) \ >+#define DO(stat, col, fmt) \ > mvwprintw(wnd, row, col, fmt, stat) >-#define R(row, stat) DO(rate.hits.stat, row, 31+1, "%3"PRIu64) >-#define H(row, stat) DO(delta.hits.stat, row, 31+1+5, "%7"PRIu64); \ >- DO(curstat.hits.stat, row, 31+1+5+8+8, "%12"PRIu64) >-#define M(row, stat) DO(delta.misses.stat, row, 31+1+5+8, "%7"PRIu64); \ >- DO(curstat.misses.stat, row, 31+1+5+8+8+13, "%12"PRIu64) >-#define E(row, stat) R(row, stat); H(row, stat); M(row, stat); >- E(1, arcstats); >- E(2, arcstats_demand_data); >- E(3, arcstats_demand_metadata); >- E(4, arcstats_prefetch_data); >- E(5, arcstats_prefetch_metadata); >- E(6, zfetchstats); >- E(7, arcstats_l2); >- E(8, vdev_cache_stats); >+#define R(stat) DO(rate.hits.stat, 31+1, "%3"PRIu64) >+#define H(stat) DO(delta.hits.stat, 31+1+5, "%7"PRIu64); \ >+ DO(curstat.hits.stat, 31+1+5+8+8, "%12"PRIu64) >+#define M(stat) DO(delta.misses.stat, 31+1+5+8, "%7"PRIu64); \ >+ DO(curstat.misses.stat, 31+1+5+8+8+13, "%12"PRIu64) >+#define E(stat) R(stat); H(stat); M(stat); ++row >+ E(arcstats); >+ E(arcstats_demand_data); >+ E(arcstats_demand_metadata); >+ E(arcstats_prefetch_data); >+ E(arcstats_prefetch_metadata); >+ E(zfetchstats); >+ E(arcstats_l2); >+ E(vdev_cache_stats); > #undef DO > #undef E > #undef M > #undef H > #undef R >+ dsshow(12, 0, 18, &cur_dev, &last_dev); > } > > int > initzarc(void) > { >+ dsinit(12); > getinfo(&initstat); > curstat = oldstat = initstat; >+ > return 1; > } > >@@ -178,6 +186,15 @@ > static void > getinfo(struct zarcstats *ls) > { >+ struct devinfo *tmp_dinfo; >+ >+ tmp_dinfo = last_dev.dinfo; >+ last_dev.dinfo = cur_dev.dinfo; >+ cur_dev.dinfo = tmp_dinfo; >+ >+ last_dev.snap_time = cur_dev.snap_time; >+ dsgetinfo( &cur_dev ); >+ > size_t size = sizeof( ls->hits.arcstats ); > if ( sysctlbyname("kstat.zfs.misc.arcstats.hits", > &ls->hits.arcstats, &size, NULL, 0 ) != 0 )
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 213310
:
175531
|
200735
|
200757