]> git.notmuchmail.org Git - notmuch/blob - performance-test/perf-test-lib.sh
perf-test: add caching of xapian database
[notmuch] / performance-test / perf-test-lib.sh
1 . ./version.sh
2
3 corpus_size=large
4
5 while test "$#" -ne 0
6 do
7         case "$1" in
8         -d|--debug)
9                 debug=t;
10                 shift
11                 ;;
12         -s|--small)
13                 corpus_size=small;
14                 shift
15                 ;;
16         -m|--medium)
17                 corpus_size=medium;
18                 shift
19                 ;;
20         -l|--large)
21                 corpus_size=large;
22                 shift
23                 ;;
24         *)
25                 echo "error: unknown performance test option '$1'" >&2; exit 1 ;;
26         esac
27 done
28 . ../test/test-lib-common.sh
29
30 set -e
31
32 if ! test -x ../notmuch
33 then
34         echo >&2 'You do not seem to have built notmuch yet.'
35         exit 1
36 fi
37
38 DB_CACHE_DIR=${TEST_DIRECTORY}/notmuch.cache.$corpus_size
39
40 add_email_corpus ()
41 {
42     rm -rf ${MAIL_DIR}
43
44     case "$corpus_size" in
45         small)
46             mail_subdir="mail/enron/bailey-s"
47             check_for="${TEST_DIRECTORY}/corpus/$mail_subdir"
48             ;;
49         medium)
50             mail_subdir="mail/notmuch-archive"
51             check_for="${TEST_DIRECTORY}/corpus/$mail_subdir"
52             ;;
53         *)
54             mail_subdir=mail
55             check_for="${TEST_DIRECTORY}/corpus/$mail_subdir/enron/wolfe-j"
56     esac
57
58     MAIL_CORPUS="${TEST_DIRECTORY}/corpus/$mail_subdir"
59     args=()
60     if [ ! -d "$check_for" ] ; then
61         args+=("notmuch-email-corpus/$mail_subdir")
62     fi
63
64     if [[ ${#args[@]} > 0 ]]; then
65         if command -v pixz > /dev/null; then
66             XZ=pixz
67         else
68             XZ=xz
69         fi
70
71         printf "Unpacking corpus\n"
72         mkdir -p "${TEST_DIRECTORY}/corpus"
73
74         tar --checkpoint=.5000 --extract --strip-components=1 \
75             --directory ${TEST_DIRECTORY}/corpus \
76             --use-compress-program ${XZ} \
77             --file ../download/notmuch-email-corpus-${PERFTEST_VERSION}.tar.xz \
78             "${args[@]}"
79
80         printf "\n"
81
82     fi
83
84     cp -lr $MAIL_CORPUS $MAIL_DIR
85
86 }
87
88 time_start () {
89
90     add_email_corpus
91
92     print_header
93
94     if [ -d $DB_CACHE_DIR ]; then
95         cp -r $DB_CACHE_DIR ${MAIL_DIR}/.notmuch
96     else
97         time_run 'Initial notmuch new' "notmuch new"
98         cache_database
99     fi
100 }
101
102 cache_database () {
103     if [ -d $MAIL_DIR/.notmuch ]; then
104         cp -r $MAIL_DIR/.notmuch $DB_CACHE_DIR
105     else
106         echo "Warning: No database found to cache"
107     fi
108 }
109
110 uncache_database () {
111     rm -rf $DB_CACHE_DIR
112 }
113
114 print_header () {
115     printf "[v%4s %6s]          Wall(s)\tUsr(s)\tSys(s)\tRes(K)\tIn/Out(512B)\n" \
116            ${PERFTEST_VERSION} ${corpus_size}
117 }
118
119 time_run () {
120     printf "  %-22s" "$1"
121     if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
122     if ! eval >&3 "/usr/bin/time -f '%e\t%U\t%S\t%M\t%I/%O' $2" ; then
123         test_failure=$(($test_failure + 1))
124         return 1
125     fi
126     return 0
127 }
128
129 time_done () {
130     if [ "$test_failure" = "0" ]; then
131         rm -rf "$remove_tmp"
132         exit 0
133     else
134         exit 1
135     fi
136 }
137
138 cd -P "$test" || error "Cannot setup test environment"
139 test_failure=0
140
141 echo
142 echo $(basename "$0"): "Testing ${test_description:-notmuch performance}"