Skip to content

Commit

Permalink
Add a new analysis --count-blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
EncodePanda committed Oct 12, 2021
1 parent c834f35 commit f289c6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ouroboros-consensus-cardano/tools/db-analyser/Analysis.hs
Expand Up @@ -61,6 +61,7 @@ data AnalysisName =
| ShowEBBs
| OnlyValidation
| StoreLedgerStateAt SlotNo
| CountBlocks
deriving Show

runAnalysis ::
Expand All @@ -77,6 +78,7 @@ runAnalysis ShowBlockTxsSize = showBlockTxsSize
runAnalysis ShowEBBs = showEBBs
runAnalysis OnlyValidation = \_ -> return ()
runAnalysis (StoreLedgerStateAt slotNo) = storeLedgerStateAt slotNo
runAnalysis CountBlocks = countBlocks

type Analysis blk = AnalysisEnv blk -> IO ()

Expand Down Expand Up @@ -253,6 +255,18 @@ storeLedgerStateAt slotNo (AnalysisEnv { db, registry, initLedger, cfg, limit, l
(encodeDisk ccfg)
(encodeDisk ccfg)

countBlocks ::
forall blk .
( HasAnalysis blk
)
=> Analysis blk
countBlocks (AnalysisEnv { db, registry, initLedger, limit }) = do
putStrLn $ "About to count number of blocks ..."
counted <- processAll db registry (GetPure ()) initLedger limit 0 process
putStrLn $ "Counted: " <> show counted <> " blocks."
where
process :: Int -> () -> IO Int
process count _ = pure $ count + 1
{-------------------------------------------------------------------------------
Auxiliary: processing all blocks in the DB
-------------------------------------------------------------------------------}
Expand Down
4 changes: 4 additions & 0 deletions ouroboros-consensus-cardano/tools/db-analyser/Main.hs
Expand Up @@ -145,6 +145,10 @@ parseAnalysis = asum [
, help "Show all EBBs and their predecessors"
]
, storeLedgerParser
, flag' CountBlocks $ mconcat [
long "count-blocks"
, help "Count number of blocks processed"
]
, pure OnlyValidation
]

Expand Down

0 comments on commit f289c6d

Please sign in to comment.