-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbench_disk.sh
More file actions
executable file
·125 lines (102 loc) · 3.27 KB
/
bench_disk.sh
File metadata and controls
executable file
·125 lines (102 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
# bench_disk.sh - a rough disk benchmark tool using dd
# author : Chad Mayfield (code@chadmayfield.com)
# license : gplv3
# TODO:
# - fix sudo issue... doesn't work
# - add user defined bs and count
# - add bonnie++ and ioping functions
path=$1
#log_file=/var/log/diskbench.log
tmp_file=tempfile
dev_in=/dev/zero
dev_out=/dev/null # where to write it
block_size=1M # block size to write
count=1024 # number of blocks to write
# verify we have correct args
if [ $# -ne 1 ]; then
echo "Please specify a path to test!"
exit 1
fi
# verify that our path that exists
if [ ! -d "$path" ]; then
echo "Path does not exist: $path"
exit 1
fi
# don't mess with permissions, just switch to root
if [ $UID -ne 0 ]; then
# echo "Must be run as root, please enter your password:"
# sudo -ik $0 $@
echo "Must be run as root!"
exit 1
fi
# TODO: added arg for size of tempfile and iterations
# TODO: check for disk space available so we kill anything
##### functions start #####
# TODO: add logging to file and console for historical data
#log() {
# echo "$(date): $@" >> $logfile
#}
# dd benchmarking commands (in part) adapted from the archlinux wiki
# https://wiki.archlinux.org/index.php/SSD_Benchmarking#Using_dd
do_seq_write() {
# sequential write
echo -n " writing..."
dd if="$dev_in" of="$path/$tmp_file" bs=1M count=1024 conv=fdatasync,notrunc &>/tmp/$$
# seq_write=$(grep -v records /tmp/$$)
w_speed=$(grep -v records /tmp/$$ | awk '{print $8" "$9 }')
w_size=$(grep -v records /tmp/$$ | awk '{print $3" "$4}' | tr -d '()')
w_time=$(grep -v records /tmp/$$ | awk '{print $6" "$7}' | tr -d ',' )
}
do_flush() {
# flush cache
echo -n " flushing cache..."
echo 3 > /proc/sys/vm/drop_caches
}
do_seq_read() {
# sequential read
echo -n " reading..."
dd if="$path/$tmp_file" of=$dev_out bs=$block_size count=$count &> /tmp/$$
# seq_read=$(grep -v records /tmp/$$)
r_speed=$(grep -v records /tmp/$$ | awk '{print $8" "$9 }')
r_size=$(grep -v records /tmp/$$ | awk '{print $3" "$4}' | tr -d '()')
r_time=$(grep -v records /tmp/$$ | awk '{print $6" "$7}' | tr -d ',' )
}
do_cached_read() {
# cached sequential read
echo -n " reading (cached)..."
dd if="$path/$tmp_file" of=$dev_out bs=$block_size count=$count &> /tmp/$$
# cached_read=$(grep -v records /tmp/$$)
rc_speed=$(grep -v records /tmp/$$ | awk '{print $8" "$9 }')
rc_size=$(grep -v records /tmp/$$ | awk '{print $3" "$4}' | tr -d '()')
rc_time=$(grep -v records /tmp/$$ | awk '{print $6" "$7}' | tr -d ',' )
}
cleanup() {
# remove test file
rm -f $tmp_file /tmp/$$
sleep 2
}
echo "beginning dd tests:"
for i in do_seq_write do_flush do_seq_read do_cached_read
do
$i
sleep 1
echo "done"
done
# TODO: add ioping and bonnie++ tests
#echo "beginning bonnie++ tests:"
#echo " coming soon"
cleanup
echo "dd results:"
# raw dd output
#echo " "
#echo "Sequential write: $seq_write"
#echo "Sequential read : $seq_read"
#echo "Cached read : $cached_read"
#echo " "
# prettier output
printf "%s\n" " path $path"
printf "%s\n" " write $w_speed \t($w_size in $w_time)"
printf "%s\n" " read $r_speed \t($r_size in $r_time)"
printf "%s\n" " cached $rc_speed \t($rc_size in $rc_time)"
#EOF