@@ -117,7 +117,6 @@ import qualified Development.Shake as Shake
117
117
import Control.Monad.Extra
118
118
import Data.Time
119
119
import GHC.Generics
120
- import System.IO.Unsafe
121
120
import Language.LSP.Types
122
121
import qualified Control.Monad.STM as STM
123
122
import Control.Monad.IO.Class
@@ -371,29 +370,24 @@ data IdeState = IdeState
371
370
,shakeSession :: MVar ShakeSession
372
371
,shakeClose :: IO ()
373
372
,shakeExtras :: ShakeExtras
374
- ,shakeProfileDir :: Maybe FilePath
373
+ ,shakeDatabaseProfile :: ShakeDatabase -> IO ( Maybe FilePath )
375
374
,stopProgressReporting :: IO ()
376
375
}
377
376
378
377
379
378
380
379
-- This is debugging code that generates a series of profiles, if the Boolean is true
381
- shakeDatabaseProfile :: Maybe FilePath -> ShakeDatabase -> IO (Maybe FilePath )
382
- shakeDatabaseProfile mbProfileDir shakeDb =
380
+ shakeDatabaseProfileIO :: Maybe FilePath -> IO (ShakeDatabase -> IO (Maybe FilePath ))
381
+ shakeDatabaseProfileIO mbProfileDir = do
382
+ profileStartTime <- formatTime defaultTimeLocale " %Y%m%d-%H%M%S" <$> getCurrentTime
383
+ profileCounter <- newVar (0 :: Int )
384
+ return $ \ shakeDb ->
383
385
for mbProfileDir $ \ dir -> do
384
386
count <- modifyVar profileCounter $ \ x -> let ! y = x+ 1 in return (y,y)
385
387
let file = " ide-" ++ profileStartTime ++ " -" ++ takeEnd 5 (" 0000" ++ show count) <.> " html"
386
388
shakeProfileDatabase shakeDb $ dir </> file
387
389
return (dir </> file)
388
390
389
- {-# NOINLINE profileStartTime #-}
390
- profileStartTime :: String
391
- profileStartTime = unsafePerformIO $ formatTime defaultTimeLocale " %Y%m%d-%H%M%S" <$> getCurrentTime
392
-
393
- {-# NOINLINE profileCounter #-}
394
- profileCounter :: Var Int
395
- profileCounter = unsafePerformIO $ newVar 0
396
-
397
391
setValues :: IdeRule k v
398
392
=> Var Values
399
393
-> k
@@ -502,6 +496,7 @@ shakeOpen lspEnv logger debouncer
502
496
shakeDb <- shakeDbM
503
497
initSession <- newSession shakeExtras shakeDb []
504
498
shakeSession <- newMVar initSession
499
+ shakeDatabaseProfile <- shakeDatabaseProfileIO shakeProfileDir
505
500
let ideState = IdeState {.. }
506
501
507
502
IdeOptions { optOTMemoryProfiling = IdeOTMemoryProfiling otProfilingEnabled } <- getIdeOptionsIO shakeExtras
@@ -628,7 +623,7 @@ shakeRestart IdeState{..} acts =
628
623
shakeSession
629
624
(\ runner -> do
630
625
(stopTime,() ) <- duration (cancelShakeSession runner)
631
- res <- shakeDatabaseProfile shakeProfileDir shakeDb
626
+ res <- shakeDatabaseProfile shakeDb
632
627
let profile = case res of
633
628
Just fp -> " , profile saved at " <> fp
634
629
_ -> " "
0 commit comments