2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2014 - 2017, 2019 Yoshihiro Ota
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/types.h>
32 #include <sys/sysctl.h>
45 uint64_t arcstats_demand_data;
46 uint64_t arcstats_demand_metadata;
47 uint64_t arcstats_prefetch_data;
48 uint64_t arcstats_prefetch_metadata;
51 uint64_t vdev_cache_stats;
54 static struct zarcstats {
57 } curstat, initstat, oldstat;
60 struct zfield current;
65 getinfo(struct zarcstats *ls);
71 return (subwin(stdscr, LINES - 3 - 1, 0, MAINWIN_ROW, 0));
90 wmove(wnd, 0, 0); wclrtoeol(wnd);
91 mvwprintw(wnd, 0, 31+1, "%4.4s %6.6s %6.6s | Total %4.4s %6.6s %6.6s",
92 "Rate", "Hits", "Misses", "Rate", "Hits", "Misses");
93 #define L(str) mvwprintw(wnd, row++, 5, \
94 "%-26.26s: %% | %%", #str)
96 L(arcstats.demand_data);
97 L(arcstats.demand_metadata);
98 L(arcstats.prefetch_data);
99 L(arcstats.prefetch_metadata);
108 calc_rate(uint64_t hits, uint64_t misses)
111 return 100 * hits / (hits + misses);
117 domode(struct zarcstats *delta, struct zarcrates *rate)
120 delta->hits.stat = (curstat.hits.stat - oldstat.hits.stat); \
121 delta->misses.stat = (curstat.misses.stat - oldstat.misses.stat); \
122 rate->current.stat = calc_rate(delta->hits.stat, delta->misses.stat); \
123 rate->total.stat = calc_rate(curstat.hits.stat, curstat.misses.stat)
125 DO(arcstats_demand_data);
126 DO(arcstats_demand_metadata);
127 DO(arcstats_prefetch_data);
128 DO(arcstats_prefetch_metadata);
131 DO(vdev_cache_stats);
133 DO(arcstats_demand_data);
134 DO(arcstats_demand_metadata);
135 DO(arcstats_prefetch_data);
136 DO(arcstats_prefetch_metadata);
139 DO(vdev_cache_stats);
147 struct zarcstats delta = {};
148 struct zarcrates rate = {};
150 domode(&delta, &rate);
152 #define DO(stat, col, width) \
153 sysputuint64(wnd, row, col, width, stat, HN_DIVISOR_1000)
154 #define RATES(stat) mvwprintw(wnd, row, 31+1, "%3"PRIu64, rate.current.stat);\
155 mvwprintw(wnd, row, 31+1+5+7+7+8, "%3"PRIu64, rate.total.stat)
156 #define HITS(stat) DO(delta.hits.stat, 31+1+5, 6); \
157 DO(curstat.hits.stat, 31+1+5+7+7+8+5, 6)
158 #define MISSES(stat) DO(delta.misses.stat, 31+1+5+7, 6); \
159 DO(curstat.misses.stat, 31+1+5+7+7+8+5+7, 6)
160 #define E(stat) RATES(stat); HITS(stat); MISSES(stat); ++row
162 E(arcstats_demand_data);
163 E(arcstats_demand_metadata);
164 E(arcstats_prefetch_data);
165 E(arcstats_prefetch_metadata);
174 dsshow(12, 0, 18, &cur_dev, &last_dev);
182 curstat = oldstat = initstat;
195 getinfo(struct zarcstats *ls)
197 struct devinfo *tmp_dinfo;
199 tmp_dinfo = last_dev.dinfo;
200 last_dev.dinfo = cur_dev.dinfo;
201 cur_dev.dinfo = tmp_dinfo;
203 last_dev.snap_time = cur_dev.snap_time;
206 size_t size = sizeof(ls->hits.arcstats);
207 if (sysctlbyname("kstat.zfs.misc.arcstats.hits",
208 &ls->hits.arcstats, &size, NULL, 0) != 0)
210 GETSYSCTL("kstat.zfs.misc.arcstats.misses",
211 ls->misses.arcstats);
212 GETSYSCTL("kstat.zfs.misc.arcstats.demand_data_hits",
213 ls->hits.arcstats_demand_data);
214 GETSYSCTL("kstat.zfs.misc.arcstats.demand_data_misses",
215 ls->misses.arcstats_demand_data);
216 GETSYSCTL("kstat.zfs.misc.arcstats.demand_metadata_hits",
217 ls->hits.arcstats_demand_metadata);
218 GETSYSCTL("kstat.zfs.misc.arcstats.demand_metadata_misses",
219 ls->misses.arcstats_demand_metadata);
220 GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_data_hits",
221 ls->hits.arcstats_prefetch_data);
222 GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_data_misses",
223 ls->misses.arcstats_prefetch_data);
224 GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_metadata_hits",
225 ls->hits.arcstats_prefetch_metadata);
226 GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_metadata_misses",
227 ls->misses.arcstats_prefetch_metadata);
228 GETSYSCTL("kstat.zfs.misc.zfetchstats.hits",
229 ls->hits.zfetchstats);
230 GETSYSCTL("kstat.zfs.misc.zfetchstats.misses",
231 ls->misses.zfetchstats);
232 GETSYSCTL("kstat.zfs.misc.arcstats.l2_hits",
233 ls->hits.arcstats_l2);
234 GETSYSCTL("kstat.zfs.misc.arcstats.l2_misses",
235 ls->misses.arcstats_l2);
236 GETSYSCTL("kstat.zfs.misc.vdev_cache_stats.hits",
237 ls->hits.vdev_cache_stats);
238 GETSYSCTL("kstat.zfs.misc.vdev_cache_stats.misses",
239 ls->misses.vdev_cache_stats);