Summary: I'm separating code-cleanup part of https://reviews.facebook.net/D14517. This will make D14517 easier to understand and this diff easier to review. Test Plan: make check Reviewers: haobo, kailiu, sdong, dhruba, tnovak Reviewed By: tnovak CC: leveldb Differential Revision: https://reviews.facebook.net/D15099main
parent
0f4a75b710
commit
83681bf9ef
@ -1,14 +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.
|
||||
|
||||
#include "db/db_statistics.h" |
||||
|
||||
namespace rocksdb { |
||||
|
||||
std::shared_ptr<Statistics> CreateDBStatistics() { |
||||
return std::make_shared<DBStatistics>(); |
||||
} |
||||
|
||||
} // namespace rocksdb
|
@ -1,63 +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.
|
||||
//
|
||||
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||
|
||||
#pragma once |
||||
#include <cassert> |
||||
#include <stdlib.h> |
||||
#include <vector> |
||||
#include <memory> |
||||
|
||||
#include "rocksdb/statistics.h" |
||||
#include "util/histogram.h" |
||||
#include "port/port.h" |
||||
#include "util/mutexlock.h" |
||||
|
||||
|
||||
namespace rocksdb { |
||||
|
||||
class DBStatistics: public Statistics { |
||||
public: |
||||
DBStatistics() : allTickers_(TICKER_ENUM_MAX), |
||||
allHistograms_(HISTOGRAM_ENUM_MAX) { } |
||||
|
||||
virtual ~DBStatistics() {} |
||||
|
||||
virtual long getTickerCount(Tickers tickerType) { |
||||
assert(tickerType < TICKER_ENUM_MAX); |
||||
return allTickers_[tickerType].getCount(); |
||||
} |
||||
|
||||
virtual void setTickerCount(Tickers tickerType, uint64_t count) { |
||||
assert(tickerType < TICKER_ENUM_MAX); |
||||
allTickers_[tickerType].setTickerCount(count); |
||||
} |
||||
|
||||
virtual void recordTick(Tickers tickerType, uint64_t count) { |
||||
assert(tickerType < TICKER_ENUM_MAX); |
||||
allTickers_[tickerType].recordTick(count); |
||||
} |
||||
|
||||
virtual void measureTime(Histograms histogramType, uint64_t value) { |
||||
assert(histogramType < HISTOGRAM_ENUM_MAX); |
||||
allHistograms_[histogramType].Add(value); |
||||
} |
||||
|
||||
virtual void histogramData(Histograms histogramType, |
||||
HistogramData * const data) { |
||||
assert(histogramType < HISTOGRAM_ENUM_MAX); |
||||
allHistograms_[histogramType].Data(data); |
||||
} |
||||
|
||||
std::vector<Ticker> allTickers_; |
||||
std::vector<HistogramImpl> allHistograms_; |
||||
}; |
||||
|
||||
std::shared_ptr<Statistics> CreateDBStatistics(); |
||||
|
||||
} // namespace rocksdb
|
@ -0,0 +1,53 @@ |
||||
// 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" |
||||
|
||||
#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::atomic_uint_fast64_t tickers_[TICKER_ENUM_MAX]; |
||||
HistogramImpl histograms_[HISTOGRAM_ENUM_MAX]; |
||||
}; |
||||
|
||||
// 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, |
||||
uint64_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); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue