Friday, January 16, 2015

Colorized DD Sequential Write Benchmark Alias

alias bm='_(){ CP="\\033[1;3"; Y="${CP}3m"; C="${CP}6m"; R="${CP}1m"; G="${CP}2m"; RST="${CP}0m"; if [ ! -w "." ]; then echo -en "${R}Current directory is not writable aborting benchmark.\n"; else SIZE=${1:-500}; FS=$(df . |sed "1d"|awk "{print \$1}"); LGFILE="./largefile43bm52342"; AVAILSPC=$(df -BM .|sed "1d"|awk "{print \$4}"|sed "s/M$//"); [[ ! -f "${LGFILE}" ]] && ((${SIZE}<$AVAILSPC)) && { DDRES=$(dd if=/dev/zero of="${LGFILE}" bs=1M count=${SIZE} 2>&1); DDRES=$(echo "${DDRES}" |tr "\n" " "| cut -d " " -f14-); rm "${LGFILE}"; echo -en "${Y}Sequential Write Benchmark for${RST} ${C}${FS}${RST}${Y}:${RST} ${G}(${SIZE}MB @) ${DDRES}${RST}\n"; } || { [[ -f "${LGFILE}" ]] && echo -en "${R}A file with the same name as the test file already exists: ${LGFILE}\nAborting benchmark, choose a new location on the same FS.\n(Where a file with the same name as the test file does not exist.)\n${RST}" || echo -en "${R}Not enough space on ${FS} for benchmark,\nAvail space: ${AVAILSPC}MB, Attempted ${SIZE}MB..\nTry again with a smaller size.\n${RST}"; }; fi; }; _' 

It optionally takes one argument, the size in MB of a file to test - if no argument is provided it will default to 500MB, it is fairly well behaved, it will check that there is space on the FS where it is run. And its output looks like this:   

Sequential Write Benchmark for /dev/sdb1: (500MB @) 178.3 MB/s

No comments:

Post a Comment