/src/rocksdb/cache/cache_entry_roles.cc
Line | Count | Source |
1 | | // Copyright (c) Facebook, Inc. and its affiliates. 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 | | #include "cache/cache_entry_roles.h" |
7 | | |
8 | | #include <mutex> |
9 | | |
10 | | #include "port/lang.h" |
11 | | |
12 | | namespace ROCKSDB_NAMESPACE { |
13 | | |
14 | | std::array<std::string, kNumCacheEntryRoles> kCacheEntryRoleToCamelString{{ |
15 | | "DataBlock", |
16 | | "FilterBlock", |
17 | | "FilterMetaBlock", |
18 | | "DeprecatedFilterBlock", |
19 | | "IndexBlock", |
20 | | "OtherBlock", |
21 | | "WriteBuffer", |
22 | | "CompressionDictionaryBuildingBuffer", |
23 | | "FilterConstruction", |
24 | | "BlockBasedTableReader", |
25 | | "FileMetadata", |
26 | | "BlobValue", |
27 | | "BlobCache", |
28 | | "Misc", |
29 | | }}; |
30 | | |
31 | | std::array<std::string, kNumCacheEntryRoles> kCacheEntryRoleToHyphenString{{ |
32 | | "data-block", |
33 | | "filter-block", |
34 | | "filter-meta-block", |
35 | | "deprecated-filter-block", |
36 | | "index-block", |
37 | | "other-block", |
38 | | "write-buffer", |
39 | | "compression-dictionary-building-buffer", |
40 | | "filter-construction", |
41 | | "block-based-table-reader", |
42 | | "file-metadata", |
43 | | "blob-value", |
44 | | "blob-cache", |
45 | | "misc", |
46 | | }}; |
47 | | |
48 | 0 | const std::string& GetCacheEntryRoleName(CacheEntryRole role) { |
49 | 0 | return kCacheEntryRoleToHyphenString[static_cast<size_t>(role)]; |
50 | 0 | } |
51 | | |
52 | 0 | const std::string& BlockCacheEntryStatsMapKeys::CacheId() { |
53 | 0 | static const std::string kCacheId = "id"; |
54 | 0 | return kCacheId; |
55 | 0 | } |
56 | | |
57 | 0 | const std::string& BlockCacheEntryStatsMapKeys::CacheCapacityBytes() { |
58 | 0 | static const std::string kCacheCapacityBytes = "capacity"; |
59 | 0 | return kCacheCapacityBytes; |
60 | 0 | } |
61 | | |
62 | | const std::string& |
63 | 0 | BlockCacheEntryStatsMapKeys::LastCollectionDurationSeconds() { |
64 | 0 | static const std::string kLastCollectionDurationSeconds = |
65 | 0 | "secs_for_last_collection"; |
66 | 0 | return kLastCollectionDurationSeconds; |
67 | 0 | } |
68 | | |
69 | 0 | const std::string& BlockCacheEntryStatsMapKeys::LastCollectionAgeSeconds() { |
70 | 0 | static const std::string kLastCollectionAgeSeconds = |
71 | 0 | "secs_since_last_collection"; |
72 | 0 | return kLastCollectionAgeSeconds; |
73 | 0 | } |
74 | | |
75 | | namespace { |
76 | | |
77 | | std::string GetPrefixedCacheEntryRoleName(const std::string& prefix, |
78 | 0 | CacheEntryRole role) { |
79 | 0 | const std::string& role_name = GetCacheEntryRoleName(role); |
80 | 0 | std::string prefixed_role_name; |
81 | 0 | prefixed_role_name.reserve(prefix.size() + role_name.size()); |
82 | 0 | prefixed_role_name.append(prefix); |
83 | 0 | prefixed_role_name.append(role_name); |
84 | 0 | return prefixed_role_name; |
85 | 0 | } |
86 | | |
87 | | } // namespace |
88 | | |
89 | 0 | std::string BlockCacheEntryStatsMapKeys::EntryCount(CacheEntryRole role) { |
90 | 0 | const static std::string kPrefix = "count."; |
91 | 0 | return GetPrefixedCacheEntryRoleName(kPrefix, role); |
92 | 0 | } |
93 | | |
94 | 0 | std::string BlockCacheEntryStatsMapKeys::UsedBytes(CacheEntryRole role) { |
95 | 0 | const static std::string kPrefix = "bytes."; |
96 | 0 | return GetPrefixedCacheEntryRoleName(kPrefix, role); |
97 | 0 | } |
98 | | |
99 | 0 | std::string BlockCacheEntryStatsMapKeys::UsedPercent(CacheEntryRole role) { |
100 | 0 | const static std::string kPrefix = "percent."; |
101 | 0 | return GetPrefixedCacheEntryRoleName(kPrefix, role); |
102 | 0 | } |
103 | | |
104 | | } // namespace ROCKSDB_NAMESPACE |