Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ -f /usr/bin/fio ] && [ -f /usr/bin/df ]; then #Dependency check
- :
- else
- echo -e "\033[1;31mError: This script requires fio and df to run, please make sure both are installed."
- exit
- fi
- echo "What drive do you want to test? (Default: $HOME on /dev/$(df $HOME | grep /dev | cut -d/ -f3 | cut -d" " -f1) )"
- echo -e "\033[0;33mOnly directory paths (e.g. /home/user/) are valid targets.\033[0;00m"
- read -e TARGET
- echo "
- How many times to run the test? (Default: 5)"
- read LOOPS
- echo "How large should each test be in MiB? (Default: 1024)"
- echo -e "\033[0;33mOnly multiples of 32 are permitted!\033[0;00m"
- read SIZE
- echo "Do you want to write only zeroes to your test files to imitate dd benchmarks? (Default: 0)"
- echo -e "\033[0;33mEnabling this setting may drastically alter your results, not recommended unless you know what you're doing.\033[0;00m"
- read WRITEZERO
- read -p "Would you like to include legacy tests (512kb & Q1T1 Sequential Read/Write)? [Y/N]" -n 1 -r
- LEGACY=$REPLY
- if [[ $LEGACY =~ ^[Yy]$ ]]; then
- :
- else
- LEGACY=no
- fi
- if [ -d $TARGET ]; then
- TARGET=$HOME
- elif [ -d $TARGET ]; then
- :
- else
- echo -e "\033[1;31mError: $TARGET is not a valid path."
- exit
- fi
- if [ -z $LOOPS ]; then
- LOOPS=5
- elif [ "$LOOPS" -eq "$LOOPS" ] 2>/dev/null; then
- :
- else
- echo -e "\033[1;31mError: $LOOPS is not a valid number, please use a number to declare how many times to loop tests."
- exit
- fi
- if [ -z $SIZE ]; then
- SIZE=1024
- elif [ "$SIZE" -eq "$SIZE" ] 2>/dev/null && ! (( $SIZE % 32 )) 2>/dev/null;then
- :
- else
- echo -e "\033[1;31mError: The test size must be an integer set to a multiple of 32. Please write a multiple of 32 for the size setting (Optimal settings: 1024, 2048, 4096, 8192, 16384)."
- exit
- fi
- if [ -z $WRITEZERO ]; then
- WRITEZERO=0
- elif [ "$WRITEZERO" -eq 1 ] 2>/dev/null || [ "$WRITEZERO" -eq 0 ] 2>/dev/null; then
- :
- else
- echo -e "\033[1;31mError: WRITEZERO only accepts 0 or 1, $WRITEZERO is not a valid argument."
- exit
- fi
- DRIVE=$(df $TARGET | grep /dev | cut -d/ -f3 | cut -d" " -f1 | rev | cut -c 2- | rev)
- if [[ $DRIVE = "nvme"* ]]; then #NVME Compatibility
- DRIVE=$(echo ${DRIVE:0:$((${#DRIVE}-1))})
- fi
- DRIVEMODEL=$(cat /sys/block/$DRIVE/device/model | sed 's/ *$//g')
- DRIVESIZE=$(($(cat /sys/block/$DRIVE/size)*512/1024/1024/1024))GB
- DRIVEPERCENT=$(df -h $TARGET | cut -d ' ' -f11 | tail -n 1)
- DRIVEUSED=$(df -h $TARGET | cut -d ' ' -f6 | tail -n 1)
- echo "
- Settings are as follows:
- Target Directory: $TARGET
- Target Drive: $DRIVE
- Size Of Test: $SIZE MiB
- Number Of Loops: $LOOPS
- Write Zeroes: $WRITEZERO
- Legacy Tests: $LEGACY
- "
- read -p "Are you sure these are correct? [Y/N]" -n 1 -r
- if [[ $REPLY =~ ^[Yy]$ ]]; then
- echo ""
- else
- echo ""
- exit
- fi
- QSIZE=$(($SIZE / 32)) #Size of Q32Seq tests
- SIZE+=m
- QSIZE+=m
- echo "
- Running Benchmark on: /dev/$DRIVE, $DRIVEMODEL ($DRIVESIZE), please wait...
- "
- if [[ $LEGACY =~ ^[Yy]$ ]]; then
- fio --loops=$LOOPS --size=$SIZE --filename=$TARGET/.fiomark.tmp --stonewall --ioengine=libaio --direct=1 --zero_buffers=$WRITEZERO --output-format=json \
- --name=Bufread --loops=1 --bs=$SIZE --iodepth=1 --numjobs=1 --rw=readwrite \
- --name=Seqread --bs=$SIZE --iodepth=1 --numjobs=1 --rw=read \
- --name=Seqwrite --bs=$SIZE --iodepth=1 --numjobs=1 --rw=write \
- --name=512kread --bs=512k --iodepth=1 --numjobs=1 --rw=read \
- --name=512kwrite --bs=512k --iodepth=1 --numjobs=1 --rw=write \
- --name=SeqQ32T1read --bs=$QSIZE --iodepth=32 --numjobs=1 --rw=read \
- --name=SeqQ32T1write --bs=$QSIZE --iodepth=32 --numjobs=1 --rw=write \
- --name=4kread --bs=4k --iodepth=1 --numjobs=1 --rw=randread \
- --name=4kwrite --bs=4k --iodepth=1 --numjobs=1 --rw=randwrite \
- --name=4kQ32T1read --bs=4k --iodepth=32 --numjobs=1 --rw=randread \
- --name=4kQ32T1write --bs=4k --iodepth=32 --numjobs=1 --rw=randwrite \
- --name=4kQ8T8read --bs=4k --iodepth=8 --numjobs=8 --rw=randread \
- --name=4kQ8T8write --bs=4k --iodepth=8 --numjobs=8 --rw=randwrite > $TARGET/.fiomark.txt
- SEQR="$(($(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "Seqread"' | grep bw_bytes | cut -d: -f2 | sed s:,::g)/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "Seqread"' | grep -m1 iops | cut -d: -f2 | cut -d. -f1 | sed 's: ::g') IOPS]"
- SEQW="$(($(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "Seqwrite"' | grep bw_bytes | sed '2!d' | cut -d: -f2 | sed s:,::g)/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "Seqwrite"' | grep iops | sed '7!d' | cut -d: -f2 | cut -d. -f1 | sed 's: ::g') IOPS]"
- F12KR="$(($(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "512kread"' | grep bw_bytes | cut -d: -f2 | sed s:,::g)/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "512kread"' | grep -m1 iops | cut -d: -f2 | cut -d. -f1 | sed 's: ::g') IOPS]"
- F12KW="$(($(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "512kwrite"' | grep bw_bytes | sed '2!d' | cut -d: -f2 | sed s:,::g)/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "512kwrite"' | grep iops | sed '7!d' | cut -d: -f2 | cut -d. -f1 | sed 's: ::g') IOPS]"
- echo -e "
- Results from /dev/$DRIVE, $DRIVEMODEL ($DRIVESIZE):
- \033[0;33m
- Sequential Read: $SEQR
- Sequential Write: $SEQW
- \033[0;32m
- 512KB Read: $F12KR
- 512KB Write: $F12KW
- "
- else
- fio --loops=$LOOPS --size=$SIZE --filename=$TARGET/.fiomark.tmp --stonewall --ioengine=libaio --direct=1 --zero_buffers=$WRITEZERO --output-format=json \
- --name=Bufread --loops=1 --bs=$SIZE --iodepth=1 --numjobs=1 --rw=readwrite \
- --name=SeqQ32T1read --bs=$QSIZE --iodepth=32 --numjobs=1 --rw=read \
- --name=SeqQ32T1write --bs=$QSIZE --iodepth=32 --numjobs=1 --rw=write \
- --name=4kread --bs=4k --iodepth=1 --numjobs=1 --rw=randread \
- --name=4kwrite --bs=4k --iodepth=1 --numjobs=1 --rw=randwrite \
- --name=4kQ32T1read --bs=4k --iodepth=32 --numjobs=1 --rw=randread \
- --name=4kQ32T1write --bs=4k --iodepth=32 --numjobs=1 --rw=randwrite \
- --name=4kQ8T8read --bs=4k --iodepth=8 --numjobs=8 --rw=randread \
- --name=4kQ8T8write --bs=4k --iodepth=8 --numjobs=8 --rw=randwrite > $TARGET/.fiomark.txt
- fi
- SEQ32R="$(($(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "SeqQ32T1read"' | grep bw_bytes | cut -d: -f2 | sed s:,::g)/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "SeqQ32T1read"' | grep -m1 iops | cut -d: -f2 | cut -d. -f1 | sed 's: ::g') IOPS]"
- SEQ32W="$(($(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "SeqQ32T1write"' | grep bw_bytes | sed '2!d' | cut -d: -f2 | sed s:,::g)/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "SeqQ32T1write"' | grep iops | sed '7!d' | cut -d: -f2 | cut -d. -f1 | sed 's: ::g') IOPS]"
- FKR="$(($(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "4kread"' | grep bw_bytes | cut -d: -f2 | sed s:,::g)/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "4kread"' | grep -m1 iops | cut -d: -f2 | cut -d. -f1 | sed 's: ::g') IOPS]"
- FKW="$(($(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "4kwrite"' | grep bw_bytes | sed '2!d' | cut -d: -f2 | sed s:,::g)/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "4kwrite"' | grep iops | sed '7!d' | cut -d: -f2 | cut -d. -f1 | sed 's: ::g') IOPS]"
- FK32R="$(($(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "4kQ32T1read"' | grep bw_bytes | cut -d: -f2 | sed s:,::g)/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "4kQ32T1read"' | grep -m1 iops | cut -d: -f2 | cut -d. -f1 | sed 's: ::g') IOPS]"
- FK32W="$(($(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "4kQ32T1write"' | grep bw_bytes | sed '2!d' | cut -d: -f2 | sed s:,::g)/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "4kQ32T1write"' | grep iops | sed '7!d' | cut -d: -f2 | cut -d. -f1 | sed 's: ::g') IOPS]"
- FK8R="$(($(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "4kQ8T8read"' | grep bw_bytes | sed 's/ "bw_bytes" : //g' | sed 's:,::g' | awk '{ SUM += $1} END { print SUM }')/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A15 '"name" : "4kQ8T8read"' | grep iops | sed 's/ "iops" : //g' | sed 's:,::g' | awk '{ SUM += $1} END { print SUM }' | cut -d. -f1) IOPS]"
- FK8W="$(($(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "4kQ8T8write"' | grep bw_bytes | sed 's/ "bw_bytes" : //g' | sed 's:,::g' | awk '{ SUM += $1} END { print SUM }')/1000/1000)) MB/s [ $(cat $TARGET/.fiomark.txt | grep -A80 '"name" : "4kQ8T8write"' | grep '"iops" '| sed 's/ "iops" : //g' | sed 's:,::g' | awk '{ SUM += $1} END { print SUM }' | cut -d. -f1) IOPS]"
- echo -e "\033[1;36mSequential Q32T1 Read: $SEQ32R
- Sequential Q32T1 Write: $SEQ32W
- \033[0;36m
- 4KB Read: $FKR
- 4KB Write: $FKW
- \033[1;33m
- 4KB Q32T1 Read: $FK32R
- 4KB Q32T1 Write: $FK32W
- \033[1;35m
- 4KB Q8T8 Read: $FK8R
- 4KB Q8T8 Write: $FK8W
- \033[0;00m"
- read -p "Would you like to save these results? [Y/N]" -n 1 -r
- if [[ $REPLY =~ ^[Nn]$ ]]; then
- echo ""
- else
- echo "
- Saving at $HOME/$DRIVE$(date +%F%I%M%S).txt
- "
- if [[ $LEGACY =~ ^[Yy]$ ]]; then
- echo "-----------------------------------------------------------------------
- Flexible I/O Tester - $(fio --version) (C) axboe
- Fio Github : https://github.com/axboe/fio
- Script Source : https://unix.stackexchange.com/a/480191/72554
- -----------------------------------------------------------------------
- * MB/s = 1,000,000 bytes/s
- * KB = 1000 bytes, KiB = 1024 bytes
- Legacy Seq Read (Q= 1,T= 1) : $SEQR
- Legacy Seq Write (Q= 1,T= 1) : $SEQW
- 512KiB Seq Read (Q= 1,T= 1) : $F12KR
- 512KiB Seq Write (Q= 1,T= 1) : $F12KW
- Sequential Read (Q= 32,T= 1) : $SEQ32R
- Sequential Write (Q= 32,T= 1) : $SEQ32W
- Random Read 4KiB (Q= 8,T= 8) : $FK8R
- Random Write 4KiB (Q= 8,T= 8) : $FK8W
- Random Read 4KiB (Q= 32,T= 1) : $FK32R
- Random Write 4KiB (Q= 32,T= 1) : $FK32W
- Random Read 4KiB (Q= 1,T= 1) : $FKR
- Random Write 4KiB (Q= 1,T= 1) : $FKW
- Test : ${SIZE:0:$((${#SIZE}-1))} MiB [$DRIVEMODEL, $DRIVE $DRIVEPERCENT ($DRIVEUSED/${DRIVESIZE:0:$((${#DRIVESIZE}-2))}GiB] (x$LOOPS) [Interval=0 sec]
- Date : $(date +%F | sed 's:-:/:g') $(date +%T)
- OS : $(uname -srm)
- " > "$HOME/$DRIVE$(date +%F%I%M%S).txt"
- else
- echo "-----------------------------------------------------------------------
- Flexible I/O Tester - $(fio --version) (C) axboe
- Fio Github : https://github.com/axboe/fio
- Script Source : https://unix.stackexchange.com/a/480191/72554
- -----------------------------------------------------------------------
- * MB/s = 1,000,000 bytes/s
- * KB = 1000 bytes, KiB = 1024 bytes
- Sequential Read (Q= 32,T= 1) : $SEQ32R
- Sequential Write (Q= 32,T= 1) : $SEQ32W
- Random Read 4KiB (Q= 8,T= 8) : $FK8R
- Random Write 4KiB (Q= 8,T= 8) : $FK8W
- Random Read 4KiB (Q= 32,T= 1) : $FK32R
- Random Write 4KiB (Q= 32,T= 1) : $FK32W
- Random Read 4KiB (Q= 1,T= 1) : $FKR
- Random Write 4KiB (Q= 1,T= 1) : $FKW
- Test : ${SIZE:0:$((${#SIZE}-1))} MiB [$DRIVEMODEL, $DRIVE $DRIVEPERCENT (${DRIVEUSED:0:$((${#DRIVUSED}-1))}/${DRIVESIZE:0:$((${#DRIVESIZE}-2))} GiB] (x$LOOPS) [Interval=0 sec]
- Date : $(date +%F | sed 's:-:/:g') $(date +%T)
- OS : $(uname -srm)
- " > "$HOME/$DRIVE$(date +%F%I%M%S).txt"
- fi
- fi
- rm $TARGET/.fiomark.txt $TARGET/.fiomark.tmp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement