From 0634a3a5bd93c7d09b8c8c7332f48277a751658b Mon Sep 17 00:00:00 2001 From: EncodePanda Date: Thu, 7 Oct 2021 13:41:01 +0200 Subject: [PATCH] Add 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..1ca502b4b01 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 processed..." + counted <- processAll db registry GetBlock initLedger limit 0 process + putStrLn $ "Counted: " <> show counted + where + process :: Int -> blk -> IO Int + process count _blk = 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 ]