diff options
-rwxr-xr-x | tools/disktest_sysbench.sh | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/tools/disktest_sysbench.sh b/tools/disktest_sysbench.sh new file mode 100755 index 0000000000..8c2f4cecad --- /dev/null +++ b/tools/disktest_sysbench.sh | |||
@@ -0,0 +1,151 @@ | |||
1 | #!/bin/bash | ||
2 | # __________ __ ___. | ||
3 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | # \/ \/ \/ \/ \/ | ||
8 | # $Id$ | ||
9 | # | ||
10 | # Copyright (C) 2020 William Wilgus | ||
11 | ################################################################################ | ||
12 | # | ||
13 | # chmod +x disktest_sysbench.sh | ||
14 | # | ||
15 | # apt install sysbench | ||
16 | # | ||
17 | # ./disktest_sysbench.sh /device path filesz(kb) block > ./disklog.txt | ||
18 | # | ||
19 | ################################################################################ | ||
20 | echo "Disktest Benchmarking [] $(date)" | ||
21 | |||
22 | set -uo pipefail | ||
23 | IFS=$'\n\t' | ||
24 | |||
25 | CMD=$(command -v sysbench) | ||
26 | TESTDURSEC=300 #5 minutes/test | ||
27 | VERBOSITY=5 | ||
28 | BLOCKSZ=('test all' 512 1024 4096 16384 65536 1048576) | ||
29 | THREADS=1 #--validate may fail if threads > 1 (some versions) | ||
30 | |||
31 | if [ -z "$CMD" ]; then | ||
32 | echo "This script requires 'sysbench' try: 'apt install sysbench' or your system package handler" | ||
33 | exit 1 | ||
34 | else | ||
35 | echo "using sysbench found @ $CMD" | ||
36 | echo "" | ||
37 | fi | ||
38 | |||
39 | if [ $# -lt 1 ]; then | ||
40 | echo "Usage: $0 <filepath_to_device>, <filesize_in_kB> <block 0-${#BLOCKSZ[@]}>" | ||
41 | exit 1 | ||
42 | fi | ||
43 | |||
44 | DEV_DIR=$1 | ||
45 | TEST_PATH="$DEV_DIR/disktest_sysbench" | ||
46 | SIZEKB=${2:-'10*1024'} #10Mb file [default] | ||
47 | SIZEBYTE=$((SIZEKB*1024)) | ||
48 | BLOCK=${3:-5} #65535 default | ||
49 | if (($BLOCK > ${#BLOCKSZ[@]})) ;then | ||
50 | $BLOCK = 0 | ||
51 | fi | ||
52 | |||
53 | BeginDiskTest() { | ||
54 | local start=$BLOCK | ||
55 | local blocks=$BLOCK+1 | ||
56 | local bs=0 | ||
57 | local cwd="/" | ||
58 | local filenum=0 | ||
59 | local sysbench_cmd | ||
60 | local out | ||
61 | |||
62 | if (( blocks == 1 )) ;then | ||
63 | start=1 | ||
64 | blocks=${#BLOCKSZ[@]} | ||
65 | fi | ||
66 | |||
67 | for (( b=$start; b<$blocks; b++ )) | ||
68 | do | ||
69 | bs=${BLOCKSZ[b]} | ||
70 | filenum=$(( SIZEBYTE / bs )) | ||
71 | # note try bigger block sizes if you run out of file handles | ||
72 | if (( $(ulimit -Sn ) < $(($filenum + 100)) )) ;then | ||
73 | local hard=$(ulimit -Hn) #get hard limit | ||
74 | echo attempting to increase soft file limit to $hard | ||
75 | ulimit -Sn $hard | ||
76 | fi | ||
77 | ################################################################################ | ||
78 | sysbench_cmd=(fileio --validate --file-total-size=$SIZEBYTE --file-block-size=$bs --file-num=$filenum --threads=$THREADS --max-requests=0 --time=$TESTDURSEC --file-extra-flags=direct --verbosity=$VERBOSITY --file-fsync-all=on) | ||
79 | echo "--------------------------------------------------------------------------------" | ||
80 | echo "Command Lines to be executed:" | ||
81 | echo "--------------------------------------------------------------------------------" | ||
82 | echo "Test Prep:" | ||
83 | echo ${CMD##*/} " fileio --file-total-size=$SIZEBYTE --file-block-size=$bs --file-num=$filenum prepare" | ||
84 | echo "" | ||
85 | echo "Sequential Write:" | ||
86 | echo ${CMD##*/} "${sysbench_cmd[@]}" --file-test-mode=seqwr run | ||
87 | echo "" | ||
88 | echo "Random R/W:" | ||
89 | echo ${CMD##*/} "${sysbench_cmd[@]}" --file-test-mode=rndrw run | ||
90 | echo "" | ||
91 | echo "Sequential Read:" | ||
92 | echo ${CMD##*/} "${sysbench_cmd[@]}" --file-test-mode=seqrd run | ||
93 | echo "--------------------------------------------------------------------------------" | ||
94 | echo "" | ||
95 | ################################################################################ | ||
96 | echo "Preparing ${filenum} files, ${SIZEKB}KB file Block Size: ${BLOCKSZ[b]}B..." | ||
97 | $CMD fileio --file-total-size=$SIZEBYTE --file-block-size=$bs --file-num=$filenum --verbosity=0 prepare | ||
98 | echo "" | ||
99 | echo "--------------------------------------------------------------------------------" | ||
100 | echo "SEQUENTIAL WRITE [$DEV_DIR] BLOCK SIZE: $bs" | ||
101 | echo "--------------------------------------------------------------------------------" | ||
102 | echo "" | ||
103 | out=$($CMD "${sysbench_cmd[@]}" --file-test-mode=seqwr run 2>&1) #exec command | ||
104 | printf "%s\n" "${out#*Threads started!}" | ||
105 | echo "--------------------------------------------------------------------------------" | ||
106 | echo "" | ||
107 | echo "--------------------------------------------------------------------------------" | ||
108 | echo "RANDOM WRITE/READ [$DEV_DIR] BLOCK SIZE: $bs" | ||
109 | echo "--------------------------------------------------------------------------------" | ||
110 | out=$("$CMD" "${sysbench_cmd[@]}" --file-test-mode=rndrw run 2>&1) #exec command | ||
111 | printf "%s\n" "${out#*Threads started!}" | ||
112 | echo "--------------------------------------------------------------------------------" | ||
113 | echo "" | ||
114 | echo "--------------------------------------------------------------------------------" | ||
115 | echo "SEQUENTIAL READ [$DEV_DIR] BLOCK SIZE: $bs" | ||
116 | echo "--------------------------------------------------------------------------------" | ||
117 | out=$("$CMD" "${sysbench_cmd[@]}" --file-test-mode=seqrd run 2>&1) #exec command | ||
118 | printf "%s\n" "${out#*Threads started!}" | ||
119 | echo "--------------------------------------------------------------------------------" | ||
120 | done | ||
121 | echo "--------------------------------------------------------------------------------" | ||
122 | echo "Finished [$DEV_DIR] $(date)" | ||
123 | echo "--------------------------------------------------------------------------------" | ||
124 | } | ||
125 | ################################################################################ | ||
126 | echo "Device Filepath: $1" | ||
127 | echo "Testfile Folder: $TEST_PATH" | ||
128 | echo "Filesize: $SIZEKB kB" | ||
129 | echo "Blocksize (bytes): ${BLOCKSZ[BLOCK]}" | ||
130 | echo "Test Duration (SEC) $TESTDURSEC Each" | ||
131 | echo "Tests: Random R/W, Sequential Write, Sequential Read" | ||
132 | echo "" | ||
133 | echo "Ready to create test files on device @ $TEST_PATH" | ||
134 | echo Continue Y/n? | ||
135 | read prompt | ||
136 | if [ "$prompt" != "${prompt#[Yy]}" ] ;then | ||
137 | [ -d $TEST_PATH ] || mkdir $TEST_PATH | ||
138 | cd "$TEST_PATH" | ||
139 | cwd=$(pwd -P) | ||
140 | if [ "$cwd" = "$TEST_PATH" ] ;then | ||
141 | BeginDiskTest | ||
142 | else | ||
143 | echo "couldn't cd to device directory " | ||
144 | exit 2 | ||
145 | fi | ||
146 | else | ||
147 | echo "exiting" | ||
148 | exit 0 | ||
149 | fi | ||
150 | |||
151 | exit 0 | ||