Skip to content

Commit 91df537

Browse files
committed
trace interface regeneration events
1 parent 8b5a1e0 commit 91df537

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ import Data.Functor
102102
import qualified Data.HashMap.Strict as HashMap
103103
import Data.Tuple.Extra (dupe)
104104
import Data.Unique as Unique
105+
import Development.IDE.Core.Tracing (withTrace)
105106
import qualified Language.LSP.Server as LSP
106107
import qualified Language.LSP.Types as LSP
107108

@@ -899,7 +900,8 @@ loadHieFile ncu f = do
899900
-- Assumes file exists.
900901
-- Requires the 'HscEnv' to be set up with dependencies
901902
loadInterface
902-
:: MonadIO m => HscEnv
903+
:: (MonadIO m, MonadMask m)
904+
=> HscEnv
903905
-> ModSummary
904906
-> SourceModified
905907
-> Maybe LinkableType
@@ -939,7 +941,15 @@ loadInterface session ms sourceMod linkableNeeded regen = do
939941
hmi <- liftIO $ mkDetailsFromIface sessionWithMsDynFlags iface linkable
940942
return ([], Just $ mkHiFileResult ms hmi)
941943
else regen linkableNeeded
942-
(_reason, _) -> regen linkableNeeded
944+
(_reason, _) -> withTrace "regenerate interface" $ \setTag -> do
945+
setTag "Module" $ moduleNameString $ moduleName $ ms_mod ms
946+
setTag "Reason" $ showReason _reason
947+
regen linkableNeeded
948+
949+
showReason :: RecompileRequired -> String
950+
showReason UpToDate = "UpToDate"
951+
showReason MustCompile = "MustCompile"
952+
showReason (RecompBecause s) = s
943953

944954
mkDetailsFromIface :: HscEnv -> ModIface -> Maybe Linkable -> IO HomeModInfo
945955
mkDetailsFromIface session iface linkable = do

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Development.IDE.Core.Tracing
88
, getInstrumentCached
99
, otTracedProvider
1010
, otSetUri
11+
, withTrace
1112
)
1213
where
1314

@@ -19,7 +20,7 @@ import Control.Exception.Safe (SomeException, catch,
1920
generalBracket)
2021
import Control.Monad (forM_, forever, void, when,
2122
(>=>))
22-
import Control.Monad.Catch (ExitCase (..))
23+
import Control.Monad.Catch (ExitCase (..), MonadMask)
2324
import Control.Monad.Extra (whenJust)
2425
import Control.Monad.IO.Unlift
2526
import Control.Seq (r0, seqList, seqTuple2, using)
@@ -57,6 +58,15 @@ import OpenTelemetry.Eventlog (Instrument, SpanInFlight (..),
5758
mkValueObserver, observe,
5859
setTag, withSpan, withSpan_)
5960

61+
withTrace :: (MonadMask m, MonadIO m) =>
62+
String -> ((String -> String -> m ()) -> m a) -> m a
63+
withTrace name act
64+
| userTracingEnabled
65+
= withSpan (fromString name) $ \sp -> do
66+
let setSpan' k v = setTag sp (fromString k) (fromString v)
67+
act setSpan'
68+
| otherwise = act (\_ _ -> pure ())
69+
6070
-- | Trace a handler using OpenTelemetry. Adds various useful info into tags in the OpenTelemetry span.
6171
otTracedHandler
6272
:: MonadUnliftIO m

0 commit comments

Comments
 (0)