From 5a0a89dd10574dd6d6704d6ebe839998a9d59dab Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 6 Mar 2018 14:50:33 -0600 Subject: [PATCH] cache/lru_cache: expose usage/capacity for high priority pool. Signed-off-by: Mark Nelson --- cache/lru_cache.cc | 26 ++++++++++++++++++++++++++ cache/lru_cache.h | 18 +++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/cache/lru_cache.cc b/cache/lru_cache.cc index a128296f..7b360389 100644 --- a/cache/lru_cache.cc +++ b/cache/lru_cache.cc @@ -449,6 +449,16 @@ size_t LRUCacheShard::GetPinnedUsage() const { return usage_ - lru_usage_; } +size_t LRUCacheShard::GetHighPriPoolCapacity() { + MutexLock l(&mutex_); + return high_pri_pool_capacity_; +} + +size_t LRUCacheShard::GetHighPriPoolUsage() { + MutexLock l(&mutex_); + return high_pri_pool_usage_; +} + std::string LRUCacheShard::GetPrintableOptions() const { const int kBufferSize = 200; char buffer[kBufferSize]; @@ -515,6 +525,22 @@ size_t LRUCache::TEST_GetLRUSize() { return lru_size_of_all_shards; } +size_t LRUCache::GetHighPriPoolCapacity() { + size_t size = 0; + for (int i = 0; i < num_shards_; i++) { + size += shards_[i].GetHighPriPoolCapacity(); + } + return size; +} + +size_t LRUCache::GetHighPriPoolUsage() { + size_t size = 0; + for (int i = 0; i < num_shards_; i++) { + size += shards_[i].GetHighPriPoolUsage(); + } + return size; +} + double LRUCache::GetHighPriPoolRatio() { double result = 0.0; if (num_shards_ > 0) { diff --git a/cache/lru_cache.h b/cache/lru_cache.h index f5219ad3..bb8c2477 100644 --- a/cache/lru_cache.h +++ b/cache/lru_cache.h @@ -202,11 +202,15 @@ class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShard : public CacheShard { void TEST_GetLRUList(LRUHandle** lru, LRUHandle** lru_low_pri); - // Retrieves number of elements in LRU, for unit test purpose only - // not threadsafe + // Retrieves number of elements in LRU, for unit test purpose only + // not threadsafe size_t TEST_GetLRUSize(); - // Retrives high pri pool ratio + // Retrieve pool capacities and usages. Protected with mutex_. + size_t GetHighPriPoolCapacity(); + size_t GetHighPriPoolUsage(); + + // Retrives high pri pool ratio double GetHighPriPoolRatio(); private: @@ -289,9 +293,13 @@ class LRUCache : public ShardedCache { virtual uint32_t GetHash(Handle* handle) const override; virtual void DisownData() override; - // Retrieves number of elements in LRU, for unit test purpose only + // Retrieves number of elements in LRU, for unit test purpose only size_t TEST_GetLRUSize(); - // Retrives high pri pool ratio + // Retrieves high pri pool ratio + size_t GetHighPriPoolCapacity(); + // Retrieves high pri pool capacty + size_t GetHighPriPoolUsage(); + // Retrieves high pri pool ratio double GetHighPriPoolRatio(); private: -- 2.47.3