17
17
--
18
18
-- [Enabling Tracing]
19
19
--
20
- -- Tracing is disabled by default, because it carries a relatively small, but
21
- -- tangible cost. To enable tracing, the environment variable
22
- -- @DISTRIBUTED_PROCESS_TRACE_ENABLED@ must be set to some value (actual content
23
- -- is ignored). When the environment variable /is/ set, the system will
24
- -- generate /trace events/ in various circumstances - see 'TraceEvent' for a
25
- -- list of all the published events. A user can additionally publish custom
26
- -- trace events in the form of 'TraceEvLog' log messages or pass custom
27
- -- (i.e., completely user defined) event data using the 'traceMessage' function.
28
- -- If the environment variable is not set, no trace events will ever be
29
- -- published.
20
+ -- Throughout the lifecycle of a local node, the distributed-process runtime
21
+ -- generates /trace events/, describing internal runtime activities such as
22
+ -- the spawning and death of processes, message sending, delivery and so on.
23
+ -- See the 'MxEvent' type's documentation for a list of all the published
24
+ -- event types, which correspond directly to the types of 'Management' event.
25
+ -- Users can additionally publish custom trace events in the form of
26
+ -- 'MxLog' log messages or pass custom (i.e., completely user defined)
27
+ -- event data using the 'traceMessage' function.
30
28
--
31
29
-- All published traces are forwarded to a /tracer process/, which can be
32
30
-- specified (and changed) at runtime using 'traceEnable'. Some pre-defined
37
35
--
38
36
-- [Working with multiple tracer processes]
39
37
--
40
- -- The system tracing facility only ever writes to a single tracer process. This
38
+ -- The tracing facility only ever writes to a single tracer process. This
41
39
-- invariant insulates the tracer controller and ensures a fast path for
42
40
-- handling all trace events. /This/ module provides facilities for layering
43
41
-- trace handlers using Cloud Haskell's built-in delegation primitives.
44
42
--
45
43
-- The 'startTracer' function wraps the registered @tracer@ process with the
46
- -- supplied handler and also forwarding trace events to the original tracer.
44
+ -- supplied handler and also forwards trace events to the original tracer.
47
45
-- The corresponding 'stopTracer' function terminates tracer processes in
48
- -- reverse of the order in which they were started, and re-establishes the
46
+ -- reverse of the order in which they were started, and re-registers the
49
47
-- previous tracer process.
50
48
--
51
49
-- [Built in tracers]
52
50
--
53
51
-- The built in tracers provide a simple /logging/ facility that writes trace
54
52
-- events out to either a log file, @stderr@ or the GHC eventlog. These tracers
55
53
-- can be configured using environment variables, or specified manually using
56
- -- the 'traceEnable' function. The base tracer process cannot be
54
+ -- the 'traceEnable' function.
57
55
--
58
56
-- When a new local node is started, the contents of several environment
59
- -- variables are checked to determine how the default tracer process
60
- -- will handle trace events. If none of these variables is set, then the
61
- -- trace events will be effectively ignored, although they will still be
62
- -- generated and passed through the system. Only one configuration will be
63
- -- chosen - the first that contains a (valid) value. These environment
64
- -- variables, in the order they're checked , are:
57
+ -- variables are checked to determine which default tracer process is selected.
58
+ -- If none of these variables is set, a no-op tracer process is installed,
59
+ -- which effectively ignores all trace messages. Note that in this case,
60
+ -- trace events are still generated and passed through the system.
61
+ -- Only one default tracer will be chosen - the first that contains a (valid)
62
+ -- value. These environment variables, in the order they're examined , are:
65
63
--
66
64
-- 1. @DISTRIBUTED_PROCESS_TRACE_FILE@
67
65
-- This is checked for a valid file path. If it exists and the file can be
68
66
-- opened for writing, all trace output will be directed thence. If the supplied
69
- -- path is invalid, or the file is unavailable for writing - e.g., because
70
- -- another node has already started tracing to it - then this tracer will be
71
- -- disabled.
67
+ -- path is invalid, or the file is unavailable for writing, this tracer will not
68
+ -- be selected.
72
69
--
73
70
-- 2. @DISTRIBUTED_PROCESS_TRACE_CONSOLE@
74
71
-- This is checked for /any/ non-empty value. If set, then all trace output will
81
78
-- Users of the /simplelocalnet/ Cloud Haskell backend should also note that
82
79
-- because the trace file option only supports trace output from a single node
83
80
-- (so as to avoid interleaving), a file trace configured for the master node
84
- -- will prevent slaves from tracing to the file and will need to fall back to
85
- -- the console or eventlog tracers instead.
81
+ -- will prevent slaves from tracing to the file. They will need to fall back to
82
+ -- the console or eventlog tracers instead, which can be accomplished by setting
83
+ -- one of these environment variables /as well/, since the latter will only be
84
+ -- selected on slaves (when the file tracer selection fails).
86
85
--
87
86
-- Support for writing to the eventlog requires specific intervention to work,
88
87
-- without which, written traces are silently dropped/ignored and no output will
93
92
module Control.Distributed.Process.Debug
94
93
( -- * Exported Data Types
95
94
TraceArg (.. )
96
- , TraceEvent (.. )
97
95
, TraceFlags (.. )
98
96
, TraceSubject (.. )
99
97
-- * Configuring Tracing
100
- , isTracingEnabled
101
98
, enableTrace
102
99
, enableTraceAsync
103
100
, disableTrace
@@ -147,35 +144,36 @@ import Control.Distributed.Process.Internal.Types
147
144
, LocalProcess (.. )
148
145
, ProcessMonitorNotification (.. )
149
146
)
150
- import Control.Distributed.Process.Internal.Trace.Types
147
+ import Control.Distributed.Process.Management.Types
148
+ ( MxEvent (.. )
149
+ )
150
+ import Control.Distributed.Process.Management.Trace.Types
151
151
( TraceArg (.. )
152
- , TraceEvent (.. )
153
152
, TraceFlags (.. )
154
153
, TraceSubject (.. )
155
154
, defaultTraceFlags
156
155
)
157
- import Control.Distributed.Process.Internal .Trace.Tracer
156
+ import Control.Distributed.Process.Management .Trace.Tracer
158
157
( systemLoggerTracer
159
158
, logfileTracer
160
159
, eventLogTracer
161
160
)
162
- import Control.Distributed.Process.Internal .Trace.Primitives
161
+ import Control.Distributed.Process.Management .Trace.Primitives
163
162
( withRegisteredTracer
164
163
, enableTrace
165
164
, enableTraceAsync
166
165
, disableTrace
167
166
, setTraceFlags
168
167
, setTraceFlagsAsync
169
168
, getTraceFlags
170
- , isTracingEnabled
171
169
, traceOn
172
170
, traceOff
173
171
, traceOnly
174
172
, traceLog
175
173
, traceLogFmt
176
174
, traceMessage
177
175
)
178
- import qualified Control.Distributed.Process.Internal .Trace.Remote as Remote
176
+ import qualified Control.Distributed.Process.Management .Trace.Remote as Remote
179
177
import Control.Distributed.Process.Node
180
178
181
179
import Control.Exception (SomeException )
@@ -200,7 +198,7 @@ import Prelude hiding (catch)
200
198
-- through all the layers in turn. Once the top layer is stopped, the user
201
199
-- is responsible for re-registering the original (prior) tracer pid before
202
200
-- terminating. See 'withTracer' for a mechanism that handles that.
203
- startTracer :: (TraceEvent -> Process () ) -> Process ProcessId
201
+ startTracer :: (MxEvent -> Process () ) -> Process ProcessId
204
202
startTracer handler = do
205
203
withRegisteredTracer $ \ pid -> do
206
204
node <- processNode <$> ask
@@ -212,7 +210,7 @@ startTracer handler = do
212
210
-- disable tracing thereafter, before giving the result (or exception
213
211
-- in case of failure).
214
212
withTracer :: forall a .
215
- (TraceEvent -> Process () )
213
+ (MxEvent -> Process () )
216
214
-> Process a
217
215
-> Process (Either SomeException a )
218
216
withTracer handler proc = do
@@ -227,7 +225,7 @@ withTracer handler proc = do
227
225
Nothing -> return ()
228
226
Just _ -> do
229
227
ref <- monitor tracer
230
- send tracer TraceEvDisable
228
+ send tracer MxTraceDisable
231
229
receiveWait [
232
230
matchIf (\ (ProcessMonitorNotification ref' _ _) -> ref == ref')
233
231
(\ _ -> return () )
@@ -244,12 +242,12 @@ withFlags flags proc = do
244
242
finally (setTraceFlags flags >> try proc )
245
243
(setTraceFlags oldFlags)
246
244
247
- traceProxy :: ProcessId -> (TraceEvent -> Process () ) -> Process ()
245
+ traceProxy :: ProcessId -> (MxEvent -> Process () ) -> Process ()
248
246
traceProxy pid act = do
249
- proxy pid $ \ (ev :: TraceEvent ) ->
247
+ proxy pid $ \ (ev :: MxEvent ) ->
250
248
case ev of
251
- (TraceEvTakeover _) -> return False
252
- TraceEvDisable -> die " disabled"
249
+ (MxTraceTakeover _) -> return False
250
+ MxTraceDisable -> die " disabled"
253
251
_ -> act ev >> return True
254
252
255
253
-- | Stops a user supplied tracer started with 'startTracer'.
@@ -264,8 +262,7 @@ traceProxy pid act = do
264
262
-- supplied tracers (i.e., processes started via 'startTracer') have exited,
265
263
-- subsequent calls to this function will have no effect.
266
264
--
267
- -- If tracing support is disabled for the node, this function will also
268
- -- have no effect. If the last tracer to have been registered was not started
265
+ -- If the last tracer to have been registered was not started
269
266
-- with 'startTracer' then the behaviour of this function is /undefined/.
270
267
stopTracer :: Process ()
271
268
stopTracer =
@@ -276,5 +273,5 @@ stopTracer =
276
273
basePid <- whereis " tracer.initial"
277
274
case basePid == (Just pid) of
278
275
True -> return ()
279
- False -> send pid TraceEvDisable
276
+ False -> send pid MxTraceDisable
280
277
0 commit comments