speed-check.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #!/bin/bash
  2. #
  3. # This is a template for a script used for day-to-day size and
  4. # performance monitoring of SQLite. Typical usage:
  5. #
  6. # sh speed-check.sh trunk # Baseline measurement of trunk
  7. # sh speed-check.sh x1 # Measure some experimental change
  8. # fossil xdiff --tk cout-trunk.txt cout-x1.txt # View chanages
  9. #
  10. # There are multiple output files, all with a base name given by
  11. # the first argument:
  12. #
  13. # summary-$BASE.txt # Copy of standard output
  14. # cout-$BASE.txt # cachegrind output
  15. # explain-$BASE.txt # EXPLAIN listings (only with --explain)
  16. #
  17. if test "$1" = ""
  18. then
  19. echo "Usage: $0 OUTPUTFILE [OPTIONS]"
  20. exit
  21. fi
  22. NAME=$1
  23. shift
  24. #CC_OPTS="-DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_MEMSYS5"
  25. CC_OPTS="-DSQLITE_ENABLE_MEMSYS5"
  26. CC=gcc
  27. SPEEDTEST_OPTS="--shrink-memory --reprepare --stats --heap 10000000 64"
  28. SIZE=5
  29. LEAN_OPTS="-DSQLITE_THREADSAFE=0"
  30. LEAN_OPTS="$LEAN_OPTS -DSQLITE_DEFAULT_MEMSTATUS=0"
  31. LEAN_OPTS="$LEAN_OPTS -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1"
  32. LEAN_OPTS="$LEAN_OPTS -DSQLITE_LIKE_DOESNT_MATCH_BLOBS"
  33. LEAN_OPTS="$LEAN_OPTS -DSQLITE_MAX_EXPR_DEPTH=0"
  34. LEAN_OPTS="$LEAN_OPTS -DSQLITE_OMIT_DECLTYPE"
  35. LEAN_OPTS="$LEAN_OPTS -DSQLITE_OMIT_DEPRECATED"
  36. LEAN_OPTS="$LEAN_OPTS -DSQLITE_OMIT_PROGRESS_CALLBACK"
  37. LEAN_OPTS="$LEAN_OPTS -DSQLITE_OMIT_SHARED_CACHE"
  38. LEAN_OPTS="$LEAN_OPTS -DSQLITE_USE_ALLOCA"
  39. BASELINE="trunk"
  40. doExplain=0
  41. doCachegrind=1
  42. doVdbeProfile=0
  43. doWal=1
  44. doDiff=1
  45. while test "$1" != ""; do
  46. case $1 in
  47. --nodiff)
  48. doDiff=0
  49. ;;
  50. --reprepare)
  51. SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1"
  52. ;;
  53. --autovacuum)
  54. SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1"
  55. ;;
  56. --utf16be)
  57. SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1"
  58. ;;
  59. --stats)
  60. SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1"
  61. ;;
  62. --without-rowid)
  63. SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1"
  64. ;;
  65. --strict)
  66. SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1"
  67. ;;
  68. --nomemstat)
  69. SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1"
  70. ;;
  71. --multithread)
  72. SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1"
  73. ;;
  74. --singlethread)
  75. SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1"
  76. ;;
  77. --serialized)
  78. SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1"
  79. ;;
  80. --temp)
  81. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --temp 6"
  82. ;;
  83. --legacy)
  84. doWal=0
  85. CC_OPTS="$CC_OPTS -DSPEEDTEST_OMIT_HASH"
  86. ;;
  87. --verify)
  88. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --verify"
  89. ;;
  90. --wal)
  91. doWal=1
  92. ;;
  93. --size)
  94. shift; SIZE=$1
  95. ;;
  96. --cachesize)
  97. shift; SPEEDTEST_OPTS="$SPEEDTEST_OPTS --cachesize $1"
  98. ;;
  99. --stmtcache)
  100. shift; SPEEDTEST_OPTS="$SPEEDTEST_OPTS --stmtcache $1"
  101. ;;
  102. --checkpoint)
  103. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --checkpoint"
  104. ;;
  105. --explain)
  106. doExplain=1
  107. ;;
  108. --vdbeprofile)
  109. rm -f vdbe_profile.out
  110. CC_OPTS="$CC_OPTS -DVDBE_PROFILE"
  111. doCachegrind=0
  112. doVdbeProfile=1
  113. ;;
  114. --lean)
  115. CC_OPTS="$CC_OPTS $LEAN_OPTS"
  116. ;;
  117. --clang)
  118. CC=clang
  119. ;;
  120. --icc)
  121. CC=/home/drh/intel/bin/icc
  122. ;;
  123. --gcc7)
  124. CC=gcc-7
  125. ;;
  126. --heap)
  127. CC_OPTS="$CC_OPTS -DSQLITE_ENABLE_MEMSYS5"
  128. shift;
  129. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --heap $1 64"
  130. ;;
  131. --lookaside)
  132. shift;
  133. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --lookaside $1 $2"
  134. shift;
  135. ;;
  136. --repeat)
  137. CC_OPTS="$CC_OPTS -DSQLITE_ENABLE_RCACHE"
  138. shift;
  139. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --repeat $1"
  140. ;;
  141. --mmap)
  142. shift;
  143. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --mmap $1"
  144. ;;
  145. --rtree)
  146. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --testset rtree"
  147. CC_OPTS="$CC_OPTS -DSQLITE_ENABLE_RTREE"
  148. ;;
  149. --persist)
  150. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --persist"
  151. ;;
  152. --orm)
  153. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --testset orm"
  154. ;;
  155. --cte)
  156. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --testset cte"
  157. ;;
  158. --fp)
  159. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --testset fp"
  160. ;;
  161. --parsenumber)
  162. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --testset parsenumber"
  163. ;;
  164. --stmtscanstatus)
  165. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --stmtscanstatus"
  166. ;;
  167. -*)
  168. CC_OPTS="$CC_OPTS $1"
  169. ;;
  170. *)
  171. BASELINE=$1
  172. ;;
  173. esac
  174. shift
  175. done
  176. if test $doWal -eq 1; then
  177. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --journal wal"
  178. fi
  179. SPEEDTEST_OPTS="$SPEEDTEST_OPTS --size $SIZE"
  180. echo "NAME = $NAME" | tee summary-$NAME.txt
  181. echo "SPEEDTEST_OPTS = $SPEEDTEST_OPTS" | tee -a summary-$NAME.txt
  182. echo "CC_OPTS = $CC_OPTS" | tee -a summary-$NAME.txt
  183. rm -f cachegrind.out.* speedtest1 speedtest1.db sqlite3.o
  184. if test $doVdbeProfile -eq 1; then
  185. rm -f vdbe_profile.out
  186. fi
  187. $CC -g -Os -Wall -I. $CC_OPTS -c sqlite3.c
  188. size sqlite3.o | tee -a summary-$NAME.txt
  189. if test $doExplain -eq 1; then
  190. $CC -g -Os -Wall -I. $CC_OPTS \
  191. -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
  192. ./shell.c ./sqlite3.c -o sqlite3 -ldl -lpthread
  193. fi
  194. SRC=./speedtest1.c
  195. $CC -g -Os -Wall -I. $CC_OPTS $SRC ./sqlite3.o -o speedtest1 -ldl -lpthread
  196. ls -l speedtest1 | tee -a summary-$NAME.txt
  197. if test $doCachegrind -eq 1; then
  198. valgrind --tool=cachegrind ./speedtest1 speedtest1.db \
  199. $SPEEDTEST_OPTS 2>&1 | tee -a summary-$NAME.txt
  200. else
  201. ./speedtest1 speedtest1.db $SPEEDTEST_OPTS 2>&1 | tee -a summary-$NAME.txt
  202. fi
  203. size sqlite3.o | tee -a summary-$NAME.txt
  204. wc sqlite3.c
  205. if test $doCachegrind -eq 1; then
  206. cg_anno.tcl cachegrind.out.* >cout-$NAME.txt
  207. echo '*****************************************************' >>cout-$NAME.txt
  208. sed 's/^[0-9=-]\{9\}/==00000==/' summary-$NAME.txt >>cout-$NAME.txt
  209. fi
  210. if test $doExplain -eq 1; then
  211. ./speedtest1 --explain $SPEEDTEST_OPTS | ./sqlite3 >explain-$NAME.txt
  212. fi
  213. if test $doVdbeProfile -eq 1; then
  214. tclsh ../sqlite/tool/vdbe_profile.tcl >vdbeprofile-$NAME.txt
  215. open vdbeprofile-$NAME.txt
  216. fi
  217. if test "$NAME" != "$BASELINE" -a $doVdbeProfile -ne 1 -a $doDiff -ne 0; then
  218. fossil test-diff --tk -c 20 cout-$BASELINE.txt cout-$NAME.txt
  219. fi