@@ -1,685 +0,0 @@
3−# Note that this script is used in the "streamly" package as well as
4−# in "streaming-benchmarks" package. Any changes to the script should be
5−# generic enough so that it works in both the cases.
7−#------------------------------------------------------------------------------
11−SCRIPT_DIR=$(cd `dirname $0`; pwd)
14−source $SCRIPT_DIR/build-lib.sh
18− echo " [--benchmarks <"bench1 bench2 ..." | help>]"
19− echo " [--prefix <benchmark name prefix to match>"
20− echo " [--fields <"field1 field2 ..." | help>]"
21− echo " [--sort-by-name]"
23− echo " [--diff-style <absolute|percent|multiples>]"
24− echo " [--diff-cutoff-percent <percent-value>]"
27− echo " [--no-measure]"
33− echo " [--dev-build]"
35− echo " [--with-compiler <compiler exe name>]"
36− echo " [--cabal-build-options <options>]"
37− echo " [--rtsopts <opts>]"
38− #echo " [--commit-compare] [--base <commit>] [--candidate <commit>]"
39− #echo " -- <gauge options or benchmarks>"
41− echo "--benchmarks: benchmarks to run, use 'help' for list of benchmarks"
42− echo "--compare: compare the specified benchmarks with each other"
44− echo "--diff-cutoff-percent: Diff percentage used for benchmark selection."
45− echo "This applies only to the second column of the report and makes sense"
46− echo "only while comparing benchmarks."
47− echo "A positive cutoff value selects only regressions, whereas, a negative"
48− echo "cutoff value selects only improvements."
50− echo "--fields: measurement fields to report, use 'help' for a list"
51− echo "--graphs: Generate graphical reports"
52− echo "--no-measure: Don't run benchmarks, run reports from previous results"
53− echo "--append: Don't overwrite previous results, append for comparison"
54− echo "--long: Use much longer stream size for infinite stream benchmarks"
55− echo "--slow: Slightly more accurate results at the expense of speed"
56− echo "--quick: Faster results, useful for longer benchmarks"
57− echo "--raw: Run the benchmarks but don't report them. This is useful when"
58− echo " you only want to work with the csv files generated."
59− echo "--cabal-build-options: Pass any cabal build options to be used for build"
60− echo " e.g. --cabal-build-options \"--flag dev\""
62− echo "When specific space complexity group is chosen then (and only then) "
63− echo "RTS memory restrictions are used accordingly. For example, "
64− echo "bench.sh --benchmarks Data.Parser -- Data.Parser/o-1-space "
65− echo "restricts Heap/Stack space for O(1) characterstics"
67− #echo "When using --commit-compare, by default comparative chart of HEAD^ vs HEAD"
68− #echo "commit is generated, in the 'charts' directory."
69− #echo "Use --base and --candidate to select the commits to compare."
71− #echo "Any arguments after a '--' are passed directly to gauge"
75−#-----------------------------------------------------------------------------
76−# Reporting utility functions
77−#-----------------------------------------------------------------------------
80− echo "Comparison groups:"
81− for i in $COMPARISONS
91− local prog_path=$BENCH_REPORT_DIR/bin/bench-report
94− if test ! -x "$prog_path" -a "$BUILD_ONCE" = "0"
96− echo "Building bench-report executables"
98− pushd $BENCH_REPORT_DIR
100− cmd="$CABAL_EXECUTABLE install --installdir bin bench-report"
101− if test "$USE_NIX" -eq 0
103− $cmd || die "bench-report build failed"
105− nix-shell --run "$cmd" || die "bench-report build failed"
108− elif test ! -x "$prog_path"
115−build_report_progs() {
116− if test "$RAW" = "0"
118− build_report_prog || exit 1
120− prog=$BENCH_REPORT_DIR/bin/bench-report
121− test -x $prog || die "Cannot find bench-report executable"
122− echo "Using bench-report executable [$prog]"
126−# We run the benchmarks in isolation in a separate process so that different
127−# benchmarks do not interfere with other. To enable that we need to pass the
128−# benchmark exe path to gauge as an argument. Unfortunately it cannot find its
129−# own path currently.
131−# The path is dependent on the architecture and cabal version.
133−bench_output_file() {
135− echo "charts/$bench_name/results.csv"
138−#------------------------------------------------------------------------------
140−#------------------------------------------------------------------------------
142−# tasty-bench does not like an option set twice
143−set_super_quick_mode () {
147−# For certain long benchmarks if the user has not requested super quick
148−# mode we anyway use a slightly quicker mode.
149−use_quicker_mode () {
150− if test "$QUICK_MODE" -eq 0
156−#------------------------------------------------------------------------------
157−# Determine options from benchmark name
158−#------------------------------------------------------------------------------
160−# Global environment passed:
161−# BENCH_EXEC_PATH: the benchmark executable
162−# RTS_OPTIONS: additional RTS options
163−# QUICK_MODE: whether we are in quick mode
164−# USE_GAUGE: whether to use gauge or tasty-bench
165−# LONG: whether to use a large stream size
169− local BENCH_NAME_ORIG
170− BENCH_NAME_ORIG="$1"
173− local SUPER_QUICK_OPTIONS
174− local QUICKER_OPTIONS
175− if test "$USE_GAUGE" -eq 0
177− SUPER_QUICK_OPTIONS="--stdev 1000000"
178− QUICKER_OPTIONS="--stdev 100"
180− # Do not keep time limit as 0 otherwise GC stats may remain 0 in some cases.
181− SUPER_QUICK_OPTIONS="--quick --min-duration 0 --time-limit 0.01 --include-first-iter"
182− QUICKER_OPTIONS="--min-samples 3 --time-limit 1"
189− # XXX this is a hack to make the "/" separated names used in the functions
190− # determining options based on benchmark name. For tasty-bench the benchmark
191− # names are separated by "." instead of "/" and are prefixed by "All".
193− # For example, All.Prelude.Serial/x.y.z => Prelude.Serial/x/y/z
194− if test "$USE_GAUGE" -eq 0
196− # Remove the prefix "All."
197− BENCH_NAME0=$(echo $BENCH_NAME_ORIG | sed -e s/^All\.//)
199− # Module names could contain dots e.g. "Prelude.Serial". So we insert
200− # an explicit "/" to separate the module name part and the rest of
201− # the benchmark name. For example, Prelude.Serial/elimination.drain
202− BENCH_NAME1=$(echo $BENCH_NAME0 | cut -f1 -d '/')
204− if test "$BENCH_NAME1" = "$BENCH_NAME0"
206− # There is no "/" separator
207− BENCH_NAME1=$(echo $BENCH_NAME0 | sed -e 's/\./\//g')
210− BENCH_NAME2=/$(echo $BENCH_NAME0 | cut -f2- -d '/' | sed -e 's/\./\//g')
212− BENCH_NAME="${BENCH_NAME1}${BENCH_NAME2}"
214− BENCH_NAME=$BENCH_NAME_ORIG
220−$(bench_rts_options $(basename $BENCH_EXEC_PATH) $BENCH_NAME) \
224− local QUICK_MODE_TYPE
226− $(if test "$QUICK_MODE" -ne 0; then set_super_quick_mode; fi) \
227− $(bench_speed_options $(basename $BENCH_EXEC_PATH) $BENCH_NAME)"
229− local QUICK_BENCH_OPTIONS
230− for i in $QUICK_MODE_TYPE
233− super_quick) QUICK_BENCH_OPTIONS="$SUPER_QUICK_OPTIONS"; break ;;
234− quicker) QUICK_BENCH_OPTIONS="$QUICKER_OPTIONS"; break ;;
240− local STREAM_SIZE_OPT
241− if test "$LONG" -ne 0
243− STREAM_SIZE=10000000
244− STREAM_LEN=$(env LC_ALL=en_US.UTF-8 printf "--stream-size %'.f\n" $STREAM_SIZE)
245− STREAM_SIZE_OPT="--stream-size $STREAM_SIZE"
248− echo "$BENCH_NAME_ORIG: \
251− $QUICK_BENCH_OPTIONS" \
254− #------------------------------------------------------------------------------
255− # Run benchmark with options and collect results
256− #------------------------------------------------------------------------------
259− output_file=$(bench_output_file $(basename $BENCH_EXEC_PATH))
260− mkdir -p `dirname $output_file`
261− rm -f ${output_file}.tmp
263− local BENCH_NAME_ESC
264− if test $USE_GAUGE -eq 0
266− # Escape "\" and double quotes in benchmark names
267− BENCH_NAME_ESC=$(echo "$BENCH_NAME_ORIG" | sed -e 's/\\/\\\\/g' | sed -e 's/"/\\"/g')
272− $QUICK_BENCH_OPTIONS \
274− --csv=${output_file}.tmp \
275− -p '$0 == "'"$BENCH_NAME_ESC"'"' || die "Benchmark execution failed."
277− # Convert cpuTime field from picoseconds to seconds
278− awk --version 2>&1 | grep -q "GNU Awk" \
279− || die "Need GNU awk. [$(which awk)] is not GNU awk."
280− tail -n +2 ${output_file}.tmp | \
281− awk 'BEGIN {FPAT = "([^,]+)|(\"[^\"]+\")";OFS=","} {$2=$2/1000000000000;print}' \
287− $QUICK_BENCH_OPTIONS \
289− --csvraw=${output_file}.tmp \
290− -m exact "$BENCH_NAME" || die "Benchmark execution failed."
291− tail -n +2 ${output_file}.tmp \
297− local target_prog="$1"
298− local target_name="$2"
299− local output_file="$3"
302− if test "$LONG" -ne 0
304− MATCH="$target_name/o-1-space"
306− MATCH="$BENCH_PREFIX"
308− echo "name,iters,time,cycles,cpuTime,utime,stime,maxrss,minflt,majflt,nvcsw,nivcsw,allocated,numGcs,bytesCopied,mutatorWallSeconds,mutatorCpuSeconds,gcWallSeconds,gcCpuSeconds" >> $output_file
309− # keep only benchmark names with shortest prefix e.g. "a/b/c" and "a/b", we
310− # should only keep "a/b" otherwise benchmarks will run multiple times. why?
313− | while read -r name; \
314− do bench_exec_one "$name" "${GAUGE_ARGS[@]}" || exit 1; done \
315− || die "Benchmark execution failed."
318−invoke_tasty_bench () {
319− local target_prog="$1"
320− local target_name="$2"
321− local output_file="$3"
324− if test "$LONG" -ne 0
326− MATCH="-p /$target_name\/o-1-space/"
328− if test -n "$BENCH_PREFIX"
331− local escaped_name=$(echo "$BENCH_PREFIX" | sed -e 's/\//\\\//g')
332− MATCH="-p /$escaped_name/"
335− echo "Name,cpuTime,2*Stdev (ps),Allocated,bytesCopied,maxrss" >> $output_file
336− $target_prog -l $MATCH \
338− | while read -r name; \
339− do bench_exec_one "$name" "${GAUGE_ARGS[@]}" || exit 1; done \
340− || die "Benchmark execution failed."
343−run_bench_target () {
344− local package_name=$1
346− local target_name=$3
349− if test -z "$BENCHMARK_PACKAGE_VERSION"
351− echo "Please set BENCHMARK_PACKAGE_VERSION in bench_config"
354− target_prog=$(cabal_target_prog $package_name-$BENCHMARK_PACKAGE_VERSION $component $target_name) || \
355− die "Cannot find executable for target $target_name"
357− echo "Running executable $target_name ..."
359− # Needed by bench_exec_one
360− BENCH_EXEC_PATH=$target_prog
362− local output_file=$(bench_output_file $target_name)
363− mkdir -p `dirname $output_file`
364− if test "$USE_GAUGE" -eq 0
365− then invoke_tasty_bench "$target_prog" "$target_name" "$output_file"
366− else invoke_gauge "$target_prog" "$target_name" "$output_file"
373−run_bench_targets() {
376− run_bench_target $1 $2 $i
380−run_benches_comparing() {
383− if test -z "$CANDIDATE"
385− CANDIDATE=$(git rev-parse HEAD)
389− # XXX Should be where the current branch is forked from master
392− echo "Comparing baseline commit [$BASE] with candidate [$CANDIDATE]"
393− echo "Checking out base commit [$BASE] for benchmarking"
394− # XXX git checkout will overwrite this script itself and the scripts
395− # imported/used by this script.
396− git checkout "$BASE" || die "Checkout of base commit [$BASE] failed"
398− # $BUILD_BENCH || die "build failed"
399− run_build "$BUILD_BENCH" $BENCHMARK_PACKAGE_NAME bench "$TARGETS"
400− run_bench_targets $BENCHMARK_PACKAGE_NAME b "$bench_list" target_exe_extra_args
402− echo "Checking out candidate commit [$CANDIDATE] for benchmarking"
403− git checkout "$CANDIDATE" || \
404− die "Checkout of candidate [$CANDIDATE] commit failed"
406− # $BUILD_BENCH || die "build failed"
407− run_build "$BUILD_BENCH" $BENCHMARK_PACKAGE_NAME bench "$TARGETS"
408− run_bench_targets $BENCHMARK_PACKAGE_NAME b "$bench_list" target_exe_extra_args
409− # XXX reset back to the original commit
412−backup_output_file() {
414− local output_file=$(bench_output_file $bench_name)
416− if test -e $output_file -a "$APPEND" != 1
418− mv -f -v $output_file ${output_file}.prev
425− for i in $bench_list
427− backup_output_file $i
430− if test "$COMMIT_COMPARE" = "0"
432− run_build "$BUILD_BENCH" $BENCHMARK_PACKAGE_NAME bench "$TARGETS"
433− run_bench_targets $BENCHMARK_PACKAGE_NAME b "$bench_list" target_exe_extra_args
435− run_benches_comparing "$bench_list"
441− prog=$BENCH_REPORT_DIR/bin/bench-report
442− test -x $prog || die "Cannot find bench-report executable"
443− test -z "$SILENT" && echo
447− test -z "$SILENT" && echo "Generating reports for ${i}..."
450− $(test "$USE_GAUGE" = 1 && echo "--use-gauge") \
451− $(test "$GRAPH" = 1 && echo "--graphs") \
452− $(test "$SORT_BY_NAME" = 1 && echo "--sort-by-name") \
453− $(test -n "$BENCH_DIFF_STYLE" && echo "--diff-style $BENCH_DIFF_STYLE") \
454− $(test -n "$BENCH_CUTOFF_PERCENT" && echo "--diff-cutoff-percent $BENCH_CUTOFF_PERCENT") \
459−#-----------------------------------------------------------------------------
460−# Execution starts here
461−#-----------------------------------------------------------------------------
463−USE_GIT_CABAL=1 # This is used by set_common_vars
482−CABAL_BUILD_OPTIONS="--flag fusion-plugin --flag limit-build-mem"
484−#-----------------------------------------------------------------------------
486−#-----------------------------------------------------------------------------
491− -h|--help|help) print_help ;;
492− # options with arguments
493− --benchmarks) shift; TARGETS=$1; shift ;;
494− --targets) shift; TARGETS=$1; shift ;;
495− --prefix) shift; BENCH_PREFIX="$1"; shift ;;
496− --fields) shift; FIELDS=$1; shift ;;
497− --base) shift; BASE=$1; shift ;;
498− --candidate) shift; CANDIDATE=$1; shift ;;
499− --with-compiler) shift; CABAL_WITH_COMPILER=$1; shift ;;
500− --cabal-build-flags) shift; CABAL_BUILD_OPTIONS+=" $1"; shift ;;
501− --cabal-build-options) shift; CABAL_BUILD_OPTIONS+=" $1"; shift ;;
502− --rtsopts) shift; RTS_OPTIONS=$1; shift ;;
503− --config) shift; BENCH_CONFIG_FILE=$1; shift ;;
504− --diff-style) shift; BENCH_DIFF_STYLE=$1; shift ;;
505− --diff-cutoff-percent) shift; BENCH_CUTOFF_PERCENT=$1; shift ;;
507− --slow) SLOW=1; shift ;;
508− --silent) SILENT=1; shift ;;
509− --quick) QUICK_MODE=1; shift ;;
510− --compare) COMPARE=1; shift ;;
511− --commit-compare) COMMIT_COMPARE=1; shift ;;
512− --raw) RAW=1; shift ;;
513− --append) APPEND=1; shift ;;
514− --long) LONG=1; shift ;;
515− --sort-by-name) SORT_BY_NAME=1; shift ;;
516− --graphs) GRAPH=1; shift ;;
517− --no-measure) MEASURE=0; shift ;;
518− # This is used in build-lib.sh to enable dev_build function which is used
519− # in targets.sh to enable or disable some targets.
520− --dev-build) RUNNING_DEVBUILD=1; shift ;;
521− --use-nix) USE_NIX=1; shift ;;
522− --use-gauge) USE_GAUGE=1; shift ;;
524− *) echo "Unknown flags: $*"; echo; print_help ;;
529−if test -z "$BENCH_CONFIG_FILE"
531− die "Please use --config to specify config file"
534−source "$BENCH_CONFIG_FILE" || \
535− die "Failed to source config file $BENCH_CONFIG_FILE"
537−# Defined in $BENCH_CONFIG_FILE
542− FIELDS=$DEFAULT_FIELDS
547−#-----------------------------------------------------------------------------
549−#-----------------------------------------------------------------------------
551−only_real_benchmarks () {
555− for j in $COMPARISONS
562− if test "$SKIP" -eq 0
569−# defined in $BENCH_CONFIG_FILE
572−if test "$(has_item "$TARGETS" help)" = "help"
580−COMMON_FIELDS="allocated bytescopied cputime maxrss"
581−if test "$USE_GAUGE" -eq 1
583− ALL_FIELDS="$COMMON_FIELDS time cycles utime stime minflt majflt nvcsw nivcsw"
585− ALL_FIELDS="$COMMON_FIELDS"
587−if test "$(has_item "$FIELDS" help)" = "help"
589− echo "Supported fields: $ALL_FIELDS"
590− echo "Default fields: $DEFAULT_FIELDS"
594−if test "$LONG" -ne 0
596− if test -n "$TARGETS"
598− echo "Cannot specify benchmarks [$TARGETS] with --long"
601− TARGETS=$infinite_grp
604−DEFAULT_TARGETS="$(all_grp)"
605−TARGETS=$(set_targets)
607−TARGETS_ORIG=$TARGETS
608−TARGETS=$(only_real_benchmarks)
610−test -z "$SILENT" && echo "Using benchmark suites [$TARGETS]"
612−#-----------------------------------------------------------------------------
613−# Build reporting utility
614−#-----------------------------------------------------------------------------
616−# We need to build the report progs first at the current (latest) commit before
617−# checking out any other commit for benchmarking.
619−then build_report_progs
620−else silently build_report_progs
623−#-----------------------------------------------------------------------------
624−# Build and run targets
625−#-----------------------------------------------------------------------------
627−if test "$USE_GAUGE" -eq 1
629− BUILD_FLAGS="--flag use-gauge"
632−BUILD_BENCH="$CABAL_EXECUTABLE v2-build $BUILD_FLAGS $CABAL_BUILD_OPTIONS --enable-benchmarks"
633−if test "$MEASURE" = "1"
635− run_measurements "$TARGETS"
638−#-----------------------------------------------------------------------------
640−#-----------------------------------------------------------------------------
643−build_comparison_results () {
648− constituents=$(eval "echo -n \$${name}")
649− mkdir -p "charts/$name"
650− dest_file="charts/$name/results.csv"
652− for j in $constituents
654− cat "charts/$j/results.csv" >> $dest_file
658−if test "$COMPARE" -eq 1
660− DYN_CMP_GRP="$(echo "$TARGETS" | sed -e 's/ /_/g')_cmp"
661− eval "$DYN_CMP_GRP=\"$TARGETS\""
662− COMPARISON_REPORTS=$DYN_CMP_GRP
663− build_comparison_results $DYN_CMP_GRP
665− COMPARISON_REPORTS=""
668−for i in $COMPARISONS
670− if test "$(has_item "$TARGETS_ORIG" $i)" = $i
672− COMPARISON_REPORTS="$COMPARISON_REPORTS $i"
673− build_comparison_results $i
679− run_reports "$TARGETS"
680− run_reports "$COMPARISON_REPORTS"
681− if test -n "$DYN_CMP_GRP"
683− rm -rf "charts/$DYN_CMP_GRP"