Created
June 21, 2023 20:01
-
-
Save eatnumber1/a95b68fd80d6450b3c87bde8fc2d6aa9 to your computer and use it in GitHub Desktop.
Draw a sparkline of dirty pages over time on Linux.
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/bash | |
set -e | |
set -o pipefail | |
statefile="$(mktemp --tmpdir=/run spark-dirty-pages.XXXXX)" | |
trap 'rm -f $statefile' INT HUP QUIT | |
function watch_iter { | |
declare -a dirty | |
readarray -t dirty < "$statefile" | |
dirty+=( "$(grep Dirty /proc/meminfo | awk '{print $2 "K";}' | numfmt --from=iec)" ) | |
declare -i trimstart | |
(( trimstart = ${#dirty[@]} - COLUMNS )) | |
if (( trimstart < 0 )); then | |
trimstart=0 | |
fi | |
dirty=( "${dirty[@]:$trimstart:$COLUMNS}" ) | |
# Flush the state file | |
printf "%s\n" "${dirty[@]}" > "$statefile" | |
echo "Dirty: $(numfmt --to=iec --suffix=B ${dirty[-1]})" | |
# https://github.com/holman/spark | |
spark <<< "${dirty[@]}" | |
} | |
export -f watch_iter | |
export statefile | |
watch -ex "$@" -- "$BASH" -c watch_iter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment