#define FOLLY_HISTOGRAM_H_
#include <cstddef>
-#include <cstdint>
#include <limits>
+#include <ostream>
#include <string>
#include <vector>
#include <stdexcept>
+#include "folly/detail/Stats.h"
+
namespace folly {
namespace detail {
class Histogram {
public:
typedef T ValueType;
-
- struct Bucket {
- Bucket()
- : sum(0),
- count(0) {}
-
- void clear() {
- sum = 0;
- count = 0;
- }
-
- Bucket& merge(const Bucket &bucket) {
- if (this != &bucket) {
- sum += bucket.sum;
- count += bucket.count;
- }
- return *this;
- }
-
- Bucket& operator=(const Bucket& bucket) {
- if (this != &bucket) {
- sum = bucket.sum;
- count = bucket.count;
- }
- return *this;
- }
-
- ValueType sum;
- uint64_t count;
- };
+ typedef detail::Bucket<T> Bucket;
Histogram(ValueType bucketSize, ValueType min, ValueType max)
: buckets_(bucketSize, min, max, Bucket()) {}
}
for (int i = 0; i < buckets_.getNumBuckets(); i++) {
- buckets_.getByIndex(i).merge(hist.buckets_.getByIndex(i));
+ buckets_.getByIndex(i) += hist.buckets_.getByIndex(i);
}
}
*/
std::string debugString() const;
+ /*
+ * Write the histogram contents in tab-separated values (TSV) format.
+ * Format is "min max count sum".
+ */
+ void toTSV(std::ostream& out, bool skipEmptyBuckets = true) const;
+
private:
struct CountFromBucket {
uint64_t operator()(const Bucket& bucket) const {