cache_entry_roles.cc 3.0 KB

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