Permalink
Browse files

Histogram function to write tab-separated values.

Summary: Export histograms in a tab-separated format.

Test Plan: Used it.

Reviewed By: lucian@fb.com
  • Loading branch information...
philippv authored and jdelong committed Sep 1, 2012
1 parent 6ea306c commit ad8e104a2fee25b0adaefe05286df0b84854ac90
Showing with 23 additions and 3 deletions.
  1. +16 −3 folly/Histogram-inl.h
  2. +7 −0 folly/Histogram.h
View
@@ -242,15 +242,28 @@ std::string Histogram<T>::debugString() const {
", bucketSize: ", buckets_.getBucketSize(),
", min: ", buckets_.getMin(), ", max: ", buckets_.getMax(), "\n");
- for (unsigned int n = 0; n < buckets_.getNumBuckets(); ++n) {
- folly::toAppend(" ", buckets_.getBucketMin(n), ": ",
- buckets_.getByIndex(n).count, "\n",
+ for (unsigned int i = 0; i < buckets_.getNumBuckets(); ++i) {
+ folly::toAppend(" ", buckets_.getBucketMin(i), ": ",
+ buckets_.getByIndex(i).count, "\n",
&ret);
}
return ret;
}
+template <typename T>
+void Histogram<T>::toTSV(std::ostream& out, bool skipEmptyBuckets) const {
+ for (unsigned int i = 0; i < buckets_.getNumBuckets(); ++i) {
+ // Do not output empty buckets in order to reduce data file size.
+ if (skipEmptyBuckets && getBucketByIndex(i).count == 0) {
+ continue;
+ }
+ const auto& bucket = getBucketByIndex(i);
+ out << getBucketMin(i) << '\t' << getBucketMax(i) << '\t'
+ << bucket.count << '\t' << bucket.sum << '\n';
+ }
+}
+
} // folly
#endif // FOLLY_HISTOGRAM_INL_H_
View
@@ -19,6 +19,7 @@
#include <cstddef>
#include <limits>
+#include <ostream>
#include <string>
#include <vector>
#include <stdexcept>
@@ -367,6 +368,12 @@ class Histogram {
*/
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 {

0 comments on commit ad8e104

Please sign in to comment.