|
|
|
@ -220,12 +220,11 @@ const std::vector<std::pair<Histograms, std::string>> HistogramsNameMap = { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
std::shared_ptr<Statistics> CreateDBStatistics() { |
|
|
|
|
return std::make_shared<StatisticsImpl>(nullptr, false); |
|
|
|
|
return std::make_shared<StatisticsImpl>(nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
StatisticsImpl::StatisticsImpl(std::shared_ptr<Statistics> stats, |
|
|
|
|
bool enable_internal_stats) |
|
|
|
|
: stats_(std::move(stats)), enable_internal_stats_(enable_internal_stats) {} |
|
|
|
|
StatisticsImpl::StatisticsImpl(std::shared_ptr<Statistics> stats) |
|
|
|
|
: stats_(std::move(stats)) {} |
|
|
|
|
|
|
|
|
|
StatisticsImpl::~StatisticsImpl() {} |
|
|
|
|
|
|
|
|
@ -235,10 +234,7 @@ uint64_t StatisticsImpl::getTickerCount(uint32_t tickerType) const { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint64_t StatisticsImpl::getTickerCountLocked(uint32_t tickerType) const { |
|
|
|
|
assert( |
|
|
|
|
enable_internal_stats_ ? |
|
|
|
|
tickerType < INTERNAL_TICKER_ENUM_MAX : |
|
|
|
|
tickerType < TICKER_ENUM_MAX); |
|
|
|
|
assert(tickerType < TICKER_ENUM_MAX); |
|
|
|
|
uint64_t res = 0; |
|
|
|
|
for (size_t core_idx = 0; core_idx < per_core_stats_.Size(); ++core_idx) { |
|
|
|
|
res += per_core_stats_.AccessAtCore(core_idx)->tickers_[tickerType]; |
|
|
|
@ -254,10 +250,7 @@ void StatisticsImpl::histogramData(uint32_t histogramType, |
|
|
|
|
|
|
|
|
|
std::unique_ptr<HistogramImpl> StatisticsImpl::getHistogramImplLocked( |
|
|
|
|
uint32_t histogramType) const { |
|
|
|
|
assert( |
|
|
|
|
enable_internal_stats_ ? |
|
|
|
|
histogramType < INTERNAL_HISTOGRAM_ENUM_MAX : |
|
|
|
|
histogramType < HISTOGRAM_ENUM_MAX); |
|
|
|
|
assert(histogramType < HISTOGRAM_ENUM_MAX); |
|
|
|
|
std::unique_ptr<HistogramImpl> res_hist(new HistogramImpl()); |
|
|
|
|
for (size_t core_idx = 0; core_idx < per_core_stats_.Size(); ++core_idx) { |
|
|
|
|
res_hist->Merge( |
|
|
|
@ -282,8 +275,7 @@ void StatisticsImpl::setTickerCount(uint32_t tickerType, uint64_t count) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void StatisticsImpl::setTickerCountLocked(uint32_t tickerType, uint64_t count) { |
|
|
|
|
assert(enable_internal_stats_ ? tickerType < INTERNAL_TICKER_ENUM_MAX |
|
|
|
|
: tickerType < TICKER_ENUM_MAX); |
|
|
|
|
assert(tickerType < TICKER_ENUM_MAX); |
|
|
|
|
for (size_t core_idx = 0; core_idx < per_core_stats_.Size(); ++core_idx) { |
|
|
|
|
if (core_idx == 0) { |
|
|
|
|
per_core_stats_.AccessAtCore(core_idx)->tickers_[tickerType] = count; |
|
|
|
@ -297,8 +289,7 @@ uint64_t StatisticsImpl::getAndResetTickerCount(uint32_t tickerType) { |
|
|
|
|
uint64_t sum = 0; |
|
|
|
|
{ |
|
|
|
|
MutexLock lock(&aggregate_lock_); |
|
|
|
|
assert(enable_internal_stats_ ? tickerType < INTERNAL_TICKER_ENUM_MAX |
|
|
|
|
: tickerType < TICKER_ENUM_MAX); |
|
|
|
|
assert(tickerType < TICKER_ENUM_MAX); |
|
|
|
|
for (size_t core_idx = 0; core_idx < per_core_stats_.Size(); ++core_idx) { |
|
|
|
|
sum += |
|
|
|
|
per_core_stats_.AccessAtCore(core_idx)->tickers_[tickerType].exchange( |
|
|
|
@ -312,10 +303,7 @@ uint64_t StatisticsImpl::getAndResetTickerCount(uint32_t tickerType) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void StatisticsImpl::recordTick(uint32_t tickerType, uint64_t count) { |
|
|
|
|
assert( |
|
|
|
|
enable_internal_stats_ ? |
|
|
|
|
tickerType < INTERNAL_TICKER_ENUM_MAX : |
|
|
|
|
tickerType < TICKER_ENUM_MAX); |
|
|
|
|
assert(tickerType < TICKER_ENUM_MAX); |
|
|
|
|
per_core_stats_.Access()->tickers_[tickerType].fetch_add( |
|
|
|
|
count, std::memory_order_relaxed); |
|
|
|
|
if (stats_ && tickerType < TICKER_ENUM_MAX) { |
|
|
|
@ -324,10 +312,7 @@ void StatisticsImpl::recordTick(uint32_t tickerType, uint64_t count) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void StatisticsImpl::measureTime(uint32_t histogramType, uint64_t value) { |
|
|
|
|
assert( |
|
|
|
|
enable_internal_stats_ ? |
|
|
|
|
histogramType < INTERNAL_HISTOGRAM_ENUM_MAX : |
|
|
|
|
histogramType < HISTOGRAM_ENUM_MAX); |
|
|
|
|
assert(histogramType < HISTOGRAM_ENUM_MAX); |
|
|
|
|
per_core_stats_.Access()->histograms_[histogramType].Add(value); |
|
|
|
|
if (stats_ && histogramType < HISTOGRAM_ENUM_MAX) { |
|
|
|
|
stats_->measureTime(histogramType, value); |
|
|
|
@ -359,41 +344,36 @@ std::string StatisticsImpl::ToString() const { |
|
|
|
|
std::string res; |
|
|
|
|
res.reserve(20000); |
|
|
|
|
for (const auto& t : TickersNameMap) { |
|
|
|
|
if (t.first < TICKER_ENUM_MAX || enable_internal_stats_) { |
|
|
|
|
char buffer[kTmpStrBufferSize]; |
|
|
|
|
snprintf(buffer, kTmpStrBufferSize, "%s COUNT : %" PRIu64 "\n", |
|
|
|
|
t.second.c_str(), getTickerCountLocked(t.first)); |
|
|
|
|
res.append(buffer); |
|
|
|
|
} |
|
|
|
|
assert(t.first < TICKER_ENUM_MAX); |
|
|
|
|
char buffer[kTmpStrBufferSize]; |
|
|
|
|
snprintf(buffer, kTmpStrBufferSize, "%s COUNT : %" PRIu64 "\n", |
|
|
|
|
t.second.c_str(), getTickerCountLocked(t.first)); |
|
|
|
|
res.append(buffer); |
|
|
|
|
} |
|
|
|
|
for (const auto& h : HistogramsNameMap) { |
|
|
|
|
if (h.first < HISTOGRAM_ENUM_MAX || enable_internal_stats_) { |
|
|
|
|
char buffer[kTmpStrBufferSize]; |
|
|
|
|
HistogramData hData; |
|
|
|
|
getHistogramImplLocked(h.first)->Data(&hData); |
|
|
|
|
// don't handle failures - buffer should always be big enough and arguments
|
|
|
|
|
// should be provided correctly
|
|
|
|
|
int ret = snprintf( |
|
|
|
|
buffer, kTmpStrBufferSize, |
|
|
|
|
"%s P50 : %f P95 : %f P99 : %f P100 : %f COUNT : %" PRIu64 " SUM : %" |
|
|
|
|
PRIu64 "\n", h.second.c_str(), hData.median, hData.percentile95, |
|
|
|
|
hData.percentile99, hData.max, hData.count, hData.sum); |
|
|
|
|
if (ret < 0 || ret >= kTmpStrBufferSize) { |
|
|
|
|
assert(false); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
res.append(buffer); |
|
|
|
|
assert(h.first < HISTOGRAM_ENUM_MAX); |
|
|
|
|
char buffer[kTmpStrBufferSize]; |
|
|
|
|
HistogramData hData; |
|
|
|
|
getHistogramImplLocked(h.first)->Data(&hData); |
|
|
|
|
// don't handle failures - buffer should always be big enough and arguments
|
|
|
|
|
// should be provided correctly
|
|
|
|
|
int ret = snprintf( |
|
|
|
|
buffer, kTmpStrBufferSize, |
|
|
|
|
"%s P50 : %f P95 : %f P99 : %f P100 : %f COUNT : %" PRIu64 " SUM : %" |
|
|
|
|
PRIu64 "\n", h.second.c_str(), hData.median, hData.percentile95, |
|
|
|
|
hData.percentile99, hData.max, hData.count, hData.sum); |
|
|
|
|
if (ret < 0 || ret >= kTmpStrBufferSize) { |
|
|
|
|
assert(false); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
res.append(buffer); |
|
|
|
|
} |
|
|
|
|
res.shrink_to_fit(); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool StatisticsImpl::HistEnabledForType(uint32_t type) const { |
|
|
|
|
if (LIKELY(!enable_internal_stats_)) { |
|
|
|
|
return type < HISTOGRAM_ENUM_MAX; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
return type < HISTOGRAM_ENUM_MAX; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
|