@@ -233,6 +233,8 @@ data MkBenchRules buildSystem example = forall setup. MkBenchRules
233233 setupProject :: Action setup
234234 -- | An action that invokes the executable to run the benchmark
235235 , benchProject :: setup -> buildSystem -> [CmdOption ] -> BenchProject example -> Action ()
236+ -- | An action that performs any necessary warmup. Will only be invoked once
237+ , warmupProject :: buildSystem -> FilePath -> [CmdOption ] -> example -> Action ()
236238 -- | Name of the executable to benchmark. Should match the one used to 'MkBuildRules'
237239 , executableName :: String
238240 }
@@ -262,6 +264,26 @@ benchRules :: RuleResultForExample example => FilePattern -> MkBenchRules BuildS
262264benchRules build MkBenchRules {.. } = do
263265
264266 benchResource <- newResource " ghcide-bench" 1
267+ -- warmup an example
268+ build -/- " binaries/*/*.warmup" %> \ out -> do
269+ let [_, _, ver, exampleName] = splitDirectories (dropExtension out)
270+ let exePath = build </> " binaries" </> ver </> executableName
271+ ghcPath = build </> " binaries" </> ver </> " ghc.path"
272+ need [exePath, ghcPath]
273+ buildSystem <- askOracle $ GetBuildSystem ()
274+ example <- fromMaybe (error $ " Unknown example " <> exampleName)
275+ <$> askOracle (GetExample exampleName)
276+ let exeExtraArgs = []
277+ outcsv = " "
278+ experiment = Escaped " hover"
279+ withResource benchResource 1 $ warmupProject buildSystem exePath
280+ [ EchoStdout False ,
281+ FileStdout out,
282+ RemEnv " NIX_GHC_LIBDIR" ,
283+ RemEnv " GHC_PACKAGE_PATH" ,
284+ AddPath [takeDirectory ghcPath, " ." ] []
285+ ]
286+ example
265287 -- run an experiment
266288 priority 0 $
267289 [ build -/- " */*/*/*.csv" ,
@@ -287,8 +309,9 @@ benchRules build MkBenchRules{..} = do
287309 | CheapHeapProfiling i <- [prof]]
288310 ++ [" -RTS" ]
289311 ghcPath = build </> " binaries" </> ver </> " ghc.path"
312+ warmupPath = build </> " binaries" </> ver </> exampleName <.> " warmup"
290313 experiment = Escaped $ dropExtension exp
291- need [exePath, ghcPath]
314+ need [exePath, ghcPath, warmupPath ]
292315 ghcPath <- readFile' ghcPath
293316 withResource benchResource 1 $ do
294317 benchProject setupRes buildSystem
0 commit comments