From: Otto Date: Fri, 26 Feb 2021 09:43:21 +0000 (+0100) Subject: Simple way to get a repeated 1-2-5 sequence of histograms X-Git-Tag: dnsdist-1.7.0-alpha1~116^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e616af3cd07c9c99a802e9ced59297a501639f6d;p=thirdparty%2Fpdns.git Simple way to get a repeated 1-2-5 sequence of histograms --- diff --git a/pdns/histogram.hh b/pdns/histogram.hh index 039829b057..f3c34fe57c 100644 --- a/pdns/histogram.hh +++ b/pdns/histogram.hh @@ -57,6 +57,7 @@ template class BaseHistogram { public: + BaseHistogram(const std::string& prefix, const std::vector& boundaries) : d_name(prefix) { if (!std::is_sorted(boundaries.cbegin(), boundaries.cend())) { @@ -78,10 +79,21 @@ public: d_buckets.emplace_back(str, b, 0); prev = b; } + // everything above last boundary d_buckets.emplace_back(prefix + "le-max", std::numeric_limits::max(), 0); } + BaseHistogram(const std::string& prefix, uint64_t start, int num) : + BaseHistogram(prefix, to125(start, num)) + { + } + + std::string getName() const + { + return d_name; + } + const std::vector& getRawData() const { return d_buckets; @@ -131,6 +143,31 @@ public: private: std::vector d_buckets; std::string d_name; + + + std::vector to125(uint64_t start, int num) + { + std::vector boundaries; + boundaries.reserve(num); + boundaries.emplace_back(start); + int i = 0; + while (true) { + if (++i >= num) { + break; + } + boundaries.push_back(2 * start); + if (++i >= num) { + break; + } + boundaries.push_back(5 * start); + if (++i >= num) { + break; + } + boundaries.push_back(10 * start); + start *= 10; + } + return boundaries; + } }; template