@@ -233,6 +233,8 @@ data MkBenchRules buildSystem example = forall setup. MkBenchRules
233
233
setupProject :: Action setup
234
234
-- | An action that invokes the executable to run the benchmark
235
235
, 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 ()
236
238
-- | Name of the executable to benchmark. Should match the one used to 'MkBuildRules'
237
239
, executableName :: String
238
240
}
@@ -262,6 +264,26 @@ benchRules :: RuleResultForExample example => FilePattern -> MkBenchRules BuildS
262
264
benchRules build MkBenchRules {.. } = do
263
265
264
266
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
265
287
-- run an experiment
266
288
priority 0 $
267
289
[ build -/- " */*/*/*.csv" ,
@@ -287,8 +309,9 @@ benchRules build MkBenchRules{..} = do
287
309
| CheapHeapProfiling i <- [prof]]
288
310
++ [" -RTS" ]
289
311
ghcPath = build </> " binaries" </> ver </> " ghc.path"
312
+ warmupPath = build </> " binaries" </> ver </> exampleName <.> " warmup"
290
313
experiment = Escaped $ dropExtension exp
291
- need [exePath, ghcPath]
314
+ need [exePath, ghcPath, warmupPath ]
292
315
ghcPath <- readFile' ghcPath
293
316
withResource benchResource 1 $ do
294
317
benchProject setupRes buildSystem
0 commit comments