Advertisement
Guest User

fiodiskmark

a guest
Jan 9th, 2020
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 11.21 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ -f /usr/bin/fio ] && [ -f /usr/bin/df ]; then #Dependency check
  4.     :
  5. else
  6.     echo -e "\033[1;31mError: This script requires fio and df to run, please make sure both are installed."
  7.     exit
  8. fi
  9.  
  10. echo "What drive do you want to test? (Default: $HOME on /dev/$(df $HOME | grep /dev | cut -d/ -f3 | cut -d" " -f1) )"
  11. echo -e "\033[0;33mOnly directory paths (e.g. /home/user/) are valid targets.\033[0;00m"
  12. read -e TARGET
  13.  
  14. echo "
  15. How many times to run the test? (Default: 5)"
  16. read LOOPS
  17.  
  18. echo "How large should each test be in MiB? (Default: 1024)"
  19. echo -e "\033[0;33mOnly multiples of 32 are permitted!\033[0;00m"
  20.  
  21. read SIZE
  22.  
  23. echo "Do you want to write only zeroes to your test files to imitate dd benchmarks? (Default: 0)"
  24. echo -e "\033[0;33mEnabling this setting may drastically alter your results, not recommended unless you know what you're doing.\033[0;00m"
  25. read WRITEZERO
  26.  
  27. read -p "Would you like to include legacy tests (512kb & Q1T1 Sequential Read/Write)? [Y/N]" -n 1 -r
  28. LEGACY=$REPLY
  29.  
  30. if [[ $LEGACY =~ ^[Yy]$ ]]; then
  31.     :
  32. else
  33.     LEGACY=no
  34. fi
  35.  
  36. if [ -d $TARGET ]; then
  37.     TARGET=$HOME
  38. elif [ -d $TARGET ]; then
  39.     :
  40. else
  41.     echo -e "\033[1;31mError: $TARGET is not a valid path."
  42.     exit
  43. fi
  44.  
  45. if [ -z $LOOPS ]; then
  46.     LOOPS=5
  47. elif [ "$LOOPS" -eq "$LOOPS" ] 2>/dev/null; then
  48.     :
  49. else
  50.   echo -e "\033[1;31mError: $LOOPS is not a valid number, please use a number to declare how many times to loop tests."
  51.   exit
  52. fi
  53.  
  54. if [ -z $SIZE ]; then
  55.     SIZE=1024
  56. elif [ "$SIZE" -eq "$SIZE" ] 2>/dev/null && ! (( $SIZE % 32 )) 2>/dev/null;then
  57.     :
  58. else
  59.     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)."
  60.     exit
  61. fi
  62.  
  63. if [ -z $WRITEZERO ]; then
  64.     WRITEZERO=0
  65. elif [ "$WRITEZERO" -eq 1 ] 2>/dev/null || [ "$WRITEZERO" -eq 0 ] 2>/dev/null; then
  66.     :
  67. else
  68.     echo -e "\033[1;31mError: WRITEZERO only accepts 0 or 1, $WRITEZERO is not a valid argument."
  69.     exit
  70. fi
  71.  
  72. DRIVE=$(df $TARGET | grep /dev | cut -d/ -f3 | cut -d" " -f1 | rev | cut -c 2- | rev)
  73.  
  74. if [[ $DRIVE = "nvme"* ]]; then #NVME Compatibility
  75.     DRIVE=$(echo ${DRIVE:0:$((${#DRIVE}-1))})
  76. fi
  77.  
  78. DRIVEMODEL=$(cat /sys/block/$DRIVE/device/model | sed 's/ *$//g')
  79. DRIVESIZE=$(($(cat /sys/block/$DRIVE/size)*512/1024/1024/1024))GB
  80. DRIVEPERCENT=$(df -h $TARGET | cut -d ' ' -f11 | tail -n 1)
  81. DRIVEUSED=$(df -h $TARGET | cut -d ' ' -f6 | tail -n 1)
  82.  
  83. echo "
  84. Settings are as follows:
  85. Target Directory: $TARGET
  86. Target Drive: $DRIVE
  87. Size Of Test: $SIZE MiB
  88. Number Of Loops: $LOOPS
  89. Write Zeroes: $WRITEZERO
  90. Legacy Tests: $LEGACY
  91. "
  92. read -p "Are you sure these are correct? [Y/N]" -n 1 -r
  93. if [[ $REPLY =~ ^[Yy]$ ]]; then
  94.     echo ""
  95. else
  96.     echo ""
  97.     exit
  98. fi
  99.  
  100. QSIZE=$(($SIZE / 32)) #Size of Q32Seq tests
  101. SIZE+=m
  102. QSIZE+=m
  103.  
  104. echo "
  105. Running Benchmark on: /dev/$DRIVE, $DRIVEMODEL ($DRIVESIZE), please wait...
  106. "
  107.  
  108. if [[ $LEGACY =~ ^[Yy]$ ]]; then
  109. fio --loops=$LOOPS --size=$SIZE --filename=$TARGET/.fiomark.tmp --stonewall --ioengine=libaio --direct=1 --zero_buffers=$WRITEZERO --output-format=json \
  110.   --name=Bufread --loops=1 --bs=$SIZE --iodepth=1 --numjobs=1 --rw=readwrite \
  111.   --name=Seqread --bs=$SIZE --iodepth=1 --numjobs=1 --rw=read \
  112.   --name=Seqwrite --bs=$SIZE --iodepth=1 --numjobs=1 --rw=write \
  113.   --name=512kread --bs=512k --iodepth=1 --numjobs=1 --rw=read \
  114.   --name=512kwrite --bs=512k --iodepth=1 --numjobs=1 --rw=write \
  115.   --name=SeqQ32T1read --bs=$QSIZE --iodepth=32 --numjobs=1 --rw=read \
  116.   --name=SeqQ32T1write --bs=$QSIZE --iodepth=32 --numjobs=1 --rw=write \
  117.   --name=4kread --bs=4k --iodepth=1 --numjobs=1 --rw=randread \
  118.   --name=4kwrite --bs=4k --iodepth=1 --numjobs=1 --rw=randwrite \
  119.   --name=4kQ32T1read --bs=4k --iodepth=32 --numjobs=1 --rw=randread \
  120.   --name=4kQ32T1write --bs=4k --iodepth=32 --numjobs=1 --rw=randwrite \
  121.   --name=4kQ8T8read --bs=4k --iodepth=8 --numjobs=8 --rw=randread \
  122.   --name=4kQ8T8write --bs=4k --iodepth=8 --numjobs=8 --rw=randwrite > $TARGET/.fiomark.txt
  123.  
  124. 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]"
  125. 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]"
  126. 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]"
  127. 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]"
  128.  
  129. echo -e "
  130. Results from /dev/$DRIVE, $DRIVEMODEL ($DRIVESIZE):  
  131. \033[0;33m
  132. Sequential Read: $SEQR
  133. Sequential Write: $SEQW
  134. \033[0;32m
  135. 512KB Read: $F12KR
  136. 512KB Write: $F12KW
  137. "
  138. else
  139. fio --loops=$LOOPS --size=$SIZE --filename=$TARGET/.fiomark.tmp --stonewall --ioengine=libaio --direct=1 --zero_buffers=$WRITEZERO --output-format=json \
  140.   --name=Bufread --loops=1 --bs=$SIZE --iodepth=1 --numjobs=1 --rw=readwrite \
  141.   --name=SeqQ32T1read --bs=$QSIZE --iodepth=32 --numjobs=1 --rw=read \
  142.   --name=SeqQ32T1write --bs=$QSIZE --iodepth=32 --numjobs=1 --rw=write \
  143.   --name=4kread --bs=4k --iodepth=1 --numjobs=1 --rw=randread \
  144.   --name=4kwrite --bs=4k --iodepth=1 --numjobs=1 --rw=randwrite \
  145.   --name=4kQ32T1read --bs=4k --iodepth=32 --numjobs=1 --rw=randread \
  146.   --name=4kQ32T1write --bs=4k --iodepth=32 --numjobs=1 --rw=randwrite \
  147.   --name=4kQ8T8read --bs=4k --iodepth=8 --numjobs=8 --rw=randread \
  148.   --name=4kQ8T8write --bs=4k --iodepth=8 --numjobs=8 --rw=randwrite > $TARGET/.fiomark.txt
  149. fi
  150.  
  151.  
  152.  
  153. 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]"
  154. 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]"
  155. 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]"
  156. 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]"
  157. 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]"
  158. 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]"
  159. 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]"
  160. 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]"
  161.  
  162.  
  163. echo -e "\033[1;36mSequential Q32T1 Read: $SEQ32R
  164. Sequential Q32T1 Write: $SEQ32W
  165. \033[0;36m
  166. 4KB Read: $FKR
  167. 4KB Write: $FKW
  168. \033[1;33m
  169. 4KB Q32T1 Read: $FK32R
  170. 4KB Q32T1 Write: $FK32W
  171. \033[1;35m
  172. 4KB Q8T8 Read: $FK8R
  173. 4KB Q8T8 Write: $FK8W
  174. \033[0;00m"
  175. read -p "Would you like to save these results? [Y/N]" -n 1 -r
  176. if [[ $REPLY =~ ^[Nn]$ ]]; then
  177.     echo ""
  178. else
  179.     echo "
  180. Saving at $HOME/$DRIVE$(date +%F%I%M%S).txt
  181. "
  182.     if [[ $LEGACY =~ ^[Yy]$ ]]; then
  183. echo "-----------------------------------------------------------------------
  184. Flexible I/O Tester - $(fio --version) (C) axboe
  185.                          Fio Github : https://github.com/axboe/fio
  186.                       Script Source : https://unix.stackexchange.com/a/480191/72554
  187. -----------------------------------------------------------------------
  188. * MB/s = 1,000,000 bytes/s
  189. * KB = 1000 bytes, KiB = 1024 bytes
  190.  
  191.   Legacy Seq Read (Q=  1,T= 1) :   $SEQR
  192.  Legacy Seq Write (Q=  1,T= 1) :   $SEQW
  193.   512KiB Seq Read (Q=  1,T= 1) :   $F12KR
  194.  512KiB Seq Write (Q=  1,T= 1) :   $F12KW
  195.   Sequential Read (Q= 32,T= 1) :   $SEQ32R
  196.  Sequential Write (Q= 32,T= 1) :   $SEQ32W
  197.  Random Read 4KiB (Q=  8,T= 8) :   $FK8R
  198. Random Write 4KiB (Q=  8,T= 8) :   $FK8W
  199.  Random Read 4KiB (Q= 32,T= 1) :   $FK32R
  200. Random Write 4KiB (Q= 32,T= 1) :   $FK32W
  201.  Random Read 4KiB (Q=  1,T= 1) :   $FKR
  202. Random Write 4KiB (Q=  1,T= 1) :   $FKW
  203.  
  204.  Test : ${SIZE:0:$((${#SIZE}-1))} MiB [$DRIVEMODEL, $DRIVE $DRIVEPERCENT ($DRIVEUSED/${DRIVESIZE:0:$((${#DRIVESIZE}-2))}GiB] (x$LOOPS)  [Interval=0 sec]
  205.  Date : $(date +%F | sed 's:-:/:g') $(date +%T)
  206.    OS : $(uname -srm)
  207.  " > "$HOME/$DRIVE$(date +%F%I%M%S).txt"
  208.     else
  209. echo "-----------------------------------------------------------------------
  210. Flexible I/O Tester - $(fio --version) (C) axboe
  211.                          Fio Github : https://github.com/axboe/fio
  212.                       Script Source : https://unix.stackexchange.com/a/480191/72554
  213. -----------------------------------------------------------------------
  214. * MB/s = 1,000,000 bytes/s
  215. * KB = 1000 bytes, KiB = 1024 bytes
  216.  
  217.   Sequential Read (Q= 32,T= 1) :   $SEQ32R
  218.  Sequential Write (Q= 32,T= 1) :   $SEQ32W
  219.  Random Read 4KiB (Q=  8,T= 8) :   $FK8R
  220. Random Write 4KiB (Q=  8,T= 8) :   $FK8W
  221.  Random Read 4KiB (Q= 32,T= 1) :   $FK32R
  222. Random Write 4KiB (Q= 32,T= 1) :   $FK32W
  223.  Random Read 4KiB (Q=  1,T= 1) :   $FKR
  224. Random Write 4KiB (Q=  1,T= 1) :   $FKW
  225.  
  226.  Test : ${SIZE:0:$((${#SIZE}-1))} MiB [$DRIVEMODEL, $DRIVE $DRIVEPERCENT (${DRIVEUSED:0:$((${#DRIVUSED}-1))}/${DRIVESIZE:0:$((${#DRIVESIZE}-2))} GiB] (x$LOOPS)  [Interval=0 sec]
  227.  Date : $(date +%F | sed 's:-:/:g') $(date +%T)
  228.    OS : $(uname -srm)
  229.  " > "$HOME/$DRIVE$(date +%F%I%M%S).txt"
  230.     fi
  231. fi
  232.  
  233. rm $TARGET/.fiomark.txt $TARGET/.fiomark.tmp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement