Skip to content

Instantly share code, notes, and snippets.

@deployable
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deployable/9a6009a75539d6d5d8fb to your computer and use it in GitHub Desktop.
Save deployable/9a6009a75539d6d5d8fb to your computer and use it in GitHub Desktop.
#Solaris/cross platform stat
stat_sizes() { perl -e '$file=shift; @f=stat($file); printf("%s bytes made up of %s*%s blocks\n",$f[7],$f[12],$f[11]);' "$1"; }
# Run something until it returns 0
wait_until() {
local cmd="$1"
local time_start=$(date +%s)
while ! $cmd; do
sleep 1
done
local time_end=$(date +%s)
printf "Waited %s seconds for [$cmd]\n" $(expr $time_end - $time_start)
}
# wait_until
compressratio_is_not_one() {
zfs_get_compressratio | grep -vq '1.00x'
}
# wait_until
compressratio_is_one() {
zfs_get_compressratio | grep -q '1.00x'
}
zfs_get_compressratio() {
zfs get -Hp compressratio $ZFS_FS | awk '{ print $3}'
}
# Run with: test_compression file_system
# Assumes the zfs file system is mounted on /file_system
test_compression() {
if [ -z "$1" ] || ! zfs list "$1" 2>&1 >/dev/null; then
printf "zfs file system as argument [%s]" "$1"; return 0; fi
export ZFS_FS="$1"
printf "Testing [%s]\n\n" "$ZFS_FS"
cd /$ZFS_FS || return 0
rm -f testfile*
for i in 1 4 256 8096; do
printf "Testing size [%s]\n" $(expr 4096 \* $i)
wait_until compressratio_is_one
dd if=/dev/zero bs=4k count=$i 2>/dev/null | tr "\000" "a" > testfile$i
stat_sizes testfile$i
wait_until compressratio_is_not_one
zfs_get_compressratio
echo
rm testfile$i
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment