diff --git a/db/db_impl.cc b/db/db_impl.cc index d95481079..65abe6ebf 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1875,6 +1875,7 @@ Status DBImpl::Get(const ReadOptions& options, mem->Unref(); imm.UnrefAll(); current->Unref(); + RecordTick(options_.statistics, NUMBER_KEYS_READ); return s; } @@ -1930,7 +1931,10 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) { if (status.ok() && my_batch != NULL) { // NULL batch is for compactions WriteBatch* updates = BuildBatchGroup(&last_writer); WriteBatchInternal::SetSequence(updates, last_sequence + 1); - last_sequence += WriteBatchInternal::Count(updates); + int my_batch_count = WriteBatchInternal::Count(updates); + last_sequence += my_batch_count; + // Record statistics + RecordTick(options_.statistics, NUMBER_KEYS_WRITTEN, my_batch_count); // Add to log and apply to memtable. We can release the lock // during this phase since &w is currently responsible for logging @@ -1977,7 +1981,6 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) { if (!writers_.empty()) { writers_.front()->cv.Signal(); } - return status; } diff --git a/db/db_statistics.h b/db/db_statistics.h index 532def297..04e782d5c 100644 --- a/db/db_statistics.h +++ b/db/db_statistics.h @@ -35,9 +35,9 @@ class DBStatistics: public Statistics { return allTickers_[tickerType].getCount(); } - void recordTick(Tickers tickerType) { + void recordTick(Tickers tickerType, uint64_t count) { assert(tickerType < TICKER_ENUM_MAX); - allTickers_[tickerType].recordTick(); + allTickers_[tickerType].recordTick(count); } private: diff --git a/include/leveldb/options.h b/include/leveldb/options.h index 3e7fcb9c8..5505a2467 100644 --- a/include/leveldb/options.h +++ b/include/leveldb/options.h @@ -252,6 +252,8 @@ struct Options { int max_grandparent_overlap_factor; // If non-null, then we should collect metrics about database operations + // Statistics objects should not be shared between DB instances as + // it does not use any locks to prevent concurrent updates. Statistics* statistics; // If true, then the contents of data files are not synced diff --git a/include/leveldb/statistics.h b/include/leveldb/statistics.h index 71724a2cb..967b20090 100644 --- a/include/leveldb/statistics.h +++ b/include/leveldb/statistics.h @@ -24,7 +24,11 @@ enum Tickers { COMPACTION_KEY_DROP_NEWER_ENTRY = 3, // key was written with a newer value. COMPACTION_KEY_DROP_OBSOLETE = 4, // The key is obsolete. COMPACTION_KEY_DROP_USER = 5, // user compaction function has dropped the key. - TICKER_ENUM_MAX = 6, + // Number of keys written to the database via the Put and Write call's + NUMBER_KEYS_WRITTEN = 6, + // Number of Keys read, + NUMBER_KEYS_READ = 7, + TICKER_ENUM_MAX = 8, }; @@ -40,6 +44,9 @@ class Ticker { count_++; } + inline void recordTick(int count) { + count_ += count; + } inline uint64_t getCount() { return count_; } @@ -66,7 +73,7 @@ class Statistics { virtual ~Statistics() {} virtual long getTickerCount(Tickers tickerType) = 0; - virtual void recordTick(Tickers tickerType) = 0; + virtual void recordTick(Tickers tickerType, uint64_t count = 0) = 0; protected: long numFileOpens_; @@ -75,11 +82,13 @@ class Statistics { }; // Ease of Use functions -inline void RecordTick(Statistics* const statistics, Tickers ticker) { +inline void RecordTick(Statistics* const statistics, + Tickers ticker, + uint64_t count = 1) { if (statistics != NULL) { - statistics->recordTick(ticker); + statistics->recordTick(ticker, count); } -}; +} } // namespace leveldb #endif // STORAGE_LEVELDB_INCLUDE_STATISTICS_H_