memory_util.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #include "rocksdb/utilities/memory_util.h"
  6. #include "db/db_impl/db_impl.h"
  7. namespace ROCKSDB_NAMESPACE {
  8. Status MemoryUtil::GetApproximateMemoryUsageByType(
  9. const std::vector<DB*>& dbs,
  10. const std::unordered_set<const Cache*> cache_set,
  11. std::map<MemoryUtil::UsageType, uint64_t>* usage_by_type) {
  12. usage_by_type->clear();
  13. // MemTable
  14. for (auto* db : dbs) {
  15. uint64_t usage = 0;
  16. if (db->GetAggregatedIntProperty(DB::Properties::kSizeAllMemTables,
  17. &usage)) {
  18. (*usage_by_type)[MemoryUtil::kMemTableTotal] += usage;
  19. }
  20. if (db->GetAggregatedIntProperty(DB::Properties::kCurSizeAllMemTables,
  21. &usage)) {
  22. (*usage_by_type)[MemoryUtil::kMemTableUnFlushed] += usage;
  23. }
  24. }
  25. // Table Readers
  26. for (auto* db : dbs) {
  27. uint64_t usage = 0;
  28. if (db->GetAggregatedIntProperty(DB::Properties::kEstimateTableReadersMem,
  29. &usage)) {
  30. (*usage_by_type)[MemoryUtil::kTableReadersTotal] += usage;
  31. }
  32. }
  33. // Cache
  34. for (const auto* cache : cache_set) {
  35. if (cache != nullptr) {
  36. (*usage_by_type)[MemoryUtil::kCacheTotal] += cache->GetUsage();
  37. }
  38. }
  39. return Status::OK();
  40. }
  41. } // namespace ROCKSDB_NAMESPACE