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