txgraph: expose memory usage estimate function (feature)
This commit is contained in:
1 parent
7680bb8fd4
commit
04c808ac4c
3 files changed
+39
No files matched your search
@@ -1012,6 +1012,21 @@ FUZZ_TARGET(txgraph)
|
|||||||
}
|
}
|
||||||
assert(!top_sim.IsOversized());
|
assert(!top_sim.IsOversized());
|
||||||
break;
|
break;
|
||||||
|
} else if (command-- == 0) {
|
||||||
|
// GetMainMemoryUsage().
|
||||||
|
auto usage = real->GetMainMemoryUsage();
|
||||||
|
// Test stability.
|
||||||
|
if (alt) {
|
||||||
|
auto usage2 = real->GetMainMemoryUsage();
|
||||||
|
assert(usage == usage2);
|
||||||
|
}
|
||||||
|
// Only empty graphs have 0 memory usage.
|
||||||
|
if (main_sim.GetTransactionCount() == 0) {
|
||||||
|
assert(usage == 0);
|
||||||
|
} else {
|
||||||
|
assert(usage > 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -629,6 +629,8 @@ public:
|
|||||||
std::unique_ptr<BlockBuilder> GetBlockBuilder() noexcept final;
|
std::unique_ptr<BlockBuilder> GetBlockBuilder() noexcept final;
|
||||||
std::pair<std::vector<Ref*>, FeePerWeight> GetWorstMainChunk() noexcept final;
|
std::pair<std::vector<Ref*>, FeePerWeight> GetWorstMainChunk() noexcept final;
|
||||||
|
|
||||||
|
size_t GetMainMemoryUsage() noexcept final;
|
||||||
|
|
||||||
void SanityCheck() const final;
|
void SanityCheck() const final;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2980,6 +2982,21 @@ std::vector<TxGraph::Ref*> TxGraphImpl::Trim() noexcept
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t TxGraphImpl::GetMainMemoryUsage() noexcept
|
||||||
|
{
|
||||||
|
// Make sure splits/merges are applied, as memory usage may not be representative otherwise.
|
||||||
|
SplitAll(/*up_to_level=*/0);
|
||||||
|
ApplyDependencies(/*level=*/0);
|
||||||
|
// Compute memory usage
|
||||||
|
size_t usage = /* From clusters */
|
||||||
|
m_main_clusterset.m_cluster_usage +
|
||||||
|
/* From Entry objects. */
|
||||||
|
sizeof(Entry) * m_main_clusterset.m_txcount +
|
||||||
|
/* From the chunk index. */
|
||||||
|
memusage::DynamicUsage(m_main_chunkindex);
|
||||||
|
return usage;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TxGraph::Ref::~Ref()
|
TxGraph::Ref::~Ref()
|
||||||
|
|||||||
@@ -202,6 +202,13 @@ public:
|
|||||||
* graph must not be oversized. If the graph is empty, {{}, FeePerWeight{}} is returned. */
|
* graph must not be oversized. If the graph is empty, {{}, FeePerWeight{}} is returned. */
|
||||||
virtual std::pair<std::vector<Ref*>, FeePerWeight> GetWorstMainChunk() noexcept = 0;
|
virtual std::pair<std::vector<Ref*>, FeePerWeight> GetWorstMainChunk() noexcept = 0;
|
||||||
|
|
||||||
|
/** Get the approximate memory usage for this object, just counting the main graph. If a
|
||||||
|
* staging graph is present, return a number corresponding to memory usage after
|
||||||
|
* AbortStaging() would be called. BlockBuilders' memory usage, memory usage of internally
|
||||||
|
* queued operations, and memory due to temporary caches, is not included here. Can always be
|
||||||
|
* called. */
|
||||||
|
virtual size_t GetMainMemoryUsage() noexcept = 0;
|
||||||
|
|
||||||
/** Perform an internal consistency check on this object. */
|
/** Perform an internal consistency check on this object. */
|
||||||
virtual void SanityCheck() const = 0;
|
virtual void SanityCheck() const = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user