]> git.notmuchmail.org Git - notmuch/blob - performance-test/perf-test-lib.sh
Merge tag 'debian/0.17-2'
[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     CORPUS_DIR=${TEST_DIRECTORY}/corpus
45     mkdir -p "${CORPUS_DIR}"
46
47     MAIL_CORPUS="${CORPUS_DIR}/mail.${corpus_size}"
48     TAG_CORPUS="${CORPUS_DIR}/tags"
49
50     if command -v pixz > /dev/null; then
51         XZ=pixz
52     else
53         XZ=xz
54     fi
55
56     if [ ! -d "${CORPUS_DIR}/manifest" ]; then
57
58         printf "Unpacking manifests\n"
59         tar --extract --use-compress-program ${XZ} --strip-components=1 \
60             --directory ${TEST_DIRECTORY}/corpus \
61             --wildcards --file ../download/notmuch-email-corpus-${PERFTEST_VERSION}.tar.xz \
62             'notmuch-email-corpus/manifest/*'
63     fi
64
65     file_list=$(mktemp file_listXXXXXX)
66     if [ ! -d "$TAG_CORPUS" ] ; then
67         echo "notmuch-email-corpus/tags" >> $file_list
68     fi
69
70     if [ ! -d "$MAIL_CORPUS" ] ; then
71         if [[ "$corpus_size" != "large" ]]; then
72             sed s,^,notmuch-email-corpus/, < \
73                 ${TEST_DIRECTORY}/corpus/manifest/MANIFEST.${corpus_size} >> $file_list
74         else
75             echo "notmuch-email-corpus/mail" >> $file_list
76         fi
77     fi
78
79     if [[ -s $file_list ]]; then
80
81         printf "Unpacking corpus\n"
82         tar --checkpoint=.5000 --extract --strip-components=1 \
83             --directory ${TEST_DIRECTORY}/corpus \
84             --use-compress-program ${XZ} \
85             --file ../download/notmuch-email-corpus-${PERFTEST_VERSION}.tar.xz \
86             --anchored --recursion \
87             --files-from $file_list
88
89         printf "\n"
90
91         if [[ ! -d ${MAIL_CORPUS} ]]; then
92             printf "creating link farm\n"
93
94             if [[ "$corpus_size" = large ]]; then
95                 cp -rl ${TEST_DIRECTORY}/corpus/mail ${MAIL_CORPUS}
96             else
97                 while read -r file; do
98                     tdir=${MAIL_CORPUS}/$(dirname $file)
99                     mkdir -p $tdir
100                     ln ${TEST_DIRECTORY}/corpus/$file $tdir
101                 done <${TEST_DIRECTORY}/corpus/manifest/MANIFEST.${corpus_size}
102             fi
103         fi
104
105     fi
106
107     rm $file_list
108     cp -lr $TAG_CORPUS $TMP_DIRECTORY/corpus.tags
109     cp -lr $MAIL_CORPUS $MAIL_DIR
110 }
111
112 notmuch_new_with_cache ()
113 {
114     if [ -d $DB_CACHE_DIR ]; then
115         cp -r $DB_CACHE_DIR ${MAIL_DIR}/.notmuch
116     else
117         "$1" 'Initial notmuch new' "notmuch new"
118         cache_database
119     fi
120 }
121
122 time_start ()
123 {
124     add_email_corpus
125
126     print_header
127
128     notmuch_new_with_cache time_run
129 }
130
131 memory_start ()
132 {
133     add_email_corpus
134
135     local timestamp=$(date +%Y%m%dT%H%M%S)
136     log_dir="${TEST_DIRECTORY}/log.$(basename $0)-$corpus_size-${timestamp}"
137     mkdir -p ${log_dir}
138
139     notmuch_new_with_cache memory_run
140 }
141
142 memory_run ()
143 {
144     test_count=$(($test_count+1))
145
146     log_file=$log_dir/$test_count.log
147     talloc_log=$log_dir/$test_count.talloc
148
149     printf "[ %d ]\t%s\n" $test_count "$1"
150
151     NOTMUCH_TALLOC_REPORT="$talloc_log" valgrind --leak-check=full --log-file="$log_file" $2
152
153     awk '/LEAK SUMMARY/,/suppressed/ { sub(/^==[0-9]*==/," "); print }' "$log_file"
154     echo
155     sed -n -e 's/.*[(]total *\([^)]*\)[)]/talloced at exit: \1/p' $talloc_log
156     echo
157 }
158
159 memory_done ()
160 {
161     time_done
162 }
163
164 cache_database ()
165 {
166     if [ -d $MAIL_DIR/.notmuch ]; then
167         cp -r $MAIL_DIR/.notmuch $DB_CACHE_DIR
168     else
169         echo "Warning: No database found to cache"
170     fi
171 }
172
173 uncache_database ()
174 {
175     rm -rf $DB_CACHE_DIR
176 }
177
178 print_header ()
179 {
180     printf "\t\t\tWall(s)\tUsr(s)\tSys(s)\tRes(K)\tIn/Out(512B)\n"
181 }
182
183 time_run ()
184 {
185     printf "  %-22s" "$1"
186     test_count=$(($test_count+1))
187     if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
188     if ! eval >&3 "/usr/bin/time -f '%e\t%U\t%S\t%M\t%I/%O' $2" ; then
189         test_failure=$(($test_failure + 1))
190         return 1
191     fi
192     return 0
193 }
194
195 time_done ()
196 {
197     if [ "$test_failure" = "0" ]; then
198         rm -rf "$remove_tmp"
199         exit 0
200     else
201         exit 1
202     fi
203 }
204
205 cd -P "$test" || error "Cannot setup test environment"
206 test_failure=0
207 test_count=0
208
209 printf "\n%-55s [%s %s]\n"  \
210     "$(basename "$0"): Testing ${test_description:-notmuch performance}" \
211     "${PERFTEST_VERSION}"  "${corpus_size}"