2013-10-16 21:59:46 +00:00
|
|
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
2014-01-17 20:46:06 +00:00
|
|
|
#include "util/statistics.h"
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/statistics.h"
|
2014-01-22 01:51:36 +00:00
|
|
|
#include <algorithm>
|
2013-06-19 03:28:41 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
namespace rocksdb {
|
2013-06-19 03:28:41 +00:00
|
|
|
|
2014-01-17 20:46:06 +00:00
|
|
|
std::shared_ptr<Statistics> CreateDBStatistics() {
|
|
|
|
return std::make_shared<StatisticsImpl>();
|
|
|
|
}
|
|
|
|
|
2014-01-29 23:08:41 +00:00
|
|
|
StatisticsImpl::StatisticsImpl() {}
|
2014-01-17 20:46:06 +00:00
|
|
|
|
|
|
|
StatisticsImpl::~StatisticsImpl() {}
|
|
|
|
|
|
|
|
long StatisticsImpl::getTickerCount(Tickers tickerType) {
|
|
|
|
assert(tickerType < TICKER_ENUM_MAX);
|
2014-01-29 23:08:41 +00:00
|
|
|
return tickers_[tickerType].value;
|
2014-01-17 20:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StatisticsImpl::setTickerCount(Tickers tickerType, uint64_t count) {
|
|
|
|
assert(tickerType < TICKER_ENUM_MAX);
|
2014-01-29 23:08:41 +00:00
|
|
|
tickers_[tickerType].value = count;
|
2014-01-17 20:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StatisticsImpl::recordTick(Tickers tickerType, uint64_t count) {
|
|
|
|
assert(tickerType < TICKER_ENUM_MAX);
|
2014-01-29 23:08:41 +00:00
|
|
|
tickers_[tickerType].value += count;
|
2014-01-17 20:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StatisticsImpl::measureTime(Histograms histogramType, uint64_t value) {
|
|
|
|
assert(histogramType < HISTOGRAM_ENUM_MAX);
|
|
|
|
histograms_[histogramType].Add(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StatisticsImpl::histogramData(Histograms histogramType,
|
|
|
|
HistogramData* const data) {
|
|
|
|
assert(histogramType < HISTOGRAM_ENUM_MAX);
|
|
|
|
histograms_[histogramType].Data(data);
|
|
|
|
}
|
|
|
|
|
2013-06-19 03:28:41 +00:00
|
|
|
namespace {
|
2014-01-17 20:46:06 +00:00
|
|
|
|
2013-06-19 03:28:41 +00:00
|
|
|
// 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);
|
|
|
|
};
|
|
|
|
|
2014-01-17 20:46:06 +00:00
|
|
|
std::string TickerToString(Statistics* dbstats, const Tickers& ticker,
|
|
|
|
const std::string& name) {
|
2013-06-19 03:28:41 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
} // namespace rocksdb
|