Skip to content

Commit

Permalink
Add command line option to dump config in ini format
Browse files Browse the repository at this point in the history
The computed configuration for each benchmark is written to
stdout in a ini-style format.
  • Loading branch information
dmpots committed Jan 24, 2012
1 parent c6fa6f2 commit 1c5fd3c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
7 changes: 7 additions & 0 deletions tools/fibon-run/Fibon/Run/CommandLine.hs
Expand Up @@ -27,6 +27,7 @@ data Opt = Opt {
, optAction :: Action
, optReuseDir :: ReuseDir
, optRunMode :: RunMode
, optIniConfig :: Bool
}

defaultOpts :: Opt
Expand All @@ -40,6 +41,7 @@ defaultOpts = Opt {
, optAction = Run
, optReuseDir = Nothing
, optRunMode = Sequential
, optIniConfig = False
}


Expand Down Expand Up @@ -136,6 +138,11 @@ options = [
Option ['p'] ["parallel"]
(NoArg (\(e, opt) -> (e, opt {optRunMode = Parallel})))
"run benchmarks in parallel (for testing)"
,
Option [] ["dump-config"]
(NoArg (\(e, opt) -> (e, opt {optIniConfig = True})))
"dump config to stdout in ini format"

]

usage :: String
Expand Down
37 changes: 29 additions & 8 deletions tools/fibon-run/Fibon/Run/Main.hs
Expand Up @@ -13,6 +13,7 @@ import Data.Serialize
import Data.Time.LocalTime(getZonedTime)
import Data.Time.Format(formatTime)
import Fibon.Benchmarks
import Fibon.BenchmarkInstance(BenchmarkInstance(stdinInput))
import Fibon.FlagConfig
import Fibon.Result
import Fibon.Run.Actions
Expand Down Expand Up @@ -56,7 +57,7 @@ main = do
-- build.
progEnv <- getEnvironment
let bundles = makeBundles runConfig workingDir benchRoot reuseId progEnv
mapM_ dumpBundleConfig bundles
dumpConfig (optIniConfig opts) bundles

-- Run the benchmarks to get the results. If we are reusing a previous build
-- then only run the "Run" action.
Expand Down Expand Up @@ -252,25 +253,45 @@ mergeConfigOpts rc opt = rc {
, iterations = maybe (iterations rc) id (optIterations opt)
}

dumpConfig :: Bool -> [BenchmarkBundle] -> IO ()
dumpConfig True bbs = mapM_ dumpBundleConfigIni bbs >> exitSuccess
dumpConfig False bbs = mapM_ dumpBundleConfig bbs

dumpBundleConfig :: BenchmarkBundle -> IO ()
dumpBundleConfig bb = do
Log.config configString
where
configString = bundleName bb
++ dumpConfig "ConfigFlags" (configureFlags . fullFlags)
++ dumpConfig "BuildFlags" (buildFlags . fullFlags)
++ dumpConfig "RunFlags" (runFlags . fullFlags)
++ dumpConfig "RunScript" script
++ dumpConfig "RunScriptArgs" scriptArgs
dumpConfig :: String -> (BenchmarkBundle -> [String]) -> String
dumpConfig configName accessor = "\n" ++ paramSpace ++ configName ++
++ dump "ConfigFlags" (configureFlags . fullFlags)
++ dump "BuildFlags" (buildFlags . fullFlags)
++ dump "RunFlags" (runFlags . fullFlags)
++ dump "RunScript" script
++ dump "RunScriptArgs" scriptArgs
dump :: String -> (BenchmarkBundle -> [String]) -> String
dump configName accessor = "\n" ++ paramSpace ++ configName ++
(concatMap (\f -> "\n" ++ flagSpaces ++ f) (accessor bb))
paramSpace = " "
flagSpaces = " "++ paramSpace
script = map fst . maybeToList . runScript
scriptArgs = concatMap snd . maybeToList . runScript

dumpBundleConfigIni :: BenchmarkBundle -> IO ()
dumpBundleConfigIni bb = do
putStrLn configString
where
configString = "[" ++ bundleName bb ++"]"
++ dump "configure" (configureFlags . fullFlags)
++ dump "build" (buildFlags . fullFlags)
++ dump "run" (runFlags . fullFlags)
++ dump "stdin" (maybeToList . stdinInput . benchDetails)
++ dump "script" script
++ dump "script-args" scriptArgs
dump :: String -> (BenchmarkBundle -> [String]) -> String
dump configName accessor = "\n" ++ configName ++ " = " ++
(concatMap (\f -> f ++ " ") (accessor bb))
script = map fst . maybeToList . runScript
scriptArgs = concatMap snd . maybeToList . runScript

{------------------------------------------------------------------------------
-- Command line parsing
------------------------------------------------------------------------------}
Expand Down

0 comments on commit 1c5fd3c

Please sign in to comment.