@@ -89,6 +89,7 @@ static leveldb::Options GetOptions(size_t nCacheSize)
89
89
}
90
90
91
91
CDBWrapper::CDBWrapper (const fs::path& path, size_t nCacheSize, bool fMemory , bool fWipe , bool obfuscate)
92
+ : m_name(fs::basename(path))
92
93
{
93
94
penv = nullptr ;
94
95
readoptions.verify_checksums = true ;
@@ -155,11 +156,30 @@ CDBWrapper::~CDBWrapper()
155
156
156
157
bool CDBWrapper::WriteBatch (CDBBatch& batch, bool fSync )
157
158
{
159
+ const bool log_memory = LogAcceptCategory (BCLog::LEVELDB);
160
+ double mem_before = 0 ;
161
+ if (log_memory) {
162
+ mem_before = DynamicMemoryUsage () / 1024 / 1024 ;
163
+ }
158
164
leveldb::Status status = pdb->Write (fSync ? syncoptions : writeoptions, &batch.batch );
159
165
dbwrapper_private::HandleError (status);
166
+ if (log_memory) {
167
+ double mem_after = DynamicMemoryUsage () / 1024 / 1024 ;
168
+ LogPrint (BCLog::LEVELDB, " WriteBatch memory usage: db=%s, before=%.1fMiB, after=%.1fMiB\n " ,
169
+ m_name, mem_before, mem_after);
170
+ }
160
171
return true ;
161
172
}
162
173
174
+ size_t CDBWrapper::DynamicMemoryUsage () const {
175
+ std::string memory;
176
+ if (!pdb->GetProperty (" leveldb.approximate-memory-usage" , &memory)) {
177
+ LogPrint (BCLog::LEVELDB, " Failed to get approximate-memory-usage property\n " );
178
+ return 0 ;
179
+ }
180
+ return stoul (memory);
181
+ }
182
+
163
183
// Prefixed with null character to avoid collisions with other keys
164
184
//
165
185
// We must use a string constructor which specifies length so that we copy
0 commit comments