#include "leveldb/write_batch.h"
#include "leveldb/statistics.h"
#include "port/port.h"
+#include "util/bit_set.h"
#include "util/crc32c.h"
#include "util/histogram.h"
#include "util/mutexlock.h"
#include "util/stack_trace.h"
#include "util/string_util.h"
#include "util/testutil.h"
-#include "util/bit_set.h"
#include "hdfs/env_hdfs.h"
// Comma-separated list of operations to run in the specified order
#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:
Benchmark()
: cache_(FLAGS_cache_size >= 0 ?
RunBenchmark(num_threads, name, method);
}
}
- PrintStatistics();
+ if (FLAGS_statistics) {
+ fprintf(stdout, "STATISTICS:\n%s\n", dbstats->ToString().c_str());
+ }
}
private:
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");
+ "STATISTCS:\n %s",
+ dbstats->ToString().c_str());
}
}
Status ReadFirstLine(const std::string& fname, WriteBatch* const batch);
- void PrintHistogram(Histograms histogram_type, std::string name);
-
void PrintStatistics();
// dump leveldb.stats to LOG
virtual void measureTime(Histograms histogramType, uint64_t time) = 0;
virtual void histogramData(Histograms type, HistogramData * const data) = 0;
-
+ // String representation of the statistic object.
+ std::string ToString();
};
// Create a concrete DBStatistics object
--- /dev/null
+#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