fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
5.1 KiB
145 lines
5.1 KiB
9 years ago
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||
7 years ago
|
// This source code is licensed under both the GPLv2 (found in the
|
||
|
// COPYING file in the root directory) and Apache 2.0 License
|
||
|
// (found in the LICENSE.Apache file in the root directory).
|
||
11 years ago
|
//
|
||
|
#pragma once
|
||
11 years ago
|
#include <atomic>
|
||
6 years ago
|
#include <map>
|
||
10 years ago
|
#include <string>
|
||
6 years ago
|
#include <vector>
|
||
10 years ago
|
|
||
8 years ago
|
#include "monitoring/histogram.h"
|
||
8 years ago
|
#include "port/likely.h"
|
||
|
#include "port/port.h"
|
||
2 years ago
|
#include "rocksdb/statistics.h"
|
||
8 years ago
|
#include "util/core_local.h"
|
||
10 years ago
|
#include "util/mutexlock.h"
|
||
8 years ago
|
|
||
|
#ifdef __clang__
|
||
|
#define ROCKSDB_FIELD_UNUSED __attribute__((__unused__))
|
||
|
#else
|
||
|
#define ROCKSDB_FIELD_UNUSED
|
||
|
#endif // __clang__
|
||
11 years ago
|
|
||
6 years ago
|
#ifndef STRINGIFY
|
||
|
#define STRINGIFY(x) #x
|
||
|
#define TOSTRING(x) STRINGIFY(x)
|
||
|
#endif
|
||
|
|
||
5 years ago
|
namespace ROCKSDB_NAMESPACE {
|
||
11 years ago
|
|
||
10 years ago
|
enum TickersInternal : uint32_t {
|
||
|
INTERNAL_TICKER_ENUM_START = TICKER_ENUM_MAX,
|
||
|
INTERNAL_TICKER_ENUM_MAX
|
||
|
};
|
||
|
|
||
|
enum HistogramsInternal : uint32_t {
|
||
|
INTERNAL_HISTOGRAM_START = HISTOGRAM_ENUM_MAX,
|
||
|
INTERNAL_HISTOGRAM_ENUM_MAX
|
||
|
};
|
||
|
|
||
6 years ago
|
class StatisticsImpl : public Statistics {
|
||
11 years ago
|
public:
|
||
6 years ago
|
StatisticsImpl(std::shared_ptr<Statistics> stats);
|
||
11 years ago
|
virtual ~StatisticsImpl();
|
||
3 years ago
|
const char* Name() const override { return kClassName(); }
|
||
|
static const char* kClassName() { return "BasicStatistics"; }
|
||
11 years ago
|
|
||
10 years ago
|
virtual uint64_t getTickerCount(uint32_t ticker_type) const override;
|
||
|
virtual void histogramData(uint32_t histogram_type,
|
||
|
HistogramData* const data) const override;
|
||
9 years ago
|
std::string getHistogramString(uint32_t histogram_type) const override;
|
||
10 years ago
|
|
||
|
virtual void setTickerCount(uint32_t ticker_type, uint64_t count) override;
|
||
8 years ago
|
virtual uint64_t getAndResetTickerCount(uint32_t ticker_type) override;
|
||
10 years ago
|
virtual void recordTick(uint32_t ticker_type, uint64_t count) override;
|
||
6 years ago
|
// The function is implemented for now for backward compatibility reason.
|
||
|
// In case a user explictly calls it, for example, they may have a wrapped
|
||
|
// Statistics object, passing the call to recordTick() into here, nothing
|
||
|
// will break.
|
||
|
void measureTime(uint32_t histogramType, uint64_t time) override {
|
||
|
recordInHistogram(histogramType, time);
|
||
|
}
|
||
6 years ago
|
virtual void recordInHistogram(uint32_t histogram_type,
|
||
|
uint64_t value) override;
|
||
10 years ago
|
|
||
8 years ago
|
virtual Status Reset() override;
|
||
10 years ago
|
virtual std::string ToString() const override;
|
||
6 years ago
|
virtual bool getTickerMap(std::map<std::string, uint64_t>*) const override;
|
||
10 years ago
|
virtual bool HistEnabledForType(uint32_t type) const override;
|
||
11 years ago
|
|
||
3 years ago
|
const Customizable* Inner() const override { return stats_.get(); }
|
||
|
|
||
11 years ago
|
private:
|
||
8 years ago
|
// If non-nullptr, forwards updates to the object pointed to by `stats_`.
|
||
|
std::shared_ptr<Statistics> stats_;
|
||
|
// Synchronizes anything that operates across other cores' local data,
|
||
8 years ago
|
// such that operations like Reset() can be performed atomically.
|
||
8 years ago
|
mutable port::Mutex aggregate_lock_;
|
||
10 years ago
|
|
||
8 years ago
|
// The ticker/histogram data are stored in this structure, which we will store
|
||
|
// per-core. It is cache-aligned, so tickers/histograms belonging to different
|
||
|
// cores can never share the same cache line.
|
||
|
//
|
||
|
// Alignment attributes expand to nothing depending on the platform
|
||
6 years ago
|
struct ALIGN_AS(CACHE_LINE_SIZE) StatisticsData {
|
||
8 years ago
|
std::atomic_uint_fast64_t tickers_[INTERNAL_TICKER_ENUM_MAX] = {{0}};
|
||
|
HistogramImpl histograms_[INTERNAL_HISTOGRAM_ENUM_MAX];
|
||
6 years ago
|
#ifndef HAVE_ALIGNED_NEW
|
||
8 years ago
|
char
|
||
|
padding[(CACHE_LINE_SIZE -
|
||
|
(INTERNAL_TICKER_ENUM_MAX * sizeof(std::atomic_uint_fast64_t) +
|
||
|
INTERNAL_HISTOGRAM_ENUM_MAX * sizeof(HistogramImpl)) %
|
||
7 years ago
|
CACHE_LINE_SIZE)] ROCKSDB_FIELD_UNUSED;
|
||
6 years ago
|
#endif
|
||
2 years ago
|
void* operator new(size_t s) { return port::cacheline_aligned_alloc(s); }
|
||
|
void* operator new[](size_t s) { return port::cacheline_aligned_alloc(s); }
|
||
|
void operator delete(void* p) { port::cacheline_aligned_free(p); }
|
||
|
void operator delete[](void* p) { port::cacheline_aligned_free(p); }
|
||
11 years ago
|
};
|
||
|
|
||
3 years ago
|
#ifndef TEST_CACHE_LINE_SIZE
|
||
2 years ago
|
static_assert(sizeof(StatisticsData) % CACHE_LINE_SIZE == 0,
|
||
|
"Expected " TOSTRING(CACHE_LINE_SIZE) "-byte aligned");
|
||
3 years ago
|
#endif
|
||
8 years ago
|
|
||
8 years ago
|
CoreLocalArray<StatisticsData> per_core_stats_;
|
||
8 years ago
|
|
||
8 years ago
|
uint64_t getTickerCountLocked(uint32_t ticker_type) const;
|
||
8 years ago
|
std::unique_ptr<HistogramImpl> getHistogramImplLocked(
|
||
|
uint32_t histogram_type) const;
|
||
8 years ago
|
void setTickerCountLocked(uint32_t ticker_type, uint64_t count);
|
||
11 years ago
|
};
|
||
|
|
||
|
// Utility functions
|
||
6 years ago
|
inline void RecordInHistogram(Statistics* statistics, uint32_t histogram_type,
|
||
|
uint64_t value) {
|
||
11 years ago
|
if (statistics) {
|
||
6 years ago
|
statistics->recordInHistogram(histogram_type, value);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
inline void RecordTimeToHistogram(Statistics* statistics,
|
||
|
uint32_t histogram_type, uint64_t value) {
|
||
|
if (statistics) {
|
||
|
statistics->reportTimeToHistogram(histogram_type, value);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
inline void RecordTick(Statistics* statistics, uint32_t ticker_type,
|
||
11 years ago
|
uint64_t count = 1) {
|
||
|
if (statistics) {
|
||
10 years ago
|
statistics->recordTick(ticker_type, count);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
inline void SetTickerCount(Statistics* statistics, uint32_t ticker_type,
|
||
11 years ago
|
uint64_t count) {
|
||
|
if (statistics) {
|
||
10 years ago
|
statistics->setTickerCount(ticker_type, count);
|
||
11 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
5 years ago
|
} // namespace ROCKSDB_NAMESPACE
|