Skip to content

Commit f766e55

Browse files
authored
Restore Shake profiling (#621)
* restore a comment * Fix Shake profiling A Shake profile is generated as part of the Shake session restart * simplify message
1 parent c5143e5 commit f766e55

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

src/Development/IDE/Core/Shake.hs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ import Control.Monad.Extra
8686
import Data.Time
8787
import GHC.Generics
8888
import System.IO.Unsafe
89-
import Numeric.Extra
9089
import Language.Haskell.LSP.Types
9190
import Data.Foldable (traverse_)
9291

@@ -177,15 +176,6 @@ instance Eq Key where
177176
instance Hashable Key where
178177
hashWithSalt salt (Key key) = hashWithSalt salt (typeOf key, key)
179178

180-
-- | The result of an IDE operation. Warnings and errors are in the Diagnostic,
181-
-- and a value is in the Maybe. For operations that throw an error you
182-
-- expect a non-empty list of diagnostics, at least one of which is an error,
183-
-- and a Nothing. For operations that succeed you expect perhaps some warnings
184-
-- and a Just. For operations that depend on other failing operations you may
185-
-- get empty diagnostics and a Nothing, to indicate this phase throws no fresh
186-
-- errors but still failed.
187-
--
188-
189179
data Value v
190180
= Succeeded TextDocumentVersion v
191181
| Stale TextDocumentVersion v
@@ -260,15 +250,13 @@ data IdeState = IdeState
260250

261251

262252
-- This is debugging code that generates a series of profiles, if the Boolean is true
263-
shakeRunDatabaseProfile :: Maybe FilePath -> ShakeDatabase -> [Action a] -> IO ([a], Maybe FilePath)
264-
shakeRunDatabaseProfile mbProfileDir shakeDb acts = do
265-
(time, (res,_)) <- duration $ shakeRunDatabase shakeDb acts
266-
proFile <- for mbProfileDir $ \dir -> do
253+
shakeDatabaseProfile :: Maybe FilePath -> ShakeDatabase -> IO (Maybe FilePath)
254+
shakeDatabaseProfile mbProfileDir shakeDb =
255+
for mbProfileDir $ \dir -> do
267256
count <- modifyVar profileCounter $ \x -> let !y = x+1 in return (y,y)
268-
let file = "ide-" ++ profileStartTime ++ "-" ++ takeEnd 5 ("0000" ++ show count) ++ "-" ++ showDP 2 time <.> "html"
257+
let file = "ide-" ++ profileStartTime ++ "-" ++ takeEnd 5 ("0000" ++ show count) <.> "html"
269258
shakeProfileDatabase shakeDb $ dir </> file
270259
return (dir </> file)
271-
return (res, proFile)
272260

273261
{-# NOINLINE profileStartTime #-}
274262
profileStartTime :: String
@@ -429,7 +417,13 @@ shakeRestart it@IdeState{shakeExtras=ShakeExtras{logger}, ..} systemActs =
429417
shakeSession
430418
(\runner -> do
431419
(stopTime,queue) <- duration (cancelShakeSession runner)
432-
logDebug logger $ T.pack $ "Restarting build session (aborting the previous one took " ++ showDuration stopTime ++ ")"
420+
res <- shakeDatabaseProfile shakeProfileDir shakeDb
421+
let profile = case res of
422+
Just fp -> ", profile saved at " <> fp
423+
_ -> ""
424+
logDebug logger $ T.pack $
425+
"Restarting build session (aborting the previous one took " ++
426+
showDuration stopTime ++ profile ++ ")"
433427
return queue
434428
)
435429
-- It is crucial to be masked here, otherwise we can get killed
@@ -483,19 +477,13 @@ newSession IdeState{shakeExtras=ShakeExtras{..}, ..} systemActs userActs = do
483477
<* liftIO (cancel progressThread)
484478
]
485479
res <- try @SomeException
486-
(restore $ shakeRunDatabaseProfile shakeProfileDir shakeDb systemActs')
480+
(restore $ shakeRunDatabase shakeDb systemActs')
487481
let res' = case res of
488482
Left e -> "exception: " <> displayException e
489483
Right _ -> "completed"
490-
profile = case res of
491-
Right (_, Just fp) ->
492-
let link = case filePathToUri' $ toNormalizedFilePath' fp of
493-
NormalizedUri _ x -> x
494-
in ", profile saved at " <> T.unpack link
495-
_ -> ""
496484
-- Wrap up in a thread to avoid calling interruptible
497485
-- operations inside the masked section
498-
let wrapUp = logDebug logger $ T.pack $ "Finishing build session(" ++ res' ++ profile ++ ")"
486+
let wrapUp = logDebug logger $ T.pack $ "Finishing build session(" ++ res' ++ ")"
499487
return wrapUp
500488

501489
-- Do the work in a background thread

src/Development/IDE/Types/Diagnostics.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ import Data.Text.Prettyprint.Doc.Render.Terminal (Color(..), color)
3232

3333
import Development.IDE.Types.Location
3434

35+
36+
-- | The result of an IDE operation. Warnings and errors are in the Diagnostic,
37+
-- and a value is in the Maybe. For operations that throw an error you
38+
-- expect a non-empty list of diagnostics, at least one of which is an error,
39+
-- and a Nothing. For operations that succeed you expect perhaps some warnings
40+
-- and a Just. For operations that depend on other failing operations you may
41+
-- get empty diagnostics and a Nothing, to indicate this phase throws no fresh
42+
-- errors but still failed.
43+
--
3544
-- A rule on a file should only return diagnostics for that given file. It should
3645
-- not propagate diagnostic errors through multiple phases.
3746
type IdeResult v = ([FileDiagnostic], Maybe v)

0 commit comments

Comments
 (0)