@@ -29,10 +29,13 @@ import qualified Ouroboros.Network.AnchoredFragment as AF
29
29
30
30
import Control.Concurrent (threadDelay )
31
31
import Control.Concurrent.Async (async )
32
+ import Control.Concurrent.STM.TVar (readTVar , registerDelay )
32
33
import Control.Monad.Class.MonadAsync (link )
33
- import Control.Monad.STM (atomically , retry )
34
+ import Control.Monad.STM (STM , atomically , check , retry )
34
35
import "contra-tracer" Control.Tracer (Tracer , traceWith )
35
36
import Data.Aeson (Value (Number , String ), toJSON , (.=) )
37
+ import Data.Text as Text
38
+ import GHC.Conc (unsafeIOToSTM )
36
39
37
40
startLedgerMetricsTracer
38
41
:: forall blk
@@ -65,14 +68,21 @@ startLedgerMetricsTracer tr everyNThSlot nodeKernelData = do
65
68
SNothing -> go i prevSlot
66
69
67
70
waitForDifferentSlot :: StrictMaybe SlotNo -> IO (StrictMaybe SlotNo )
68
- waitForDifferentSlot prev =
71
+ waitForDifferentSlot prev = do
69
72
mapNodeKernelDataIO (\ nk -> atomically $ do
70
73
mSlot <- getCurrentSlot (getBlockchainTime nk)
71
74
case mSlot of
72
- CurrentSlot s'
73
- | SJust s' /= prev -> return s'
74
- _ -> retry
75
- ) nodeKernelData
75
+ CurrentSlot s' | SJust s' /= prev -> return s'
76
+ _ -> do
77
+ delaySTM $ 5 * 1000 -- 5 milliseconds
78
+ retry
79
+ ) nodeKernelData
80
+
81
+ -- STM action that completes after a given delay (in microseconds)
82
+ delaySTM :: Int -> STM ()
83
+ delaySTM micros = do
84
+ tvar <- unsafeIOToSTM (registerDelay micros) -- gives you a TVar Bool
85
+ readTVar tvar >>= check
76
86
77
87
data LedgerMetrics =
78
88
LedgerMetrics {
@@ -151,16 +161,19 @@ instance MetaTrace LedgerMetrics where
151
161
severityFor _ _ = Nothing
152
162
153
163
metricsDocFor (Namespace _ [" LedgerMetrics" ]) =
154
- [ (" utxoSize" , " UTxO set size " )
155
- , (" delegMapSize" , " Delegation map size " )
156
- , (" drepCount" , " " )
157
- , (" drepMapSize" , " " )
164
+ [ (" utxoSize" , " Size of the current UTxO set (number of entries) " )
165
+ , (" delegMapSize" , " Size of the delegation map (number of delegators) " )
166
+ , (" drepCount" , " Number of active DReps (Delegated Representatives) " )
167
+ , (" drepMapSize" , " Size of the DRep map (number of stake keys mapped to DReps) " )
158
168
]
159
169
metricsDocFor _ = []
160
170
161
- documentFor (Namespace _ [" LedgerMetrics" ]) = Just $ mconcat
162
- [ " " -- TODO YUP
163
- ]
171
+ documentFor (Namespace _ [" LedgerMetrics" ]) = Just $ Text. unlines
172
+ [ " Periodic trace emitted every Nth slot, approximately 700 milliseconds after slot start."
173
+ , " It queries the current ledger state to report metrics such as UTxO size, delegation map size,"
174
+ , " and DRep participation. This trace helps monitor ledger growth and governance dynamics over time."
175
+ ]
176
+
164
177
165
178
documentFor _ = Nothing
166
179
0 commit comments