Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new analysis --count-blocks #3418

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ouroboros-consensus-cardano/tools/db-analyser/Analysis.hs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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