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 #pragma once
9 
10 #include <map>
11 #include <string>
12 #include <unordered_set>
13 #include <vector>
14 
15 #include "rocksdb/cache.h"
16 #include "rocksdb/db.h"
17 
18 namespace ROCKSDB_NAMESPACE {
19 
20 // Returns the current memory usage of the specified DB instances.
21 class MemoryUtil {
22  public:
23   enum UsageType : int {
24     // Memory usage of all the mem-tables.
25     kMemTableTotal = 0,
26     // Memory usage of those un-flushed mem-tables.
27     kMemTableUnFlushed = 1,
28     // Memory usage of all the table readers.
29     kTableReadersTotal = 2,
30     // Memory usage by Cache.
31     kCacheTotal = 3,
32     kNumUsageTypes = 4
33   };
34 
35   // Returns the approximate memory usage of different types in the input
36   // list of DBs and Cache set.  For instance, in the output map
37   // usage_by_type, usage_by_type[kMemTableTotal] will store the memory
38   // usage of all the mem-tables from all the input rocksdb instances.
39   //
40   // Note that for memory usage inside Cache class, we will
41   // only report the usage of the input "cache_set" without
42   // including those Cache usage inside the input list "dbs"
43   // of DBs.
44   static Status GetApproximateMemoryUsageByType(
45       const std::vector<DB*>& dbs,
46       const std::unordered_set<const Cache*> cache_set,
47       std::map<MemoryUtil::UsageType, uint64_t>* usage_by_type);
48 };
49 }  // namespace ROCKSDB_NAMESPACE
50 #endif  // !ROCKSDB_LITE
51