Commit 7215e665 authored by Alex D's avatar Alex D 🍄 Committed by Alex D

Hadrian: make nofib rule more fine-grained

A bunch of new flags added:
 * --cachegrind for enabling valgrind
 * --nofib-runs for specifying number of test runs
 * --nofib-mode for controlling time mode
 * --nofib-log  for specifying output file name
parent 274e21f0
Pipeline #26130 passed with stages
in 317 minutes and 32 seconds
......@@ -203,10 +203,17 @@ time you fire up a build. This is not possible with the Make build system.
``` sh
# Make
cd nofib; make clean; make boot; make 2>&1 | tee nofib-log
cd nofib; make clean; make boot; make 2>&1 | tee nofib-log # (1)
cd nofib; make clean; make boot; mode=fast; make mode=fast NoFibRuns=3 2>&1 | tee nofib-log # (2)
cd nofib; make clean; make boot; make EXTRA_RUNTEST_OPTS="-cachegrind" 2>&1 | tee new-log # (3)
# Hadrian
build nofib # builds the compiler and everything we need if necessary, too
# builds the compiler and everything we need if necessary, too
build nofib # (1)
build nofib --nofib-mode=fast --nofib-runs=3 # (2)
build nofib --cachegrind --nofib-log=new-log # (3)
# Note that if with --cachegrind is passed, --nofib-runs will be set to 1.
```
- `make FAST=YES`
......
module CommandLine (
TestArgs(..), NofibArgs(..), TestSpeed(..), NofibMode,
optDescrs, cmdLineArgsMap, cmdFlavour, lookupFreeze1, lookupFreeze2, lookupSkipDepends,
cmdBignum, cmdBignumCheck, cmdProgressInfo, cmdConfigure, cmdCompleteSetting,
cmdDocsArgs, lookupBuildRoot, TestArgs(..), TestSpeed(..), defaultTestArgs,
cmdPrefix
cmdDocsArgs, lookupBuildRoot, defaultTestArgs, cmdPrefix,
defaultNofibArgs, lookupNofibArgs,
) where
import Data.Char
import Data.Either
import qualified Data.HashMap.Strict as Map
import Data.List.Extra
......@@ -32,6 +34,7 @@ data CommandLineArgs = CommandLineArgs
, progressInfo :: ProgressInfo
, buildRoot :: BuildRoot
, testArgs :: TestArgs
, nofibArgs :: NofibArgs
, docTargets :: DocTargets
, prefix :: Maybe FilePath
, completeStg :: Maybe String }
......@@ -50,6 +53,7 @@ defaultCommandLineArgs = CommandLineArgs
, progressInfo = Brief
, buildRoot = BuildRoot "_build"
, testArgs = defaultTestArgs
, nofibArgs = defaultNofibArgs
, docTargets = Set.fromList [minBound..maxBound]
, prefix = Nothing
, completeStg = Nothing }
......@@ -94,6 +98,52 @@ defaultTestArgs = TestArgs
, brokenTests = []
, testAccept = False }
type NofibMode = TestSpeed
data NofibArgs = NofibArgs
{ logFile :: Maybe String
, mode :: NofibMode
, cacheGrind :: Bool
, numOfRuns :: String
} deriving (Eq, Show)
defaultNofibArgs :: NofibArgs
defaultNofibArgs = NofibArgs
{ logFile = Just "nofib-log"
, mode = TestNormal
, cacheGrind = False
, numOfRuns = "10"
}
readNofibCacheGrind :: Either String (CommandLineArgs -> CommandLineArgs)
readNofibCacheGrind =
Right $ \flags -> flags {
nofibArgs = (nofibArgs flags) { cacheGrind = True }
}
readNofibNumOfRuns :: Maybe String -> Either String (CommandLineArgs -> CommandLineArgs)
readNofibNumOfRuns maybeRuns = case maybeRuns of
Nothing -> Right id
Just runs ->
if all isNumber runs
then Right $ \flags -> flags {
nofibArgs = (nofibArgs flags) { numOfRuns = runs }
}
else Left "Cannot parse nofib number or runs"
readNofibLogFile :: Maybe String -> Either String (CommandLineArgs -> CommandLineArgs)
readNofibLogFile f =
Right $ \flags -> flags {
nofibArgs = (nofibArgs flags) { logFile = f }
}
readNofibMode :: Maybe String -> Either String (CommandLineArgs -> CommandLineArgs)
readNofibMode tm =
maybe (Left "Cannot parse nofib time mode") (Right . set) (read_test_speed =<< lower <$> tm)
where
set :: NofibMode -> CommandLineArgs -> CommandLineArgs
set flag flags = flags { nofibArgs = (nofibArgs flags) { mode = flag} }
readConfigure :: Either String (CommandLineArgs -> CommandLineArgs)
readConfigure = Right $ \flags -> flags { configure = True }
......@@ -187,16 +237,17 @@ readTestRootDirs rootdirs = Right $ \flags ->
readTestSpeed :: Maybe String -> Either String (CommandLineArgs -> CommandLineArgs)
readTestSpeed ms =
maybe (Left "Cannot parse test-speed") (Right . set) (go =<< lower <$> ms)
maybe (Left "Cannot parse test-speed") (Right . set) (read_test_speed =<< lower <$> ms)
where
go :: String -> Maybe TestSpeed
go "fast" = Just TestFast
go "slow" = Just TestSlow
go "normal" = Just TestNormal
go _ = Nothing
set :: TestSpeed -> CommandLineArgs -> CommandLineArgs
set flag flags = flags { testArgs = (testArgs flags) {testSpeed = flag} }
read_test_speed :: String -> Maybe TestSpeed
read_test_speed "fast" = Just TestFast
read_test_speed "slow" = Just TestSlow
read_test_speed "normal" = Just TestNormal
read_test_speed _ = Nothing
readTestSummary :: Maybe String -> Either String (CommandLineArgs -> CommandLineArgs)
readTestSummary filepath = Right $ \flags -> flags { testArgs = (testArgs flags) { testSummary = filepath } }
......@@ -285,6 +336,14 @@ optDescrs =
"Only run performance tests."
, Option [] ["skip-perf"] (NoArg readTestSkipPerf)
"Skip performance tests."
, Option [] ["cachegrind"] (NoArg readNofibCacheGrind)
"Nofib: Get instruction counts, memory reads/writes, and \"cache misses\" using Valgrind."
, Option [] ["nofib-runs"] (OptArg readNofibNumOfRuns "NOFIB_NUM_OF_RUNS")
"Nofib: Number of times benchmark will be run. Default=10"
, Option [] ["nofib-mode"] (OptArg readNofibMode "NOFIB_MODE")
"Nofib: Benchmark time mode (fast, norm, slow). Default=norm"
, Option [] ["nofib-log"] (OptArg readNofibLogFile "NOFIB_LOG_FILE")
"Nofib: Results file name. Default=nofib-log"
, Option [] ["test-root-dirs"] (OptArg readTestRootDirs "DIR1:[DIR2:...:DIRn]")
"Test root directories to look at (all by default)."
, Option [] ["test-speed"] (OptArg readTestSpeed "SPEED")
......@@ -369,6 +428,9 @@ lookupFreeze2 = freeze2 . lookupExtra defaultCommandLineArgs
lookupSkipDepends :: Map.HashMap TypeRep Dynamic -> Bool
lookupSkipDepends = skipDepends . lookupExtra defaultCommandLineArgs
lookupNofibArgs :: Rules NofibArgs
lookupNofibArgs = nofibArgs <$> userSettingRules defaultCommandLineArgs
cmdBignum :: Action (Maybe String)
cmdBignum = bignum <$> cmdLineArgs
......
......@@ -10,7 +10,7 @@ module Hadrian.Utilities (
unifyPath, (-/-), makeRelativeNoSysLink,
-- * Accessing Shake's type-indexed map
insertExtra, lookupExtra, userSetting,
insertExtra, lookupExtra, userSetting, userSettingRules,
-- * Paths
BuildRoot (..), buildRoot, buildRootRules, isGeneratedSource,
......
module Rules.Nofib where
import Base
import CommandLine
import Expression
import Oracles.Setting
import Packages
......@@ -8,22 +9,25 @@ import Packages
import System.Environment
import System.Exit
nofibLogFile :: FilePath
nofibLogFile = "nofib-log"
defNofibLogFile :: FilePath
defNofibLogFile = "nofib-log"
-- | Rules for running the @nofib@ benchmark suite.
nofibRules :: Rules ()
nofibRules = do
root <- buildRootRules
flags <- lookupNofibArgs
-- a phony "nofib" rule that just triggers
-- the rule below.
let nofibLogFile = fromMaybe defNofibLogFile (logFile flags)
"nofib" ~> need [root -/- nofibLogFile]
-- a rule to produce <build root>/nofig-log
-- a rule to produce <build root>/<nofib-logFile>
-- by running the nofib suite and capturing
-- the relevant output.
root -/- nofibLogFile %> \fp -> do
putVerbose (show flags)
needNofibDeps
makePath <- builderPath (Make "nofib")
......@@ -36,12 +40,12 @@ nofibRules = do
-- this runs make commands in the nofib
-- subdirectory, passing the path to
-- the GHC to benchmark and perl to
-- nofib's makefiles.
let nofibArgs = ["WithNofibHc=" ++ (top -/- ghcPath)]
-- the GHC to benchmark.
let bootArgs = mkNofibBootArgs (top -/- ghcPath) flags
let runArgs = mkNofibRunArgs flags
unit $ cmd (Cwd "nofib") [makePath] ["clean"]
unit $ cmd (Cwd "nofib") [makePath] (nofibArgs ++ ["boot"])
(Exit e, Stdouterr log) <- cmd (Cwd "nofib") [makePath] nofibArgs
unit $ cmd (Cwd "nofib") [makePath] (bootArgs ++ ["boot"])
(Exit e, Stdouterr log) <- cmd (Cwd "nofib") [makePath] (bootArgs ++ runArgs)
writeFile' fp log
if e == ExitSuccess
then putLoud $ "nofib log available at " ++ fp
......@@ -54,3 +58,21 @@ needNofibDeps = do
mtlPath <- pkgConfFile (vanillaContext Stage1 mtl )
need [ unlitPath, mtlPath ]
needBuilder (Ghc CompileHs Stage2)
mkNofibBootArgs :: FilePath -> NofibArgs -> [String]
mkNofibBootArgs ghcPath args =
[ "WithNofibHc=" ++ ghcPath
, "mode=" ++ (timeModeToStr (mode args))
]
mkNofibRunArgs :: NofibArgs -> [String]
mkNofibRunArgs args =
[ if cachegrind then "EXTRA_RUNTEST_OPTS=-cachegrind" else ""
, "NoFibRuns=" ++ (if cachegrind then "1" else (numOfRuns args))
, "mode=" ++ (timeModeToStr (mode args))
] where cachegrind = cacheGrind args
timeModeToStr :: NofibMode -> String
timeModeToStr TestSlow = "slow"
timeModeToStr TestNormal = "norm"
timeModeToStr TestFast = "fast"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment