@@ -99,7 +99,7 @@ import Control.Distributed.Process.Internal.Types
99 , LocalProcessId(..)
99 , LocalProcessId(..)
100 , ProcessId(..)
100 , ProcessId(..)
101 , LocalNode(..)
101 , LocalNode(..)
102− , Tracer
102+ , Tracer(InactiveTracer)
103 , LocalNodeState(..)
103 , LocalNodeState(..)
104 , LocalProcess(..)
104 , LocalProcess(..)
105 , LocalProcessState(..)
105 , LocalProcessState(..)
@@ -144,9 +144,9 @@ import Control.Distributed.Process.Internal.Types
144 , ImplicitReconnect(WithImplicitReconnect, NoImplicitReconnect)
144 , ImplicitReconnect(WithImplicitReconnect, NoImplicitReconnect)
146import Control.Distributed.Process.Internal.Trace
146import Control.Distributed.Process.Internal.Trace
147− ( trace
147+ ( TraceArg(..)
148 , traceFormat
148 , traceFormat
149− , defaultTracer
149+ , startTracing
150 , stopTracer
150 , stopTracer
152import Control.Distributed.Process.Serializable (Serializable)
152import Control.Distributed.Process.Serializable (Serializable)
@@ -200,18 +200,18 @@ createBareLocalNode endPoint rtable = do
200 , _localPidUnique = unq
200 , _localPidUnique = unq
201 , _localConnections = Map.empty
201 , _localConnections = Map.empty
203− tracer <- defaultTracer
204 ctrlChan <- newChan
203 ctrlChan <- newChan
205 let node = LocalNode { localNodeId = NodeId $ NT.address endPoint
204 let node = LocalNode { localNodeId = NodeId $ NT.address endPoint
206 , localEndPoint = endPoint
205 , localEndPoint = endPoint
207 , localState = state
206 , localState = state
208 , localCtrlChan = ctrlChan
207 , localCtrlChan = ctrlChan
209− , localTracer = tracer
208+ , localTracer = InactiveTracer
210 , remoteTable = rtable
209 , remoteTable = rtable
211+ tracedNode <- startTracing node
212− void . forkIO $ runNodeController node
212+ void . forkIO $ runNodeController tracedNode
213− void . forkIO $ handleIncomingMessages node
213+ void . forkIO $ handleIncomingMessages tracedNode
214− return node
214+ return tracedNode
216-- | Start and register the service processes on a node
216-- | Start and register the service processes on a node
217-- (for now, this is only the logger)
217-- (for now, this is only the logger)
@@ -225,6 +225,10 @@ startServiceProcesses node = do
225 [ match $ \((time, pid, string) ::(String, ProcessId, String)) -> do
225 [ match $ \((time, pid, string) ::(String, ProcessId, String)) -> do
226 liftIO . hPutStrLn stderr $ time ++ " " ++ show pid ++ ": " ++ string
226 liftIO . hPutStrLn stderr $ time ++ " " ++ show pid ++ ": " ++ string
228+ , match $ \((time, string) :: (String, String)) -> do
229+ -- this is a 'trace' message from the local node tracer
230+ liftIO . hPutStrLn stderr $ time ++ " [trace] " ++ string
228 , match $ \(ch :: SendPort ()) -> -- a shutdown request
232 , match $ \(ch :: SendPort ()) -> -- a shutdown request
229 sendChan ch ()
233 sendChan ch ()
@@ -431,15 +435,18 @@ handleIncomingMessages node = go initConnectionState
433 NT.ErrorEvent (NT.TransportError NT.EventEndPointFailed str) ->
437 NT.ErrorEvent (NT.TransportError NT.EventEndPointFailed str) ->
434− fail $ "Cloud Haskell fatal error: end point failed: " ++ str
438+ fatal $ "Cloud Haskell fatal error: end point failed: " ++ str
435 NT.ErrorEvent (NT.TransportError NT.EventTransportFailed str) ->
439 NT.ErrorEvent (NT.TransportError NT.EventTransportFailed str) ->
436− fail $ "Cloud Haskell fatal error: transport failed: " ++ str
440+ fatal $ "Cloud Haskell fatal error: transport failed: " ++ str
437 NT.EndPointClosed ->
441 NT.EndPointClosed ->
438− return ()
442+ stopTracer (localTracer node) >> return ()
439 NT.ReceivedMulticast _ _ ->
443 NT.ReceivedMulticast _ _ ->
440 -- If we received a multicast message, something went horribly wrong
444 -- If we received a multicast message, something went horribly wrong
441 -- and we just give up
445 -- and we just give up
442− fail "Cloud Haskell fatal error: received unexpected multicast"
446+ fatal "Cloud Haskell fatal error: received unexpected multicast"
448+ fatal :: String -> IO ()
449+ fatal msg = stopTracer (localTracer node) >> fail msg
444 invalidRequest :: NT.ConnectionId -> ConnectionState -> IO ()
451 invalidRequest :: NT.ConnectionId -> ConnectionState -> IO ()
445 invalidRequest cid st = do
452 invalidRequest cid st = do
@@ -447,7 +454,8 @@ handleIncomingMessages node = go initConnectionState
447 -- node. That is, we should report the remote node as having died, and we
454 -- node. That is, we should report the remote node as having died, and we
448 -- should close incoming connections (this requires a Transport layer
455 -- should close incoming connections (this requires a Transport layer
449 -- extension).
456 -- extension).
450− traceEventFmtIO node "" ["[network] invalid request: ", (show cid)]
457+ traceEventFmtIO node "" [(TraceStr "[network] invalid request: "),
451 go ( incomingAt cid ^= Nothing
459 go ( incomingAt cid ^= Nothing
@@ -510,21 +518,17 @@ traceNotifyDied node ident reason =
510 case reason of
518 case reason of
511 DiedNormal -> return ()
519 DiedNormal -> return ()
512 _ -> traceNcEventFmt node " "
520 _ -> traceNcEventFmt node " "
513− ["[node-controller]", (show ident), (show reason)]
521+ [(TraceStr "[node-controller]"),
515−traceNcEvent :: LocalNode -> String -> NC ()
516−traceNcEvent node msg = liftIO $ traceEventIO node msg
518−traceNcEventFmt :: LocalNode -> String -> [String] -> NC ()
525+traceNcEventFmt :: LocalNode -> String -> [TraceArg] -> NC ()
519traceNcEventFmt node fmt args =
526traceNcEventFmt node fmt args =
520 liftIO $ traceEventFmtIO node fmt args
527 liftIO $ traceEventFmtIO node fmt args
522−traceEventIO :: LocalNode -> String -> IO ()
523−traceEventIO node msg = withLocalTracer node $ \t -> trace t msg
525traceEventFmtIO :: LocalNode
529traceEventFmtIO :: LocalNode
526 -> String
530 -> String
527− -> [String]
531+ -> [TraceArg]
529traceEventFmtIO node fmt args =
533traceEventFmtIO node fmt args =
530 withLocalTracer node $ \t -> traceFormat t fmt args
534 withLocalTracer node $ \t -> traceFormat t fmt args