Commit ad8e104a authored by Philip Pronin's avatar Philip Pronin Committed by Jordan DeLong

Histogram function to write tab-separated values.

Summary: Export histograms in a tab-separated format.

Test Plan: Used it.

Reviewed By: lucian@fb.com
parent 6ea306c4
...@@ -242,15 +242,28 @@ std::string Histogram<T>::debugString() const { ...@@ -242,15 +242,28 @@ std::string Histogram<T>::debugString() const {
", bucketSize: ", buckets_.getBucketSize(), ", bucketSize: ", buckets_.getBucketSize(),
", min: ", buckets_.getMin(), ", max: ", buckets_.getMax(), "\n"); ", min: ", buckets_.getMin(), ", max: ", buckets_.getMax(), "\n");
for (unsigned int n = 0; n < buckets_.getNumBuckets(); ++n) { for (unsigned int i = 0; i < buckets_.getNumBuckets(); ++i) {
folly::toAppend(" ", buckets_.getBucketMin(n), ": ", folly::toAppend(" ", buckets_.getBucketMin(i), ": ",
buckets_.getByIndex(n).count, "\n", buckets_.getByIndex(i).count, "\n",
&ret); &ret);
} }
return 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 } // folly
#endif // FOLLY_HISTOGRAM_INL_H_ #endif // FOLLY_HISTOGRAM_INL_H_
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <cstddef> #include <cstddef>
#include <limits> #include <limits>
#include <ostream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <stdexcept> #include <stdexcept>
...@@ -367,6 +368,12 @@ class Histogram { ...@@ -367,6 +368,12 @@ class Histogram {
*/ */
std::string debugString() const; 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: private:
struct CountFromBucket { struct CountFromBucket {
uint64_t operator()(const Bucket& bucket) const { uint64_t operator()(const Bucket& bucket) const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment