]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Simple way to get a repeated 1-2-5 sequence of histograms
authorOtto <otto.moerbeek@open-xchange.com>
Fri, 26 Feb 2021 09:43:21 +0000 (10:43 +0100)
committerOtto <otto.moerbeek@open-xchange.com>
Tue, 29 Jun 2021 13:04:29 +0000 (15:04 +0200)
pdns/histogram.hh

index 039829b057ee00a1e5fe73c9c1e469dc82b5a327..f3c34fe57cbf530ebe0d42eaa25968d9a2792caf 100644 (file)
@@ -57,6 +57,7 @@ template <class B>
 class BaseHistogram
 {
 public:
+
   BaseHistogram(const std::string& prefix, const std::vector<uint64_t>& 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<uint64_t>::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<B>& getRawData() const
   {
     return d_buckets;
@@ -131,6 +143,31 @@ public:
 private:
   std::vector<B> d_buckets;
   std::string d_name;
+
+
+  std::vector<uint64_t> to125(uint64_t start, int num)
+  {
+    std::vector<uint64_t> 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 <class T>