aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorW. J. van der Laan <laanwj@protonmail.com>2021-11-29 16:01:42 +0100
committerW. J. van der Laan <laanwj@protonmail.com>2021-11-29 16:39:05 +0100
commit913b7148a26c3cca93f8bf20f6c57609d0ede0a6 (patch)
treeef1c6a8932e87feb850029b053d9e69572c7f316 /src
parenta574f4ad390908ace794eb10fdb917d66c57094b (diff)
parent2bc51c5c3215398875c04456a3f3df1c07b830b5 (diff)
downloadbitcoin-913b7148a26c3cca93f8bf20f6c57609d0ede0a6.tar.xz
Merge bitcoin/bitcoin#22902: tracing: utxocache tracepoints
2bc51c5c3215398875c04456a3f3df1c07b830b5 [tracing] tracepoints to utxocache add, spent and uncache (Arnab Sen) a26e8eef43c5ff0f4a5cd44d1d331a7bd72564a5 [tracing] tracepoint for utxocache flushes (Arnab Sen) Pull request description: This PR adds some of the UTXO set cache tracepoints proposed in https://github.com/bitcoin/bitcoin/issues/20981#issuecomment-802688809. The first tracepoints were added in bitcoin#22006. tracepoint | description -- | -- `utxocache:flush` | Is called after the caches and indexes are flushed `utxocache:add` | when a new coin is added to the UTXO cache `utxocache:spent` | when a coin is spent `utxocache:uncache` | when coin is removed from the UTXO cache The tracepoints are further documented in `docs/tracing.md` and the usage is shown via the two newly added example scripts in `contrib/tracing/`. ACKs for top commit: laanwj: Code and documentation review ACK 2bc51c5c3215398875c04456a3f3df1c07b830b5 Tree-SHA512: d6b4f435d3260de4c48b36956f9311f65ab3b52cd03b1e0a4ba9cf47a774d8c4b31878e222b11e0ba5d233a68f7567f8a367b12a6392f688c10c11529341e837
Diffstat (limited to 'src')
-rw-r--r--src/coins.cpp19
-rw-r--r--src/validation.cpp7
2 files changed, 26 insertions, 0 deletions
diff --git a/src/coins.cpp b/src/coins.cpp
index ce0b131de6..daead6055e 100644
--- a/src/coins.cpp
+++ b/src/coins.cpp
@@ -7,6 +7,7 @@
#include <consensus/consensus.h>
#include <logging.h>
#include <random.h>
+#include <util/trace.h>
#include <version.h>
bool CCoinsView::GetCoin(const COutPoint &outpoint, Coin &coin) const { return false; }
@@ -95,6 +96,12 @@ void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possi
it->second.coin = std::move(coin);
it->second.flags |= CCoinsCacheEntry::DIRTY | (fresh ? CCoinsCacheEntry::FRESH : 0);
cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
+ TRACE5(utxocache, add,
+ outpoint.hash.data(),
+ (uint32_t)outpoint.n,
+ (uint32_t)coin.nHeight,
+ (int64_t)coin.out.nValue,
+ (bool)coin.IsCoinBase());
}
void CCoinsViewCache::EmplaceCoinInternalDANGER(COutPoint&& outpoint, Coin&& coin) {
@@ -120,6 +127,12 @@ bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
CCoinsMap::iterator it = FetchCoin(outpoint);
if (it == cacheCoins.end()) return false;
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
+ TRACE5(utxocache, spent,
+ outpoint.hash.data(),
+ (uint32_t)outpoint.n,
+ (uint32_t)it->second.coin.nHeight,
+ (int64_t)it->second.coin.out.nValue,
+ (bool)it->second.coin.IsCoinBase());
if (moveout) {
*moveout = std::move(it->second.coin);
}
@@ -231,6 +244,12 @@ void CCoinsViewCache::Uncache(const COutPoint& hash)
CCoinsMap::iterator it = cacheCoins.find(hash);
if (it != cacheCoins.end() && it->second.flags == 0) {
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
+ TRACE5(utxocache, uncache,
+ hash.hash.data(),
+ (uint32_t)hash.n,
+ (uint32_t)it->second.coin.nHeight,
+ (int64_t)it->second.coin.out.nValue,
+ (bool)it->second.coin.IsCoinBase());
cacheCoins.erase(it);
}
}
diff --git a/src/validation.cpp b/src/validation.cpp
index c96adb77ff..86d2ae7577 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2101,6 +2101,13 @@ bool CChainState::FlushStateToDisk(
nLastFlush = nNow;
full_flush_completed = true;
}
+ TRACE6(utxocache, flush,
+ (int64_t)(GetTimeMicros() - nNow.count()), // in microseconds (µs)
+ (u_int32_t)mode,
+ (u_int64_t)coins_count,
+ (u_int64_t)coins_mem_usage,
+ (bool)fFlushForPrune,
+ (bool)fDoFullFlush);
}
if (full_flush_completed) {
// Update best block in wallet (so we can detect restored wallets).