mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Merge branch 'master' into performance
Conflicts: db/db_impl.cc db/db_test.cc db/memtable.cc db/version_set.cc include/rocksdb/statistics.h util/statistics_imp.h
This commit is contained in:
@@ -16,27 +16,38 @@
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
HistogramBucketMapper::HistogramBucketMapper() :
|
||||
// Add newer bucket index here.
|
||||
// Should be alwyas added in sorted order.
|
||||
bucketValues_({
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 25, 30, 35, 40, 45,
|
||||
50, 60, 70, 80, 90, 100, 120, 140, 160, 180, 200, 250, 300, 350, 400, 450,
|
||||
500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000,
|
||||
3500, 4000, 4500, 5000, 6000, 7000, 8000, 9000, 10000, 12000, 14000,
|
||||
16000, 18000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 60000,
|
||||
70000, 80000, 90000, 100000, 120000, 140000, 160000, 180000, 200000,
|
||||
250000, 300000, 350000, 400000, 450000, 500000, 600000, 700000, 800000,
|
||||
900000, 1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2500000,
|
||||
3000000, 3500000, 4000000, 4500000, 5000000, 6000000, 7000000, 8000000,
|
||||
9000000, 10000000, 12000000, 14000000, 16000000, 18000000, 20000000,
|
||||
25000000, 30000000, 35000000, 40000000, 45000000, 50000000, 60000000,
|
||||
70000000, 80000000, 90000000, 100000000, 120000000, 140000000, 160000000,
|
||||
180000000, 200000000, 250000000, 300000000, 350000000, 400000000,
|
||||
450000000, 500000000, 600000000, 700000000, 800000000, 900000000,
|
||||
1000000000}),
|
||||
maxBucketValue_(bucketValues_.back()),
|
||||
minBucketValue_(bucketValues_.front()) {
|
||||
HistogramBucketMapper::HistogramBucketMapper()
|
||||
:
|
||||
// Add newer bucket index here.
|
||||
// Should be alwyas added in sorted order.
|
||||
// If you change this, you also need to change
|
||||
// size of array buckets_ in HistogramImpl
|
||||
bucketValues_(
|
||||
{1, 2, 3, 4, 5, 6,
|
||||
7, 8, 9, 10, 12, 14,
|
||||
16, 18, 20, 25, 30, 35,
|
||||
40, 45, 50, 60, 70, 80,
|
||||
90, 100, 120, 140, 160, 180,
|
||||
200, 250, 300, 350, 400, 450,
|
||||
500, 600, 700, 800, 900, 1000,
|
||||
1200, 1400, 1600, 1800, 2000, 2500,
|
||||
3000, 3500, 4000, 4500, 5000, 6000,
|
||||
7000, 8000, 9000, 10000, 12000, 14000,
|
||||
16000, 18000, 20000, 25000, 30000, 35000,
|
||||
40000, 45000, 50000, 60000, 70000, 80000,
|
||||
90000, 100000, 120000, 140000, 160000, 180000,
|
||||
200000, 250000, 300000, 350000, 400000, 450000,
|
||||
500000, 600000, 700000, 800000, 900000, 1000000,
|
||||
1200000, 1400000, 1600000, 1800000, 2000000, 2500000,
|
||||
3000000, 3500000, 4000000, 4500000, 5000000, 6000000,
|
||||
7000000, 8000000, 9000000, 10000000, 12000000, 14000000,
|
||||
16000000, 18000000, 20000000, 25000000, 30000000, 35000000,
|
||||
40000000, 45000000, 50000000, 60000000, 70000000, 80000000,
|
||||
90000000, 100000000, 120000000, 140000000, 160000000, 180000000,
|
||||
200000000, 250000000, 300000000, 350000000, 400000000, 450000000,
|
||||
500000000, 600000000, 700000000, 800000000, 900000000, 1000000000}),
|
||||
maxBucketValue_(bucketValues_.back()),
|
||||
minBucketValue_(bucketValues_.front()) {
|
||||
for (size_t i =0; i < bucketValues_.size(); ++i) {
|
||||
valueIndexMap_[bucketValues_[i]] = i;
|
||||
}
|
||||
@@ -62,24 +73,17 @@ namespace {
|
||||
const HistogramBucketMapper bucketMapper;
|
||||
}
|
||||
|
||||
|
||||
HistogramImpl::HistogramImpl() :
|
||||
min_(bucketMapper.LastValue()),
|
||||
max_(0),
|
||||
num_(0),
|
||||
sum_(0),
|
||||
sum_squares_(0),
|
||||
buckets_(std::vector<uint64_t>(bucketMapper.BucketCount(), 0)) {}
|
||||
|
||||
void HistogramImpl::Clear() {
|
||||
min_ = bucketMapper.LastValue();
|
||||
max_ = 0;
|
||||
num_ = 0;
|
||||
sum_ = 0;
|
||||
sum_squares_ = 0;
|
||||
buckets_.resize(bucketMapper.BucketCount(), 0);
|
||||
memset(buckets_, 0, sizeof buckets_);
|
||||
}
|
||||
|
||||
bool HistogramImpl::Empty() { return sum_squares_ == 0; }
|
||||
|
||||
void HistogramImpl::Add(uint64_t value) {
|
||||
const size_t index = bucketMapper.IndexForValue(value);
|
||||
buckets_[index] += 1;
|
||||
|
||||
@@ -52,9 +52,8 @@ class HistogramBucketMapper {
|
||||
|
||||
class HistogramImpl {
|
||||
public:
|
||||
HistogramImpl();
|
||||
virtual ~HistogramImpl() {}
|
||||
virtual void Clear();
|
||||
virtual bool Empty();
|
||||
virtual void Add(uint64_t value);
|
||||
void Merge(const HistogramImpl& other);
|
||||
|
||||
@@ -67,13 +66,14 @@ class HistogramImpl {
|
||||
virtual void Data(HistogramData * const data) const;
|
||||
|
||||
private:
|
||||
double min_;
|
||||
double max_;
|
||||
double num_;
|
||||
double sum_;
|
||||
double sum_squares_;
|
||||
std::vector<uint64_t> buckets_;
|
||||
|
||||
// To be able to use HistogramImpl as thread local variable, its constructor
|
||||
// has to be static. That's why we're using manually values from BucketMapper
|
||||
double min_ = 1000000000; // this is BucketMapper:LastValue()
|
||||
double max_ = 0;
|
||||
double num_ = 0;
|
||||
double sum_ = 0;
|
||||
double sum_squares_ = 0;
|
||||
uint64_t buckets_[138] = {0}; // this is BucketMapper::BucketCount()
|
||||
};
|
||||
|
||||
} // namespace rocksdb
|
||||
|
||||
@@ -3,12 +3,51 @@
|
||||
// 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.
|
||||
//
|
||||
#include "util/statistics.h"
|
||||
#include "rocksdb/statistics.h"
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
std::shared_ptr<Statistics> CreateDBStatistics() {
|
||||
return std::make_shared<StatisticsImpl>();
|
||||
}
|
||||
|
||||
StatisticsImpl::StatisticsImpl()
|
||||
: tickers_(TICKER_ENUM_MAX),
|
||||
histograms_(HISTOGRAM_ENUM_MAX) {}
|
||||
|
||||
StatisticsImpl::~StatisticsImpl() {}
|
||||
|
||||
long StatisticsImpl::getTickerCount(Tickers tickerType) {
|
||||
assert(tickerType < TICKER_ENUM_MAX);
|
||||
return tickers_[tickerType];
|
||||
}
|
||||
|
||||
void StatisticsImpl::setTickerCount(Tickers tickerType, uint64_t count) {
|
||||
assert(tickerType < TICKER_ENUM_MAX);
|
||||
tickers_[tickerType] = count;
|
||||
}
|
||||
|
||||
void StatisticsImpl::recordTick(Tickers tickerType, uint64_t count) {
|
||||
assert(tickerType < TICKER_ENUM_MAX);
|
||||
tickers_[tickerType] += count;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// a buffer size used for temp string buffers
|
||||
const int kBufferSize = 200;
|
||||
|
||||
@@ -32,11 +71,8 @@ std::string HistogramToString (
|
||||
return std::string(buffer);
|
||||
};
|
||||
|
||||
std::string TickerToString (
|
||||
Statistics* dbstats,
|
||||
const Tickers& ticker,
|
||||
const std::string& name) {
|
||||
|
||||
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));
|
||||
|
||||
56
util/statistics.h
Normal file
56
util/statistics.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// 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.
|
||||
//
|
||||
#pragma once
|
||||
#include "rocksdb/statistics.h"
|
||||
#include "util/histogram.h"
|
||||
#include "util/mutexlock.h"
|
||||
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
#define UNLIKELY(val) (__builtin_expect((val), 0))
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
class StatisticsImpl : public Statistics {
|
||||
public:
|
||||
StatisticsImpl();
|
||||
virtual ~StatisticsImpl();
|
||||
|
||||
virtual long getTickerCount(Tickers tickerType);
|
||||
virtual void setTickerCount(Tickers tickerType, uint64_t count);
|
||||
virtual void recordTick(Tickers tickerType, uint64_t count);
|
||||
virtual void measureTime(Histograms histogramType, uint64_t value);
|
||||
virtual void histogramData(Histograms histogramType,
|
||||
HistogramData* const data);
|
||||
|
||||
private:
|
||||
std::vector<std::atomic_uint_fast64_t> tickers_;
|
||||
std::vector<HistogramImpl> histograms_;
|
||||
};
|
||||
|
||||
// Utility functions
|
||||
inline void MeasureTime(Statistics* statistics, Histograms histogramType,
|
||||
uint64_t value) {
|
||||
if (statistics) {
|
||||
statistics->measureTime(histogramType, value);
|
||||
}
|
||||
}
|
||||
|
||||
inline void RecordTick(Statistics* statistics, Tickers ticker,
|
||||
uint64_t count = 1) {
|
||||
if (statistics) {
|
||||
statistics->recordTick(ticker, count);
|
||||
}
|
||||
}
|
||||
|
||||
inline void SetTickerCount(Statistics* statistics, Tickers ticker,
|
||||
uint64_t count) {
|
||||
if (statistics) {
|
||||
statistics->setTickerCount(ticker, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// 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.
|
||||
//
|
||||
#pragma once
|
||||
#include "rocksdb/statistics.h"
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
// Utility functions
|
||||
inline void RecordTick(Statistics* statistics,
|
||||
Tickers ticker,
|
||||
int64_t count = 1) {
|
||||
assert(HistogramsNameMap.size() == HISTOGRAM_ENUM_MAX);
|
||||
assert(TickersNameMap.size() == TICKER_ENUM_MAX);
|
||||
if (statistics) {
|
||||
statistics->recordTick(ticker, count);
|
||||
}
|
||||
}
|
||||
|
||||
inline void SetTickerCount(Statistics* statistics,
|
||||
Tickers ticker,
|
||||
uint64_t count) {
|
||||
assert(HistogramsNameMap.size() == HISTOGRAM_ENUM_MAX);
|
||||
assert(TickersNameMap.size() == TICKER_ENUM_MAX);
|
||||
if (statistics) {
|
||||
statistics->setTickerCount(ticker, count);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
//
|
||||
#pragma once
|
||||
#include "rocksdb/env.h"
|
||||
#include "util/statistics_imp.h"
|
||||
#include "util/statistics.h"
|
||||
|
||||
namespace rocksdb {
|
||||
// Auto-scoped.
|
||||
@@ -28,11 +28,7 @@ class StopWatch {
|
||||
return env_->NowMicros() - start_time_;
|
||||
}
|
||||
|
||||
~StopWatch() {
|
||||
if (statistics_) {
|
||||
statistics_->measureTime(histogram_name_, ElapsedMicros());
|
||||
}
|
||||
}
|
||||
~StopWatch() { MeasureTime(statistics_, histogram_name_, ElapsedMicros()); }
|
||||
|
||||
private:
|
||||
Env* const env_;
|
||||
|
||||
Reference in New Issue
Block a user