Skip to content

Commit 5f850b0

Browse files
committed
[bench] Include ms/blk stats in Connect* benchmarks.
1 parent 18ba984 commit 5f850b0

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/validation.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,7 @@ static int64_t nTimeConnect = 0;
14921492
static int64_t nTimeIndex = 0;
14931493
static int64_t nTimeCallbacks = 0;
14941494
static int64_t nTimeTotal = 0;
1495+
static int64_t nBlocksTotal = 0;
14951496

14961497
/** Apply the effects of this block (with given index) on the UTXO set represented by coins.
14971498
* Validity checks that depend on the UTXO set are also done; ConnectBlock()
@@ -1522,6 +1523,8 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
15221523
return true;
15231524
}
15241525

1526+
nBlocksTotal++;
1527+
15251528
bool fScriptChecks = true;
15261529
if (!hashAssumeValid.IsNull()) {
15271530
// We've been configured with the hash of a block which has been externally verified to have a valid history.
@@ -1549,7 +1552,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
15491552
}
15501553

15511554
int64_t nTime1 = GetTimeMicros(); nTimeCheck += nTime1 - nTimeStart;
1552-
LogPrint(BCLog::BENCH, " - Sanity checks: %.2fms [%.2fs]\n", 0.001 * (nTime1 - nTimeStart), nTimeCheck * 0.000001);
1555+
LogPrint(BCLog::BENCH, " - Sanity checks: %.2fms [%.2fs (%.2fms/blk)]\n", 0.001 * (nTime1 - nTimeStart), nTimeCheck * 0.000001, nTimeCheck * 0.001 / nBlocksTotal);
15531556

15541557
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
15551558
// unless those are already completely spent.
@@ -1616,7 +1619,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
16161619
}
16171620

16181621
int64_t nTime2 = GetTimeMicros(); nTimeForks += nTime2 - nTime1;
1619-
LogPrint(BCLog::BENCH, " - Fork checks: %.2fms [%.2fs]\n", 0.001 * (nTime2 - nTime1), nTimeForks * 0.000001);
1622+
LogPrint(BCLog::BENCH, " - Fork checks: %.2fms [%.2fs (%.2fms/blk)]\n", 0.001 * (nTime2 - nTime1), nTimeForks * 0.000001, nTimeForks * 0.001 / nBlocksTotal);
16201623

16211624
CBlockUndo blockundo;
16221625

@@ -1690,7 +1693,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
16901693
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
16911694
}
16921695
int64_t nTime3 = GetTimeMicros(); nTimeConnect += nTime3 - nTime2;
1693-
LogPrint(BCLog::BENCH, " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime3 - nTime2), 0.001 * (nTime3 - nTime2) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime3 - nTime2) / (nInputs-1), nTimeConnect * 0.000001);
1696+
LogPrint(BCLog::BENCH, " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs (%.2fms/blk)]\n", (unsigned)block.vtx.size(), 0.001 * (nTime3 - nTime2), 0.001 * (nTime3 - nTime2) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime3 - nTime2) / (nInputs-1), nTimeConnect * 0.000001, nTimeConnect * 0.001 / nBlocksTotal);
16941697

16951698
CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus());
16961699
if (block.vtx[0]->GetValueOut() > blockReward)
@@ -1702,7 +1705,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
17021705
if (!control.Wait())
17031706
return state.DoS(100, error("%s: CheckQueue failed", __func__), REJECT_INVALID, "block-validation-failed");
17041707
int64_t nTime4 = GetTimeMicros(); nTimeVerify += nTime4 - nTime2;
1705-
LogPrint(BCLog::BENCH, " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs]\n", nInputs - 1, 0.001 * (nTime4 - nTime2), nInputs <= 1 ? 0 : 0.001 * (nTime4 - nTime2) / (nInputs-1), nTimeVerify * 0.000001);
1708+
LogPrint(BCLog::BENCH, " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs (%.2fms/blk)]\n", nInputs - 1, 0.001 * (nTime4 - nTime2), nInputs <= 1 ? 0 : 0.001 * (nTime4 - nTime2) / (nInputs-1), nTimeVerify * 0.000001, nTimeVerify * 0.001 / nBlocksTotal);
17061709

17071710
if (fJustCheck)
17081711
return true;
@@ -1734,10 +1737,10 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
17341737
view.SetBestBlock(pindex->GetBlockHash());
17351738

17361739
int64_t nTime5 = GetTimeMicros(); nTimeIndex += nTime5 - nTime4;
1737-
LogPrint(BCLog::BENCH, " - Index writing: %.2fms [%.2fs]\n", 0.001 * (nTime5 - nTime4), nTimeIndex * 0.000001);
1740+
LogPrint(BCLog::BENCH, " - Index writing: %.2fms [%.2fs (%.2fms/blk)]\n", 0.001 * (nTime5 - nTime4), nTimeIndex * 0.000001, nTimeIndex * 0.001 / nBlocksTotal);
17381741

17391742
int64_t nTime6 = GetTimeMicros(); nTimeCallbacks += nTime6 - nTime5;
1740-
LogPrint(BCLog::BENCH, " - Callbacks: %.2fms [%.2fs]\n", 0.001 * (nTime6 - nTime5), nTimeCallbacks * 0.000001);
1743+
LogPrint(BCLog::BENCH, " - Callbacks: %.2fms [%.2fs (%.2fms/blk)]\n", 0.001 * (nTime6 - nTime5), nTimeCallbacks * 0.000001, nTimeCallbacks * 0.001 / nBlocksTotal);
17411744

17421745
return true;
17431746
}
@@ -2088,26 +2091,26 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
20882091
return error("ConnectTip(): ConnectBlock %s failed", pindexNew->GetBlockHash().ToString());
20892092
}
20902093
nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2;
2091-
LogPrint(BCLog::BENCH, " - Connect total: %.2fms [%.2fs]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001);
2094+
LogPrint(BCLog::BENCH, " - Connect total: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001, nTimeConnectTotal * 0.001 / nBlocksTotal);
20922095
bool flushed = view.Flush();
20932096
assert(flushed);
20942097
}
20952098
int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3;
2096-
LogPrint(BCLog::BENCH, " - Flush: %.2fms [%.2fs]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001);
2099+
LogPrint(BCLog::BENCH, " - Flush: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001, nTimeFlush * 0.001 / nBlocksTotal);
20972100
// Write the chain state to disk, if necessary.
20982101
if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED))
20992102
return false;
21002103
int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
2101-
LogPrint(BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001);
2104+
LogPrint(BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001, nTimeChainState * 0.001 / nBlocksTotal);
21022105
// Remove conflicting transactions from the mempool.;
21032106
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight);
21042107
disconnectpool.removeForBlock(blockConnecting.vtx);
21052108
// Update chainActive & related variables.
21062109
UpdateTip(pindexNew, chainparams);
21072110

21082111
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
2109-
LogPrint(BCLog::BENCH, " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001);
2110-
LogPrint(BCLog::BENCH, "- Connect block: %.2fms [%.2fs]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001);
2112+
LogPrint(BCLog::BENCH, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001, nTimePostConnect * 0.001 / nBlocksTotal);
2113+
LogPrint(BCLog::BENCH, "- Connect block: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001, nTimeTotal * 0.001 / nBlocksTotal);
21112114

21122115
connectTrace.BlockConnected(pindexNew, std::move(pthisBlock));
21132116
return true;

0 commit comments

Comments
 (0)