Skip to content

Commit b6a39b5

Browse files
committed
cardano-node: LedgerMetrics enhancement
1 parent 271977b commit b6a39b5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import qualified Ouroboros.Network.AnchoredFragment as AF
2929

3030
import Control.Concurrent (threadDelay)
3131
import Control.Concurrent.Async (async)
32+
import Control.Monad (when)
3233
import Control.Monad.Class.MonadAsync (link)
3334
import Control.Monad.STM (atomically, retry)
3435
import "contra-tracer" Control.Tracer (Tracer, traceWith)
@@ -57,16 +58,16 @@ startLedgerMetricsTracer tr everyNThSlot nodeKernelData = do
5758
go 1 SNothing
5859
where
5960
go :: Int -> StrictMaybe SlotNo -> IO ()
60-
go !i !prevSlot = do
61+
go !countdown !prevSlot = do
6162
!query <- waitForDifferentSlot prevSlot
6263
threadDelay $ 700 * 1000
6364
case query of
64-
SJust slot'
65-
| i `mod` everyNThSlot == 0 -> do
66-
traceLedgerMetrics nodeKernelData slot' tr
67-
go (i + 1) (SJust slot')
68-
| otherwise -> go (i + 1) (SJust slot')
69-
SNothing -> go i prevSlot
65+
SJust slot' -> do
66+
let nextCountdown = if countdown <= 1 then everyNThSlot else countdown - 1
67+
when (countdown == 1) $
68+
traceLedgerMetrics nodeKernelData slot' tr
69+
go nextCountdown (SJust slot')
70+
SNothing -> go countdown prevSlot
7071

7172
waitForDifferentSlot :: StrictMaybe SlotNo -> IO (StrictMaybe SlotNo)
7273
waitForDifferentSlot prev = do

0 commit comments

Comments
 (0)