Add counters to count gets and writes

Summary: Add Tickers to count Write's and Get's

Test Plan: make check

Reviewers: dhruba, chip

Reviewed By: dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D7977
main
Abhishek Kona 12 years ago
parent 3c3df7402f
commit 16903c35b0
  1. 7
      db/db_impl.cc
  2. 4
      db/db_statistics.h
  3. 2
      include/leveldb/options.h
  4. 19
      include/leveldb/statistics.h

@ -1875,6 +1875,7 @@ Status DBImpl::Get(const ReadOptions& options,
mem->Unref(); mem->Unref();
imm.UnrefAll(); imm.UnrefAll();
current->Unref(); current->Unref();
RecordTick(options_.statistics, NUMBER_KEYS_READ);
return s; 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 if (status.ok() && my_batch != NULL) { // NULL batch is for compactions
WriteBatch* updates = BuildBatchGroup(&last_writer); WriteBatch* updates = BuildBatchGroup(&last_writer);
WriteBatchInternal::SetSequence(updates, last_sequence + 1); 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 // Add to log and apply to memtable. We can release the lock
// during this phase since &w is currently responsible for logging // 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()) { if (!writers_.empty()) {
writers_.front()->cv.Signal(); writers_.front()->cv.Signal();
} }
return status; return status;
} }

@ -35,9 +35,9 @@ class DBStatistics: public Statistics {
return allTickers_[tickerType].getCount(); return allTickers_[tickerType].getCount();
} }
void recordTick(Tickers tickerType) { void recordTick(Tickers tickerType, uint64_t count) {
assert(tickerType < TICKER_ENUM_MAX); assert(tickerType < TICKER_ENUM_MAX);
allTickers_[tickerType].recordTick(); allTickers_[tickerType].recordTick(count);
} }
private: private:

@ -252,6 +252,8 @@ struct Options {
int max_grandparent_overlap_factor; int max_grandparent_overlap_factor;
// If non-null, then we should collect metrics about database operations // 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; Statistics* statistics;
// If true, then the contents of data files are not synced // If true, then the contents of data files are not synced

@ -24,7 +24,11 @@ enum Tickers {
COMPACTION_KEY_DROP_NEWER_ENTRY = 3, // key was written with a newer value. 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_OBSOLETE = 4, // The key is obsolete.
COMPACTION_KEY_DROP_USER = 5, // user compaction function has dropped the key. 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_++; count_++;
} }
inline void recordTick(int count) {
count_ += count;
}
inline uint64_t getCount() { inline uint64_t getCount() {
return count_; return count_;
} }
@ -66,7 +73,7 @@ class Statistics {
virtual ~Statistics() {} virtual ~Statistics() {}
virtual long getTickerCount(Tickers tickerType) = 0; virtual long getTickerCount(Tickers tickerType) = 0;
virtual void recordTick(Tickers tickerType) = 0; virtual void recordTick(Tickers tickerType, uint64_t count = 0) = 0;
protected: protected:
long numFileOpens_; long numFileOpens_;
@ -75,11 +82,13 @@ class Statistics {
}; };
// Ease of Use functions // 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) { if (statistics != NULL) {
statistics->recordTick(ticker); statistics->recordTick(ticker, count);
} }
}; }
} // namespace leveldb } // namespace leveldb
#endif // STORAGE_LEVELDB_INCLUDE_STATISTICS_H_ #endif // STORAGE_LEVELDB_INCLUDE_STATISTICS_H_

Loading…
Cancel
Save