Skip to content

Commit 1f19001

Browse files
authored
Merge pull request IntersectMBO#5403 from input-output-hk/jutaro/benchmark-new
Optimize new tracing
2 parents a29ee68 + 093f4b3 commit 1f19001

File tree

38 files changed

+752
-691
lines changed

38 files changed

+752
-691
lines changed

bench/locli/src/Cardano/Unlog/LogObject.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ where
3131
import Cardano.Prelude hiding (Text, show)
3232
import Prelude (id, show, unzip3)
3333

34-
import Control.Monad (fail)
3534
import qualified Data.Aeson as AE
3635
import qualified Data.Aeson.Key as Aeson
3736
import qualified Data.Aeson.KeyMap as KeyMap
@@ -480,7 +479,7 @@ instance FromJSON LogObject where
480479
case (kind, wrapped, unwrapped) of
481480
(Nothing, Just _, Just x) -> (,) <$> pure x <*> (fromText <$> x .: "kind")
482481
(Just kind0, _, _) -> pure (v, kind0)
483-
_ -> fail $ "Unexpected LogObject .data: " <> show v
482+
_ -> pure (v, "")
484483

485484
parsePartialResourceStates :: Value -> Parser (Resources Word64)
486485
parsePartialResourceStates =

cardano-node/cardano-node.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ common project-config
3838
-Wpartial-fields
3939
-Wredundant-constraints
4040
-Wunused-packages
41-
4241
common maybe-Win32
4342
if os(windows)
4443
build-depends: Win32

cardano-node/src/Cardano/Node/Configuration/Logging.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ createLoggingLayer ver nodeConfig' p = do
289289
>>= maybe (pure ())
290290
(traceResourceStats
291291
(appendName "node" tr))
292-
Conc.threadDelay 1000000 -- TODO: make configurable
292+
Conc.threadDelay 1000000 -- microseconds = 1 sec
293293

294294
traceResourceStats :: Trace IO Text -> ResourceStats -> IO ()
295295
traceResourceStats tr rs = do

cardano-node/src/Cardano/Node/Handlers/Shutdown.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module Cardano.Node.Handlers.Shutdown
2727
where
2828

2929
import Control.Concurrent.Async (race_)
30+
import Control.DeepSeq (NFData)
3031
import Control.Exception (try)
3132
import Control.Exception.Base (throwIO)
3233
import Control.Monad (void, when)
@@ -59,6 +60,8 @@ data ShutdownOn
5960

6061
deriving instance FromJSON ShutdownOn
6162
deriving instance ToJSON ShutdownOn
63+
deriving instance NFData ShutdownOn
64+
6265

6366
parseShutdownOn :: Opt.Parser ShutdownOn
6467
parseShutdownOn = asum
@@ -90,6 +93,8 @@ data ShutdownTrace
9093
-- ^ Will terminate upon reaching a ChainDB sync limit
9194
deriving (Generic, FromJSON, ToJSON)
9295

96+
deriving instance NFData ShutdownTrace
97+
9398
data AndWithOrigin
9499
= AndWithOriginBlock (BlockNo, WithOrigin BlockNo)
95100
| AndWithOriginSlot (SlotNo, WithOrigin SlotNo)

cardano-node/src/Cardano/Node/Startup.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
{-# LANGUAGE FlexibleContexts #-}
44
{-# LANGUAGE GADTs #-}
55
{-# LANGUAGE MultiParamTypeClasses #-}
6+
{-# LANGUAGE StandaloneDeriving #-}
67
{-# LANGUAGE TypeApplications #-}
78
{-# LANGUAGE UndecidableInstances #-}
89

910
module Cardano.Node.Startup where
1011

1112
import qualified Cardano.Api as Api
13+
import Control.DeepSeq (NFData)
1214
import Prelude
1315

1416
import Data.Aeson (FromJSON, ToJSON)
@@ -181,6 +183,8 @@ data NodeInfo = NodeInfo
181183
, niSystemStartTime :: UTCTime
182184
} deriving (Eq, Generic, ToJSON, FromJSON, Show)
183185

186+
deriving instance (NFData NodeInfo)
187+
184188
instance MetaTrace NodeInfo where
185189
namespaceFor NodeInfo {} =
186190
Namespace [] ["NodeInfo"]
@@ -265,6 +269,8 @@ data NodeStartupInfo = NodeStartupInfo {
265269
, suiSlotsPerKESPeriod :: Word64
266270
} deriving (Eq, Generic, ToJSON, FromJSON, Show)
267271

272+
deriving instance (NFData NodeStartupInfo)
273+
268274
instance MetaTrace NodeStartupInfo where
269275
namespaceFor NodeStartupInfo {} =
270276
Namespace [] ["NodeStartupInfo"]
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{-# LANGUAGE ConstraintKinds #-}
22
{-# LANGUAGE FlexibleContexts #-}
3+
{-# LANGUAGE FlexibleInstances #-}
34
{-# LANGUAGE PackageImports #-}
5+
6+
47
module Cardano.Node.Tracing
58
( Tracers (..)
69
, ConsensusStartupException (..)
@@ -9,7 +12,7 @@ module Cardano.Node.Tracing
912
import Prelude (IO)
1013

1114
import Codec.CBOR.Read (DeserialiseFailure)
12-
import "contra-tracer" Control.Tracer (Tracer)
15+
import "contra-tracer" Control.Tracer (Tracer (..))
1316

1417
import qualified Ouroboros.Consensus.Network.NodeToClient as NodeToClient
1518
import qualified Ouroboros.Consensus.Network.NodeToNode as NodeToNode
@@ -21,7 +24,7 @@ import Ouroboros.Network.NodeToClient (LocalAddress, NodeToClientVersi
2124
import Ouroboros.Network.NodeToNode (NodeToNodeVersion, RemoteAddress)
2225

2326
import Cardano.Node.Handlers.Shutdown (ShutdownTrace)
24-
import Cardano.Node.Startup (NodeInfo, NodeStartupInfo, StartupTrace)
27+
import Cardano.Node.Startup (NodeInfo, NodeStartupInfo, StartupTrace (..))
2528

2629
import Cardano.Logging.Resources
2730
import Cardano.Node.Tracing.StateRep (NodeState)
@@ -31,25 +34,25 @@ import Cardano.Node.Tracing.Tracers.Peer (PeerT)
3134

3235
data Tracers peer localPeer blk p2p = Tracers
3336
{ -- | Trace the ChainDB
34-
chainDBTracer :: Tracer IO (ChainDB.TraceEvent blk)
37+
chainDBTracer :: !(Tracer IO (ChainDB.TraceEvent blk))
3538
-- | Consensus-specific tracers.
36-
, consensusTracers :: Consensus.Tracers IO peer localPeer blk
39+
, consensusTracers :: !(Consensus.Tracers IO peer localPeer blk)
3740
-- | Tracers for the node-to-node protocols.
38-
, nodeToNodeTracers :: NodeToNode.Tracers IO peer blk DeserialiseFailure
41+
, nodeToNodeTracers :: !(NodeToNode.Tracers IO peer blk DeserialiseFailure)
3942
--, serialisedBlockTracer :: NodeToNode.SerialisedTracer IO peer blk (SerialisedBlockTrace)
4043
-- | Tracers for the node-to-client protocols
41-
, nodeToClientTracers :: NodeToClient.Tracers IO localPeer blk DeserialiseFailure
44+
, nodeToClientTracers :: !(NodeToClient.Tracers IO localPeer blk DeserialiseFailure)
4245
-- | Diffusion tracers
43-
, diffusionTracers :: Diffusion.Tracers RemoteAddress NodeToNodeVersion
46+
, diffusionTracers :: !(Diffusion.Tracers RemoteAddress NodeToNodeVersion
4447
LocalAddress NodeToClientVersion
45-
IO
46-
, diffusionTracersExtra :: Diffusion.ExtraTracers p2p
47-
48-
, startupTracer :: Tracer IO (StartupTrace blk)
49-
, shutdownTracer :: Tracer IO ShutdownTrace
50-
, nodeInfoTracer :: Tracer IO NodeInfo
51-
, nodeStartupInfoTracer :: Tracer IO NodeStartupInfo
52-
, nodeStateTracer :: Tracer IO NodeState
53-
, resourcesTracer :: Tracer IO ResourceStats
54-
, peersTracer :: Tracer IO [PeerT blk]
48+
IO)
49+
, diffusionTracersExtra :: !(Diffusion.ExtraTracers p2p)
50+
51+
, startupTracer :: !(Tracer IO (StartupTrace blk))
52+
, shutdownTracer :: !(Tracer IO ShutdownTrace)
53+
, nodeInfoTracer :: !(Tracer IO NodeInfo)
54+
, nodeStartupInfoTracer :: !(Tracer IO NodeStartupInfo)
55+
, nodeStateTracer :: !(Tracer IO NodeState)
56+
, resourcesTracer :: !(Tracer IO ResourceStats)
57+
, peersTracer :: !(Tracer IO [PeerT blk])
5558
}

cardano-node/src/Cardano/Node/Tracing/DefaultTraceConfig.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defaultCardanoConfig :: TraceConfig
1212
defaultCardanoConfig = emptyTraceConfig {
1313
tcOptions = Map.fromList
1414
[([],
15-
[ ConfSeverity (SeverityF Nothing) -- Means Silence
15+
[ ConfSeverity (SeverityF (Just Notice)) -- Means Silence
1616
, ConfDetail DNormal
1717
, ConfBackend [Stdout MachineFormat
1818
, EKGBackend

cardano-node/src/Cardano/Node/Tracing/Peers.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DeriveAnyClass #-}
12
{-# LANGUAGE DeriveGeneric #-}
23
{-# LANGUAGE StandaloneDeriving #-}
34

@@ -6,6 +7,7 @@ module Cardano.Node.Tracing.Peers
67
, traceNodePeers
78
) where
89

10+
import Control.DeepSeq (NFData)
911
import Data.Aeson (FromJSON, ToJSON)
1012
import Data.Text (Text)
1113
import GHC.Generics (Generic)
@@ -21,10 +23,12 @@ type PeerInfoPP = Text -- The result of 'ppPeer' function.
2123
newtype NodePeers = NodePeers [PeerInfoPP]
2224

2325
deriving instance Generic NodePeers
26+
deriving instance NFData NodePeers
2427

2528
instance ToJSON NodePeers
2629
instance FromJSON NodePeers
2730

31+
2832
instance MetaTrace NodePeers where
2933
namespaceFor NodePeers {} =
3034
Namespace [] ["NodePeers"]

cardano-node/src/Cardano/Node/Tracing/StateRep.hs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{-# LANGUAGE FlexibleInstances #-}
44
{-# LANGUAGE GADTs #-}
55
{-# LANGUAGE LambdaCase #-}
6+
{-# LANGUAGE StandaloneDeriving #-}
67

78
{-# OPTIONS_GHC -Wno-orphans #-}
89

@@ -22,6 +23,7 @@ import Cardano.Api (textShow)
2223

2324
import Cardano.Logging
2425

26+
import Control.DeepSeq (NFData)
2527
import Data.Aeson
2628
import Data.Text (Text)
2729
import Data.Time.Clock
@@ -41,9 +43,17 @@ import qualified Cardano.Node.Startup as Startup
4143
import Cardano.Slotting.Slot (EpochNo, SlotNo (..), WithOrigin)
4244
import Cardano.Tracing.OrphanInstances.Network ()
4345

44-
instance FromJSON ChunkNo
46+
deriving instance FromJSON ChunkNo
4547

46-
instance ToJSON ChunkNo
48+
deriving instance ToJSON ChunkNo
49+
50+
deriving instance NFData ChunkNo
51+
52+
deriving instance Generic NPV.NodeToNodeVersion
53+
deriving instance NFData NPV.NodeToNodeVersion
54+
55+
deriving instance Generic NPV.NodeToClientVersion
56+
deriving instance NFData NPV.NodeToClientVersion
4757

4858
data OpeningDbs
4959
= StartedOpeningImmutableDB
@@ -54,23 +64,31 @@ data OpeningDbs
5464
| OpenedLgrDB
5565
deriving (Generic, FromJSON, ToJSON)
5666

67+
deriving instance (NFData OpeningDbs)
68+
5769
data Replays
5870
= ReplayFromGenesis (WithOrigin SlotNo)
5971
| ReplayFromSnapshot SlotNo (WithOrigin SlotNo) (WithOrigin SlotNo)
6072
| ReplayedBlock SlotNo (WithOrigin SlotNo) (WithOrigin SlotNo)
6173
deriving (Generic, FromJSON, ToJSON)
6274

75+
deriving instance (NFData Replays)
76+
6377
data InitChainSelection
6478
= InitChainStartedSelection
6579
| InitChainSelected
6680
deriving (Generic, FromJSON, ToJSON)
6781

82+
deriving instance (NFData InitChainSelection)
83+
6884
type SyncPercentage = Double
6985

7086
data AddedToCurrentChain
7187
= AddedToCurrentChain !EpochNo !SlotNo !SyncPercentage
7288
deriving (Generic, FromJSON, ToJSON)
7389

90+
deriving instance (NFData AddedToCurrentChain)
91+
7492
data StartupState
7593
= StartupSocketConfigError Text
7694
| StartupDBValidation
@@ -81,6 +99,8 @@ data StartupState
8199
| WarningDevelopmentNodeToClientVersions [NPV.NodeToClientVersion]
82100
deriving (Generic, FromJSON, ToJSON)
83101

102+
deriving instance (NFData StartupState)
103+
84104
-- | The representation of the current state of node.
85105
-- All node states prior to tracing system going online are effectively invisible.
86106
data NodeState
@@ -94,22 +114,24 @@ data NodeState
94114
| NodeShutdown ShutdownTrace
95115
deriving (Generic, FromJSON, ToJSON)
96116

117+
deriving instance (NFData NodeState)
118+
97119
instance LogFormatting NodeState where
98120
forMachine _ = \case
99121
NodeOpeningDbs x -> mconcat
100-
["openingDb" .= toJSON x]
122+
[ "kind" .= String "NodeOpeningDbs", "openingDb" .= toJSON x]
101123
NodeReplays x -> mconcat
102-
["replays" .= toJSON x]
124+
[ "kind" .= String "NodeReplays", "replays" .= toJSON x]
103125
NodeInitChainSelection x -> mconcat
104-
["chainSel" .= toJSON x]
126+
[ "kind" .= String "NodeInitChainSelection", "chainSel" .= toJSON x]
105127
NodeKernelOnline -> mconcat
106-
[]
128+
[ "kind" .= String "NodeInitChainSelection"]
107129
NodeAddBlock x -> mconcat
108-
["addBlock" .= toJSON x]
130+
[ "kind" .= String "NodeAddBlock", "addBlock" .= toJSON x]
109131
NodeStartup x -> mconcat
110-
["startup" .= toJSON x]
132+
[ "kind" .= String "NodeStartup", "startup" .= toJSON x]
111133
NodeShutdown x -> mconcat
112-
["shutdown" .= toJSON x]
134+
[ "kind" .= String "NodeShutdown", "shutdown" .= toJSON x]
113135
_ -> mempty
114136

115137
instance MetaTrace NodeState where

0 commit comments

Comments
 (0)