2013-10-16 23:59:46 +02:00
|
|
|
// 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.
|
|
|
|
//
|
2011-03-18 23:37:00 +01: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.
|
|
|
|
|
2013-10-05 07:32:05 +02:00
|
|
|
#pragma once
|
2013-08-23 17:38:13 +02:00
|
|
|
#include "rocksdb/statistics.h"
|
2013-02-15 20:53:17 +01:00
|
|
|
|
2013-01-29 21:23:31 +01:00
|
|
|
#include <cassert>
|
2011-03-18 23:37:00 +01:00
|
|
|
#include <string>
|
2013-01-29 21:23:31 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2015-07-02 02:21:38 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2013-01-29 21:23:31 +01:00
|
|
|
class HistogramBucketMapper {
|
|
|
|
public:
|
|
|
|
|
|
|
|
HistogramBucketMapper();
|
|
|
|
|
|
|
|
// converts a value to the bucket index.
|
2014-09-04 16:04:37 +02:00
|
|
|
size_t IndexForValue(const uint64_t value) const;
|
2013-01-29 21:23:31 +01:00
|
|
|
// number of buckets required.
|
|
|
|
|
2014-09-04 16:04:37 +02:00
|
|
|
size_t BucketCount() const {
|
2013-01-29 21:23:31 +01:00
|
|
|
return bucketValues_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LastValue() const {
|
|
|
|
return maxBucketValue_;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t FirstValue() const {
|
|
|
|
return minBucketValue_;
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:39:30 +01:00
|
|
|
uint64_t BucketLimit(const size_t bucketNumber) const {
|
2013-01-29 21:23:31 +01:00
|
|
|
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 20:53:17 +01:00
|
|
|
class HistogramImpl {
|
2011-03-18 23:37:00 +01:00
|
|
|
public:
|
2015-07-13 21:11:05 +02:00
|
|
|
HistogramImpl() { memset(buckets_, 0, sizeof(buckets_)); }
|
2013-02-15 20:53:17 +01:00
|
|
|
virtual void Clear();
|
2014-01-17 21:46:06 +01:00
|
|
|
virtual bool Empty();
|
2013-02-15 20:53:17 +01:00
|
|
|
virtual void Add(uint64_t 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 21:23:31 +01:00
|
|
|
|
2014-09-04 16:04:37 +02:00
|
|
|
virtual ~HistogramImpl() {}
|
|
|
|
|
2011-03-18 23:37:00 +01:00
|
|
|
private:
|
2014-01-17 21:46:06 +01:00
|
|
|
// 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;
|
2015-07-02 01:13:49 +02:00
|
|
|
uint64_t buckets_[138]; // this is BucketMapper::BucketCount()
|
2011-03-18 23:37:00 +01:00
|
|
|
};
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
} // namespace rocksdb
|