FreeBSD Bugzilla – Attachment 175531 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]
patch to display dev activities on zarc screen
systat-devstat-on-zarc.diff (text/plain), 16.57 KB, created by
ota
on 2016-10-08 16:21:32 UTC
(
hide
)
Description:
patch to display dev activities on zarc screen
Filename:
MIME Type:
Creator:
ota
Created:
2016-10-08 16:21:32 UTC
Size:
16.57 KB
patch
obsolete
>Index: devs.c >=================================================================== >--- devs.c (revision 306437) >+++ devs.c (working copy) >@@ -1,5 +1,6 @@ > /* > * Copyright (c) 1998 Kenneth D. Merry. >+ * 2015 Yoshihiro Ota > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without >@@ -67,7 +68,6 @@ > #include <sys/resource.h> > > #include <ctype.h> >-#include <devstat.h> > #include <err.h> > #include <stdlib.h> > #include <string.h> >@@ -82,6 +82,8 @@ > DS_MATCHTYPE_PATTERN > } last_match_type; > >+struct statinfo cur, last, run; >+ > last_match_type last_type; > struct device_selection *dev_select; > long generation; >@@ -99,10 +101,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 >@@ -111,6 +111,18 @@ > if (devstat_checkversion(NULL) < 0) > errx(1, "%s", devstat_errbuf); > >+ if( cur.dinfo ) // init was alreay ran >+ return(1); >+ >+ if ((num_devices = devstat_getnumdevs(NULL)) < 0) { >+ warnx("%s", devstat_errbuf); >+ return(0); >+ } >+ >+ cur.dinfo = calloc(1, sizeof(struct devinfo)); >+ last.dinfo = calloc(1, sizeof(struct devinfo)); >+ run.dinfo = calloc(1, sizeof(struct devinfo)); >+ > generation = 0; > num_devices = 0; > num_selected = 0; >@@ -118,11 +130,11 @@ > select_generation = 0; > last_type = DS_MATCHTYPE_NONE; > >- if (devstat_getdevs(NULL, s1) == -1) >+ if (devstat_getdevs(NULL, &cur) == -1) > errx(1, "%s", devstat_errbuf); > >- num_devices = s1->dinfo->numdevs; >- generation = s1->dinfo->generation; >+ num_devices = cur.dinfo->numdevs; >+ generation = cur.dinfo->generation; > > dev_select = NULL; > >@@ -132,7 +144,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.dinfo->devices, num_devices, > NULL, 0, NULL, 0, DS_SELECT_ADD, maxshowdevs, 0) == -1) > errx(1, "%d %s", __LINE__, devstat_errbuf); > >@@ -139,6 +151,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) > { >@@ -319,3 +349,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: devs.h >=================================================================== >--- devs.h (revision 306437) >+++ devs.h (working copy) >@@ -1,5 +1,6 @@ > /*- > * Copyright (c) 1998 David E. O'Brien >+ * 2015 Yoshihiro Ota > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without >@@ -26,5 +27,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, last, run; >+ >+#endif >Index: iostat.c >=================================================================== >--- iostat.c (revision 306437) >+++ iostat.c (working copy) >@@ -77,8 +77,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 */ >@@ -109,17 +107,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(100) != 1) > return(0); > > return(1); >Index: systat.h >=================================================================== >--- systat.h (revision 306437) >+++ systat.h (working copy) >@@ -66,3 +66,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: vmstat.c >=================================================================== >--- vmstat.c (revision 306437) >+++ vmstat.c (working copy) >@@ -63,7 +63,6 @@ > #include <time.h> > #include <unistd.h> > #include <utmpx.h> >-#include <devstat.h> > #include "systat.h" > #include "extern.h" > #include "devs.h" >@@ -122,7 +121,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 >@@ -133,11 +131,7 @@ > 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 getinfo(struct Info *); >-static void putint(int, 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; >@@ -203,18 +197,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", >@@ -312,7 +297,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"); >@@ -365,27 +350,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) >@@ -488,6 +453,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); > > putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7); > putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7); >@@ -537,20 +504,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, &last); >+ break; >+ case RUN: >+ dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur, &run); >+ break; >+ case BOOT: >+ dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur, NULL); >+ break; >+ } > putint(s.numdirtybuffers, VNSTATROW, VNSTATCOL, 7); > putint(s.desiredvnodes, VNSTATROW + 1, VNSTATCOL, 7); > putint(s.numvnodes, VNSTATROW + 2, VNSTATCOL, 7); >@@ -661,7 +625,7 @@ > return (s.time[indx] * 100.0 / lt); > } > >-static void >+void > putint(int n, int l, int lc, int w) > { > int snr; >@@ -691,7 +655,7 @@ > addstr(b); > } > >-static void >+void > putfloat(double f, int l, int lc, int w, int d, int nz) > { > int snr; >@@ -723,7 +687,7 @@ > addstr(b); > } > >-static void >+void > putlongdouble(long double f, int l, int lc, int w, int d, int nz) > { > int snr; >@@ -821,18 +785,7 @@ > cur.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; >- } >+ dsgetinfo(&cur); > } > > static void >@@ -859,38 +812,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: zarc.c >=================================================================== >--- zarc.c (revision 306437) >+++ zarc.c (working copy) >@@ -1,6 +1,5 @@ > /*- >- * Copyright (c) 2014 >- * The Regents of the University of California. All rights reserved. >+ * Copyright (c) 2014, 2015, 2016 Yoshihiro Ota > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions >@@ -33,10 +32,13 @@ > #include <sys/types.h> > #include <sys/sysctl.h> > >+#include <stdlib.h> > #include <string.h> >+#include <err.h> > > #include "systat.h" > #include "extern.h" >+#include "devs.h" > > struct zfield{ > uint64_t arcstats; >@@ -76,21 +78,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) >@@ -130,6 +134,7 @@ > void > showzarc(void) > { >+ int row = 1; > struct zarcstats delta, rate; > > memset(&delta, 0, sizeof delta); >@@ -137,34 +142,36 @@ > > 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, "%3lu") >-#define H(row, stat) DO(delta.hits.stat, row, 31+1+5, "%7lu"); \ >- DO(curstat.hits.stat, row, 31+1+5+8+8, "%12lu") >-#define M(row, stat) DO(delta.misses.stat, row, 31+1+5+8, "%7lu"); \ >- DO(curstat.misses.stat, row, 31+1+5+8+8+13, "%12lu") >-#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); >-#undef DO >+#define R(stat) DO(rate.hits.stat, 31+1, "%3lu") >+#define H(stat) DO(delta.hits.stat, 31+1+5, "%7lu"); \ >+ DO(curstat.hits.stat, 31+1+5+8+8, "%12lu") >+#define M(stat) DO(delta.misses.stat, 31+1+5+8, "%7lu"); \ >+ DO(curstat.misses.stat, 31+1+5+8+8+13, "%12lu") >+#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 E > #undef M > #undef H > #undef R >+ dsshow(12, 0, 18, &cur, &last); > } > > int > initzarc(void) > { >+ dsinit(12); > getinfo(&initstat); > curstat = oldstat = initstat; >+ > return 1; > } > >@@ -177,6 +184,15 @@ > static void > getinfo(struct zarcstats *ls) > { >+ struct devinfo *tmp_dinfo; >+ >+ tmp_dinfo = last.dinfo; >+ last.dinfo = cur.dinfo; >+ cur.dinfo = tmp_dinfo; >+ >+ last.snap_time = cur.snap_time; >+ dsgetinfo( &cur ); >+ > 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