@@ -8,6 +8,7 @@ source $SCRIPT_DIR/build-lib.sh
88print_help () {
99 echo "Usage: $0 "
1010 echo " [--benchmarks <"bench1 bench2 ..." | help>]"
11+ echo " [--prefix <benchmark name prefix to match>"
1112 echo " [--fields <"field1 field2 ..." | help>]"
1213 echo " [--graphs]"
1314 echo " [--no-measure]"
@@ -142,11 +143,58 @@ bench_output_file() {
142143 echo "charts/$bench_name/results.csv"
143144}
144145
146+invoke_gauge () {
147+ local target_prog="$1"
148+ local target_name="$2"
149+ local output_file="$3"
150+
151+ local MATCH=""
152+ if test "$LONG" -ne 0
153+ then
154+ MATCH="$target_name/o-1-space"
155+ else
156+ MATCH="$BENCH_PREFIX"
157+ fi
158+ echo "name,iters,time,cycles,cpuTime,utime,stime,maxrss,minflt,majflt,nvcsw,nivcsw,allocated,numGcs,bytesCopied,mutatorWallSeconds,mutatorCpuSeconds,gcWallSeconds,gcCpuSeconds" >> $output_file
159+ # keep only benchmark names with shortest prefix e.g. "a/b/c" and "a/b", we
160+ # should only keep "a/b" otherwise benchmarks will run multiple times. why?
161+ $target_prog -l \
162+ | grep "^$target_name" \
163+ | grep "^$MATCH" \
164+ | sort \
165+ | awk 'BEGIN {prev="XXX"} {if (substr($0,1,length(prev)) != prev) {print $0; prev=$0}}' \
166+ | while read -r name; \
167+ do bin/bench-exec-one.sh "$name" "${GAUGE_ARGS[@]}"; done
168+}
169+
170+invoke_tasty_bench () {
171+ local target_prog="$1"
172+ local target_name="$2"
173+ local output_file="$3"
174+
175+ local MATCH=""
176+ if test "$LONG" -ne 0
177+ then
178+ MATCH="-p /$target_name\/o-1-space/"
179+ else
180+ if test -n "$BENCH_PREFIX"
181+ then
182+ # escape "/"
183+ local escaped_name=$(echo "$BENCH_PREFIX" | sed -e 's/\//\\\//g')
184+ MATCH="-p /$escaped_name/"
185+ fi
186+ fi
187+ echo "Name,cpuTime,2*Stdev (ps),Allocated,bytesCopied" >> $output_file
188+ $target_prog -l $MATCH \
189+ | grep "^All" \
190+ | while read -r name; \
191+ do bin/bench-exec-one.sh "$name" "${GAUGE_ARGS[@]}"; done
192+}
193+
145194run_bench_target () {
146195 local package_name=$1
147196 local component=$2
148197 local target_name=$3
149− local output_file=$(bench_output_file $target_name)
150198
151199 local target_prog
152200 target_prog=$(cabal_target_prog $package_name $component $target_name) || \
@@ -156,46 +204,16 @@ run_bench_target () {
156204
157205 # Needed by bench-exec-one.sh
158206 export BENCH_EXEC_PATH=$target_prog
159− if test "$LONG" -ne 0
160− then
161− BENCH_ARGS="-p /$target_name\/o-1-space/"
162− STREAM_SIZE=10000000
163− export STREAM_SIZE
164− fi
207+ export RTS_OPTIONS
208+ export QUICK_MODE
209+ export USE_GAUGE
210+ export LONG
165211
166− local MATCH=""
212+ local output_file=$(bench_output_file $target_name)
213+ mkdir -p `dirname $output_file`
167214 if test "$USE_GAUGE" -eq 0
168− then
169− if test "$LONG" -ne 0
170− then
171− MATCH="-p /$target_name\/o-1-space/"
172− else
173− if test -n "$GAUGE_ARGS"
174− then
175− local GAUGE_ARGS1=$(echo "$GAUGE_ARGS" | sed -e 's/\//\\\//g')
176− MATCH="-p /$GAUGE_ARGS1/"
177− fi
178− fi
179− echo "Name,cpuTime,2*Stdev (ps),Allocated,bytesCopied" >> $output_file
180− $target_prog -l $MATCH \
181− | grep "^All" \
182− | while read -r name; do bin/bench-exec-one.sh "$name"; done
183− else
184− if test "$LONG" -ne 0
185− then
186− MATCH="$target_name/o-1-space"
187− else
188− MATCH="$GAUGE_ARGS"
189− fi
190− echo "name,iters,time,cycles,cpuTime,utime,stime,maxrss,minflt,majflt,nvcsw,nivcsw,allocated,numGcs,bytesCopied,mutatorWallSeconds,mutatorCpuSeconds,gcWallSeconds,gcCpuSeconds" >> $output_file
191− # XXX We may have to use "sort | awk" to keep only benchmark names with
192− # shortest prefix e.g. "a/b/c" and "a/b", we should only keep "a/b"
193− # otherwise benchmarks will run multiple times.
194− $target_prog -l \
195− | grep "^$target_name" \
196− | grep "^$MATCH" \
197− | sort | paste -sd "," - | awk 'BEGIN {FS=","} {t="XU987"; for(i=1;i<=NF;i++) if (substr($i,1,length(t)) != t) {print $i; t=$i}}' \
198− | while read -r name; do bin/bench-exec-one.sh "$name"; done
215+ then invoke_tasty_bench "$target_prog" "$target_name" "$output_file"
216+ else invoke_gauge "$target_prog" "$target_name" "$output_file"
199217 fi
200218}
201219
@@ -284,7 +302,6 @@ run_reports() {
284302cd $SCRIPT_DIR/..
285303
286304USE_GAUGE=0
287−export USE_GAUGE
288305USE_GIT_CABAL=1
289306set_common_vars
290307
@@ -318,6 +335,7 @@ do
318335 # options with arguments
319336 --benchmarks) shift; TARGETS=$1; shift ;;
320337 --targets) shift; TARGETS=$1; shift ;;
338+ --prefix) shift; BENCH_PREFIX="$1" shift ;;
321339 --fields) shift; FIELDS=$1; shift ;;
322340 --base) shift; BASE=$1; shift ;;
323341 --candidate) shift; CANDIDATE=$1; shift ;;
@@ -334,13 +352,13 @@ do
334352 --long) LONG=1; shift ;;
335353 --graphs) GRAPH=1; shift ;;
336354 --no-measure) MEASURE=0; shift ;;
337− --dev-build) RUNNING_DEVBUILD=1; shift ;;
355+ --dev-build) RUNNING_DEVBUILD=1; shift ;;
356+ --use-gauge) USE_GAUGE=1; shift ;;
338357 --) shift; break ;;
339− -*|--*) echo "Unknown flags: $*"; echo; print_help ;;
340− *) break ;;
358+ *) echo "Unknown flags: $*"; echo; print_help ;;
341359 esac
342360done
343−GAUGE_ARGS=$*
361+GAUGE_ARGS=("$@")
344362
345363set_derived_vars
346364
@@ -414,13 +432,15 @@ build_report_progs
414432# Build and run targets
415433#-----------------------------------------------------------------------------
416434
417−BUILD_BENCH="$CABAL_EXECUTABLE v2-build $CABAL_BUILD_OPTIONS --enable-benchmarks"
435+if test "$USE_GAUGE" -eq 1
436+then
437+ BUILD_FLAGS="--flag use-gauge"
438+fi
439+
440+BUILD_BENCH="$CABAL_EXECUTABLE v2-build $BUILD_FLAGS $CABAL_BUILD_OPTIONS --enable-benchmarks"
418441if test "$MEASURE" = "1"
419442then
420443 run_build "$BUILD_BENCH" streamly-benchmarks bench "$TARGETS"
421− export QUICK_MODE
422− export RTS_OPTIONS
423− export LONG
424444 run_measurements "$TARGETS"
425445fi
426446