Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/systat/zarc.c
/*- | /*- | ||||
* Copyright (c) 2014 | * Copyright (c) 2014 - 2017 Yoshihiro Ota | ||||
* The Regents of the University of California. All rights reserved. | |||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
Show All 16 Lines | |||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
/* #include <stdlib.h> */ | |||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <err.h> | |||||
#include "systat.h" | #include "systat.h" | ||||
#include "extern.h" | #include "extern.h" | ||||
#include "devs.h" | |||||
struct zfield{ | struct zfield{ | ||||
uint64_t arcstats; | uint64_t arcstats; | ||||
uint64_t arcstats_demand_data; | uint64_t arcstats_demand_data; | ||||
uint64_t arcstats_demand_metadata; | uint64_t arcstats_demand_metadata; | ||||
uint64_t arcstats_prefetch_data; | uint64_t arcstats_prefetch_data; | ||||
uint64_t arcstats_prefetch_metadata; | uint64_t arcstats_prefetch_metadata; | ||||
uint64_t zfetchstats; | uint64_t zfetchstats; | ||||
Show All 23 Lines | closezarc(WINDOW *w) | ||||
wclear(w); | wclear(w); | ||||
wrefresh(w); | wrefresh(w); | ||||
delwin(w); | delwin(w); | ||||
} | } | ||||
void | void | ||||
labelzarc(void) | labelzarc(void) | ||||
{ | { | ||||
int row = 1; | |||||
wmove(wnd, 0, 0); wclrtoeol(wnd); | wmove(wnd, 0, 0); wclrtoeol(wnd); | ||||
mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s", | mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s", | ||||
"rate", "hits", "misses", "total hits", "total misses"); | "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, ":"); \ | ||||
mvwprintw(wnd, row, 31+4, "%%") | mvwprintw(wnd, row, 31+4, "%%"); ++row | ||||
L(1, "arcstats"); | L(arcstats); | ||||
L(2, "arcstats.demand_data"); | L(arcstats.demand_data); | ||||
L(3, "arcstats.demand_metadata"); | L(arcstats.demand_metadata); | ||||
L(4, "arcstats.prefetch_data"); | L(arcstats.prefetch_data); | ||||
L(5, "arcstats.prefetch_metadata"); | L(arcstats.prefetch_metadata); | ||||
L(6, "zfetchstats"); | L(zfetchstats); | ||||
L(7, "arcstats.l2"); | L(arcstats.l2); | ||||
L(8, "vdev_cache_stats"); | L(vdev_cache_stats); | ||||
#undef L | #undef L | ||||
dslabel(12, 0, 18); | |||||
} | } | ||||
static int calc(uint64_t hits, uint64_t misses) | static int calc(uint64_t hits, uint64_t misses) | ||||
{ | { | ||||
if( hits ) | if( hits ) | ||||
return 100 * hits / ( hits + misses ); | return 100 * hits / ( hits + misses ); | ||||
else | else | ||||
return 0; | return 0; | ||||
Show All 23 Lines | #define DO(stat) \ | ||||
DO(arcstats_l2); | DO(arcstats_l2); | ||||
DO(vdev_cache_stats); | DO(vdev_cache_stats); | ||||
#undef DO | #undef DO | ||||
} | } | ||||
void | void | ||||
showzarc(void) | showzarc(void) | ||||
{ | { | ||||
int row = 1; | |||||
struct zarcstats delta, rate; | struct zarcstats delta, rate; | ||||
memset(&delta, 0, sizeof delta); | memset(&delta, 0, sizeof delta); | ||||
memset(&rate, 0, sizeof rate); | memset(&rate, 0, sizeof rate); | ||||
domode(&delta, &rate); | domode(&delta, &rate); | ||||
#define DO(stat, row, col, fmt) \ | #define DO(stat, col, fmt) \ | ||||
mvwprintw(wnd, row, col, fmt, stat) | mvwprintw(wnd, row, col, fmt, stat) | ||||
#define R(row, stat) DO(rate.hits.stat, row, 31+1, "%3"PRIu64) | #define R(stat) DO(rate.hits.stat, 31+1, "%3"PRIu64) | ||||
#define H(row, stat) DO(delta.hits.stat, row, 31+1+5, "%7"PRIu64); \ | #define H(stat) DO(delta.hits.stat, 31+1+5, "%7"PRIu64); \ | ||||
DO(curstat.hits.stat, row, 31+1+5+8+8, "%12"PRIu64) | DO(curstat.hits.stat, 31+1+5+8+8, "%12"PRIu64) | ||||
#define M(row, stat) DO(delta.misses.stat, row, 31+1+5+8, "%7"PRIu64); \ | #define M(stat) DO(delta.misses.stat, 31+1+5+8, "%7"PRIu64); \ | ||||
DO(curstat.misses.stat, row, 31+1+5+8+8+13, "%12"PRIu64) | DO(curstat.misses.stat, 31+1+5+8+8+13, "%12"PRIu64) | ||||
#define E(row, stat) R(row, stat); H(row, stat); M(row, stat); | #define E(stat) R(stat); H(stat); M(stat); ++row | ||||
E(1, arcstats); | E(arcstats); | ||||
E(2, arcstats_demand_data); | E(arcstats_demand_data); | ||||
E(3, arcstats_demand_metadata); | E(arcstats_demand_metadata); | ||||
E(4, arcstats_prefetch_data); | E(arcstats_prefetch_data); | ||||
E(5, arcstats_prefetch_metadata); | E(arcstats_prefetch_metadata); | ||||
E(6, zfetchstats); | E(zfetchstats); | ||||
E(7, arcstats_l2); | E(arcstats_l2); | ||||
E(8, vdev_cache_stats); | E(vdev_cache_stats); | ||||
#undef DO | #undef DO | ||||
#undef E | #undef E | ||||
#undef M | #undef M | ||||
#undef H | #undef H | ||||
#undef R | #undef R | ||||
dsshow(12, 0, 18, &cur_dev, &last_dev); | |||||
} | } | ||||
int | int | ||||
initzarc(void) | initzarc(void) | ||||
{ | { | ||||
dsinit(12); | |||||
getinfo(&initstat); | getinfo(&initstat); | ||||
curstat = oldstat = initstat; | curstat = oldstat = initstat; | ||||
return 1; | return 1; | ||||
} | } | ||||
void | void | ||||
resetzarc(void) | resetzarc(void) | ||||
{ | { | ||||
initzarc(); | initzarc(); | ||||
} | } | ||||
static void | static void | ||||
getinfo(struct zarcstats *ls) | 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 ); | size_t size = sizeof( ls->hits.arcstats ); | ||||
if ( sysctlbyname("kstat.zfs.misc.arcstats.hits", | if ( sysctlbyname("kstat.zfs.misc.arcstats.hits", | ||||
&ls->hits.arcstats, &size, NULL, 0 ) != 0 ) | &ls->hits.arcstats, &size, NULL, 0 ) != 0 ) | ||||
return; | return; | ||||
GETSYSCTL("kstat.zfs.misc.arcstats.misses", | GETSYSCTL("kstat.zfs.misc.arcstats.misses", | ||||
ls->misses.arcstats); | ls->misses.arcstats); | ||||
GETSYSCTL("kstat.zfs.misc.arcstats.demand_data_hits", | GETSYSCTL("kstat.zfs.misc.arcstats.demand_data_hits", | ||||
ls->hits.arcstats_demand_data); | ls->hits.arcstats_demand_data); | ||||
Show All 34 Lines |