From 72c45c66c65245aa548722213c3859c0610051b7 Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Sat, 29 Sep 2012 18:02:02 -0700 Subject: [PATCH] Print the block cache size in the LOG. Summary: Print the block cache size in the LOG. Test Plan: run db_bench and look at LOG. This is helpful while I was debugging one use-case. Reviewers: heyongqiang, MarkCallaghan Reviewed By: heyongqiang Differential Revision: https://reviews.facebook.net/D5739 --- include/leveldb/cache.h | 3 +++ util/cache.cc | 5 +++++ util/options.cc | 2 ++ 3 files changed, 10 insertions(+) diff --git a/include/leveldb/cache.h b/include/leveldb/cache.h index a7bd2afa7..f0aa4b130 100644 --- a/include/leveldb/cache.h +++ b/include/leveldb/cache.h @@ -82,6 +82,9 @@ class Cache { // its cache keys. virtual uint64_t NewId() = 0; + // returns the maximum configured capacity of the cache + virtual size_t GetCapacity() = 0; + private: void LRU_Remove(Handle* e); void LRU_Append(Handle* e); diff --git a/util/cache.cc b/util/cache.cc index dedb370b3..6dfa4d121 100644 --- a/util/cache.cc +++ b/util/cache.cc @@ -276,6 +276,7 @@ class ShardedLRUCache : public Cache { port::Mutex id_mutex_; uint64_t last_id_; int numShardBits; + size_t capacity_; static inline uint32_t HashSlice(const Slice& s) { return Hash(s.data(), s.size(), 0); @@ -287,6 +288,7 @@ class ShardedLRUCache : public Cache { void init(size_t capacity, int numbits) { numShardBits = numbits; + capacity_ = capacity; int numShards = 1 << numShardBits; shard_ = new LRUCache[numShards]; const size_t per_shard = (capacity + (numShards - 1)) / numShards; @@ -329,6 +331,9 @@ class ShardedLRUCache : public Cache { MutexLock l(&id_mutex_); return ++(last_id_); } + virtual uint64_t GetCapacity() { + return capacity_; + } }; } // end anonymous namespace diff --git a/util/options.cc b/util/options.cc index bd9027be9..f8c02df09 100644 --- a/util/options.cc +++ b/util/options.cc @@ -7,6 +7,7 @@ #include "leveldb/comparator.h" #include "leveldb/env.h" #include "leveldb/filter_policy.h" +#include "leveldb/cache.h" namespace leveldb { @@ -56,6 +57,7 @@ Options::Dump( Log(log," Options.write_buffer_size: %zd", write_buffer_size); Log(log," Options.max_open_files: %d", max_open_files); Log(log," Options.block_cache: %p", block_cache); + Log(log," Options.block_cache_size: %zd", block_cache->GetCapacity()); Log(log," Options.block_size: %zd", block_size); Log(log,"Options.block_restart_interval: %d", block_restart_interval); Log(log," Options.compression: %d", compression); -- GitLab