Skip to content

Commit a862a64

Browse files
authored
db-analyser: add block size to --benchmark-ledger-ops and --show-block-header-size (#1241)
For example, the analysis in PR #1240 can be simplified via this PR.
2 parents 0dc2699 + 9d3c574 commit a862a64

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Patch
9+
10+
- A bullet item for the Patch category.
11+
12+
-->
13+
<!--
14+
### Non-Breaking
15+
16+
- A bullet item for the Non-Breaking category.
17+
18+
-->
19+
20+
### Breaking
21+
22+
- Added a `blockBytes` column to the output of --benchmark-ledger-ops and --show-header-size.

ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Analysis.hs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import Data.Int (Int64)
4141
import Data.List (intercalate)
4242
import qualified Data.Map.Strict as Map
4343
import Data.Singletons
44-
import Data.Word (Word16, Word64)
44+
import Data.Word (Word16, Word32, Word64)
4545
import qualified Debug.Trace as Debug
4646
import qualified GHC.Stats as GC
4747
import NoThunks.Class (noThunks)
@@ -182,11 +182,12 @@ data TraceEvent blk =
182182
| CountedBlocksEvent Int
183183
-- ^ triggered once during CountBLocks analysis,
184184
-- when blocks were counted
185-
| HeaderSizeEvent BlockNo SlotNo Word16
185+
| HeaderSizeEvent BlockNo SlotNo Word16 Word32
186186
-- ^ triggered when header size has been measured
187187
-- * block's number
188188
-- * slot number when the block was forged
189189
-- * block's header size
190+
-- * block's size
190191
| MaxHeaderSizeEvent Word16
191192
-- ^ triggered once during ShowBlockTxsSize analysis,
192193
-- holding maximum encountered header size
@@ -238,10 +239,11 @@ instance (HasAnalysis blk, LedgerSupportsProtocol blk) => Show (TraceEvent blk)
238239
, "Known: " <> show known
239240
]
240241
show (CountedBlocksEvent counted) = "Counted " <> show counted <> " blocks."
241-
show (HeaderSizeEvent bn sn headerSize) = intercalate "\t" $ [
242+
show (HeaderSizeEvent bn sn hSz bSz) = intercalate "\t" $ [
242243
show bn
243244
, show sn
244-
, "header size: " <> show headerSize
245+
, "header size: " <> show hSz
246+
, "block size: " <> show bSz
245247
]
246248
show (MaxHeaderSizeEvent size) =
247249
"Maximum encountered header size = " <> show size
@@ -312,15 +314,16 @@ countTxOutputs AnalysisEnv { db, registry, startFrom, limit, tracer } = do
312314
showHeaderSize :: forall blk. HasAnalysis blk => Analysis blk StartFromPoint
313315
showHeaderSize AnalysisEnv { db, registry, startFrom, limit, tracer } = do
314316
maxHeaderSize <-
315-
processAll db registry ((,) <$> GetHeader <*> GetHeaderSize) startFrom limit 0 process
317+
processAll db registry ((,,) <$> GetHeader <*> GetHeaderSize <*> GetBlockSize) startFrom limit 0 process
316318
traceWith tracer $ MaxHeaderSizeEvent maxHeaderSize
317319
pure $ Just $ ResultMaxHeaderSize maxHeaderSize
318320
where
319-
process :: Word16 -> (Header blk, Word16) -> IO Word16
320-
process maxHeaderSize (hdr, headerSize) = do
321+
process :: Word16 -> (Header blk, Word16, SizeInBytes) -> IO Word16
322+
process maxHeaderSize (hdr, headerSize, blockSize) = do
321323
let event = HeaderSizeEvent (blockNo hdr)
322324
(blockSlot hdr)
323325
headerSize
326+
(getSizeInBytes blockSize)
324327
traceWith tracer event
325328
return $ maxHeaderSize `max` headerSize
326329

@@ -548,7 +551,14 @@ benchmarkLedgerOps mOutfile ledgerAppMode AnalysisEnv {db, registry, startFrom,
548551
F.writeMetadata outFileHandle outFormat ledgerAppMode
549552
F.writeHeader outFileHandle outFormat
550553

551-
void $ processAll db registry GetBlock startFrom limit initLedger (process outFileHandle outFormat)
554+
void $ processAll
555+
db
556+
registry
557+
((,) <$> GetBlock <*> GetBlockSize)
558+
startFrom
559+
limit
560+
initLedger
561+
(process outFileHandle outFormat)
552562
pure Nothing
553563
where
554564
ccfg = topLevelConfigProtocol cfg
@@ -560,9 +570,9 @@ benchmarkLedgerOps mOutfile ledgerAppMode AnalysisEnv {db, registry, startFrom,
560570
IO.Handle
561571
-> F.OutputFormat
562572
-> ExtLedgerState blk
563-
-> blk
573+
-> (blk, SizeInBytes)
564574
-> IO (ExtLedgerState blk)
565-
process outFileHandle outFormat prevLedgerState blk = do
575+
process outFileHandle outFormat prevLedgerState (blk, sz) = do
566576
prevRtsStats <- GC.getRTSStats
567577
let
568578
-- Compute how many nanoseconds the mutator used from the last
@@ -604,6 +614,7 @@ benchmarkLedgerOps mOutfile ledgerAppMode AnalysisEnv {db, registry, startFrom,
604614
, DP.mut_headerApply = tHdrApp `div` 1000
605615
, DP.mut_blockTick = tBlkTick `div` 1000
606616
, DP.mut_blockApply = tBlkApp `div` 1000
617+
, DP.blockByteSize = getSizeInBytes sz
607618
, DP.blockStats = DP.BlockStats $ HasAnalysis.blockStats blk
608619
}
609620

ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Analysis/BenchmarkLedgerOps/FileWriting.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,6 @@ dataPointCsvBuilder =
112112
, ("mut_headerApply" , decimal . DP.mut_headerApply)
113113
, ("mut_blockTick" , decimal . DP.mut_blockTick)
114114
, ("mut_blockApply" , decimal . DP.mut_blockApply)
115+
, ("blockBytes" , decimal . DP.blockByteSize)
115116
, ("...era-specific stats" , Builder.intercalate csvSeparator . DP.unBlockStats . DP.blockStats)
116117
]

ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Analysis/BenchmarkLedgerOps/SlotDataPoint.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ data SlotDataPoint =
5555
, mut_headerApply :: !Int64
5656
, mut_blockTick :: !Int64
5757
, mut_blockApply :: !Int64
58+
, blockByteSize :: !Word32
5859
-- | Free-form information about the block.
5960
, blockStats :: !BlockStats
6061
} deriving (Generic, Show)

0 commit comments

Comments
 (0)