@@ -45,7 +45,6 @@ CConditionVariable cvBlockChange;
45
45
int nScriptCheckThreads = 0 ;
46
46
bool fImporting = false ;
47
47
bool fReindex = false ;
48
- bool fBenchmark = false ;
49
48
bool fTxIndex = false ;
50
49
bool fIsBareMultisigStd = true ;
51
50
unsigned int nCoinCacheSize = 5000 ;
@@ -1680,6 +1679,12 @@ void ThreadScriptCheck() {
1680
1679
scriptcheckqueue.Thread ();
1681
1680
}
1682
1681
1682
+ static int64_t nTimeVerify = 0 ;
1683
+ static int64_t nTimeConnect = 0 ;
1684
+ static int64_t nTimeIndex = 0 ;
1685
+ static int64_t nTimeCallbacks = 0 ;
1686
+ static int64_t nTimeTotal = 0 ;
1687
+
1683
1688
bool ConnectBlock (CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck )
1684
1689
{
1685
1690
AssertLockHeld (cs_main);
@@ -1735,7 +1740,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
1735
1740
1736
1741
CCheckQueueControl<CScriptCheck> control (fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL );
1737
1742
1738
- int64_t nStart = GetTimeMicros ();
1743
+ int64_t nTimeStart = GetTimeMicros ();
1739
1744
int64_t nFees = 0 ;
1740
1745
int nInputs = 0 ;
1741
1746
unsigned int nSigOps = 0 ;
@@ -1785,9 +1790,8 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
1785
1790
vPos.push_back (std::make_pair (tx.GetHash (), pos));
1786
1791
pos.nTxOffset += ::GetSerializeSize (tx, SER_DISK, CLIENT_VERSION);
1787
1792
}
1788
- int64_t nTime = GetTimeMicros () - nStart;
1789
- if (fBenchmark )
1790
- LogPrintf (" - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin)\n " , (unsigned )block.vtx .size (), 0.001 * nTime, 0.001 * nTime / block.vtx .size (), nInputs <= 1 ? 0 : 0.001 * nTime / (nInputs-1 ));
1793
+ int64_t nTime1 = GetTimeMicros (); nTimeConnect += nTime1 - nTimeStart;
1794
+ LogPrint (" bench" , " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n " , (unsigned )block.vtx .size (), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx .size (), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1 ), nTimeConnect * 0.000001 );
1791
1795
1792
1796
if (block.vtx [0 ].GetValueOut () > GetBlockValue (pindex->nHeight , nFees))
1793
1797
return state.DoS (100 ,
@@ -1797,9 +1801,8 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
1797
1801
1798
1802
if (!control.Wait ())
1799
1803
return state.DoS (100 , false );
1800
- int64_t nTime2 = GetTimeMicros () - nStart;
1801
- if (fBenchmark )
1802
- LogPrintf (" - Verify %u txins: %.2fms (%.3fms/txin)\n " , nInputs - 1 , 0.001 * nTime2, nInputs <= 1 ? 0 : 0.001 * nTime2 / (nInputs-1 ));
1804
+ int64_t nTime2 = GetTimeMicros (); nTimeVerify += nTime2 - nTimeStart;
1805
+ LogPrint (" bench" , " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs]\n " , nInputs - 1 , 0.001 * (nTime2 - nTimeStart), nInputs <= 1 ? 0 : 0.001 * (nTime2 - nTimeStart) / (nInputs-1 ), nTimeVerify * 0.000001 );
1803
1806
1804
1807
if (fJustCheck )
1805
1808
return true ;
@@ -1840,6 +1843,9 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
1840
1843
ret = view.SetBestBlock (pindex->GetBlockHash ());
1841
1844
assert (ret);
1842
1845
1846
+ int64_t nTime3 = GetTimeMicros (); nTimeIndex += nTime3 - nTime2;
1847
+ LogPrint (" bench" , " - Index writing: %.2fms [%.2fs]\n " , 0.001 * (nTime3 - nTime2), nTimeIndex * 0.000001 );
1848
+
1843
1849
// Watch for transactions paying to me
1844
1850
BOOST_FOREACH (const CTransaction& tx, block.vtx )
1845
1851
g_signals.SyncTransaction (tx, &block);
@@ -1849,6 +1855,9 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
1849
1855
g_signals.UpdatedTransaction (hashPrevBestCoinBase);
1850
1856
hashPrevBestCoinBase = block.vtx [0 ].GetHash ();
1851
1857
1858
+ int64_t nTime4 = GetTimeMicros (); nTimeCallbacks += nTime4 - nTime3;
1859
+ LogPrint (" bench" , " - Callbacks: %.2fms [%.2fs]\n " , 0.001 * (nTime4 - nTime3), nTimeCallbacks * 0.000001 );
1860
+
1852
1861
return true ;
1853
1862
}
1854
1863
@@ -1928,8 +1937,7 @@ bool static DisconnectTip(CValidationState &state) {
1928
1937
return error (" DisconnectTip() : DisconnectBlock %s failed" , pindexDelete->GetBlockHash ().ToString ());
1929
1938
assert (view.Flush ());
1930
1939
}
1931
- if (fBenchmark )
1932
- LogPrintf (" - Disconnect: %.2fms\n " , (GetTimeMicros () - nStart) * 0.001 );
1940
+ LogPrint (" bench" , " - Disconnect block: %.2fms\n " , (GetTimeMicros () - nStart) * 0.001 );
1933
1941
// Write the chain state to disk, if necessary.
1934
1942
if (!WriteChainState (state))
1935
1943
return false ;
@@ -1953,16 +1961,25 @@ bool static DisconnectTip(CValidationState &state) {
1953
1961
return true ;
1954
1962
}
1955
1963
1964
+ static int64_t nTimeReadFromDisk = 0 ;
1965
+ static int64_t nTimeConnectTotal = 0 ;
1966
+ static int64_t nTimeFlush = 0 ;
1967
+ static int64_t nTimeChainState = 0 ;
1968
+ static int64_t nTimePostConnect = 0 ;
1969
+
1956
1970
// Connect a new block to chainActive.
1957
1971
bool static ConnectTip (CValidationState &state, CBlockIndex *pindexNew) {
1958
1972
assert (pindexNew->pprev == chainActive.Tip ());
1959
1973
mempool.check (pcoinsTip);
1960
1974
// Read block from disk.
1975
+ int64_t nTime1 = GetTimeMicros ();
1961
1976
CBlock block;
1962
1977
if (!ReadBlockFromDisk (block, pindexNew))
1963
1978
return state.Abort (_ (" Failed to read block" ));
1964
1979
// Apply the block atomically to the chain state.
1965
- int64_t nStart = GetTimeMicros ();
1980
+ int64_t nTime2 = GetTimeMicros (); nTimeReadFromDisk += nTime2 - nTime1;
1981
+ int64_t nTime3;
1982
+ LogPrint (" bench" , " - Load block from disk: %.2fms [%.2fs]\n " , (nTime2 - nTime1) * 0.001 , nTimeReadFromDisk * 0.000001 );
1966
1983
{
1967
1984
CCoinsViewCache view (*pcoinsTip, true );
1968
1985
CInv inv (MSG_BLOCK, pindexNew->GetBlockHash ());
@@ -1972,13 +1989,17 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew) {
1972
1989
return error (" ConnectTip() : ConnectBlock %s failed" , pindexNew->GetBlockHash ().ToString ());
1973
1990
}
1974
1991
mapBlockSource.erase (inv.hash );
1992
+ nTime3 = GetTimeMicros (); nTimeConnectTotal += nTime3 - nTime2;
1993
+ LogPrint (" bench" , " - Connect total: %.2fms [%.2fs]\n " , (nTime3 - nTime2) * 0.001 , nTimeConnectTotal * 0.000001 );
1975
1994
assert (view.Flush ());
1976
1995
}
1977
- if ( fBenchmark )
1978
- LogPrintf ( " - Connect : %.2fms\n " , (GetTimeMicros () - nStart ) * 0.001 );
1996
+ int64_t nTime4 = GetTimeMicros (); nTimeFlush += nTime4 - nTime3;
1997
+ LogPrint ( " bench " , " - Flush : %.2fms [%.2fs] \n " , (nTime4 - nTime3 ) * 0.001 , nTimeFlush * 0.000001 );
1979
1998
// Write the chain state to disk, if necessary.
1980
1999
if (!WriteChainState (state))
1981
2000
return false ;
2001
+ int64_t nTime5 = GetTimeMicros (); nTimeChainState += nTime5 - nTime4;
2002
+ LogPrint (" bench" , " - Writing chainstate: %.2fms [%.2fs]\n " , (nTime5 - nTime4) * 0.001 , nTimeChainState * 0.000001 );
1982
2003
// Remove conflicting transactions from the mempool.
1983
2004
list<CTransaction> txConflicted;
1984
2005
mempool.removeForBlock (block.vtx , pindexNew->nHeight , txConflicted);
@@ -1994,6 +2015,9 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew) {
1994
2015
BOOST_FOREACH (const CTransaction &tx, block.vtx ) {
1995
2016
SyncWithWallets (tx, &block);
1996
2017
}
2018
+ int64_t nTime6 = GetTimeMicros (); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
2019
+ LogPrint (" bench" , " - Connect postprocess: %.2fms [%.2fs]\n " , (nTime6 - nTime5) * 0.001 , nTimePostConnect * 0.000001 );
2020
+ LogPrint (" bench" , " - Connect block: %.2fms [%.2fs]\n " , (nTime6 - nTime1) * 0.001 , nTimeTotal * 0.000001 );
1997
2021
return true ;
1998
2022
}
1999
2023
0 commit comments