3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/types.h>
34 #include <sys/sysctl.h>
43 uint64_t arcstats_demand_data;
44 uint64_t arcstats_demand_metadata;
45 uint64_t arcstats_prefetch_data;
46 uint64_t arcstats_prefetch_metadata;
49 uint64_t vdev_cache_stats;
52 static struct zarcstats {
55 } curstat, initstat, oldstat;
58 getinfo(struct zarcstats *ls);
63 return (subwin(stdscr, LINES-3-1, 0, MAINWIN_ROW, 0));
79 wmove(wnd, 0, 0); wclrtoeol(wnd);
80 mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s",
81 "rate", "hits", "misses", "total hits", "total misses");
82 #define L(row, str) mvwprintw(wnd, row, 5, str); \
83 mvwprintw(wnd, row, 31, ":"); \
84 mvwprintw(wnd, row, 31+4, "%%")
86 L(2, "arcstats.demand_data");
87 L(3, "arcstats.demand_metadata");
88 L(4, "arcstats.prefetch_data");
89 L(5, "arcstats.prefetch_metadata");
92 L(8, "vdev_cache_stats");
96 static int calc(uint64_t hits, uint64_t misses)
99 return 100 * hits / ( hits + misses );
105 domode(struct zarcstats *delta, struct zarcstats *rate)
108 delta->hits.stat = (curstat.hits.stat - oldstat.hits.stat); \
109 delta->misses.stat = (curstat.misses.stat - oldstat.misses.stat); \
110 rate->hits.stat = calc(delta->hits.stat, delta->misses.stat)
112 DO(arcstats_demand_data);
113 DO(arcstats_demand_metadata);
114 DO(arcstats_prefetch_data);
115 DO(arcstats_prefetch_metadata);
118 DO(vdev_cache_stats);
120 DO(arcstats_demand_data);
121 DO(arcstats_demand_metadata);
122 DO(arcstats_prefetch_data);
123 DO(arcstats_prefetch_metadata);
126 DO(vdev_cache_stats);
133 struct zarcstats delta, rate;
135 memset(&delta, 0, sizeof delta);
136 memset(&rate, 0, sizeof rate);
138 domode(&delta, &rate);
140 #define DO(stat, row, col, fmt) \
141 mvwprintw(wnd, row, col, fmt, stat)
142 #define R(row, stat) DO(rate.hits.stat, row, 31+1, "%3lu")
143 #define H(row, stat) DO(delta.hits.stat, row, 31+1+5, "%7lu"); \
144 DO(curstat.hits.stat, row, 31+1+5+8+8, "%12lu")
145 #define M(row, stat) DO(delta.misses.stat, row, 31+1+5+8, "%7lu"); \
146 DO(curstat.misses.stat, row, 31+1+5+8+8+13, "%12lu")
147 #define E(row, stat) R(row, stat); H(row, stat); M(row, stat);
149 E(2, arcstats_demand_data);
150 E(3, arcstats_demand_metadata);
151 E(4, arcstats_prefetch_data);
152 E(5, arcstats_prefetch_metadata);
155 E(8, vdev_cache_stats);
167 curstat = oldstat = initstat;
178 getinfo(struct zarcstats *ls)
180 size_t size = sizeof( ls->hits.arcstats );
181 if ( sysctlbyname("kstat.zfs.misc.arcstats.hits",
182 &ls->hits.arcstats, &size, NULL, 0 ) != 0 )
184 GETSYSCTL("kstat.zfs.misc.arcstats.misses",
185 ls->misses.arcstats);
186 GETSYSCTL("kstat.zfs.misc.arcstats.demand_data_hits",
187 ls->hits.arcstats_demand_data);
188 GETSYSCTL("kstat.zfs.misc.arcstats.demand_data_misses",
189 ls->misses.arcstats_demand_data);
190 GETSYSCTL("kstat.zfs.misc.arcstats.demand_metadata_hits",
191 ls->hits.arcstats_demand_metadata);
192 GETSYSCTL("kstat.zfs.misc.arcstats.demand_metadata_misses",
193 ls->misses.arcstats_demand_metadata);
194 GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_data_hits",
195 ls->hits.arcstats_prefetch_data);
196 GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_data_misses",
197 ls->misses.arcstats_prefetch_data);
198 GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_metadata_hits",
199 ls->hits.arcstats_prefetch_metadata);
200 GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_metadata_misses",
201 ls->misses.arcstats_prefetch_metadata);
202 GETSYSCTL("kstat.zfs.misc.zfetchstats.hits",
203 ls->hits.zfetchstats);
204 GETSYSCTL("kstat.zfs.misc.zfetchstats.misses",
205 ls->misses.zfetchstats);
206 GETSYSCTL("kstat.zfs.misc.arcstats.l2_hits",
207 ls->hits.arcstats_l2);
208 GETSYSCTL("kstat.zfs.misc.arcstats.l2_misses",
209 ls->misses.arcstats_l2);
210 GETSYSCTL("kstat.zfs.misc.vdev_cache_stats.hits",
211 ls->hits.vdev_cache_stats);
212 GETSYSCTL("kstat.zfs.misc.vdev_cache_stats.misses",
213 ls->misses.vdev_cache_stats);