]> git.notmuchmail.org Git - notmuch/blob - performance-test/perf-test-lib.sh
perf-test: unpack tags.
[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     TAG_CORPUS="${TEST_DIRECTORY}/corpus/tags"
60
61     args=()
62     if [ ! -d "$TAG_CORPUS" ] ; then
63         args+=("notmuch-email-corpus/tags")
64     fi
65
66     if [ ! -d "$check_for" ] ; then
67         args+=("notmuch-email-corpus/$mail_subdir")
68     fi
69
70     if [[ ${#args[@]} > 0 ]]; then
71         if command -v pixz > /dev/null; then
72             XZ=pixz
73         else
74             XZ=xz
75         fi
76
77         printf "Unpacking corpus\n"
78         mkdir -p "${TEST_DIRECTORY}/corpus"
79
80         tar --checkpoint=.5000 --extract --strip-components=1 \
81             --directory ${TEST_DIRECTORY}/corpus \
82             --use-compress-program ${XZ} \
83             --file ../download/notmuch-email-corpus-${PERFTEST_VERSION}.tar.xz \
84             "${args[@]}"
85
86         printf "\n"
87
88     fi
89
90     cp -lr $TAG_CORPUS $TMP_DIRECTORY/corpus.tags
91     cp -lr $MAIL_CORPUS $MAIL_DIR
92
93 }
94
95 time_start () {
96
97     add_email_corpus
98
99     print_header
100
101     if [ -d $DB_CACHE_DIR ]; then
102         cp -r $DB_CACHE_DIR ${MAIL_DIR}/.notmuch
103     else
104         time_run 'Initial notmuch new' "notmuch new"
105         cache_database
106     fi
107 }
108
109 cache_database () {
110     if [ -d $MAIL_DIR/.notmuch ]; then
111         cp -r $MAIL_DIR/.notmuch $DB_CACHE_DIR
112     else
113         echo "Warning: No database found to cache"
114     fi
115 }
116
117 uncache_database () {
118     rm -rf $DB_CACHE_DIR
119 }
120
121 print_header () {
122     printf "[v%4s %6s]          Wall(s)\tUsr(s)\tSys(s)\tRes(K)\tIn/Out(512B)\n" \
123            ${PERFTEST_VERSION} ${corpus_size}
124 }
125
126 time_run () {
127     printf "  %-22s" "$1"
128     if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
129     if ! eval >&3 "/usr/bin/time -f '%e\t%U\t%S\t%M\t%I/%O' $2" ; then
130         test_failure=$(($test_failure + 1))
131         return 1
132     fi
133     return 0
134 }
135
136 time_done () {
137     if [ "$test_failure" = "0" ]; then
138         rm -rf "$remove_tmp"
139         exit 0
140     else
141         exit 1
142     fi
143 }
144
145 cd -P "$test" || error "Cannot setup test environment"
146 test_failure=0
147
148 echo
149 echo $(basename "$0"): "Testing ${test_description:-notmuch performance}"