Skip to content

Commit dcef9a2

Browse files
committed
logs: add timing information to FlushStateToDisk()
1 parent 41edaf2 commit dcef9a2

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/validation.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <flatfile.h>
1919
#include <hash.h>
2020
#include <index/txindex.h>
21+
#include <logging.h>
22+
#include <logging/timer.h>
2123
#include <policy/fees.h>
2224
#include <policy/policy.h>
2325
#include <policy/settings.h>
@@ -2023,15 +2025,23 @@ bool CChainState::FlushStateToDisk(
20232025
static int64_t nLastFlush = 0;
20242026
std::set<int> setFilesToPrune;
20252027
bool full_flush_completed = false;
2028+
2029+
const size_t coins_count = CoinsTip().GetCacheSize();
2030+
const size_t coins_mem_usage = CoinsTip().DynamicMemoryUsage();
2031+
20262032
try {
20272033
{
20282034
bool fFlushForPrune = false;
20292035
bool fDoFullFlush = false;
20302036
LOCK(cs_LastBlockFile);
20312037
if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0) && !fReindex) {
20322038
if (nManualPruneHeight > 0) {
2039+
LOG_TIME_MILLIS("find files to prune (manual)", BCLog::BENCH);
2040+
20332041
FindFilesToPruneManual(setFilesToPrune, nManualPruneHeight);
20342042
} else {
2043+
LOG_TIME_MILLIS("find files to prune", BCLog::BENCH);
2044+
20352045
FindFilesToPrune(setFilesToPrune, chainparams.PruneAfterHeight());
20362046
fCheckForPruning = false;
20372047
}
@@ -2070,10 +2080,17 @@ bool CChainState::FlushStateToDisk(
20702080
if (!CheckDiskSpace(GetBlocksDir())) {
20712081
return AbortNode(state, "Disk space is too low!", _("Error: Disk space is too low!").translated, CClientUIInterface::MSG_NOPREFIX);
20722082
}
2073-
// First make sure all block and undo data is flushed to disk.
2074-
FlushBlockFile();
2083+
{
2084+
LOG_TIME_MILLIS("write block and undo data to disk", BCLog::BENCH);
2085+
2086+
// First make sure all block and undo data is flushed to disk.
2087+
FlushBlockFile();
2088+
}
2089+
20752090
// Then update all block file information (which may refer to block and undo files).
20762091
{
2092+
LOG_TIME_MILLIS("write block index to disk", BCLog::BENCH);
2093+
20772094
std::vector<std::pair<int, const CBlockFileInfo*> > vFiles;
20782095
vFiles.reserve(setDirtyFileInfo.size());
20792096
for (std::set<int>::iterator it = setDirtyFileInfo.begin(); it != setDirtyFileInfo.end(); ) {
@@ -2091,12 +2108,18 @@ bool CChainState::FlushStateToDisk(
20912108
}
20922109
}
20932110
// Finally remove any pruned files
2094-
if (fFlushForPrune)
2111+
if (fFlushForPrune) {
2112+
LOG_TIME_MILLIS("unlink pruned files", BCLog::BENCH);
2113+
20952114
UnlinkPrunedFiles(setFilesToPrune);
2115+
}
20962116
nLastWrite = nNow;
20972117
}
20982118
// Flush best chain related state. This can only be done if the blocks / block index write was also done.
20992119
if (fDoFullFlush && !CoinsTip().GetBestBlock().IsNull()) {
2120+
LOG_TIME_SECONDS(strprintf("write coins cache to disk (%d coins, %.2fkB)",
2121+
coins_count, coins_mem_usage / 1000));
2122+
21002123
// Typical Coin structures on disk are around 48 bytes in size.
21012124
// Pushing a new one to the database can cause it to be written
21022125
// twice (once in the log, and once in the tables). This is already

0 commit comments

Comments
 (0)