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