Last active
April 26, 2022 14:20
-
-
Save Low-power/2c22effce226debe790add1440221315 to your computer and use it in GitHub Desktop.
Portable arc_summary reimplementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Copyright 2015-2022 Rivoreo | |
# Permission is hereby granted, free of charge, to any person obtaining | |
# a copy of this software and associated documentation files (the | |
# "Software"), to deal in the Software without restriction, including | |
# without limitation the rights to use, copy, modify, merge, publish, | |
# distribute, sublicense, and/or sell copies of the Software, and to | |
# permit persons to whom the Software is furnished to do so, subject to | |
# the following conditions: | |
# The above copyright notice and this permission notice shall be | |
# included in all copies or substantial portions of the Software. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
# NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE | |
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
# Based on arc_summary.pl by Ben Rockwood, the original copyright notice and license follows: | |
# Copyright (c) 2008, Ben Rockwood (benr@cuddletech.com) | |
# All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without modification, | |
# are permitted provided that the following conditions are met: | |
# * Redistributions of source code must retain the above copyright notice, this | |
# list of conditions and the following disclaimer. | |
# * Redistributions in binary form must reproduce the above copyright notice, | |
# this list of conditions and the following disclaimer in the documentation | |
# and/or other materials provided with the distribution. | |
# * Neither the name of the Ben Rockwood nor the names of its contributors may be | |
# used to endorse or promote products derived from this software without specific | |
# prior written permission. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS | |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | |
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | |
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
# | |
if [ -x "`which kstat`" ]; then | |
# Solaris | |
read_kstat() { | |
if [ $# != 3 ]; then | |
#echo "Usage: read_kstat <module> <class> <name>" 1>&2 | |
echo "# ($#) != 3" 1>&2 | |
exit 2 | |
fi | |
eval "`kstat -p -m $1 -c $2 -n $3 | sed -E -e \"/^$1:0:/!d\" -e 's/.+://' -e 's/[[:space:]]+/=/'`" | |
} | |
elif [ -d /proc/spl/kstat/zfs ]; then | |
# OpenZFS on Linux | |
read_kstat() { | |
if [ $# != 3 ]; then | |
echo "# ($#) != 3" 1>&2 | |
exit 2 | |
fi | |
eval "`sed -E -e 1,2d -e 's/ .+ /=/' /proc/spl/kstat/$1/$3`" | |
} | |
elif [ -x "`which sysctl`" ]; then | |
# BSD | |
read_kstat() { | |
if [ $# != 3 ]; then | |
echo "# ($#) != 3" 1>&2 | |
exit 2 | |
fi | |
eval "`sysctl -e kstat.$1.$2.$3 | sed -E 's/.+\\.//'`" | |
} | |
else | |
echo "No known method to read kstat" 1>&2 | |
exit 1 | |
fi | |
set -e | |
set -u | |
read_kstat zfs misc arcstats | |
#### ARC Sizing ############### | |
echo "ARC Size:" | |
printf " Current Size %11u MiB\\n" $((size/1024/1024)) | |
printf " Target Size (Adaptive) %11u MiB\\n" $((c/1024/1024)) | |
printf " Min Size (Hard Limit) %11u MiB\\n" $((c_min/1024/1024)) | |
printf " Max Size (High Water) %11u MiB\\n" $((c_max/1024/1024)) | |
echo | |
echo "ARC Size Breakdown:" | |
printf " Most Recently Used Cache Size % 3u%% %6u MiB\\n" $((p*100/c)) $((p/1024/1024)) | |
mfu_size=$((c-p)) | |
printf " Most Frequently Used Cache Size % 3u%% %6u MiB\\n" $((mfu_size*100/c)) $((mfu_size/1024/1024)) | |
echo | |
################################## | |
####### ARC Efficency ######################### | |
total_accesses=$((hits+misses)) | |
real_hits=$((mfu_hits+mru_hits)) | |
echo "ARC Efficency:" | |
printf " Total Cache Accesses %15u\\n" $total_accesses | |
printf " Cache Hit Ratio %3d%% %10u\\n" $((hits*100/total_accesses)) $hits | |
printf " Cache Miss Ratio %3d%% %10u\\n" $((misses*100/total_accesses)) $misses | |
printf " Actual Hit Ratio %3d%% %10u\\n" $((real_hits*100/total_accesses)) $real_hits | |
echo | |
demand_data_total=$((demand_data_hits+demand_data_misses)) | |
if [ $demand_data_total = 0 ]; then | |
echo " Data Demand Efficiency NOT APPLICABLE" | |
else | |
printf " Data Demand Efficiency %3u%%\\n" $((demand_data_hits*100/demand_data_total)) | |
fi | |
prefetch_data_total=$((prefetch_data_hits+prefetch_data_misses)) | |
if [ $prefetch_data_total = 0 ]; then | |
echo " Data Prefetch Efficiency DISABLED" | |
else | |
printf " Data Prefetch Efficiency %3u%%\\n" $((prefetch_data_hits*100/prefetch_data_total)) | |
fi | |
echo | |
anon_hits=$((hits-(mfu_hits+mru_hits+mfu_ghost_hits+mru_ghost_hits))) | |
#[ $anon_hits -lt 0 ] && anon_hits=0 | |
echo " CACHE HITS BY CACHE LIST:" | |
printf " Anonymously Used " | |
if [ $anon_hits -lt 0 ]; then | |
echo " Counter Rolled" | |
else | |
printf "%3u%% %10u\\n" $((anon_hits*100/hits)) $anon_hits | |
fi | |
printf " Most Recently Used %3u%% %10u\\n" $((mru_hits*100/hits)) $mru_hits | |
printf " Most Frequently Used %3u%% %10u\\n" $((mfu_hits*100/hits)) $mfu_hits | |
printf " Most Recently Used Ghost %3u%% %10u\\n" $((mru_ghost_hits*100/hits)) $mru_ghost_hits | |
printf " Most Frequently Used Ghost %3u%% %10u\\n" $((mfu_ghost_hits*100/hits)) $mfu_ghost_hits | |
echo | |
echo " CACHE HITS BY DATA TYPE:" | |
printf " Demand Data %3u%% %10u\\n" $((demand_data_hits*100/hits)) $demand_data_hits | |
printf " Prefetch Data %3u%% %10u\\n" $((prefetch_data_hits*100/hits)) $prefetch_data_hits | |
printf " Demand Metadata %3u%% %10u\\n" $((demand_metadata_hits*100/hits)) $demand_metadata_hits | |
printf " Prefetch Metadata %3u%% %10u\\n" $((prefetch_metadata_hits*100/hits)) $prefetch_metadata_hits | |
echo " CACHE MISSES BY DATA TYPE:" | |
printf " Demand Data %3u%% %10u\\n" $((demand_data_misses*100/hits)) $demand_data_misses | |
printf " Prefetch Data %3u%% %10u\\n" $((prefetch_data_misses*100/hits)) $prefetch_data_misses | |
printf " Demand Metadata %3u%% %10u\\n" $((demand_metadata_misses*100/hits)) $demand_metadata_misses | |
printf " Prefetch Metadata %3u%% %10u\\n" $((prefetch_metadata_misses*100/hits)) $prefetch_metadata_misses | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment