rocksdb/utilities/memory/memory_util.cc
Yueh-Hsuan Chiang 7d7ee2b654 Add Memory Insight support to utilities
Summary:
This patch introduces utilities/memory, which currently includes
GetApproximateMemoryUsageByType that reports different types of
rocksdb memory usage given a list of input DBs.

The API also take care of the case where Cache could be shared
across multiple column families / multiple db instances.

Currently, it reports memory usage of memtable, table-readers
and cache.

Test Plan: utilities/memory/memory_test.cc

Reviewers: igor, anthony, IslamAbdelRahman, sdong

Reviewed By: sdong

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D49257
2015-11-03 17:52:17 -08:00

53 lines
1.5 KiB
C++

// Copyright (c) 2013, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
#ifndef ROCKSDB_LITE
#include "rocksdb/utilities/memory_util.h"
#include "db/db_impl.h"
namespace rocksdb {
Status MemoryUtil::GetApproximateMemoryUsageByType(
const std::vector<DB*>& dbs,
const std::unordered_set<const Cache*> cache_set,
std::map<MemoryUtil::UsageType, uint64_t>* usage_by_type) {
usage_by_type->clear();
// MemTable
for (auto* db : dbs) {
uint64_t usage = 0;
if (db->GetAggregatedIntProperty(DB::Properties::kSizeAllMemTables,
&usage)) {
(*usage_by_type)[MemoryUtil::kMemTableTotal] += usage;
}
if (db->GetAggregatedIntProperty(DB::Properties::kCurSizeAllMemTables,
&usage)) {
(*usage_by_type)[MemoryUtil::kMemTableUnFlushed] += usage;
}
}
// Table Readers
for (auto* db : dbs) {
uint64_t usage = 0;
if (db->GetAggregatedIntProperty(DB::Properties::kEstimateTableReadersMem,
&usage)) {
(*usage_by_type)[MemoryUtil::kTableReadersTotal] += usage;
}
}
// Cache
for (const auto* cache : cache_set) {
if (cache != nullptr) {
(*usage_by_type)[MemoryUtil::kCacheTotal] += cache->GetUsage();
}
}
return Status::OK();
}
} // namespace rocksdb
#endif // !ROCKSDB_LITE