1{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE TypeSynonymInstances #-}
3-- | Keeps the tracing API calls separate from the Tracer implementation,
4-- which allows us to avoid a nasty import cycle between tracing and
5-- the messaging primitives that rely on it, and also between the node
6-- controller (which requires access to the tracing related elements of
7-- our RemoteTable) and the Debug module, which requires @forkProcess@.
8-- This module is also used by the management agent, which relies on the
9-- tracing infrastructure's messaging fabric.
10module Control.Distributed.Process.Management.Internal.Trace.Primitives
11 ( -- * Sending Trace Data
15 -- * Configuring A Tracer
28 , withRegisteredTracer
31import Control.Applicative
32import Control.Distributed.Process.Internal.Primitives
38import Control.Distributed.Process.Management.Internal.Trace.Types
45import qualified Control.Distributed.Process.Management.Internal.Trace.Types as Tracer
56 , getCurrentTraceClient
58import Control.Distributed.Process.Internal.Types
62 , LocalNode(localEventBus)
66import Control.Distributed.Process.Serializable
67import Control.Monad.IO.Class (liftIO)
68import Control.Monad.Reader (ask)
70import qualified Data.Set as Set (fromList)
73--------------------------------------------------------------------------------
75--------------------------------------------------------------------------------
77-- | Converts a list of identifiers (that can be
78-- mapped to process ids), to a 'TraceSubject'.
79class Traceable a where
80 uod :: [a] -> TraceSubject
82instance Traceable ProcessId where
83 uod = TraceProcs . Set.fromList
85instance Traceable String where
86 uod = TraceNames . Set.fromList
88-- | Turn tracing for for a subset of trace targets.
89traceOnly :: Traceable a => [a] -> Maybe TraceSubject
92-- | Trace all targets.
93traceOn :: Maybe TraceSubject
94traceOn = Just TraceAll
97traceOff :: Maybe TraceSubject
100-- | Enable tracing to the supplied process.
101enableTraceAsync :: ProcessId -> Process ()
102enableTraceAsync pid = withLocalTracer $ \t -> liftIO $ Tracer.enableTrace t pid
104-- TODO: refactor _Sync versions of trace configuration functions...
106-- | Enable tracing to the supplied process and wait for a @TraceOk@
107-- response from the trace coordinator process.
108enableTrace :: ProcessId -> Process ()
110 withLocalTracerSync $ \t sp -> Tracer.enableTraceSync t sp pid
112-- | Disable the currently configured trace.
113disableTraceAsync :: Process ()
114disableTraceAsync = withLocalTracer $ \t -> liftIO $ Tracer.disableTrace t
116-- | Disable the currently configured trace and wait for a @TraceOk@
117-- response from the trace coordinator process.
118disableTrace :: Process ()
120 withLocalTracerSync $ \t sp -> Tracer.disableTraceSync t sp
122getTraceFlags :: Process TraceFlags
125 withLocalTracer $ \t -> liftIO $ Tracer.getTraceFlags t sp
128-- | Set the given flags for the current tracer.
129setTraceFlagsAsync :: TraceFlags -> Process ()
130setTraceFlagsAsync f = withLocalTracer $ \t -> liftIO $ Tracer.setTraceFlags t f
132-- | Set the given flags for the current tracer and wait for a @TraceOk@
133-- response from the trace coordinator process.
134setTraceFlags :: TraceFlags -> Process ()
136 withLocalTracerSync $ \t sp -> Tracer.setTraceFlagsSync t sp f
138-- | Send a log message to the internal tracing facility. If tracing is
139-- enabled, this will create a custom trace log event.
141traceLog :: String -> Process ()
142traceLog s = withLocalTracer $ \t -> liftIO $ Tracer.traceLog t s
144-- | Send a log message to the internal tracing facility, using the given
145-- list of printable 'TraceArg's interspersed with the preceding delimiter.
147traceLogFmt :: String -> [TraceArg] -> Process ()
148traceLogFmt d ls = withLocalTracer $ \t -> liftIO $ Tracer.traceLogFmt t d ls
150-- | Send an arbitrary 'Message' to the tracer process.
151traceMessage :: Serializable m => m -> Process ()
152traceMessage msg = withLocalTracer $ \t -> liftIO $ Tracer.traceMessage t msg
154withLocalTracer :: (MxEventBus -> Process ()) -> Process ()
155withLocalTracer act = do
156 node <- processNode <$> ask
157 act (localEventBus node)
159withLocalTracerSync :: (MxEventBus -> SendPort TraceOk -> IO ()) -> Process ()
160withLocalTracerSync act = do
162 withLocalTracer $ \t -> liftIO $ (act t sp)
163 TraceOk <- receiveChan rp
166withRegisteredTracer :: (ProcessId -> Process a) -> Process a
167withRegisteredTracer act = do
169 withLocalTracer $ \t -> liftIO $ Tracer.getCurrentTraceClient t sp
170 currentTracer <- receiveChan rp
171 case currentTracer of
172 Nothing -> do mTP <- whereis "tracer.initial"
173 -- NB: this should NOT ever happen, but forcing pattern matches
174 -- is not considered cool in later versions of MonadFail
177 Nothing -> die $ "System Invariant Violation: Tracer Process "
178 ++ "Name Not Found (whereis tracer.initial)"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list