[rocksdb][refactor] statistic printing code to one place

Summary: $title

Test Plan: db_bench --statistics=1

Reviewers: haobo

Reviewed By: haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D11373
main
Abhishek Kona 12 years ago
parent 09de7a3b6a
commit 5ef6bb8c37
  1. 32
      db/db_bench.cc
  2. 30
      db/db_impl.cc
  3. 2
      db/db_impl.h
  4. 3
      include/leveldb/statistics.h
  5. 55
      util/statistics.cc

@ -15,6 +15,7 @@
#include "leveldb/write_batch.h" #include "leveldb/write_batch.h"
#include "leveldb/statistics.h" #include "leveldb/statistics.h"
#include "port/port.h" #include "port/port.h"
#include "util/bit_set.h"
#include "util/crc32c.h" #include "util/crc32c.h"
#include "util/histogram.h" #include "util/histogram.h"
#include "util/mutexlock.h" #include "util/mutexlock.h"
@ -22,7 +23,6 @@
#include "util/stack_trace.h" #include "util/stack_trace.h"
#include "util/string_util.h" #include "util/string_util.h"
#include "util/testutil.h" #include "util/testutil.h"
#include "util/bit_set.h"
#include "hdfs/env_hdfs.h" #include "hdfs/env_hdfs.h"
// Comma-separated list of operations to run in the specified order // Comma-separated list of operations to run in the specified order
@ -738,32 +738,6 @@ class Benchmark {
#endif #endif
} }
void PrintHistogram(const Histograms& histogram_type,
const std::string& name) {
HistogramData histogramData;
dbstats->histogramData(histogram_type, &histogramData);
fprintf(stdout, "%s statistics Percentiles :", name.c_str());
fprintf(stdout, "50 : %f ", histogramData.median);
fprintf(stdout, "95 : %f ", histogramData.percentile95);
fprintf(stdout, "99 : %f\n", histogramData.percentile99);
}
void PrintTicker(const Tickers& ticker, const std::string& name) {
fprintf(stdout, "%s COUNT : %ld\n",
name.c_str(), dbstats->getTickerCount(ticker));
}
void PrintStatistics() {
if (FLAGS_statistics) {
for (auto& t : TickersNameMap) {
PrintTicker(t.first, t.second);
}
for (auto& h : HistogramsNameMap) {
PrintHistogram(h.first, h.second);
}
}
}
public: public:
Benchmark() Benchmark()
: cache_(FLAGS_cache_size >= 0 ? : cache_(FLAGS_cache_size >= 0 ?
@ -949,7 +923,9 @@ unique_ptr<char []> GenerateKeyFromInt(int v, const char* suffix = "")
RunBenchmark(num_threads, name, method); RunBenchmark(num_threads, name, method);
} }
} }
PrintStatistics(); if (FLAGS_statistics) {
fprintf(stdout, "STATISTICS:\n%s\n", dbstats->ToString().c_str());
}
} }
private: private:

@ -314,38 +314,12 @@ const Status DBImpl::CreateArchivalDirectory() {
return Status::OK(); 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() { void DBImpl::PrintStatistics() {
auto dbstats = options_.statistics; auto dbstats = options_.statistics;
if (dbstats) { if (dbstats) {
Log(options_.info_log, Log(options_.info_log,
"Statistics counters:\n" "STATISTCS:\n %s",
"File opened:%ld closed:%ld errors:%ld\n" dbstats->ToString().c_str());
"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");
} }
} }

@ -212,8 +212,6 @@ class DBImpl : public DB {
Status ReadFirstLine(const std::string& fname, WriteBatch* const batch); Status ReadFirstLine(const std::string& fname, WriteBatch* const batch);
void PrintHistogram(Histograms histogram_type, std::string name);
void PrintStatistics(); void PrintStatistics();
// dump leveldb.stats to LOG // dump leveldb.stats to LOG

@ -186,7 +186,8 @@ class Statistics {
virtual void measureTime(Histograms histogramType, uint64_t time) = 0; virtual void measureTime(Histograms histogramType, uint64_t time) = 0;
virtual void histogramData(Histograms type, HistogramData * const data) = 0; virtual void histogramData(Histograms type, HistogramData * const data) = 0;
// String representation of the statistic object.
std::string ToString();
}; };
// Create a concrete DBStatistics object // Create a concrete DBStatistics object

@ -0,0 +1,55 @@
#include "leveldb/statistics.h"
#include <cstdio>
namespace leveldb {
namespace {
// a buffer size used for temp string buffers
const int kBufferSize = 200;
std::string HistogramToString (
Statistics* dbstats,
const Histograms& histogram_type,
const std::string& name) {
char buffer[kBufferSize];
HistogramData histogramData;
dbstats->histogramData(histogram_type, &histogramData);
snprintf(
buffer,
kBufferSize,
"%s statistics Percentiles :=> 50 : %f 95 : %f 99 : %f\n",
name.c_str(),
histogramData.median,
histogramData.percentile95,
histogramData.percentile99
);
return std::string(buffer);
};
std::string TickerToString (
Statistics* dbstats,
const Tickers& ticker,
const std::string& name) {
char buffer[kBufferSize];
snprintf(buffer, kBufferSize, "%s COUNT : %ld\n",
name.c_str(), dbstats->getTickerCount(ticker));
return std::string(buffer);
};
} // namespace
std::string Statistics::ToString() {
std::string res;
res.reserve(20000);
for (const auto& t : TickersNameMap) {
res.append(TickerToString(this, t.first, t.second));
}
for (const auto& h : HistogramsNameMap) {
res.append(HistogramToString(this, h.first, h.second));
}
res.shrink_to_fit();
return res;
}
} // namespace leveldb
Loading…
Cancel
Save