@@ -148,6 +148,7 @@ import GHC.Fingerprint
148
148
import Language.LSP.Types.Capabilities
149
149
import OpenTelemetry.Eventlog
150
150
151
+ import Control.Concurrent.STM.Stats (atomicallyNamed )
151
152
import Control.Exception.Extra hiding (bracket_ )
152
153
import Data.Aeson (toJSON )
153
154
import qualified Data.ByteString.Char8 as BS8
@@ -340,7 +341,7 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
340
341
f <- MaybeT $ pure $ HMap. lookup (Key k) pmap
341
342
(dv,del,ver) <- MaybeT $ runIdeAction " lastValueIO" s $ f file
342
343
MaybeT $ pure $ (,del,ver) <$> fromDynamic dv
343
- atomically $ case mv of
344
+ atomicallyNamed " lastValueIO " $ case mv of
344
345
Nothing -> do
345
346
STM. focus (Focus. alter (alterValue $ Failed True )) (toKey k file) state
346
347
return Nothing
@@ -356,13 +357,13 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
356
357
-- Something already succeeded before, leave it alone
357
358
_ -> old
358
359
359
- atomically (STM. lookup (toKey k file) state) >>= \ case
360
+ atomicallyNamed " lastValueIO 4 " (STM. lookup (toKey k file) state) >>= \ case
360
361
Nothing -> readPersistent
361
362
Just (ValueWithDiagnostics v _) -> case v of
362
363
Succeeded ver (fromDynamic -> Just v) ->
363
- atomically $ Just . (v,) <$> mappingForVersion positionMapping file ver
364
+ atomicallyNamed " lastValueIO 5 " $ Just . (v,) <$> mappingForVersion positionMapping file ver
364
365
Stale del ver (fromDynamic -> Just v) ->
365
- atomically $ Just . (v,) . maybe id addDelta del <$> mappingForVersion positionMapping file ver
366
+ atomicallyNamed " lastValueIO 6 " $ Just . (v,) . maybe id addDelta del <$> mappingForVersion positionMapping file ver
366
367
Failed p | not p -> readPersistent
367
368
_ -> pure Nothing
368
369
@@ -439,7 +440,7 @@ deleteValue
439
440
-> k
440
441
-> NormalizedFilePath
441
442
-> STM ()
442
- deleteValue ShakeExtras {dirtyKeys, state} key file = do
443
+ deleteValue ShakeExtras {dirtyKeys, state} key file = atomicallyNamed " deleteValue " $ do
443
444
STM. delete (toKey key file) state
444
445
modifyTVar' dirtyKeys $ HSet. insert (toKey key file)
445
446
@@ -454,7 +455,6 @@ recordDirtyKeys ShakeExtras{dirtyKeys} key file = do
454
455
return $ withEventTrace " recordDirtyKeys" $ \ addEvent -> do
455
456
addEvent (fromString $ " dirty " <> show key) (fromString $ unlines $ map fromNormalizedFilePath file)
456
457
457
-
458
458
-- | We return Nothing if the rule has not run and Just Failed if it has failed to produce a value.
459
459
getValues ::
460
460
forall k v .
@@ -627,8 +627,8 @@ shakeRestart IdeState{..} reason acts =
627
627
(\ runner -> do
628
628
(stopTime,() ) <- duration (cancelShakeSession runner)
629
629
res <- shakeDatabaseProfile shakeDb
630
- backlog <- readTVarIO ( dirtyKeys shakeExtras)
631
- queue <- atomically $ peekInProgress $ actionQueue shakeExtras
630
+ backlog <- readTVarIO $ dirtyKeys shakeExtras
631
+ queue <- atomicallyNamed " actionQueue - peek " $ peekInProgress $ actionQueue shakeExtras
632
632
let profile = case res of
633
633
Just fp -> " , profile saved at " <> fp
634
634
_ -> " "
@@ -661,7 +661,7 @@ notifyTestingLogMessage extras msg = do
661
661
shakeEnqueue :: ShakeExtras -> DelayedAction a -> IO (IO a )
662
662
shakeEnqueue ShakeExtras {actionQueue, logger} act = do
663
663
(b, dai) <- instantiateDelayedAction act
664
- atomically $ pushQueue dai actionQueue
664
+ atomicallyNamed " actionQueue - push " $ pushQueue dai actionQueue
665
665
let wait' b =
666
666
waitBarrier b `catches`
667
667
[ Handler (\ BlockedIndefinitelyOnMVar ->
@@ -670,7 +670,7 @@ shakeEnqueue ShakeExtras{actionQueue, logger} act = do
670
670
, Handler (\ e@ AsyncCancelled -> do
671
671
logPriority logger Debug $ T. pack $ actionName act <> " was cancelled"
672
672
673
- atomically $ abortQueue dai actionQueue
673
+ atomicallyNamed " actionQueue - abort " $ abortQueue dai actionQueue
674
674
throw e)
675
675
]
676
676
return (wait' b >>= either throwIO return )
@@ -685,7 +685,7 @@ newSession
685
685
-> IO ShakeSession
686
686
newSession extras@ ShakeExtras {.. } shakeDb acts reason = do
687
687
IdeOptions {optRunSubset} <- getIdeOptionsIO extras
688
- reenqueued <- atomically $ peekInProgress actionQueue
688
+ reenqueued <- atomicallyNamed " actionQueue - peek " $ peekInProgress actionQueue
689
689
allPendingKeys <-
690
690
if optRunSubset
691
691
then Just <$> readTVarIO dirtyKeys
@@ -694,14 +694,14 @@ newSession extras@ShakeExtras{..} shakeDb acts reason = do
694
694
-- A daemon-like action used to inject additional work
695
695
-- Runs actions from the work queue sequentially
696
696
pumpActionThread otSpan = do
697
- d <- liftIO $ atomically $ popQueue actionQueue
697
+ d <- liftIO $ atomicallyNamed " action queue - pop " $ popQueue actionQueue
698
698
actionFork (run otSpan d) $ \ _ -> pumpActionThread otSpan
699
699
700
700
-- TODO figure out how to thread the otSpan into defineEarlyCutoff
701
701
run _otSpan d = do
702
702
start <- liftIO offsetTime
703
703
getAction d
704
- liftIO $ atomically $ doneQueue d actionQueue
704
+ liftIO $ atomicallyNamed " actionQueue - done " $ doneQueue d actionQueue
705
705
runTime <- liftIO start
706
706
let msg = T. pack $ " finish: " ++ actionName d
707
707
++ " (took " ++ showDuration runTime ++ " )"
@@ -804,7 +804,7 @@ garbageCollectKeys label maxAge checkParents agedKeys = do
804
804
| age > maxAge
805
805
, Just (kt,_) <- fromKeyType k
806
806
, not (kt `HSet.member` preservedKeys checkParents)
807
- = atomically $ do
807
+ = atomicallyNamed " GC " $ do
808
808
gotIt <- STM. focus (Focus. member <* Focus. delete) k values
809
809
when gotIt $
810
810
modifyTVar' dk (HSet. insert k)
@@ -908,7 +908,7 @@ useWithStaleFast' key file = do
908
908
wait <- delayedAction $ mkDelayedAction (" C:" ++ show key ++ " :" ++ fromNormalizedFilePath file) Debug $ use key file
909
909
910
910
s@ ShakeExtras {state} <- askShake
911
- r <- liftIO $ atomically $ getValues state key file
911
+ r <- liftIO $ atomicallyNamed " useStateFast " $ getValues state key file
912
912
liftIO $ case r of
913
913
-- block for the result if we haven't computed before
914
914
Nothing -> do
@@ -1017,7 +1017,7 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
1017
1017
(if optSkipProgress options key then id else inProgress progress file) $ do
1018
1018
val <- case old of
1019
1019
Just old | mode == RunDependenciesSame -> do
1020
- v <- liftIO $ atomically $ getValues state key file
1020
+ v <- liftIO $ atomicallyNamed " defineEarlyCutoff - read 1 " $ getValues state key file
1021
1021
case v of
1022
1022
-- No changes in the dependencies and we have
1023
1023
-- an existing successful result.
@@ -1036,10 +1036,10 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
1036
1036
(do v <- action; liftIO $ evaluate $ force v) $
1037
1037
\ (e :: SomeException ) -> do
1038
1038
pure (Nothing , ([ideErrorText file $ T. pack $ show e | not $ isBadDependency e],Nothing ))
1039
- modTime <- liftIO $ (currentValue . fst =<< ) <$> atomically (getValues state GetModificationTime file)
1039
+ modTime <- liftIO $ (currentValue . fst =<< ) <$> atomicallyNamed " defineEarlyCutoff - read 2 " (getValues state GetModificationTime file)
1040
1040
(bs, res) <- case res of
1041
1041
Nothing -> do
1042
- staleV <- liftIO $ atomically $ getValues state key file
1042
+ staleV <- liftIO $ atomicallyNamed " defineEarlyCutoff -read 3 " $ getValues state key file
1043
1043
pure $ case staleV of
1044
1044
Nothing -> (toShakeValue ShakeResult bs, Failed False )
1045
1045
Just v -> case v of
@@ -1050,7 +1050,7 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
1050
1050
(Failed b, _) ->
1051
1051
(toShakeValue ShakeResult bs, Failed b)
1052
1052
Just v -> pure (maybe ShakeNoCutoff ShakeResult bs, Succeeded (vfsVersion =<< modTime) v)
1053
- liftIO $ atomically $ setValues state key file res (Vector. fromList diags)
1053
+ liftIO $ atomicallyNamed " defineEarlyCutoff - write " $ setValues state key file res (Vector. fromList diags)
1054
1054
doDiagnostics diags
1055
1055
let eq = case (bs, fmap decodeShakeValue old) of
1056
1056
(ShakeResult a, Just (ShakeResult b)) -> cmp a b
@@ -1062,7 +1062,7 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
1062
1062
(if eq then ChangedRecomputeSame else ChangedRecomputeDiff )
1063
1063
(encodeShakeValue bs) $
1064
1064
A res
1065
- liftIO $ atomically $ modifyTVar' dirtyKeys (HSet. delete $ toKey key file)
1065
+ liftIO $ atomicallyNamed " defineEarlyCutoff - dirtyKeys " $ modifyTVar' dirtyKeys (HSet. delete $ toKey key file)
1066
1066
return res
1067
1067
1068
1068
traceA :: A v -> String
@@ -1150,7 +1150,7 @@ updateFileDiagnostics :: MonadIO m
1150
1150
-> [(ShowDiagnostic ,Diagnostic )] -- ^ current results
1151
1151
-> m ()
1152
1152
updateFileDiagnostics fp k ShakeExtras {logger, diagnostics, hiddenDiagnostics, publishedDiagnostics, state, debouncer, lspEnv} current = liftIO $ do
1153
- modTime <- (currentValue . fst =<< ) <$> atomically (getValues state GetModificationTime fp)
1153
+ modTime <- (currentValue . fst =<< ) <$> atomicallyNamed " diagnostics - read " (getValues state GetModificationTime fp)
1154
1154
let (currentShown, currentHidden) = partition ((== ShowDiag ) . fst ) current
1155
1155
uri = filePathToUri' fp
1156
1156
ver = vfsVersion =<< modTime
@@ -1160,13 +1160,13 @@ updateFileDiagnostics fp k ShakeExtras{logger, diagnostics, hiddenDiagnostics, p
1160
1160
-- published. Otherwise, we might never publish certain diagnostics if
1161
1161
-- an exception strikes between modifyVar but before
1162
1162
-- publishDiagnosticsNotification.
1163
- newDiags <- liftIO $ atomically $ update (map snd currentShown) diagnostics
1164
- _ <- liftIO $ atomically $ update (map snd currentHidden) hiddenDiagnostics
1163
+ newDiags <- liftIO $ atomicallyNamed " diagnostics - update " $ update (map snd currentShown) diagnostics
1164
+ _ <- liftIO $ atomicallyNamed " diagnostics - hidden " $ update (map snd currentHidden) hiddenDiagnostics
1165
1165
let uri = filePathToUri' fp
1166
1166
let delay = if null newDiags then 0.1 else 0
1167
1167
registerEvent debouncer delay uri $ do
1168
1168
join $ mask_ $ do
1169
- lastPublish <- atomically $ STM. focus (Focus. lookupWithDefault [] <* Focus. insert newDiags) uri publishedDiagnostics
1169
+ lastPublish <- atomicallyNamed " diagnostics - publish " $ STM. focus (Focus. lookupWithDefault [] <* Focus. insert newDiags) uri publishedDiagnostics
1170
1170
let action = when (lastPublish /= newDiags) $ case lspEnv of
1171
1171
Nothing -> -- Print an LSP event.
1172
1172
logInfo logger $ showDiagnosticsColored $ map (fp,ShowDiag ,) newDiags
0 commit comments