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