From 2df65c118cd80dfcd0289ab1879bcfd5a9802b7b Mon Sep 17 00:00:00 2001 From: Haobo Xu Date: Tue, 28 May 2013 12:35:43 -0700 Subject: [PATCH] [RocksDB] Dump counters and histogram data periodically with compaction stats Summary: As title Test Plan: make check Reviewers: dhruba Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D10995 --- db/db_impl.cc | 36 ++++++++++++++++++++++++++++++++++++ db/db_impl.h | 6 ++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 77956409a..4aa797ce4 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -307,6 +307,41 @@ const Status DBImpl::CreateArchivalDirectory() { return Status::OK(); } +void DBImpl::PrintHistogram(Histograms histogram_type, std::string name) { + assert(options_.statistics); + HistogramData histogramData; + options_.statistics->histogramData(histogram_type, &histogramData); + Log(options_.info_log, "%s statistics Percentiles :", name.c_str()); + Log(options_.info_log, "50 : %f ",histogramData.median); + Log(options_.info_log, "95 : %f ", histogramData.percentile95); + Log(options_.info_log, "99 : %f\n", histogramData.percentile99); +} + +void DBImpl::PrintStatistics() { + auto dbstats = options_.statistics; + if (dbstats) { + Log(options_.info_log, + "Statistics counters:\n" + "File opened:%ld closed:%ld errors:%ld\n" + "Block Cache Hit Count:%ld Block Cache Miss Count:%ld\n" + "Bloom Filter Useful: %ld \n" + "Compaction key_drop_newer_entry: %ld key_drop_obsolete: %ld " + "Compaction key_drop_user: %ld\n", + dbstats->getTickerCount(NO_FILE_OPENS), + dbstats->getTickerCount(NO_FILE_CLOSES), + dbstats->getTickerCount(NO_FILE_ERRORS), + dbstats->getTickerCount(BLOCK_CACHE_HIT), + dbstats->getTickerCount(BLOCK_CACHE_MISS), + dbstats->getTickerCount(BLOOM_FILTER_USEFUL), + dbstats->getTickerCount(COMPACTION_KEY_DROP_NEWER_ENTRY), + dbstats->getTickerCount(COMPACTION_KEY_DROP_OBSOLETE), + dbstats->getTickerCount(COMPACTION_KEY_DROP_USER)); + PrintHistogram(DB_GET, "DB_GET"); + PrintHistogram(DB_WRITE, "DB_WRITE"); + PrintHistogram(COMPACTION_TIME, "COMPACTION_TIME"); + } +} + void DBImpl::MaybeDumpStats() { if (options_.stats_dump_period_sec == 0) return; @@ -323,6 +358,7 @@ void DBImpl::MaybeDumpStats() { std::string stats; GetProperty("leveldb.stats", &stats); Log(options_.info_log, "%s", stats.c_str()); + PrintStatistics(); } } diff --git a/db/db_impl.h b/db/db_impl.h index 5a8d4fdbe..7d434dad4 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -204,12 +204,14 @@ class DBImpl : public DB { // return true if bool CheckFileExistsAndEmpty(const LogFile& file); - Status ReadFirstRecord(const LogFile& file, WriteBatch* const result); - Status ReadFirstLine(const std::string& fname, WriteBatch* const batch); + void PrintHistogram(Histograms histogram_type, std::string name); + + void PrintStatistics(); + // dump leveldb.stats to LOG void MaybeDumpStats();