2012-05-30 08:18:16 +02:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#ifndef STORAGE_LEVELDB_INCLUDE_STATISTICS_H_
|
|
|
|
#define STORAGE_LEVELDB_INCLUDE_STATISTICS_H_
|
|
|
|
|
2013-05-10 22:19:39 +02:00
|
|
|
#include <atomic>
|
2013-02-15 20:53:17 +01:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
|
|
|
|
2012-05-30 08:18:16 +02:00
|
|
|
namespace leveldb {
|
|
|
|
|
2012-11-03 05:02:40 +01:00
|
|
|
/**
|
|
|
|
* Keep adding ticker's here.
|
|
|
|
* Any ticker should have a value less than TICKER_ENUM_MAX.
|
|
|
|
* Add a new ticker by assigning it the current value of TICKER_ENUM_MAX
|
|
|
|
* And incrementing TICKER_ENUM_MAX.
|
|
|
|
*/
|
|
|
|
enum Tickers {
|
|
|
|
BLOCK_CACHE_MISS = 0,
|
|
|
|
BLOCK_CACHE_HIT = 1,
|
2012-11-09 03:18:34 +01:00
|
|
|
BLOOM_FILTER_USEFUL = 2, // no. of times bloom filter has avoided file reads.
|
|
|
|
/**
|
|
|
|
* COMPACTION_KEY_DROP_* count the reasons for key drop during compaction
|
|
|
|
* There are 3 reasons currently.
|
|
|
|
*/
|
|
|
|
COMPACTION_KEY_DROP_NEWER_ENTRY = 3, // key was written with a newer value.
|
|
|
|
COMPACTION_KEY_DROP_OBSOLETE = 4, // The key is obsolete.
|
|
|
|
COMPACTION_KEY_DROP_USER = 5, // user compaction function has dropped the key.
|
2013-01-16 01:48:22 +01:00
|
|
|
// Number of keys written to the database via the Put and Write call's
|
|
|
|
NUMBER_KEYS_WRITTEN = 6,
|
|
|
|
// Number of Keys read,
|
|
|
|
NUMBER_KEYS_READ = 7,
|
2013-02-21 04:22:13 +01:00
|
|
|
// Bytes written / read
|
|
|
|
BYTES_WRITTEN = 8,
|
|
|
|
BYTES_READ = 9,
|
2013-02-25 22:58:34 +01:00
|
|
|
NO_FILE_CLOSES = 10,
|
|
|
|
NO_FILE_OPENS = 11,
|
|
|
|
NO_FILE_ERRORS = 12,
|
|
|
|
TICKER_ENUM_MAX = 13,
|
2012-11-03 05:02:40 +01:00
|
|
|
};
|
|
|
|
|
2013-02-21 04:22:13 +01:00
|
|
|
|
2013-02-15 20:53:17 +01:00
|
|
|
/**
|
|
|
|
* Keep adding histogram's here.
|
|
|
|
* Any histogram whould have value less than HISTOGRAM_ENUM_MAX
|
|
|
|
* Add a new Histogram by assigning it the current value of HISTOGRAM_ENUM_MAX
|
|
|
|
* And increment HISTOGRAM_ENUM_MAX
|
|
|
|
*/
|
|
|
|
enum Histograms {
|
|
|
|
DB_GET = 0,
|
|
|
|
DB_WRITE = 1,
|
2013-02-22 01:23:33 +01:00
|
|
|
COMPACTION_TIME = 2,
|
|
|
|
HISTOGRAM_ENUM_MAX = 3,
|
2013-02-15 20:53:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct HistogramData {
|
|
|
|
double median;
|
|
|
|
double percentile95;
|
|
|
|
double percentile99;
|
|
|
|
double average;
|
|
|
|
double standard_deviation;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Histogram {
|
|
|
|
public:
|
|
|
|
// clear's the histogram
|
|
|
|
virtual void Clear() = 0;
|
|
|
|
virtual ~Histogram();
|
|
|
|
// Add a value to be recorded in the histogram.
|
|
|
|
virtual void Add(uint64_t value) = 0;
|
|
|
|
virtual void Add(double value) = 0;
|
|
|
|
|
|
|
|
virtual std::string ToString() const = 0;
|
|
|
|
|
|
|
|
// Get statistics
|
|
|
|
virtual double Median() const = 0;
|
|
|
|
virtual double Percentile(double p) const = 0;
|
|
|
|
virtual double Average() const = 0;
|
|
|
|
virtual double StandardDeviation() const = 0;
|
|
|
|
virtual void Data(HistogramData * const data) const = 0;
|
|
|
|
|
|
|
|
};
|
2012-11-03 05:02:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A dumb ticker which keeps incrementing through its life time.
|
|
|
|
* Not thread safe. Locking is currently managed by external leveldb lock
|
|
|
|
*/
|
|
|
|
class Ticker {
|
|
|
|
public:
|
|
|
|
Ticker() : count_(0) { }
|
|
|
|
|
|
|
|
inline void recordTick() {
|
|
|
|
count_++;
|
|
|
|
}
|
|
|
|
|
2013-01-16 01:48:22 +01:00
|
|
|
inline void recordTick(int count) {
|
|
|
|
count_ += count;
|
|
|
|
}
|
2013-02-15 20:53:17 +01:00
|
|
|
|
2012-11-03 05:02:40 +01:00
|
|
|
inline uint64_t getCount() {
|
|
|
|
return count_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-05-10 22:19:39 +02:00
|
|
|
std::atomic_uint_fast64_t count_;
|
2012-11-03 05:02:40 +01:00
|
|
|
};
|
|
|
|
|
2012-05-30 08:18:16 +02:00
|
|
|
// Analyze the performance of a db
|
|
|
|
class Statistics {
|
2012-11-03 05:02:40 +01:00
|
|
|
public:
|
2012-05-30 08:18:16 +02:00
|
|
|
|
2012-11-03 05:02:40 +01:00
|
|
|
virtual long getTickerCount(Tickers tickerType) = 0;
|
2013-01-16 01:48:22 +01:00
|
|
|
virtual void recordTick(Tickers tickerType, uint64_t count = 0) = 0;
|
2013-02-15 20:53:17 +01:00
|
|
|
virtual void measureTime(Histograms histogramType, uint64_t count) = 0;
|
|
|
|
virtual void measureTime(Histograms histogramType, double count) = 0;
|
|
|
|
|
|
|
|
virtual void histogramData(Histograms type, HistogramData * const data) = 0;
|
2012-11-03 05:02:40 +01:00
|
|
|
|
2012-05-30 08:18:16 +02:00
|
|
|
};
|
|
|
|
|
2012-11-03 05:02:40 +01:00
|
|
|
// Ease of Use functions
|
2013-03-27 19:27:39 +01:00
|
|
|
inline void RecordTick(std::shared_ptr<Statistics> statistics,
|
2013-01-16 01:48:22 +01:00
|
|
|
Tickers ticker,
|
|
|
|
uint64_t count = 1) {
|
2013-03-27 19:27:39 +01:00
|
|
|
if (statistics) {
|
2013-01-16 01:48:22 +01:00
|
|
|
statistics->recordTick(ticker, count);
|
2012-11-03 05:02:40 +01:00
|
|
|
}
|
2013-01-16 01:48:22 +01:00
|
|
|
}
|
2012-05-30 08:18:16 +02:00
|
|
|
} // namespace leveldb
|
|
|
|
|
|
|
|
#endif // STORAGE_LEVELDB_INCLUDE_STATISTICS_H_
|