View | Details | Raw Unified | Return to bug 213310 | Differences between
and this patch

Collapse All | Expand All

(-)devs.c (-8 / +118 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * Copyright (c) 1998 Kenneth D. Merry.
2
 * Copyright (c) 1998 Kenneth D. Merry.
3
 *               2015 Yoshihiro Ota
3
 * All rights reserved.
4
 * All rights reserved.
4
 *
5
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
Lines 67-73 Link Here
67
#include <sys/resource.h>
68
#include <sys/resource.h>
68
69
69
#include <ctype.h>
70
#include <ctype.h>
70
#include <devstat.h>
71
#include <err.h>
71
#include <err.h>
72
#include <stdlib.h>
72
#include <stdlib.h>
73
#include <string.h>
73
#include <string.h>
Lines 82-87 Link Here
82
	DS_MATCHTYPE_PATTERN
82
	DS_MATCHTYPE_PATTERN
83
} last_match_type;
83
} last_match_type;
84
84
85
struct statinfo cur, last, run;
86
85
last_match_type last_type;
87
last_match_type last_type;
86
struct device_selection *dev_select;
88
struct device_selection *dev_select;
87
long generation;
89
long generation;
Lines 99-108 Link Here
99
		    int maxshowdevs, struct statinfo *s1);
101
		    int maxshowdevs, struct statinfo *s1);
100
102
101
int
103
int
102
dsinit(int maxshowdevs, struct statinfo *s1, struct statinfo *s2 __unused,
104
dsinit(int maxshowdevs)
103
       struct statinfo *s3 __unused)
104
{
105
{
105
106
	/*
106
	/*
107
	 * Make sure that the userland devstat version matches the kernel
107
	 * Make sure that the userland devstat version matches the kernel
108
	 * devstat version.  If not, exit and print a message informing
108
	 * devstat version.  If not, exit and print a message informing
Lines 111-116 Link Here
111
	if (devstat_checkversion(NULL) < 0)
111
	if (devstat_checkversion(NULL) < 0)
112
		errx(1, "%s", devstat_errbuf);
112
		errx(1, "%s", devstat_errbuf);
113
113
114
	if( cur.dinfo ) // init was alreay ran
115
		return(1);
116
117
	if ((num_devices = devstat_getnumdevs(NULL)) < 0) {
118
		warnx("%s", devstat_errbuf);
119
		return(0);
120
	}
121
122
	cur.dinfo = calloc(1, sizeof(struct devinfo));
123
	last.dinfo = calloc(1, sizeof(struct devinfo));
124
	run.dinfo = calloc(1, sizeof(struct devinfo));
125
114
	generation = 0;
126
	generation = 0;
115
	num_devices = 0;
127
	num_devices = 0;
116
	num_selected = 0;
128
	num_selected = 0;
Lines 118-128 Link Here
118
	select_generation = 0;
130
	select_generation = 0;
119
	last_type = DS_MATCHTYPE_NONE;
131
	last_type = DS_MATCHTYPE_NONE;
120
132
121
	if (devstat_getdevs(NULL, s1) == -1)
133
	if (devstat_getdevs(NULL, &cur) == -1)
122
		errx(1, "%s", devstat_errbuf);
134
		errx(1, "%s", devstat_errbuf);
123
135
124
	num_devices = s1->dinfo->numdevs;
136
	num_devices = cur.dinfo->numdevs;
125
	generation = s1->dinfo->generation;
137
	generation = cur.dinfo->generation;
126
138
127
	dev_select = NULL;
139
	dev_select = NULL;
128
140
Lines 132-138 Link Here
132
	 * or 1.  If we get back -1, though, there is an error.
144
	 * or 1.  If we get back -1, though, there is an error.
133
	 */
145
	 */
134
	if (devstat_selectdevs(&dev_select, &num_selected, &num_selections,
146
	if (devstat_selectdevs(&dev_select, &num_selected, &num_selections,
135
	    &select_generation, generation, s1->dinfo->devices, num_devices,
147
	    &select_generation, generation, cur.dinfo->devices, num_devices,
136
	    NULL, 0, NULL, 0, DS_SELECT_ADD, maxshowdevs, 0) == -1)
148
	    NULL, 0, NULL, 0, DS_SELECT_ADD, maxshowdevs, 0) == -1)
137
		errx(1, "%d %s", __LINE__, devstat_errbuf);
149
		errx(1, "%d %s", __LINE__, devstat_errbuf);
138
150
Lines 139-144 Link Here
139
	return(1);
151
	return(1);
140
}
152
}
141
153
154
155
void
156
dsgetinfo(struct statinfo* dev)
157
{
158
	switch (devstat_getdevs(NULL, dev)) {
159
	case -1:
160
		errx(1, "%s", devstat_errbuf);
161
		break;
162
	case 1:
163
		num_devices = dev->dinfo->numdevs;
164
		generation = dev->dinfo->generation;
165
		cmdkre("refresh", NULL);
166
		break;
167
	default:
168
		break;
169
	}
170
}
171
142
int
172
int
143
dscmd(const char *cmd, const char *args, int maxshowdevs, struct statinfo *s1)
173
dscmd(const char *cmd, const char *args, int maxshowdevs, struct statinfo *s1)
144
{
174
{
Lines 319-321 Link Here
319
	}
349
	}
320
	return(1);
350
	return(1);
321
}
351
}
352
353
354
void
355
dslabel(int maxdrives, int diskcol, int diskrow)
356
{
357
	int i, j;
358
359
	mvprintw(diskrow, diskcol, "Disks");
360
	mvprintw(diskrow + 1, diskcol, "KB/t");
361
	mvprintw(diskrow + 2, diskcol, "tps");
362
	mvprintw(diskrow + 3, diskcol, "MB/s");
363
	mvprintw(diskrow + 4, diskcol, "%%busy");
364
	/*
365
	 * For now, we don't support a fourth disk statistic.  So there's
366
	 * no point in providing a label for it.  If someone can think of a
367
	 * fourth useful disk statistic, there is room to add it.
368
	 */
369
	/* mvprintw(diskrow + 4, diskcol, " msps"); */
370
	j = 0;
371
	for (i = 0; i < num_devices && j < maxdrives; i++)
372
		if (dev_select[i].selected) {
373
			char tmpstr[80];
374
			sprintf(tmpstr, "%s%d", dev_select[i].device_name,
375
				dev_select[i].unit_number);
376
			mvprintw(diskrow, diskcol + 5 + 6 * j,
377
				" %5.5s", tmpstr);
378
			j++;
379
		}
380
}
381
382
static void
383
dsshow2(int diskcol, int diskrow, int dn, int lc, struct statinfo *now, struct statinfo *then)
384
{
385
	long double transfers_per_second;
386
	long double kb_per_transfer, mb_per_second;
387
	long double elapsed_time, device_busy;
388
	int di;
389
390
	di = dev_select[dn].position;
391
392
	if (then != NULL) {
393
		/* Calculate relative to previous sample */
394
		elapsed_time = now->snap_time - then->snap_time;
395
	} else {
396
		/* Calculate relative to device creation */
397
		elapsed_time = now->snap_time - devstat_compute_etime(
398
		    &now->dinfo->devices[di].creation_time, NULL);
399
	}
400
401
	if (devstat_compute_statistics(&now->dinfo->devices[di], then ?
402
	    &then->dinfo->devices[di] : NULL, elapsed_time,
403
	    DSM_KB_PER_TRANSFER, &kb_per_transfer,
404
	    DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
405
	    DSM_MB_PER_SECOND, &mb_per_second,
406
	    DSM_BUSY_PCT, &device_busy,
407
	    DSM_NONE) != 0)
408
		errx(1, "%s", devstat_errbuf);
409
410
	lc = diskcol + lc * 6;
411
	putlongdouble(kb_per_transfer, diskrow + 1, lc, 5, 2, 0);
412
	putlongdouble(transfers_per_second, diskrow + 2, lc, 5, 0, 0);
413
	putlongdouble(mb_per_second, diskrow + 3, lc, 5, 2, 0);
414
	putlongdouble(device_busy, diskrow + 4, lc, 5, 0, 0);
415
}
416
417
static void
418
dsshow3(int diskcol, int diskrow, int dn, int lc, struct statinfo *now, struct statinfo *then)
419
{
420
	dsshow2(diskcol, diskrow, dn, lc, now, then);
421
}
422
423
void
424
dsshow(int maxdrives, int diskcol, int diskrow, struct statinfo *now, struct statinfo *then)
425
{
426
	int i, lc;
427
428
	for (i = 0, lc = 0; i < num_devices && lc < maxdrives; i++)
429
		if (dev_select[i].selected)
430
			dsshow3(diskcol, diskrow, i, ++lc, now, then);
431
}
(-)devs.h (-1 / +15 lines)
Lines 1-5 Link Here
1
/*-
1
/*-
2
 * Copyright (c) 1998 David E. O'Brien
2
 * Copyright (c) 1998 David E. O'Brien
3
 *               2015 Yoshihiro Ota
3
 * All rights reserved.
4
 * All rights reserved.
4
 *
5
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
Lines 26-30 Link Here
26
 * $FreeBSD$
27
 * $FreeBSD$
27
 */
28
 */
28
29
29
int dsinit(int, struct statinfo *, struct statinfo *, struct statinfo *);
30
#ifndef DEVS_H
31
#define DEVS_H
32
33
#include <devstat.h>
34
35
int dsinit(int);
36
void dsgetinfo(struct statinfo *);
30
int dscmd(const char *, const char *, int, struct statinfo *);
37
int dscmd(const char *, const char *, int, struct statinfo *);
38
39
void dslabel(int, int, int);
40
void dsshow(int, int, int, struct statinfo *, struct statinfo *);
41
42
extern struct statinfo cur, last, run;
43
44
#endif
(-)iostat.c (-9 / +1 lines)
Lines 77-84 Link Here
77
#include "extern.h"
77
#include "extern.h"
78
#include "devs.h"
78
#include "devs.h"
79
79
80
struct statinfo cur, last;
81
82
static  int linesperregion;
80
static  int linesperregion;
83
static  double etime;
81
static  double etime;
84
static  int numbers = 0;		/* default display bar graphs */
82
static  int numbers = 0;		/* default display bar graphs */
Lines 109-125 Link Here
109
int
107
int
110
initiostat(void)
108
initiostat(void)
111
{
109
{
112
	if ((num_devices = devstat_getnumdevs(NULL)) < 0)
113
		return(0);
114
115
	cur.dinfo = calloc(1, sizeof(struct devinfo));
116
	last.dinfo = calloc(1, sizeof(struct devinfo));
117
118
	/*
110
	/*
119
	 * This value for maxshowdevs (100) is bogus.  I'm not sure exactly
111
	 * This value for maxshowdevs (100) is bogus.  I'm not sure exactly
120
	 * how to calculate it, though.
112
	 * how to calculate it, though.
121
	 */
113
	 */
122
	if (dsinit(100, &cur, &last, NULL) != 1)
114
	if (dsinit(100) != 1)
123
		return(0);
115
		return(0);
124
116
125
	return(1);
117
	return(1);
(-)systat.h (+4 lines)
Lines 66-68 Link Here
66
#define NVAL(indx)  namelist[(indx)].n_value
66
#define NVAL(indx)  namelist[(indx)].n_value
67
#define NPTR(indx)  (void *)NVAL((indx))
67
#define NPTR(indx)  (void *)NVAL((indx))
68
#define NREAD(indx, buf, len) kvm_ckread(NPTR((indx)), (buf), (len))
68
#define NREAD(indx, buf, len) kvm_ckread(NPTR((indx)), (buf), (len))
69
70
extern void putint(int, int, int, int);
71
extern void putfloat(double, int, int, int, int, int);
72
extern void putlongdouble(long double, int, int, int, int, int);
(-)vmstat.c (-102 / +20 lines)
Lines 63-69 Link Here
63
#include <time.h>
63
#include <time.h>
64
#include <unistd.h>
64
#include <unistd.h>
65
#include <utmpx.h>
65
#include <utmpx.h>
66
#include <devstat.h>
67
#include "systat.h"
66
#include "systat.h"
68
#include "extern.h"
67
#include "extern.h"
69
#include "devs.h"
68
#include "devs.h"
Lines 122-128 Link Here
122
static u_long kmem_size;
121
static u_long kmem_size;
123
static u_int v_page_count;
122
static u_int v_page_count;
124
123
125
struct statinfo cur, last, run;
126
124
127
#define	total s.Total
125
#define	total s.Total
128
#define	nchtotal s.nchstats
126
#define	nchtotal s.nchstats
Lines 133-143 Link Here
133
static void allocinfo(struct Info *);
131
static void allocinfo(struct Info *);
134
static void copyinfo(struct Info *, struct Info *);
132
static void copyinfo(struct Info *, struct Info *);
135
static float cputime(int);
133
static float cputime(int);
136
static void dinfo(int, int, struct statinfo *, struct statinfo *);
137
static void getinfo(struct Info *);
134
static void getinfo(struct Info *);
138
static void putint(int, int, int, int);
139
static void putfloat(double, int, int, int, int, int);
140
static void putlongdouble(long double, int, int, int, int, int);
141
static int ucount(void);
135
static int ucount(void);
142
136
143
static	int ncpu;
137
static	int ncpu;
Lines 203-220 Link Here
203
	int i;
197
	int i;
204
	size_t sz;
198
	size_t sz;
205
199
206
	if ((num_devices = devstat_getnumdevs(NULL)) < 0) {
200
	if (dsinit(MAXDRIVES) != 1)
207
		warnx("%s", devstat_errbuf);
208
		return(0);
201
		return(0);
209
	}
210
202
211
	cur.dinfo = calloc(1, sizeof(struct devinfo));
212
	last.dinfo = calloc(1, sizeof(struct devinfo));
213
	run.dinfo = calloc(1, sizeof(struct devinfo));
214
215
	if (dsinit(MAXDRIVES, &cur, &last, &run) != 1)
216
		return(0);
217
218
	if (nintr == 0) {
203
	if (nintr == 0) {
219
		if (sysctlbyname("hw.intrcnt", NULL, &sz, NULL, 0) == -1) {
204
		if (sysctlbyname("hw.intrcnt", NULL, &sz, NULL, 0) == -1) {
220
			error("sysctl(hw.intrcnt...) failed: %s",
205
			error("sysctl(hw.intrcnt...) failed: %s",
Lines 312-318 Link Here
312
297
313
	clear();
298
	clear();
314
	mvprintw(STATROW, STATCOL + 6, "users    Load");
299
	mvprintw(STATROW, STATCOL + 6, "users    Load");
315
	mvprintw(STATROW + 1, STATCOL + 3, "Mem usage:    %%Phy   %%Kmem");
300
	mvprintw(STATROW + 1, STATCOL + 3, "Mem usage:    %%Phy   %%Kmem   %%VM");
316
	mvprintw(MEMROW, MEMCOL, "Mem: KB    REAL            VIRTUAL");
301
	mvprintw(MEMROW, MEMCOL, "Mem: KB    REAL            VIRTUAL");
317
	mvprintw(MEMROW + 1, MEMCOL, "        Tot   Share      Tot    Share");
302
	mvprintw(MEMROW + 1, MEMCOL, "        Tot   Share      Tot    Share");
318
	mvprintw(MEMROW + 2, MEMCOL, "Act");
303
	mvprintw(MEMROW + 2, MEMCOL, "Act");
Lines 365-391 Link Here
365
	mvprintw(NAMEIROW, NAMEICOL, "Namei     Name-cache   Dir-cache");
350
	mvprintw(NAMEIROW, NAMEICOL, "Namei     Name-cache   Dir-cache");
366
	mvprintw(NAMEIROW + 1, NAMEICOL,
351
	mvprintw(NAMEIROW + 1, NAMEICOL,
367
		"   Calls    hits   %%    hits   %%");
352
		"   Calls    hits   %%    hits   %%");
368
	mvprintw(DISKROW, DISKCOL, "Disks");
353
	dslabel(MAXDRIVES, DISKCOL, DISKROW);
369
	mvprintw(DISKROW + 1, DISKCOL, "KB/t");
370
	mvprintw(DISKROW + 2, DISKCOL, "tps");
371
	mvprintw(DISKROW + 3, DISKCOL, "MB/s");
372
	mvprintw(DISKROW + 4, DISKCOL, "%%busy");
373
	/*
374
	 * For now, we don't support a fourth disk statistic.  So there's
375
	 * no point in providing a label for it.  If someone can think of a
376
	 * fourth useful disk statistic, there is room to add it.
377
	 */
378
	/* mvprintw(DISKROW + 4, DISKCOL, " msps"); */
379
	j = 0;
380
	for (i = 0; i < num_devices && j < MAXDRIVES; i++)
381
		if (dev_select[i].selected) {
382
			char tmpstr[80];
383
			sprintf(tmpstr, "%s%d", dev_select[i].device_name,
384
				dev_select[i].unit_number);
385
			mvprintw(DISKROW, DISKCOL + 5 + 6 * j,
386
				" %5.5s", tmpstr);
387
			j++;
388
		}
389
354
390
	for (i = 0; i < nintr; i++) {
355
	for (i = 0; i < nintr; i++) {
391
		if (intrloc[i] == 0)
356
		if (intrloc[i] == 0)
Lines 488-493 Link Here
488
	   STATROW + 1, STATCOL + 15, 2, 0, 1);
453
	   STATROW + 1, STATCOL + 15, 2, 0, 1);
489
	putfloat(100.0 * s.v_kmem_map_size / kmem_size,
454
	putfloat(100.0 * s.v_kmem_map_size / kmem_size,
490
	   STATROW + 1, STATCOL + 22, 2, 0, 1);
455
	   STATROW + 1, STATCOL + 22, 2, 0, 1);
456
	putfloat(100.0 * total.t_avm / total.t_vm,
457
	   STATROW + 1, STATCOL + 30, 2, 0, 1);
491
458
492
	putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7);
459
	putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7);
493
	putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7);
460
	putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7);
Lines 537-556 Link Here
537
	PUTRATE(v_intr, GENSTATROW + 1, GENSTATCOL + 15, 4);
504
	PUTRATE(v_intr, GENSTATROW + 1, GENSTATCOL + 15, 4);
538
	PUTRATE(v_soft, GENSTATROW + 1, GENSTATCOL + 20, 4);
505
	PUTRATE(v_soft, GENSTATROW + 1, GENSTATCOL + 20, 4);
539
	PUTRATE(v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 4);
506
	PUTRATE(v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 4);
540
	for (i = 0, lc = 0; i < num_devices && lc < MAXDRIVES; i++)
507
	switch(state) {
541
		if (dev_select[i].selected) {
508
	case TIME:
542
			switch(state) {
509
		dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur, &last);
543
			case TIME:
510
		break;
544
				dinfo(i, ++lc, &cur, &last);
511
	case RUN:
545
				break;
512
		dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur, &run);
546
			case RUN:
513
		break;
547
				dinfo(i, ++lc, &cur, &run);
514
	case BOOT:
548
				break;
515
		dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur, NULL);
549
			case BOOT:
516
		break;
550
				dinfo(i, ++lc, &cur, NULL);
517
	}
551
				break;
552
			}
553
		}
554
	putint(s.numdirtybuffers, VNSTATROW, VNSTATCOL, 7);
518
	putint(s.numdirtybuffers, VNSTATROW, VNSTATCOL, 7);
555
	putint(s.desiredvnodes, VNSTATROW + 1, VNSTATCOL, 7);
519
	putint(s.desiredvnodes, VNSTATROW + 1, VNSTATCOL, 7);
556
	putint(s.numvnodes, VNSTATROW + 2, VNSTATCOL, 7);
520
	putint(s.numvnodes, VNSTATROW + 2, VNSTATCOL, 7);
Lines 661-667 Link Here
661
	return (s.time[indx] * 100.0 / lt);
625
	return (s.time[indx] * 100.0 / lt);
662
}
626
}
663
627
664
static void
628
void
665
putint(int n, int l, int lc, int w)
629
putint(int n, int l, int lc, int w)
666
{
630
{
667
	int snr;
631
	int snr;
Lines 691-697 Link Here
691
	addstr(b);
655
	addstr(b);
692
}
656
}
693
657
694
static void
658
void
695
putfloat(double f, int l, int lc, int w, int d, int nz)
659
putfloat(double f, int l, int lc, int w, int d, int nz)
696
{
660
{
697
	int snr;
661
	int snr;
Lines 723-729 Link Here
723
	addstr(b);
687
	addstr(b);
724
}
688
}
725
689
726
static void
690
void
727
putlongdouble(long double f, int l, int lc, int w, int d, int nz)
691
putlongdouble(long double f, int l, int lc, int w, int d, int nz)
728
{
692
{
729
	int snr;
693
	int snr;
Lines 821-838 Link Here
821
	cur.dinfo = tmp_dinfo;
785
	cur.dinfo = tmp_dinfo;
822
786
823
	last.snap_time = cur.snap_time;
787
	last.snap_time = cur.snap_time;
824
	switch (devstat_getdevs(NULL, &cur)) {
788
	dsgetinfo(&cur);
825
	case -1:
826
		errx(1, "%s", devstat_errbuf);
827
		break;
828
	case 1:
829
		num_devices = cur.dinfo->numdevs;
830
		generation = cur.dinfo->generation;
831
		cmdkre("refresh", NULL);
832
		break;
833
	default:
834
		break;
835
	}
836
}
789
}
837
790
838
static void
791
static void
Lines 859-896 Link Here
859
812
860
	bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
813
	bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
861
}
814
}
862
863
static void
864
dinfo(int dn, int lc, struct statinfo *now, struct statinfo *then)
865
{
866
	long double transfers_per_second;
867
	long double kb_per_transfer, mb_per_second;
868
	long double elapsed_time, device_busy;
869
	int di;
870
871
	di = dev_select[dn].position;
872
873
	if (then != NULL) {
874
		/* Calculate relative to previous sample */
875
		elapsed_time = now->snap_time - then->snap_time;
876
	} else {
877
		/* Calculate relative to device creation */
878
		elapsed_time = now->snap_time - devstat_compute_etime(
879
		    &now->dinfo->devices[di].creation_time, NULL);
880
	}
881
882
	if (devstat_compute_statistics(&now->dinfo->devices[di], then ?
883
	    &then->dinfo->devices[di] : NULL, elapsed_time,
884
	    DSM_KB_PER_TRANSFER, &kb_per_transfer,
885
	    DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
886
	    DSM_MB_PER_SECOND, &mb_per_second,
887
	    DSM_BUSY_PCT, &device_busy,
888
	    DSM_NONE) != 0)
889
		errx(1, "%s", devstat_errbuf);
890
891
	lc = DISKCOL + lc * 6;
892
	putlongdouble(kb_per_transfer, DISKROW + 1, lc, 5, 2, 0);
893
	putlongdouble(transfers_per_second, DISKROW + 2, lc, 5, 0, 0);
894
	putlongdouble(mb_per_second, DISKROW + 3, lc, 5, 2, 0);
895
	putlongdouble(device_busy, DISKROW + 4, lc, 5, 0, 0);
896
}
(-)zarc.c (-28 / +44 lines)
Lines 1-6 Link Here
1
/*-
1
/*-
2
 * Copyright (c) 2014
2
 * Copyright (c) 2014, 2015, 2016 Yoshihiro Ota
3
 *	The Regents of the University of California.  All rights reserved.
4
 *
3
 *
5
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 33-42 Link Here
33
#include <sys/types.h>
32
#include <sys/types.h>
34
#include <sys/sysctl.h>
33
#include <sys/sysctl.h>
35
34
35
#include <stdlib.h>
36
#include <string.h>
36
#include <string.h>
37
#include <err.h>
37
38
38
#include "systat.h"
39
#include "systat.h"
39
#include "extern.h"
40
#include "extern.h"
41
#include "devs.h"
40
42
41
struct zfield{
43
struct zfield{
42
	uint64_t arcstats;
44
	uint64_t arcstats;
Lines 76-96 Link Here
76
void
78
void
77
labelzarc(void)
79
labelzarc(void)
78
{
80
{
81
	int row = 1;
79
	wmove(wnd, 0, 0); wclrtoeol(wnd);
82
	wmove(wnd, 0, 0); wclrtoeol(wnd);
80
	mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s",
83
	mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s",
81
		"rate", "hits", "misses", "total hits", "total misses");
84
		"rate", "hits", "misses", "total hits", "total misses");
82
#define L(row, str) mvwprintw(wnd, row, 5, str); \
85
#define L(str) mvwprintw(wnd, row, 5, #str); \
83
	mvwprintw(wnd, row, 31, ":"); \
86
	mvwprintw(wnd, row, 31, ":"); \
84
	mvwprintw(wnd, row, 31+4, "%%")
87
	mvwprintw(wnd, row, 31+4, "%%"); ++row
85
	L(1, "arcstats");
88
	L(arcstats);
86
	L(2, "arcstats.demand_data");
89
	L(arcstats.demand_data);
87
	L(3, "arcstats.demand_metadata");
90
	L(arcstats.demand_metadata);
88
	L(4, "arcstats.prefetch_data");
91
	L(arcstats.prefetch_data);
89
	L(5, "arcstats.prefetch_metadata");
92
	L(arcstats.prefetch_metadata);
90
	L(6, "zfetchstats");
93
	L(zfetchstats);
91
	L(7, "arcstats.l2");
94
	L(arcstats.l2);
92
	L(8, "vdev_cache_stats");
95
	L(vdev_cache_stats);
93
#undef L
96
#undef L
97
	dslabel(12, 0, 18);
94
}
98
}
95
99
96
static int calc(uint64_t hits, uint64_t misses)
100
static int calc(uint64_t hits, uint64_t misses)
Lines 130-135 Link Here
130
void
134
void
131
showzarc(void)
135
showzarc(void)
132
{
136
{
137
	int row = 1;
133
	struct zarcstats delta, rate;
138
	struct zarcstats delta, rate;
134
139
135
	memset(&delta, 0, sizeof delta);
140
	memset(&delta, 0, sizeof delta);
Lines 137-170 Link Here
137
142
138
	domode(&delta, &rate);
143
	domode(&delta, &rate);
139
144
140
#define DO(stat, row, col, fmt) \
145
#define DO(stat, col, fmt) \
141
	mvwprintw(wnd, row, col, fmt, stat)
146
	mvwprintw(wnd, row, col, fmt, stat)
142
#define	R(row, stat) DO(rate.hits.stat, row, 31+1, "%3lu")
147
#define	R(stat) DO(rate.hits.stat, 31+1, "%3lu")
143
#define	H(row, stat) DO(delta.hits.stat, row, 31+1+5, "%7lu"); \
148
#define	H(stat) DO(delta.hits.stat, 31+1+5, "%7lu"); \
144
	DO(curstat.hits.stat, row, 31+1+5+8+8, "%12lu")
149
	DO(curstat.hits.stat, 31+1+5+8+8, "%12lu")
145
#define	M(row, stat) DO(delta.misses.stat, row, 31+1+5+8, "%7lu"); \
150
#define	M(stat) DO(delta.misses.stat, 31+1+5+8, "%7lu"); \
146
	DO(curstat.misses.stat, row, 31+1+5+8+8+13, "%12lu")
151
	DO(curstat.misses.stat, 31+1+5+8+8+13, "%12lu")
147
#define	E(row, stat) R(row, stat); H(row, stat); M(row, stat); 
152
#define	E(stat) R(stat); H(stat); M(stat); ++row
148
	E(1, arcstats);
153
	E(arcstats);
149
	E(2, arcstats_demand_data);
154
	E(arcstats_demand_data);
150
	E(3, arcstats_demand_metadata);
155
	E(arcstats_demand_metadata);
151
	E(4, arcstats_prefetch_data);
156
	E(arcstats_prefetch_data);
152
	E(5, arcstats_prefetch_metadata);
157
	E(arcstats_prefetch_metadata);
153
	E(6, zfetchstats);
158
	E(zfetchstats);
154
	E(7, arcstats_l2);
159
	E(arcstats_l2);
155
	E(8, vdev_cache_stats);
160
	E(vdev_cache_stats);
156
#undef DO
157
#undef E
161
#undef E
158
#undef M
162
#undef M
159
#undef H
163
#undef H
160
#undef R
164
#undef R
165
	dsshow(12, 0, 18, &cur, &last);
161
}
166
}
162
167
163
int
168
int
164
initzarc(void)
169
initzarc(void)
165
{
170
{
171
	dsinit(12);
166
	getinfo(&initstat);
172
	getinfo(&initstat);
167
	curstat = oldstat = initstat;
173
	curstat = oldstat = initstat;
174
168
	return 1;
175
	return 1;
169
}
176
}
170
177
Lines 177-182 Link Here
177
static void
184
static void
178
getinfo(struct zarcstats *ls)
185
getinfo(struct zarcstats *ls)
179
{
186
{
187
	struct devinfo *tmp_dinfo;
188
189
	tmp_dinfo = last.dinfo;
190
	last.dinfo = cur.dinfo;
191
	cur.dinfo = tmp_dinfo;
192
193
	last.snap_time = cur.snap_time;
194
	dsgetinfo( &cur );
195
180
	size_t size = sizeof( ls->hits.arcstats );
196
	size_t size = sizeof( ls->hits.arcstats );
181
	if ( sysctlbyname("kstat.zfs.misc.arcstats.hits",
197
	if ( sysctlbyname("kstat.zfs.misc.arcstats.hits",
182
		&ls->hits.arcstats, &size, NULL, 0 ) != 0 )
198
		&ls->hits.arcstats, &size, NULL, 0 ) != 0 )

Return to bug 213310