]> CyberLeo.Net >> Repos - CDN/bonnie-benchmarks.git/blob - bench
Add bench framework
[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 # Scratch directory maintenance
21 scratch="/bonnie"
22 prepare_scratch() {
23   [ -d "${scratch}" ] || mkdir -p "${scratch}"
24   mount | grep -q ' on '"${scratch}"' ' && umount "${scratch}" || true
25   find "${scratch}" -uid "${bonnie_uid}" -xdev -delete
26 }
27
28 # Bonnie setup
29 bonnie_uid="4444"
30 bonnie_opts="-d /bonnie -u ${bonnie_uid} -s 12288 -n 16:16384:0 -f 0"
31 bonnie_log="${logs}/bonnie-%s-$(date +%Y-%m-%d_%H:%M:%S).csv"
32 run_bonnie() {
33   chown "${bonnie_uid}" "${scratch}"
34   /usr/local/sbin/bonnie++ ${bonnie_opts} -m "${test}" | tee -a "$(printf "${bonnie_log}" "${test}")"
35 }
36
37 # Default methods
38 setup() {
39   prepare_scratch
40 }
41 run() {
42   run_bonnie
43 }
44 teardown() {
45   prepare_scratch
46 }
47
48 # Main event
49 if [ "${#}" -eq 0 ]
50 then
51   log "Considering tests: $(cd "${tests}"; echo *)" | tee -a "${run_log}"
52   ( cd "${tests}"; ls -1 ) | script -a "${run_log}" xargs -L1 "${0}"
53 else
54   test="${1}"; shift
55   testfile="${tests}/${test}"
56   [ -f "${testfile}" ] || wtf "Test '${test}' does not exist"
57   prepare_scratch
58   ( log "Loading test: ${test}"
59     . "${testfile}"
60     prepare_scratch
61     setup
62     log "$(stopwatch run start)"
63     run; result=$?
64     log "$(stopwatch run stop) Test result ${result}"
65     teardown
66   )
67 fi