1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 5 #ifndef STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 6 #define STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 7 8 #include <string> 9 10 namespace leveldb { 11 12 class Histogram { 13 public: 14 Histogram() { } 15 ~Histogram() { } 16 17 void Clear(); 18 void Add(double value); 19 void Merge(const Histogram& other); 20 21 std::string ToString() const; 22 23 private: 24 double min_; 25 double max_; 26 double num_; 27 double sum_; 28 double sum_squares_; 29 30 enum { kNumBuckets = 154 }; 31 static const double kBucketLimit[kNumBuckets]; 32 double buckets_[kNumBuckets]; 33 34 double Median() const; 35 double Percentile(double p) const; 36 double Average() const; 37 double StandardDeviation() const; 38 }; 39 40 } // namespace leveldb 41 42 #endif // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 43