Skip to content

Commit 4e035d7

Browse files
authored
Merge branch 'master' into ghc-8.10.4
2 parents 6614dab + 9bb3bb7 commit 4e035d7

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

ghcide/bench/hist/Main.hs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import Development.Shake.Classes
5555
import System.Console.GetOpt
5656
import Data.Maybe
5757
import Control.Monad.Extra
58+
import System.FilePath
5859

5960

6061
configPath :: FilePath
@@ -84,7 +85,12 @@ main = shakeArgsWith shakeOpts [configOpt] $ \configs wants -> pure $ Just $ do
8485
_ -> want wants
8586

8687
ghcideBuildRules :: MkBuildRules BuildSystem
87-
ghcideBuildRules = MkBuildRules findGhcForBuildSystem "ghcide" buildGhcide
88+
ghcideBuildRules = MkBuildRules findGhcForBuildSystem "ghcide" projectDepends buildGhcide
89+
where
90+
projectDepends = do
91+
need . map ("src" </>) =<< getDirectoryFiles "src" ["//*.hs"]
92+
need . map ("session-loader" </>) =<< getDirectoryFiles "session-loader" ["//*.hs"]
93+
need =<< getDirectoryFiles "." ["*.cabal"]
8894

8995
--------------------------------------------------------------------------------
9096

@@ -116,7 +122,7 @@ createBuildSystem config = do
116122
let build = outputFolder configStatic
117123

118124
buildRules build ghcideBuildRules
119-
benchRules build (MkBenchRules (askOracle $ GetSamples ()) benchGhcide "ghcide")
125+
benchRules build (MkBenchRules (askOracle $ GetSamples ()) benchGhcide warmupGhcide "ghcide")
120126
csvRules build
121127
svgRules build
122128
heapProfileRules build
@@ -141,6 +147,7 @@ buildGhcide Cabal args out = do
141147
,"--install-method=copy"
142148
,"--overwrite-policy=always"
143149
,"--ghc-options=-rtsopts"
150+
,"--ghc-options=-eventlog"
144151
]
145152

146153
buildGhcide Stack args out =
@@ -150,6 +157,7 @@ buildGhcide Stack args out =
150157
,"ghcide:ghcide"
151158
,"--copy-bins"
152159
,"--ghc-options=-rtsopts"
160+
,"--ghc-options=-eventlog"
153161
]
154162

155163
benchGhcide
@@ -170,3 +178,15 @@ benchGhcide samples buildSystem args BenchProject{..} = do
170178
[ "--stack" | Stack == buildSystem
171179
]
172180

181+
warmupGhcide :: BuildSystem -> FilePath -> [CmdOption] -> Example -> Action ()
182+
warmupGhcide buildSystem exePath args example = do
183+
command args "ghcide-bench" $
184+
[ "--no-clean",
185+
"-v",
186+
"--samples=1",
187+
"--ghcide=" <> exePath,
188+
"--select=hover"
189+
] ++
190+
exampleToOptions example ++
191+
[ "--stack" | Stack == buildSystem
192+
]

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ data MkBuildRules buildSystem = MkBuildRules
177177
findGhc :: buildSystem -> FilePath -> IO FilePath
178178
-- | Name of the binary produced by 'buildProject'
179179
, executableName :: String
180+
-- | An action that captures the source dependencies, used for the HEAD build
181+
, projectDepends :: Action ()
180182
-- | Build the project found in the cwd and save the build artifacts in the output folder
181183
, buildProject :: buildSystem
182184
-> [CmdOption]
@@ -204,9 +206,8 @@ buildRules build MkBuildRules{..} = do
204206
, build -/- "binaries/HEAD/ghc.path"
205207
]
206208
&%> \[out, ghcpath] -> do
209+
projectDepends
207210
liftIO $ createDirectoryIfMissing True $ dropFileName out
208-
-- TOOD more precise dependency tracking
209-
need =<< getDirectoryFiles "." ["//*.hs", "*.cabal"]
210211
buildSystem <- askOracle $ GetBuildSystem ()
211212
buildProject buildSystem [Cwd "."] (takeDirectory out)
212213
ghcLoc <- liftIO $ findGhc buildSystem "."
@@ -233,6 +234,8 @@ data MkBenchRules buildSystem example = forall setup. MkBenchRules
233234
setupProject :: Action setup
234235
-- | An action that invokes the executable to run the benchmark
235236
, benchProject :: setup -> buildSystem -> [CmdOption] -> BenchProject example -> Action ()
237+
-- | An action that performs any necessary warmup. Will only be invoked once
238+
, warmupProject :: buildSystem -> FilePath -> [CmdOption] -> example -> Action ()
236239
-- | Name of the executable to benchmark. Should match the one used to 'MkBuildRules'
237240
, executableName :: String
238241
}
@@ -262,13 +265,34 @@ benchRules :: RuleResultForExample example => FilePattern -> MkBenchRules BuildS
262265
benchRules build MkBenchRules{..} = do
263266

264267
benchResource <- newResource "ghcide-bench" 1
268+
-- warmup an example
269+
build -/- "binaries/*/*.warmup" %> \out -> do
270+
let [_, _, ver, exampleName] = splitDirectories (dropExtension out)
271+
let exePath = build </> "binaries" </> ver </> executableName
272+
ghcPath = build </> "binaries" </> ver </> "ghc.path"
273+
need [exePath, ghcPath]
274+
buildSystem <- askOracle $ GetBuildSystem ()
275+
example <- fromMaybe (error $ "Unknown example " <> exampleName)
276+
<$> askOracle (GetExample exampleName)
277+
let exeExtraArgs = []
278+
outcsv = ""
279+
experiment = Escaped "hover"
280+
withResource benchResource 1 $ warmupProject buildSystem exePath
281+
[ EchoStdout False,
282+
FileStdout out,
283+
RemEnv "NIX_GHC_LIBDIR",
284+
RemEnv "GHC_PACKAGE_PATH",
285+
AddPath [takeDirectory ghcPath, "."] []
286+
]
287+
example
265288
-- run an experiment
266289
priority 0 $
267290
[ build -/- "*/*/*/*.csv",
268291
build -/- "*/*/*/*.gcStats.log",
269292
build -/- "*/*/*/*.output.log",
293+
build -/- "*/*/*/*.eventlog",
270294
build -/- "*/*/*/*.hp"
271-
] &%> \[outcsv, outGc, outLog, outHp] -> do
295+
] &%> \[outcsv, outGc, outLog, outEventlog, outHp] -> do
272296
let [_, flavour, exampleName, ver, exp] = splitDirectories outcsv
273297
prof = fromMaybe (error $ "Not a valid profiling mode: " <> flavour) $ profilingP flavour
274298
example <- fromMaybe (error $ "Unknown example " <> exampleName)
@@ -279,6 +303,7 @@ benchRules build MkBenchRules{..} = do
279303
let exePath = build </> "binaries" </> ver </> executableName
280304
exeExtraArgs =
281305
[ "+RTS"
306+
, "-l-au"
282307
, "-S" <> outGc]
283308
++ concat
284309
[[ "-h"
@@ -287,8 +312,9 @@ benchRules build MkBenchRules{..} = do
287312
| CheapHeapProfiling i <- [prof]]
288313
++ ["-RTS"]
289314
ghcPath = build </> "binaries" </> ver </> "ghc.path"
315+
warmupPath = build </> "binaries" </> ver </> exampleName <.> "warmup"
290316
experiment = Escaped $ dropExtension exp
291-
need [exePath, ghcPath]
317+
need [exePath, ghcPath, warmupPath]
292318
ghcPath <- readFile' ghcPath
293319
withResource benchResource 1 $ do
294320
benchProject setupRes buildSystem
@@ -299,6 +325,7 @@ benchRules build MkBenchRules{..} = do
299325
AddPath [takeDirectory ghcPath, "."] []
300326
]
301327
BenchProject {..}
328+
liftIO $ renameFile "ghcide.eventlog" outEventlog
302329
liftIO $ case prof of
303330
CheapHeapProfiling{} -> renameFile "ghcide.hp" outHp
304331
NoProfiling -> writeFile outHp dummyHp

0 commit comments

Comments
 (0)