18
18
#include < flatfile.h>
19
19
#include < hash.h>
20
20
#include < index/txindex.h>
21
+ #include < logging.h>
22
+ #include < logging/timer.h>
21
23
#include < policy/fees.h>
22
24
#include < policy/policy.h>
23
25
#include < policy/settings.h>
@@ -2023,15 +2025,23 @@ bool CChainState::FlushStateToDisk(
2023
2025
static int64_t nLastFlush = 0 ;
2024
2026
std::set<int > setFilesToPrune;
2025
2027
bool full_flush_completed = false ;
2028
+
2029
+ const size_t coins_count = CoinsTip ().GetCacheSize ();
2030
+ const size_t coins_mem_usage = CoinsTip ().DynamicMemoryUsage ();
2031
+
2026
2032
try {
2027
2033
{
2028
2034
bool fFlushForPrune = false ;
2029
2035
bool fDoFullFlush = false ;
2030
2036
LOCK (cs_LastBlockFile);
2031
2037
if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0 ) && !fReindex ) {
2032
2038
if (nManualPruneHeight > 0 ) {
2039
+ LOG_TIME_MILLIS (" find files to prune (manual)" , BCLog::BENCH);
2040
+
2033
2041
FindFilesToPruneManual (setFilesToPrune, nManualPruneHeight);
2034
2042
} else {
2043
+ LOG_TIME_MILLIS (" find files to prune" , BCLog::BENCH);
2044
+
2035
2045
FindFilesToPrune (setFilesToPrune, chainparams.PruneAfterHeight ());
2036
2046
fCheckForPruning = false ;
2037
2047
}
@@ -2070,10 +2080,17 @@ bool CChainState::FlushStateToDisk(
2070
2080
if (!CheckDiskSpace (GetBlocksDir ())) {
2071
2081
return AbortNode (state, " Disk space is too low!" , _ (" Error: Disk space is too low!" ).translated , CClientUIInterface::MSG_NOPREFIX);
2072
2082
}
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
+
2075
2090
// Then update all block file information (which may refer to block and undo files).
2076
2091
{
2092
+ LOG_TIME_MILLIS (" write block index to disk" , BCLog::BENCH);
2093
+
2077
2094
std::vector<std::pair<int , const CBlockFileInfo*> > vFiles;
2078
2095
vFiles.reserve (setDirtyFileInfo.size ());
2079
2096
for (std::set<int >::iterator it = setDirtyFileInfo.begin (); it != setDirtyFileInfo.end (); ) {
@@ -2091,12 +2108,18 @@ bool CChainState::FlushStateToDisk(
2091
2108
}
2092
2109
}
2093
2110
// Finally remove any pruned files
2094
- if (fFlushForPrune )
2111
+ if (fFlushForPrune ) {
2112
+ LOG_TIME_MILLIS (" unlink pruned files" , BCLog::BENCH);
2113
+
2095
2114
UnlinkPrunedFiles (setFilesToPrune);
2115
+ }
2096
2116
nLastWrite = nNow;
2097
2117
}
2098
2118
// Flush best chain related state. This can only be done if the blocks / block index write was also done.
2099
2119
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
+
2100
2123
// Typical Coin structures on disk are around 48 bytes in size.
2101
2124
// Pushing a new one to the database can cause it to be written
2102
2125
// twice (once in the log, and once in the tables). This is already
0 commit comments