Keep track of memory usage in CCoinsViewCache
This commit is contained in:
20
src/coins.h
20
src/coins.h
@@ -7,6 +7,7 @@
|
||||
#define BITCOIN_COINS_H
|
||||
|
||||
#include "compressor.h"
|
||||
#include "memusage.h"
|
||||
#include "serialize.h"
|
||||
#include "uint256.h"
|
||||
|
||||
@@ -252,6 +253,15 @@ public:
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t DynamicMemoryUsage() const {
|
||||
size_t ret = memusage::DynamicUsage(vout);
|
||||
BOOST_FOREACH(const CTxOut &out, vout) {
|
||||
const std::vector<unsigned char> *script = &out.scriptPubKey;
|
||||
ret += memusage::DynamicUsage(*script);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
class CCoinsKeyHasher
|
||||
@@ -356,7 +366,8 @@ class CCoinsModifier
|
||||
private:
|
||||
CCoinsViewCache& cache;
|
||||
CCoinsMap::iterator it;
|
||||
CCoinsModifier(CCoinsViewCache& cache_, CCoinsMap::iterator it_);
|
||||
size_t cachedCoinUsage; // Cached memory usage of the CCoins object before modification
|
||||
CCoinsModifier(CCoinsViewCache& cache_, CCoinsMap::iterator it_, size_t usage);
|
||||
|
||||
public:
|
||||
CCoins* operator->() { return &it->second.coins; }
|
||||
@@ -372,6 +383,7 @@ protected:
|
||||
/* Whether this cache has an active modifier. */
|
||||
bool hasModifier;
|
||||
|
||||
|
||||
/**
|
||||
* Make mutable so that we can "fill the cache" even from Get-methods
|
||||
* declared as "const".
|
||||
@@ -379,6 +391,9 @@ protected:
|
||||
mutable uint256 hashBlock;
|
||||
mutable CCoinsMap cacheCoins;
|
||||
|
||||
/* Cached dynamic memory usage for the inner CCoins objects. */
|
||||
mutable size_t cachedCoinsUsage;
|
||||
|
||||
public:
|
||||
CCoinsViewCache(CCoinsView *baseIn);
|
||||
~CCoinsViewCache();
|
||||
@@ -414,6 +429,9 @@ public:
|
||||
//! Calculate the size of the cache (in number of transactions)
|
||||
unsigned int GetCacheSize() const;
|
||||
|
||||
//! Calculate the size of the cache (in bytes)
|
||||
size_t DynamicMemoryUsage() const;
|
||||
|
||||
/**
|
||||
* Amount of bitcoins coming in to a transaction
|
||||
* Note that lightweight clients may not know anything besides the hash of previous transactions,
|
||||
|
||||
Reference in New Issue
Block a user