Skip to content

Commit

Permalink
Add treeMemoryUsage in MemoryManager::toString (#7960)
Browse files Browse the repository at this point in the history
Summary:
The number of root memory pools must be 0 during
the destruction of the `MemoryManager`, and it is nice to add
treeMemoryUsage of each pool in `MemoryManager::toString`
if there are still alive root pools, which is not normal.

Pull Request resolved: #7960

Reviewed By: tanjialiang

Differential Revision: D52023530

Pulled By: xiaoxmeng

fbshipit-source-id: bd1192c6d51b08d4be043ec4d80b355b41b91aec
  • Loading branch information
duanmeng authored and facebook-github-bot committed Dec 11, 2023
1 parent 5245e00 commit e91cdb5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 12 additions & 4 deletions velox/common/memory/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ MemoryManager::~MemoryManager() {
0,
"There are {} unexpected alive memory pools allocated by user on memory manager destruction:\n{}",
numPools(),
toString());
toString(true));
}
}

Expand Down Expand Up @@ -200,18 +200,26 @@ MemoryArbitrator* MemoryManager::arbitrator() {
return arbitrator_.get();
}

std::string MemoryManager::toString() const {
std::string MemoryManager::toString(bool detail) const {
std::stringstream out;
out << "Memory Manager[capacity "
<< (capacity_ == kMaxMemory ? "UNLIMITED" : succinctBytes(capacity_))
<< " alignment " << succinctBytes(alignment_) << " usedBytes "
<< succinctBytes(getTotalBytes()) << " number of pools " << numPools()
<< "\n";
out << "List of root pools:\n";
out << "\t" << defaultRoot_->name() << "\n";
if (detail) {
out << defaultRoot_->treeMemoryUsage();
} else {
out << "\t" << defaultRoot_->name() << "\n";
}
std::vector<std::shared_ptr<MemoryPool>> pools = getAlivePools();
for (const auto& pool : pools) {
out << "\t" << pool->name() << "\n";
if (detail) {
out << pool->treeMemoryUsage();
} else {
out << "\t" << pool->name() << "\n";
}
}
out << allocator_->toString() << "\n";
out << arbitrator_->toString();
Expand Down
6 changes: 4 additions & 2 deletions velox/common/memory/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ class MemoryManager {

MemoryArbitrator* arbitrator();

/// Returns debug string of this memory manager.
std::string toString() const;
/// Returns debug string of this memory manager. If 'detail' is true, it
/// returns the detailed tree memory usage from all the top level root memory
/// pools.
std::string toString(bool detail = false) const;

/// Returns the memory manger's internal default root memory pool for testing
/// purpose.
Expand Down

0 comments on commit e91cdb5

Please sign in to comment.