memory_util.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #ifndef ROCKSDB_LITE
  6. #include "rocksdb/utilities/memory_util.h"
  7. #include "db/db_impl/db_impl.h"
  8. namespace ROCKSDB_NAMESPACE {
  9. Status MemoryUtil::GetApproximateMemoryUsageByType(
  10. const std::vector<DB*>& dbs,
  11. const std::unordered_set<const Cache*> cache_set,
  12. std::map<MemoryUtil::UsageType, uint64_t>* usage_by_type) {
  13. usage_by_type->clear();
  14. // MemTable
  15. for (auto* db : dbs) {
  16. uint64_t usage = 0;
  17. if (db->GetAggregatedIntProperty(DB::Properties::kSizeAllMemTables,
  18. &usage)) {
  19. (*usage_by_type)[MemoryUtil::kMemTableTotal] += usage;
  20. }
  21. if (db->GetAggregatedIntProperty(DB::Properties::kCurSizeAllMemTables,
  22. &usage)) {
  23. (*usage_by_type)[MemoryUtil::kMemTableUnFlushed] += usage;
  24. }
  25. }
  26. // Table Readers
  27. for (auto* db : dbs) {
  28. uint64_t usage = 0;
  29. if (db->GetAggregatedIntProperty(DB::Properties::kEstimateTableReadersMem,
  30. &usage)) {
  31. (*usage_by_type)[MemoryUtil::kTableReadersTotal] += usage;
  32. }
  33. }
  34. // Cache
  35. for (const auto* cache : cache_set) {
  36. if (cache != nullptr) {
  37. (*usage_by_type)[MemoryUtil::kCacheTotal] += cache->GetUsage();
  38. }
  39. }
  40. return Status::OK();
  41. }
  42. } // namespace ROCKSDB_NAMESPACE
  43. #endif // !ROCKSDB_LITE