]> git.notmuchmail.org Git - notmuch/blob - performance-test/perf-test-lib.sh
perf-test: initial version of memory test infrastructure.
[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 notmuch_new_with_cache ()
95 {
96     if [ -d $DB_CACHE_DIR ]; then
97         cp -r $DB_CACHE_DIR ${MAIL_DIR}/.notmuch
98     else
99         "$1" 'Initial notmuch new' "notmuch new"
100         cache_database
101     fi
102 }
103
104 time_start ()
105 {
106     add_email_corpus
107
108     print_header
109
110     notmuch_new_with_cache time_run
111 }
112
113 memory_start ()
114 {
115     add_email_corpus
116
117     local timestamp=$(date +%Y%m%dT%H%M%S)
118     log_dir="${TEST_DIRECTORY}/log.$(basename $0)-$corpus_size-${timestamp}"
119     mkdir -p ${log_dir}
120
121     notmuch_new_with_cache memory_run
122 }
123
124 memory_run ()
125 {
126     test_count=$(($test_count+1))
127
128     log_file=$log_dir/$test_count.log
129
130     printf "[ %d ]\t%s\n" $test_count "$1"
131
132     valgrind --leak-check=full --log-file="$log_file" $2
133
134     awk '/LEAK SUMMARY/,/suppressed/ { sub(/^==[0-9]*==/," "); print }' "$log_file"
135     echo
136 }
137
138 memory_done ()
139 {
140     time_done
141 }
142
143 cache_database ()
144 {
145     if [ -d $MAIL_DIR/.notmuch ]; then
146         cp -r $MAIL_DIR/.notmuch $DB_CACHE_DIR
147     else
148         echo "Warning: No database found to cache"
149     fi
150 }
151
152 uncache_database ()
153 {
154     rm -rf $DB_CACHE_DIR
155 }
156
157 print_header ()
158 {
159     printf "\t\t\tWall(s)\tUsr(s)\tSys(s)\tRes(K)\tIn/Out(512B)\n"
160 }
161
162 time_run ()
163 {
164     printf "  %-22s" "$1"
165     test_count=$(($test_count+1))
166     if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
167     if ! eval >&3 "/usr/bin/time -f '%e\t%U\t%S\t%M\t%I/%O' $2" ; then
168         test_failure=$(($test_failure + 1))
169         return 1
170     fi
171     return 0
172 }
173
174 time_done ()
175 {
176     if [ "$test_failure" = "0" ]; then
177         rm -rf "$remove_tmp"
178         exit 0
179     else
180         exit 1
181     fi
182 }
183
184 cd -P "$test" || error "Cannot setup test environment"
185 test_failure=0
186 test_count=0
187
188 printf "\n%-55s [%s %s]\n"  \
189     "$(basename "$0"): Testing ${test_description:-notmuch performance}" \
190     "${PERFTEST_VERSION}"  "${corpus_size}"