From f289c6d18ca55a10910f72da4fabb28586d69d70 Mon Sep 17 00:00:00 2001 From: EncodePanda Date: Thu, 7 Oct 2021 13:41:01 +0200 Subject: [PATCH] Add a new analysis --count-blocks --- .../tools/db-analyser/Analysis.hs | 14 ++++++++++++++ .../tools/db-analyser/Main.hs | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/ouroboros-consensus-cardano/tools/db-analyser/Analysis.hs b/ouroboros-consensus-cardano/tools/db-analyser/Analysis.hs index a96ac6746f8..75c4db76588 100644 --- a/ouroboros-consensus-cardano/tools/db-analyser/Analysis.hs +++ b/ouroboros-consensus-cardano/tools/db-analyser/Analysis.hs @@ -61,6 +61,7 @@ data AnalysisName = | ShowEBBs | OnlyValidation | StoreLedgerStateAt SlotNo + | CountBlocks deriving Show runAnalysis :: @@ -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 () @@ -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 -------------------------------------------------------------------------------} diff --git a/ouroboros-consensus-cardano/tools/db-analyser/Main.hs b/ouroboros-consensus-cardano/tools/db-analyser/Main.hs index 5c1bc38d6f2..e56d5145044 100644 --- a/ouroboros-consensus-cardano/tools/db-analyser/Main.hs +++ b/ouroboros-consensus-cardano/tools/db-analyser/Main.hs @@ -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 ]