Skip to content

Commit 762838d

Browse files
[benchmark] add warmups (#1323)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent f4c76bb commit 762838d

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

ghcide/bench/hist/Main.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ createBuildSystem config = do
116116
let build = outputFolder configStatic
117117

118118
buildRules build ghcideBuildRules
119-
benchRules build (MkBenchRules (askOracle $ GetSamples ()) benchGhcide "ghcide")
119+
benchRules build (MkBenchRules (askOracle $ GetSamples ()) benchGhcide warmupGhcide "ghcide")
120120
csvRules build
121121
svgRules build
122122
heapProfileRules build
@@ -170,3 +170,15 @@ benchGhcide samples buildSystem args BenchProject{..} = do
170170
[ "--stack" | Stack == buildSystem
171171
]
172172

173+
warmupGhcide :: BuildSystem -> FilePath -> [CmdOption] -> Example -> Action ()
174+
warmupGhcide buildSystem exePath args example = do
175+
command args "ghcide-bench" $
176+
[ "--no-clean",
177+
"-v",
178+
"--samples=1",
179+
"--ghcide=" <> exePath,
180+
"--select=hover"
181+
] ++
182+
exampleToOptions example ++
183+
[ "--stack" | Stack == buildSystem
184+
]

shake-bench/src/Development/Benchmark/Rules.hs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
262264
benchRules 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

Comments
 (0)