Merge bitcoin/bitcoin#27673: log: don't log total disk read time in ConnectTip bench

bc862fad29 ConnectTip: don't log total disk read time in bench (Sjors Provoost)

Pull request description:

  The " Load block from disk" log introduced in #24216 incorrectly assumed `num_blocks_total` would be greater than 0. This is not guaranteed until the `ConnectBlock` call right below it.

  The total and average metric is not very useful because it does not distinguish between blocks read from disk and those loaded from memory. So rather than fixing the divide by zero issue, we just drop the metric.

  Fixes #27635

ACKs for top commit:
  MarcoFalke:
    lgtm ACK bc862fad29 🐓
  willcl-ark:
    tACK bc862fad29

Tree-SHA512: ff52ff8a8a93f1c82071ca84c57ce5839e14271943393deac0aa5555d63383708777ed96e7226be6dd71b63ed07dc27bad1634ee848e88e4d0b95d511a8267e7
This commit is contained in:
fanquake 2023-05-30 10:33:45 +01:00
commit f467b28ac3
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -2760,7 +2760,6 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
return true; return true;
} }
static SteadyClock::duration time_read_from_disk_total{};
static SteadyClock::duration time_connect_total{}; static SteadyClock::duration time_connect_total{};
static SteadyClock::duration time_flush{}; static SteadyClock::duration time_flush{};
static SteadyClock::duration time_chainstate{}; static SteadyClock::duration time_chainstate{};
@ -2834,12 +2833,11 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew,
const CBlock& blockConnecting = *pthisBlock; const CBlock& blockConnecting = *pthisBlock;
// Apply the block atomically to the chain state. // Apply the block atomically to the chain state.
const auto time_2{SteadyClock::now()}; const auto time_2{SteadyClock::now()};
time_read_from_disk_total += time_2 - time_1;
SteadyClock::time_point time_3; SteadyClock::time_point time_3;
LogPrint(BCLog::BENCH, " - Load block from disk: %.2fms [%.2fs (%.2fms/blk)]\n", // When adding aggregate statistics in the future, keep in mind that
Ticks<MillisecondsDouble>(time_2 - time_1), // num_blocks_total may be zero until the ConnectBlock() call below.
Ticks<SecondsDouble>(time_read_from_disk_total), LogPrint(BCLog::BENCH, " - Load block from disk: %.2fms\n",
Ticks<MillisecondsDouble>(time_read_from_disk_total) / num_blocks_total); Ticks<MillisecondsDouble>(time_2 - time_1));
{ {
CCoinsViewCache view(&CoinsTip()); CCoinsViewCache view(&CoinsTip());
bool rv = ConnectBlock(blockConnecting, state, pindexNew, view); bool rv = ConnectBlock(blockConnecting, state, pindexNew, view);