histogram.h raw

   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    enum { kNumBuckets = 154 };
  25  
  26    double Median() const;
  27    double Percentile(double p) const;
  28    double Average() const;
  29    double StandardDeviation() const;
  30  
  31    static const double kBucketLimit[kNumBuckets];
  32  
  33    double min_;
  34    double max_;
  35    double num_;
  36    double sum_;
  37    double sum_squares_;
  38  
  39    double buckets_[kNumBuckets];
  40  };
  41  
  42  }  // namespace leveldb
  43  
  44  #endif  // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_
  45