-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
fsbench
executable file
·93 lines (81 loc) · 2.06 KB
/
fsbench
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
#!/bin/bash
# macOS doesn't have gnu date so no +%N also dd wants m instead of M for buffer size
# about the same with FreeBSD
# patches welcome
#
# https://www.thegeekdiary.com/how-to-clear-the-buffer-pagecache-disk-cache-under-linux/
# check if called binaries are available
for a in uname date bc seq sync dd file awk tail grep shuf; do
hash $a >/dev/null
if [ ! $? -eq 0 ]; then
echo $a not found
exit 1
fi
done
trap ctrl_c INT
# catch ctrl-c
function ctrl_c() {
echo -e "\rCleaning up..."
if [ -d _fsbench ]; then
rm -rf _fsbench
fi
exit 0
}
# does the user want to test with something else than up to 50 mb files?
if [ "$#" -ne 1 ]; then
num=50
else
num=$1
if ! expr $num + 0 >/dev/null 2>&1; then
echo Syntax error: need a number.
exit 1
fi
fi
# check if there's enough diskspace, compare value above with num
freemb=`df -m . | tail -1 | awk '{print $4}'`
if [ $num -gt $freemb ]; then
echo $num MB diskspace needed, but only $freemb MB found.
exit 1
fi
totalmb=0
for a in `seq -f "%04.0f" 1 $num`; do
totalmb=`echo ${totalmb}+${a}|bc`
done
if [ `uname` = Linux ]; then
if [ 0 -eq `id -u` ]; then
# drop filesystem caches
echo 3 > /proc/sys/vm/drop_caches
echo "Filesystem:" `file -bLs $(df -h . | tail -1 | awk '{print $1}')`
fi
fi
sync
start=`date +%s.%N`
if [ -d _fsbench ]; then
rm -rf _fsbench
fi
mkdir _fsbench 2>/dev/null
if [ ! $? -eq 0 ]; then
echo "Can't create temporary directory"
exit 1
fi
mb=0
for a in `seq -f "%04.0f" 1 $num | shuf`; do
percent=`echo ${mb}*100/${totalmb}|bc`
mb=`echo ${mb}+${a}|bc`
echo -ne "${percent}% (${mb} MB)"
dd if=/dev/zero of=_fsbench/$a bs=${a}M count=1 2>/dev/null
rm _fsbench/$a
mkdir _fsbench/$a
echo -ne " \r"
done
echo
rm -rf _fsbench
sync
end=`date +%s.%N`
# print results
echo "Time used in seconds to create $num files of 1 to $num MB size, and $num"
echo -n "directories, then removing them all: "
t=`echo $end - $start | bc`
ts=`echo ${totalmb}/${t}|bc`
echo $t
echo "Making a total read/write of: $ts MB/s"