Skip to content

Commit ffac5a9

Browse files
committed
cardano-node: MuxTrace forHuman with "formatting" lib
1 parent dd72950 commit ffac5a9

File tree

3 files changed

+100
-6
lines changed

3 files changed

+100
-6
lines changed

cardano-node/cardano-node.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ library
160160
, ekg
161161
, ekg-core
162162
, filepath
163+
, formatting
163164
, generic-data
164165
, hostname
165166
, io-classes >= 0.3

cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ import Ouroboros.Consensus.Util.Enclose
8383

8484
instance (LogFormatting adr, Show adr) => LogFormatting (ConnectionId adr) where
8585
forMachine _dtal (ConnectionId local' remote) =
86-
mconcat [ "connectionId" .= String (forHuman local'
86+
mconcat [ "connectionId" .= String (showT local'
8787
<> " "
88-
<> forHuman remote)
88+
<> showT remote)
8989
]
9090
forHuman (ConnectionId local' remote) =
91-
"ConnectionId " <> forHuman local' <> " " <> forHuman remote
91+
"ConnectionId " <> showT local' <> " " <> showT remote
9292

9393
--------------------------------------------------------------------------------
9494
-- TraceLabelCreds peer a

cardano-node/src/Cardano/Node/Tracing/Tracers/Diffusion.hs

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
{-# LANGUAGE FlexibleInstances #-}
55
{-# LANGUAGE GADTs #-}
66
{-# LANGUAGE NamedFieldPuns #-}
7+
{-# LANGUAGE OverloadedStrings #-}
78
{-# LANGUAGE ScopedTypeVariables #-}
89

910

11+
1012
{-# OPTIONS_GHC -Wno-orphans #-}
1113

1214
module Cardano.Node.Tracing.Tracers.Diffusion
1315
() where
1416

17+
1518
import Cardano.Logging
1619
import Data.Aeson (Value (String), (.=))
1720
import Data.Text (pack)
21+
import Formatting
1822
import Network.Mux (MuxTrace (..), WithMuxBearer (..))
1923
import Network.Mux.Types
2024
import Network.TypedProtocol.Codec (AnyMessageAndAgency (..))
@@ -65,7 +69,7 @@ instance LogFormatting MuxTrace where
6569
forMachine _dtal (MuxTraceRecvHeaderEnd MuxSDUHeader { mhTimestamp, mhNum, mhDir, mhLength }) = mconcat
6670
[ "kind" .= String "MuxTraceRecvHeaderStart"
6771
, "msg" .= String "Bearer Receive Header End"
68-
, "timestamp" .= String (showT (unRemoteClockModel mhTimestamp))
72+
, "timestamp" .= String (showTHex (unRemoteClockModel mhTimestamp))
6973
, "miniProtocolNum" .= String (showT mhNum)
7074
, "miniProtocolDir" .= String (showT mhDir)
7175
, "length" .= String (showT mhLength)
@@ -74,7 +78,7 @@ instance LogFormatting MuxTrace where
7478
[ "kind" .= String "MuxTraceRecvDeltaQObservation"
7579
, "msg" .= String "Bearer DeltaQ observation"
7680
, "timeRemote" .= String (showT ts)
77-
, "timeLocal" .= String (showT (unRemoteClockModel mhTimestamp))
81+
, "timeLocal" .= String (showTHex (unRemoteClockModel mhTimestamp))
7882
, "length" .= String (showT mhLength)
7983
]
8084
forMachine _dtal (MuxTraceRecvDeltaQSample d sp so dqs dqvm dqvs estR sdud) = mconcat
@@ -102,7 +106,7 @@ instance LogFormatting MuxTrace where
102106
forMachine _dtal (MuxTraceSendStart MuxSDUHeader { mhTimestamp, mhNum, mhDir, mhLength }) = mconcat
103107
[ "kind" .= String "MuxTraceSendStart"
104108
, "msg" .= String "Bearer Send Start"
105-
, "timestamp" .= String (showT (unRemoteClockModel mhTimestamp))
109+
, "timestamp" .= String (showTHex (unRemoteClockModel mhTimestamp))
106110
, "miniProtocolNum" .= String (showT mhNum)
107111
, "miniProtocolDir" .= String (showT mhDir)
108112
, "length" .= String (showT mhLength)
@@ -244,6 +248,87 @@ instance LogFormatting MuxTrace where
244248
]
245249
#endif
246250

251+
forHuman MuxTraceRecvHeaderStart =
252+
"Bearer Receive Header Start"
253+
forHuman (MuxTraceRecvHeaderEnd MuxSDUHeader { mhTimestamp, mhNum, mhDir, mhLength }) =
254+
sformat ("Bearer Receive Header End: ts:" % prefixHex % "(" % shown % ") " % shown % " len " % int)
255+
(unRemoteClockModel mhTimestamp) mhNum mhDir mhLength
256+
forHuman (MuxTraceRecvDeltaQObservation MuxSDUHeader { mhTimestamp, mhLength } ts) =
257+
sformat ("Bearer DeltaQ observation: remote ts" % int % " local ts " % shown % " length " % int)
258+
(unRemoteClockModel mhTimestamp) ts mhLength
259+
forHuman (MuxTraceRecvDeltaQSample d sp so dqs dqvm dqvs estR sdud) =
260+
sformat ("Bearer DeltaQ Sample: duration " % fixed 3 % " packets " % int % " sumBytes "
261+
% int % " DeltaQ_S " % fixed 3 % " DeltaQ_VMean " % fixed 3 % "DeltaQ_VVar " % fixed 3
262+
% " DeltaQ_estR " % fixed 3 % " sizeDist " % string)
263+
d sp so dqs dqvm dqvs estR sdud
264+
forHuman (MuxTraceRecvStart len) =
265+
sformat ("Bearer Receive Start: length " % int) len
266+
forHuman (MuxTraceRecvEnd len) =
267+
sformat ("Bearer Receive End: length " % int) len
268+
forHuman (MuxTraceSendStart MuxSDUHeader { mhTimestamp, mhNum, mhDir, mhLength }) =
269+
sformat ("Bearer Send Start: ts: " % prefixHex % " (" % shown % ") " % shown % " length " % int)
270+
(unRemoteClockModel mhTimestamp) mhNum mhDir mhLength
271+
forHuman MuxTraceSendEnd =
272+
"Bearer Send End"
273+
forHuman (MuxTraceState new) =
274+
sformat ("State: " % shown) new
275+
forHuman (MuxTraceCleanExit mid dir) =
276+
sformat ("Miniprotocol (" % shown % ") " % shown % " terminated cleanly")
277+
mid dir
278+
forHuman (MuxTraceExceptionExit mid dir e) =
279+
sformat ("Miniprotocol (" % shown % ") " % shown %
280+
" terminated with exception " % shown) mid dir e
281+
forHuman (MuxTraceChannelRecvStart mid) =
282+
sformat ("Channel Receive Start on " % shown) mid
283+
forHuman (MuxTraceChannelRecvEnd mid len) =
284+
sformat ("Channel Receive End on (" % shown % ") " % int) mid len
285+
forHuman (MuxTraceChannelSendStart mid len) =
286+
sformat ("Channel Send Start on (" % shown % ") " % int) mid len
287+
forHuman (MuxTraceChannelSendEnd mid) =
288+
sformat ("Channel Send End on " % shown) mid
289+
forHuman MuxTraceHandshakeStart =
290+
"Handshake start"
291+
forHuman (MuxTraceHandshakeClientEnd duration) =
292+
sformat ("Handshake Client end, duration " % shown) duration
293+
forHuman MuxTraceHandshakeServerEnd =
294+
"Handshake Server end"
295+
forHuman (MuxTraceHandshakeClientError e duration) =
296+
-- Client Error can include an error string from the peer which could be very large.
297+
sformat ("Handshake Client Error " % string % " duration " % shown)
298+
(take 256 $ show e) duration
299+
forHuman (MuxTraceHandshakeServerError e) =
300+
sformat ("Handshake Server Error " % shown) e
301+
forHuman MuxTraceSDUReadTimeoutException =
302+
"Timed out reading SDU"
303+
forHuman MuxTraceSDUWriteTimeoutException =
304+
"Timed out writing SDU"
305+
forHuman (MuxTraceStartEagerly mid dir) =
306+
sformat ("Eagerly started (" % shown % ") in " % shown) mid dir
307+
forHuman (MuxTraceStartOnDemand mid dir) =
308+
sformat ("Preparing to start (" % shown % ") in " % shown) mid dir
309+
forHuman (MuxTraceStartedOnDemand mid dir) =
310+
sformat ("Started on demand (" % shown % ") in " % shown) mid dir
311+
forHuman (MuxTraceTerminating mid dir) =
312+
sformat ("Terminating (" % shown % ") in " % shown) mid dir
313+
forHuman MuxTraceStopping = "Mux stopping"
314+
forHuman MuxTraceStopped = "Mux stoppped"
315+
#ifdef os_HOST_linux
316+
forHuman (MuxTraceTCPInfo StructTCPInfo
317+
{ tcpi_snd_mss, tcpi_rcv_mss, tcpi_lost, tcpi_retrans
318+
, tcpi_rtt, tcpi_rttvar, tcpi_snd_cwnd }
319+
len) =
320+
sformat ("TCPInfo rtt % int % " rttvar " % ínt % " cwnd " % int %
321+
" smss " % int % " rmss " % int % " lost " % int %
322+
" retrans " % int % " len " %int)
323+
(fromIntegral tcpi_rtt :: Word) (fromIntegral tcpi_rttvar :: Word)
324+
(fromIntegral tcpi_snd_cwnd :: Word) (fromIntegral tcpi_snd_mss :: Word)
325+
(fromIntegral tcpi_rcv_mss :: Word) (fromIntegral tcpi_lost :: Word)
326+
(fromIntegral tcpi_retrans :: Word)
327+
len
328+
#else
329+
forHuman (MuxTraceTCPInfo _ len) = sformat ("TCPInfo len " % int) len
330+
#endif
331+
247332
instance MetaTrace MuxTrace where
248333
namespaceFor MuxTraceRecvHeaderStart {} =
249334
Namespace [] ["RecvHeaderStart"]
@@ -331,6 +416,8 @@ instance MetaTrace MuxTrace where
331416
severityFor (Namespace _ ["StartedOnDemand"]) _ = Just Debug
332417
severityFor (Namespace _ ["Terminating"]) _ = Just Debug
333418
severityFor (Namespace _ ["Shutdown"]) _ = Just Debug
419+
severityFor (Namespace _ ["Stopping"]) _ = Just Debug
420+
severityFor (Namespace _ ["Stopped"]) _ = Just Debug
334421
severityFor (Namespace _ ["TCPInfo"]) _ = Just Debug
335422
severityFor _ _ = Nothing
336423
@@ -386,6 +473,10 @@ instance MetaTrace MuxTrace where
386473
"Started on demand."
387474
documentFor (Namespace _ ["Terminating"]) = Just
388475
"Terminating."
476+
documentFor (Namespace _ ["Stopping"]) = Just
477+
"Mux shutdown."
478+
documentFor (Namespace _ ["Stopped"]) = Just
479+
"Mux shutdown."
389480
documentFor (Namespace _ ["Shutdown"]) = Just
390481
"Mux shutdown."
391482
documentFor (Namespace _ ["TCPInfo"]) = Just
@@ -419,6 +510,8 @@ instance MetaTrace MuxTrace where
419510
, Namespace [] ["StartOnDemand"]
420511
, Namespace [] ["StartedOnDemand"]
421512
, Namespace [] ["Terminating"]
513+
, Namespace [] ["Stopping"]
514+
, Namespace [] ["Stopped"]
422515
, Namespace [] ["Shutdown"]
423516
, Namespace [] ["TCPInfo"]
424517
]

0 commit comments

Comments
 (0)