Commit f09d03aa authored by Eugene Pekurovsky's avatar Eugene Pekurovsky Committed by Facebook Github Bot

F14Map: Add a method for getting the size of dynamically allocated map memory

Summary:
Currently, the memory used by a map instance is available only via computeStats(),
which is quite expensive. A lightweight method is needed for getting the map memory
footprint on a hot code path.

Reviewed By: nbronson

Differential Revision: D7544180

fbshipit-source-id: 3cbc98bb9f1c5e7f75fd9eb7f89016580fbb6523
parent ed118811
......@@ -249,6 +249,11 @@ class F14BasicMap {
return table_.max_size();
}
// Accounts for allocated memory only, does not include sizeof(*this).
std::size_t getAllocatedMemorySize() const {
return table_.getAllocatedMemorySize();
}
F14TableStats computeStats() const noexcept {
return table_.computeStats();
}
......
......@@ -1601,6 +1601,13 @@ class F14Table : public Policy {
clearImpl<true>();
}
// Get memory footprint, not including sizeof(*this).
std::size_t getAllocatedMemorySize() const {
auto bc = bucket_count();
return (bc == 0 ? 0 : allocSize(chunkMask_ + 1, bc)) +
this->indirectBytesUsed(size(), bc);
}
private:
static std::size_t& histoAt(
std::vector<std::size_t>& histo,
......@@ -1696,9 +1703,7 @@ class F14Table : public Policy {
stats.bucketCount = bucket_count();
stats.chunkCount = cc;
stats.totalBytes = sizeof(*this) +
(cc == 0 ? 0 : allocSize(cc, bucket_count())) +
this->indirectBytesUsed(size(), bucket_count());
stats.totalBytes = sizeof(*this) + getAllocatedMemorySize();
stats.overheadBytes = stats.totalBytes - size() * sizeof(value_type);
return stats;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment