Skip to content

Commit 2e0f6cd

Browse files
authored
GHCIDE_BUILD_PROFILING env var (#2125)
* GHCIDE_BUILD_PROFILING * profile before shutdown * mention env var in --help
1 parent 9048623 commit 2e0f6cd

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

ghcide/exe/Arguments.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ arguments :: IdePlugins IdeState -> Parser Arguments
3131
arguments plugins = Arguments
3232
<$> optional (strOption $ long "cwd" <> metavar "DIR" <> help "Change to this directory")
3333
<*> switch (long "version" <> help "Show ghcide and GHC versions")
34-
<*> optional (strOption $ long "shake-profiling" <> metavar "DIR" <> help "Dump profiling reports to this directory")
34+
<*> optional (strOption $ long "shake-profiling" <> metavar "DIR" <> help "Dump profiling reports to this directory (env var: GHCIDE_BUILD_PROFILING)")
3535
<*> switch (long "ot-memory-profiling" <> help "Record OpenTelemetry info to the eventlog. Needs the -l RTS flag to have an effect")
3636
<*> switch (long "test" <> help "Enable additional lsp messages used by the testsuite")
3737
<*> switch (long "test-no-kick" <> help "Disable kick. Useful for testing cancellation")

ghcide/src/Development/IDE/Core/Service.hs

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ module Development.IDE.Core.Service(
1212
getIdeOptions, getIdeOptionsIO,
1313
IdeState, initialise, shutdown,
1414
runAction,
15-
writeProfile,
1615
getDiagnostics,
1716
ideLogger,
1817
updatePositionMapping,
1918
) where
2019

20+
import Control.Applicative ((<|>))
2121
import Development.IDE.Core.Debouncer
2222
import Development.IDE.Core.FileExists (fileExistsRules)
2323
import Development.IDE.Core.OfInterest
@@ -30,6 +30,7 @@ import qualified Language.LSP.Types as LSP
3030

3131
import Control.Monad
3232
import Development.IDE.Core.Shake
33+
import System.Environment (lookupEnv)
3334

3435

3536
------------------------------------------------------------
@@ -46,13 +47,17 @@ initialise :: Config
4647
-> HieDb
4748
-> IndexQueue
4849
-> IO IdeState
49-
initialise defaultConfig mainRule lspEnv logger debouncer options vfs hiedb hiedbChan =
50+
initialise defaultConfig mainRule lspEnv logger debouncer options vfs hiedb hiedbChan = do
51+
shakeProfiling <- do
52+
let fromConf = optShakeProfiling options
53+
fromEnv <- lookupEnv "GHCIDE_BUILD_PROFILING"
54+
return $ fromConf <|> fromEnv
5055
shakeOpen
5156
lspEnv
5257
defaultConfig
5358
logger
5459
debouncer
55-
(optShakeProfiling options)
60+
shakeProfiling
5661
(optReportProgress options)
5762
(optTesting options)
5863
hiedb
@@ -65,9 +70,6 @@ initialise defaultConfig mainRule lspEnv logger debouncer options vfs hiedb hied
6570
fileExistsRules lspEnv vfs
6671
mainRule
6772

68-
writeProfile :: IdeState -> FilePath -> IO ()
69-
writeProfile = shakeProfile
70-
7173
-- | Shutdown the Compiler Service.
7274
shutdown :: IdeState -> IO ()
7375
shutdown = shakeShut

ghcide/src/Development/IDE/Core/Shake.hs

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ module Development.IDE.Core.Shake(
3131
GetModificationTime(GetModificationTime, GetModificationTime_, missingFileDiagnostics),
3232
shakeOpen, shakeShut,
3333
shakeEnqueue,
34-
shakeProfile,
3534
newSession,
3635
use, useNoFile, uses, useWithStaleFast, useWithStaleFast', delayedAction,
3736
FastResult(..),
@@ -550,14 +549,12 @@ shakeSessionInit IdeState{..} = do
550549
initSession <- newSession shakeExtras shakeDb []
551550
putMVar shakeSession initSession
552551

553-
shakeProfile :: IdeState -> FilePath -> IO ()
554-
shakeProfile IdeState{..} = shakeProfileDatabase shakeDb
555-
556552
shakeShut :: IdeState -> IO ()
557553
shakeShut IdeState{..} = withMVar shakeSession $ \runner -> do
558554
-- Shake gets unhappy if you try to close when there is a running
559555
-- request so we first abort that.
560556
void $ cancelShakeSession runner
557+
void $ shakeDatabaseProfile shakeDb
561558
shakeClose
562559
progressStop $ progress shakeExtras
563560

0 commit comments

Comments
 (0)