]> CyberLeo.Net >> Repos - CDN/bonnie-benchmarks.git/blob - bench
test: striped across four two-way mirrors
[CDN/bonnie-benchmarks.git] / bench
1 #!/bin/sh
2
3 _root="$(dirname "${0}")"; . "${_root}/lib/sh/env.sh"
4 want log suexec
5
6 [ "$(hostname -s)" = "nabihinew" ] || wtf "Run this on nabihinew only!"
7
8 suexec "${0}" "${@}"
9
10 want stopwatch
11
12 # Environment and needed stuff
13 tests="${_root}/tests"
14
15 # Log maintenance
16 logs="${_root}/log"
17 [ -d "${logs}" ] || mkdir -p "${logs}"
18 run_log="${logs}/bench-$(date +%Y-%m-%d_%H:%M:%S).log"
19
20 # Zpool handling
21 zpool_name="test"
22 zpool_create() {
23   echo zpool create -O mountpoint="${scratch}" "${zpool_name}" "${@}"
24   zpool create -O mountpoint="${scratch}" "${zpool_name}" "${@}" || wtf "Couldn't create zpool!"
25   zpool status
26   zpool list
27 }
28 zpool_destroy() {
29   zpool list -Ho name | grep -q "^${zpool_name}$" && zpool destroy "${zpool_name}"
30 }
31
32 # Scratch directory maintenance
33 scratch="/bonnie"
34 clean_scratch() {
35   [ -d "${scratch}" ] || mkdir -p "${scratch}"
36   zpool_destroy
37   mount | grep -q ' on '"${scratch}"' ' && umount "${scratch}" || true
38   find "${scratch}" ${bonnie_uid:+-uid "${bonnie_uid}"} -xdev -delete
39 }
40 clean_scratch
41
42 # Bonnie setup
43 bonnie_uid="4444"
44 bonnie_opts="-q -d /bonnie -u ${bonnie_uid} -s 12288 -n 16:16384:0 -f 0"
45 bonnie_log="${logs}/bonnie-%s-$(date +%Y-%m-%d_%H:%M:%S).csv"
46 run_bonnie() {
47   chown "${bonnie_uid}" "${scratch}"
48   /usr/local/sbin/bonnie++ ${bonnie_opts} -m "${test}" >> "$(printf "${bonnie_log}" "${test}")"
49 }
50
51 # Default methods
52 setup() {
53   clean_scratch
54 }
55 run() {
56   run_bonnie
57 }
58 teardown() {
59   clean_scratch
60 }
61
62 # Main event
63 if [ "${#}" -eq 0 ]
64 then
65   log "Considering tests: $(cd "${tests}"; echo *)" | tee -a "${run_log}"
66   script -a "${run_log}" sh -c "( cd '${tests}'; ls -1 ) | xargs -L1 '${0}'"
67 else
68   test="${1}"; shift
69   testfile="${tests}/${test}"
70   [ -f "${testfile}" ] || wtf "Test '${test}' does not exist"
71   ( log "Preparing test: ${test}"
72     . "${testfile}"
73     setup
74     sync
75     trap "teardown" EXIT HUP INT TERM KILL
76     log "$(stopwatch run start)"
77     run; result=$?
78     log "$(stopwatch run stop) Test result ${result}"
79     trap - EXIT HUP INT TERM KILL
80     teardown
81   )
82 fi