]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/memory/memory_usage.h
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).
9 #include <unordered_map>
11 #include <folly/container/F14Map.h>
14 #include "rocksdb/rocksdb_namespace.h"
16 namespace ROCKSDB_NAMESPACE
{
18 // Helper methods to estimate memroy usage by std containers.
20 template <class Key
, class Value
, class Hash
>
21 size_t ApproximateMemoryUsage(
22 const std::unordered_map
<Key
, Value
, Hash
>& umap
) {
23 using Map
= std::unordered_map
<Key
, Value
, Hash
>;
25 // Size of all items plus a next pointer for each item.
26 (sizeof(typename
Map::value_type
) + sizeof(void*)) * umap
.size() +
27 // Size of hash buckets.
28 umap
.bucket_count() * sizeof(void*);
32 template <class Key
, class Value
, class Hash
>
33 size_t ApproximateMemoryUsage(const folly::F14FastMap
<Key
, Value
, Hash
>& umap
) {
34 return sizeof(umap
) + umap
.getAllocatedMemorySize();
38 } // namespace ROCKSDB_NAMESPACE