on master help sign in
Add the ability to select fields to report
09f2fa7Harendra Kumar
bench.sh+19−6
@@ -125,6 +125,7 @@ list_comparisons () {
125print_help () {
125print_help () {
126 echo "Usage: $0 "
126 echo "Usage: $0 "
127 echo " [--benchmarks <"bench1 bench2 ..." | help>]"
127 echo " [--benchmarks <"bench1 bench2 ..." | help>]"
128+ echo " [--fields <"field1 field2 ..." | help>]"
128 echo " [--graphs]"
129 echo " [--graphs]"
129 echo " [--no-measure]"
130 echo " [--no-measure]"
130 echo " [--append]"
131 echo " [--append]"
@@ -136,6 +137,7 @@ print_help () {
136 echo " -- <gauge options or benchmarks>"
137 echo " -- <gauge options or benchmarks>"
137 echo
138 echo
138 echo "--benchmarks: benchmarks to run, use 'help' for list of benchmarks"
139 echo "--benchmarks: benchmarks to run, use 'help' for list of benchmarks"
140+ echo "--fields: measurement fields to report, use 'help' for a list"
139 echo "--graphs: Generate graphical reports"
141 echo "--graphs: Generate graphical reports"
140 echo "--no-measure: Don't run benchmarks, run reports from previous results"
142 echo "--no-measure: Don't run benchmarks, run reports from previous results"
141 echo "--append: Don't overwrite previous results, append for comparison"
143 echo "--append: Don't overwrite previous results, append for comparison"
@@ -394,7 +396,7 @@ run_reports() {
394 do
396 do
395 echo "Generating reports for ${i}..."
397 echo "Generating reports for ${i}..."
396 $prog $(test "$GRAPH" = 1 && echo "--graphs") \
398 $prog $(test "$GRAPH" = 1 && echo "--graphs") \
397− --benchmark $i
399+ --benchmark $i --fields "$FIELDS"
398 done
400 done
399}
401}
400
402
@@ -403,6 +405,9 @@ run_reports() {
403#-----------------------------------------------------------------------------
405#-----------------------------------------------------------------------------
404
406
405DEFAULT_BENCHMARKS="$all_grp"
407DEFAULT_BENCHMARKS="$all_grp"
408+DEFAULT_FIELDS="allocated bytescopied cputime"
409+ALL_FIELDS="$FIELDS time cycles utime stime minflt majflt nvcsw nivcsw"
410+FIELDS=$DEFAULT_FIELDS
406
411
407COMPARE=0
412COMPARE=0
408BASE=
413BASE=
@@ -438,6 +443,7 @@ do
438 -h|--help|help) print_help ;;
443 -h|--help|help) print_help ;;
439 # options with arguments
444 # options with arguments
440 --benchmarks) shift; BENCHMARKS=$1; shift ;;
445 --benchmarks) shift; BENCHMARKS=$1; shift ;;
446+ --fields) shift; FIELDS=$1; shift ;;
441 --base) shift; BASE=$1; shift ;;
447 --base) shift; BASE=$1; shift ;;
442 --candidate) shift; CANDIDATE=$1; shift ;;
448 --candidate) shift; CANDIDATE=$1; shift ;;
443 --cabal-build-flags) shift; CABAL_BUILD_FLAGS=$1; shift ;;
449 --cabal-build-flags) shift; CABAL_BUILD_FLAGS=$1; shift ;;
@@ -476,10 +482,10 @@ only_real_benchmarks () {
476 done
482 done
477}
483}
478
484
479−has_benchmark () {
485+has_item () {
480− for i in $BENCHMARKS_ORIG
486+ for i in $1
481 do
487 do
482− if test "$i" = "$1"
488+ if test "$i" = "$2"
483 then
489 then
484 echo "$i"
490 echo "$i"
485 break
491 break
@@ -488,7 +494,7 @@ has_benchmark () {
488}
494}
489
495
490BENCHMARKS_ORIG=$BENCHMARKS
496BENCHMARKS_ORIG=$BENCHMARKS
491−if test "$(has_benchmark help)" = "help"
497+if test "$(has_item "$BENCHMARKS_ORIG" help)" = "help"
492then
498then
493 list_bench_groups
499 list_bench_groups
494 list_comparisons
500 list_comparisons
@@ -496,6 +502,13 @@ then
496 exit
502 exit
497fi
503fi
498
504
505+if test "$(has_item "$FIELDS" help)" = "help"
506+then
507+ echo "Supported fields: $ALL_FIELDS"
508+ echo "Default fields: $DEFAULT_FIELDS"
509+ exit
510+fi
511+
499if test "$LONG" -ne 0
512if test "$LONG" -ne 0
500then
513then
501 if test -n "$BENCHMARKS"
514 if test -n "$BENCHMARKS"
@@ -559,7 +572,7 @@ fi
559COMPARISON_REPORTS=""
572COMPARISON_REPORTS=""
560for i in $COMPARISONS
573for i in $COMPARISONS
561do
574do
562− if test "$(has_benchmark $i)" = $i
575+ if test "$(has_item "$BENCHMARKS_ORIG" $i)" = $i
563 then
576 then
564 COMPARISON_REPORTS="$COMPARISON_REPORTS $i"
577 COMPARISON_REPORTS="$COMPARISON_REPORTS $i"
565 mkdir -p "charts/$i"
578 mkdir -p "charts/$i"
benchmark/Chart.hs+30−20
@@ -26,10 +26,11 @@ data BenchType
26data Options = Options
26data Options = Options
27 { genGraphs :: Bool
27 { genGraphs :: Bool
28 , benchType :: Maybe BenchType
28 , benchType :: Maybe BenchType
29+ , fields :: [String]
29 } deriving Show
30 } deriving Show
30
31
31defaultOptions :: Options
32defaultOptions :: Options
32−defaultOptions = Options False Nothing
33+defaultOptions = Options False Nothing ["time"]
33
34
34setGenGraphs :: Monad m => Bool -> StateT (a, Options) m ()
35setGenGraphs :: Monad m => Bool -> StateT (a, Options) m ()
35setGenGraphs val = do
36setGenGraphs val = do
@@ -41,6 +42,11 @@ setBenchType val = do
41 (args, opts) <- get
42 (args, opts) <- get
42 put (args, opts { benchType = Just val })
43 put (args, opts { benchType = Just val })
43
44
45+setFields :: Monad m => [String] -> StateT (a, Options) m ()
46+setFields val = do
47+ (args, opts) <- get
48+ put (args, opts { fields = val })
49+
44-- Like the shell "shift" to shift the command line arguments
50-- Like the shell "shift" to shift the command line arguments
45shift :: StateT ([String], Options) (MaybeT IO) (Maybe String)
51shift :: StateT ([String], Options) (MaybeT IO) (Maybe String)
46shift = do
52shift = do
@@ -59,6 +65,16 @@ parseBench = do
59 liftIO $ putStrLn "please provide a benchmark type "
65 liftIO $ putStrLn "please provide a benchmark type "
60 mzero
66 mzero
61
67
68+parseFields :: StateT ([String], Options) (MaybeT IO) ()
69+parseFields = do
70+ x <- shift
71+ case x of
72+ Just str -> setFields (words str)
73+ Nothing -> do
74+ liftIO $ putStrLn
75+ "please provide a list of fields after --fields"
76+ mzero
77+
62-- totally imperative style option parsing
78-- totally imperative style option parsing
63parseOptions :: IO (Maybe Options)
79parseOptions :: IO (Maybe Options)
64parseOptions = do
80parseOptions = do
@@ -71,8 +87,9 @@ parseOptions = do
71
87
72 parseOpt opt =
88 parseOpt opt =
73 case opt of
89 case opt of
74− "--graphs" -> setGenGraphs True
90+ "--graphs" -> setGenGraphs True
75− "--benchmark" -> parseBench
91+ "--benchmark" -> parseBench
92+ "--fields" -> parseFields
76 str -> do
93 str -> do
77 liftIO $ putStrLn $ "Unrecognized option " <> str
94 liftIO $ putStrLn $ "Unrecognized option " <> str
78 mzero
95 mzero
@@ -147,28 +164,21 @@ benchShow Options{..} cfg func inp out =
147
164
148main :: IO ()
165main :: IO ()
149main = do
166main = do
150− let cfg = defaultConfig
151− { presentation = Groups PercentDiff
152− , selectBenchmarks = selectBench
153− , selectFields = filter
154− ( flip elem [ "time"
155− , "mean"
156− , "cputime"
157− , "allocated"
158− , "bytescopied"
159− , "maxrss"
160− ]
161− . fmap toLower
162− )
163− }
164 res <- parseOptions
167 res <- parseOptions
165−
166 case res of
168 case res of
167 Nothing -> do
169 Nothing -> do
168 putStrLn "cannot parse options"
170 putStrLn "cannot parse options"
169 return ()
171 return ()
170− Just opts@Options{..} ->
172+ Just opts@Options{fields = fs, benchType = btype} ->
173+ let cfg = defaultConfig
174+ { presentation = Groups PercentDiff
175+ , selectBenchmarks = selectBench
176+ , selectFields = filter
177+ ( flip elem fs
178+ . fmap toLower
179+ )
180+ }
171− case benchType of
181+ in case btype of
172 Just (Compare str) ->
182 Just (Compare str) ->
173 showComparisons opts cfg
183 showComparisons opts cfg
174 { title = Just str }
184 { title = Just str }