2011-03-18 22:37:00 +00: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_UTIL_HISTOGRAM_H_
|
|
|
|
#define STORAGE_LEVELDB_UTIL_HISTOGRAM_H_
|
|
|
|
|
2013-02-15 19:53:17 +00:00
|
|
|
#include "leveldb/statistics.h"
|
|
|
|
|
2013-01-29 20:23:31 +00:00
|
|
|
#include <cassert>
|
2011-03-18 22:37:00 +00:00
|
|
|
#include <string>
|
2013-01-29 20:23:31 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
namespace leveldb {
|
|
|
|
|
2013-01-29 20:23:31 +00:00
|
|
|
class HistogramBucketMapper {
|
|
|
|
public:
|
|
|
|
|
|
|
|
HistogramBucketMapper();
|
|
|
|
|
|
|
|
// converts a value to the bucket index.
|
|
|
|
const size_t IndexForValue(const uint64_t value) const;
|
|
|
|
// number of buckets required.
|
|
|
|
|
|
|
|
const size_t BucketCount() const {
|
|
|
|
return bucketValues_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LastValue() const {
|
|
|
|
return maxBucketValue_;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t FirstValue() const {
|
|
|
|
return minBucketValue_;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t BucketLimit(const uint64_t bucketNumber) const {
|
|
|
|
assert(bucketNumber < BucketCount());
|
|
|
|
return bucketValues_[bucketNumber];
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::vector<uint64_t> bucketValues_;
|
|
|
|
const uint64_t maxBucketValue_;
|
|
|
|
const uint64_t minBucketValue_;
|
|
|
|
std::map<uint64_t, uint64_t> valueIndexMap_;
|
|
|
|
};
|
|
|
|
|
2013-02-15 19:53:17 +00:00
|
|
|
class HistogramImpl {
|
2011-03-18 22:37:00 +00:00
|
|
|
public:
|
2013-02-15 19:53:17 +00:00
|
|
|
HistogramImpl();
|
|
|
|
virtual ~HistogramImpl() {}
|
|
|
|
virtual void Clear();
|
|
|
|
virtual void Add(uint64_t value);
|
|
|
|
virtual void Add(double value);
|
|
|
|
void Merge(const HistogramImpl& other);
|
|
|
|
|
|
|
|
virtual std::string ToString() const;
|
|
|
|
|
|
|
|
virtual double Median() const;
|
|
|
|
virtual double Percentile(double p) const;
|
|
|
|
virtual double Average() const;
|
|
|
|
virtual double StandardDeviation() const;
|
|
|
|
virtual void Data(HistogramData * const data) const;
|
2013-01-29 20:23:31 +00:00
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
private:
|
|
|
|
double min_;
|
|
|
|
double max_;
|
|
|
|
double num_;
|
|
|
|
double sum_;
|
|
|
|
double sum_squares_;
|
2013-01-29 20:23:31 +00:00
|
|
|
std::vector<uint64_t> buckets_;
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-10-31 17:22:06 +00:00
|
|
|
} // namespace leveldb
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
#endif // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_
|