Skip to content

Commit e0caba5

Browse files
authored
Benchmarks: generate heap profiles (#1253)
* Parallelize benchmarks * [benchmarks] Collect heap profiles * [benchmarks] pass RTS options to the real thing! We were passing RTS options to the wrong thing * Drop the 8.6.5 benchmark since the vanilla rts doesn't support +RTS -h * Tone down timeout * Review feedbacks
1 parent 3464ed8 commit e0caba5

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

Diff for: .github/mergify.yml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pull_request_rules:
77
conditions:
88
- status-success=bench (8.10.2, ubuntu-latest)
99
- status-success=bench (8.8.4, ubuntu-latest)
10-
- status-success=bench (8.6.5, ubuntu-latest)
1110

1211
- status-success=nix (default, ubuntu-latest)
1312
- status-success=nix (default, macOS-latest)

Diff for: .github/workflows/bench.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
ghc: ['8.10.2', '8.8.4', '8.6.5']
11+
ghc: ['8.10.2', '8.8.4']
1212
os: [ubuntu-latest]
1313

1414
steps:

Diff for: ghcide/bench/hist/Main.hs

+7-4
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ type instance RuleResult GetExample = Maybe Example
6666
type instance RuleResult GetExamples = [Example]
6767

6868
main :: IO ()
69-
main = shakeArgs shakeOptions {shakeChange = ChangeModtimeAndDigest} $ do
69+
main = shakeArgs shakeOptions {shakeChange = ChangeModtimeAndDigest, shakeThreads = 0} $ do
7070
createBuildSystem $ \resource -> do
7171
configStatic <- liftIO $ readConfigIO config
7272
let build = outputFolder configStatic
7373
buildRules build ghcideBuildRules
7474
benchRules build resource (MkBenchRules (askOracle $ GetSamples ()) benchGhcide "ghcide")
7575
csvRules build
7676
svgRules build
77+
eventlogRules build
7778
action $ allTargets build
7879

7980
ghcideBuildRules :: MkBuildRules BuildSystem
@@ -122,6 +123,7 @@ buildGhcide Cabal args out = do
122123
,"--install-method=copy"
123124
,"--overwrite-policy=always"
124125
,"--ghc-options=-rtsopts"
126+
,"--ghc-options=-eventlog"
125127
]
126128

127129
buildGhcide Stack args out =
@@ -131,23 +133,24 @@ buildGhcide Stack args out =
131133
,"ghcide:ghcide"
132134
,"--copy-bins"
133135
,"--ghc-options=-rtsopts"
136+
,"--ghc-options=-eventlog"
134137
]
135138

136139
benchGhcide
137140
:: Natural -> BuildSystem -> [CmdOption] -> BenchProject Example -> Action ()
138141
benchGhcide samples buildSystem args BenchProject{..} = do
139142
command_ args "ghcide-bench" $
140-
[ "--timeout=3000",
143+
[ "--timeout=300",
141144
"--no-clean",
142145
"-v",
143146
"--samples=" <> show samples,
144147
"--csv=" <> outcsv,
145148
"--ghcide=" <> exePath,
149+
"--ghcide-options=" <> unwords exeExtraArgs,
146150
"--select",
147151
unescaped (unescapeExperiment experiment)
148152
] ++
149153
exampleToOptions example ++
150154
[ "--stack" | Stack == buildSystem
151-
] ++
152-
exeExtraArgs
155+
]
153156

Diff for: ghcide/ghcide.cabal

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ benchmark benchHist
219219
hs-source-dirs: bench/hist bench/lib
220220
other-modules: Experiments.Types
221221
build-tool-depends:
222-
ghcide:ghcide-bench
222+
ghcide:ghcide-bench,
223+
eventlog2html:eventlog2html
223224
default-extensions:
224225
BangPatterns
225226
DeriveFunctor

Diff for: shake-bench/src/Development/Benchmark/Rules.hs

+20-12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module Development.Benchmark.Rules
4949
benchRules, MkBenchRules(..), BenchProject(..),
5050
csvRules,
5151
svgRules,
52+
eventlogRules,
5253
allTargets,
5354
GetExample(..), GetExamples(..),
5455
IsExample(..), RuleResultForExample,
@@ -83,7 +84,7 @@ import GHC.Stack (HasCallStack)
8384
import qualified Graphics.Rendering.Chart.Backend.Diagrams as E
8485
import Graphics.Rendering.Chart.Easy ((.=))
8586
import qualified Graphics.Rendering.Chart.Easy as E
86-
import System.Directory (findExecutable, createDirectoryIfMissing)
87+
import System.Directory (createDirectoryIfMissing, findExecutable, renameFile)
8788
import System.FilePath
8889
import qualified Text.ParserCombinators.ReadP as P
8990
import Text.Read (Read (..), get,
@@ -134,11 +135,11 @@ allTargets buildFolder = do
134135
++ [ buildFolder </>
135136
getExampleName ex </>
136137
T.unpack (humanName ver) </>
137-
escaped (escapeExperiment e) <.> mode <.> "svg"
138+
escaped (escapeExperiment e) <.> mode
138139
| e <- experiments,
139140
ex <- examples,
140141
ver <- versions,
141-
mode <- ["", "diff"]
142+
mode <- ["svg", "diff.svg","eventlog.html"]
142143
]
143144

144145
--------------------------------------------------------------------------------
@@ -188,14 +189,14 @@ buildRules build MkBuildRules{..} = do
188189
[build -/- "binaries/*/" <> executableName
189190
,build -/- "binaries/*/ghc.path"
190191
] &%> \[out, ghcPath] -> do
191-
let [_, _binaries, _ver, _] = splitDirectories out
192+
let [_, _binaries, ver, _] = splitDirectories out
192193
liftIO $ createDirectoryIfMissing True $ dropFileName out
193194
commitid <- readFile' $ takeDirectory out </> "commitid"
194-
cmd_ $ "git worktree add bench-temp " ++ commitid
195+
cmd_ $ "git worktree add bench-temp-" ++ ver ++ " " ++ commitid
195196
buildSystem <- askOracle $ GetBuildSystem ()
196-
flip actionFinally (cmd_ ("git worktree remove bench-temp --force" :: String)) $ do
197-
ghcLoc <- liftIO $ findGhc buildSystem "bench-temp"
198-
buildProject buildSystem [Cwd "bench-temp"] (".." </> takeDirectory out)
197+
flip actionFinally (cmd_ ("git worktree remove bench-temp-" <> ver <> " --force" :: String)) $ do
198+
ghcLoc <- liftIO $ findGhc buildSystem ver
199+
buildProject buildSystem [Cwd $ "bench-temp-" <> ver] (".." </> takeDirectory out)
199200
writeFile' ghcPath ghcLoc
200201

201202
--------------------------------------------------------------------------------
@@ -224,17 +225,19 @@ benchRules build benchResource MkBenchRules{..} = do
224225
priority 0 $
225226
[ build -/- "*/*/*.csv",
226227
build -/- "*/*/*.benchmark-gcStats",
228+
build -/- "*/*/*.eventlog",
229+
build -/- "*/*/*.hp",
227230
build -/- "*/*/*.log"
228231
]
229-
&%> \[outcsv, outGc, outLog] -> do
232+
&%> \[outcsv, outGc, outEventLog, outHp, outLog] -> do
230233
let [_, exampleName, ver, exp] = splitDirectories outcsv
231234
example <- fromMaybe (error $ "Unknown example " <> exampleName)
232235
<$> askOracle (GetExample exampleName)
233236
buildSystem <- askOracle $ GetBuildSystem ()
234237
setupRes <- setupProject
235238
liftIO $ createDirectoryIfMissing True $ dropFileName outcsv
236239
let exePath = build </> "binaries" </> ver </> executableName
237-
exeExtraArgs = ["+RTS", "-I0.5", "-S" <> takeFileName outGc, "-RTS"]
240+
exeExtraArgs = ["+RTS", "-l-a", "-h", "-ol" <> outEventLog, "-S" <> outGc, "-RTS"]
238241
ghcPath = build </> "binaries" </> ver </> "ghc.path"
239242
experiment = Escaped $ dropExtension exp
240243
need [exePath, ghcPath]
@@ -247,8 +250,8 @@ benchRules build benchResource MkBenchRules{..} = do
247250
RemEnv "GHC_PACKAGE_PATH",
248251
AddPath [takeDirectory ghcPath, "."] []
249252
]
250-
BenchProject{..}
251-
cmd_ Shell $ "mv *.benchmark-gcStats " <> dropFileName outcsv
253+
BenchProject {..}
254+
liftIO $ renameFile "ghcide.hp" $ dropFileName outcsv </> dropExtension exp <.> "hp"
252255

253256
-- extend csv output with allocation data
254257
csvContents <- liftIO $ lines <$> readFile outcsv
@@ -378,6 +381,11 @@ svgRules build = do
378381
title = show (unescapeExperiment exp) <> " - live bytes over time"
379382
plotDiagram False diagram out
380383

384+
eventlogRules :: FilePattern -> Rules ()
385+
eventlogRules build = do
386+
build -/- "*/*/*.eventlog.html" %> \out -> do
387+
need [dropExtension out]
388+
cmd_ ("eventlog2html" :: String) [dropExtension out]
381389

382390
--------------------------------------------------------------------------------
383391
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)