File: histogram.cpp

package info (click to toggle)
actor-framework 0.18.7-1~exp1
  • links: PTS
  • area: main
  • in suites: experimental
  • size: 8,740 kB
  • sloc: cpp: 85,162; sh: 491; python: 187; makefile: 11
file content (47 lines) | stat: -rw-r--r-- 1,508 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.

#define CAF_SUITE telemetry.histogram

#include "caf/telemetry/histogram.hpp"

#include "core-test.hpp"

#include <cmath>
#include <limits>

#include "caf/telemetry/gauge.hpp"

using namespace caf;
using namespace caf::telemetry;

CAF_TEST(double histograms use infinity for the last bucket) {
  dbl_histogram h1{.1, .2, .4, .8};
  CHECK_EQ(h1.buckets().size(), 5u);
  CHECK_EQ(h1.buckets().front().upper_bound, .1);
  CHECK(std::isinf(h1.buckets().back().upper_bound));
  CHECK_EQ(h1.sum(), 0.0);
}

CAF_TEST(integer histograms use int_max for the last bucket) {
  using limits = std::numeric_limits<int64_t>;
  int_histogram h1{1, 2, 4, 8};
  CHECK_EQ(h1.buckets().size(), 5u);
  CHECK_EQ(h1.buckets().front().upper_bound, 1);
  CHECK_EQ(h1.buckets().back().upper_bound, limits::max());
  CHECK_EQ(h1.sum(), 0);
}

CAF_TEST(histograms aggregate to buckets and keep a sum) {
  int_histogram h1{2, 4, 8};
  for (int64_t value = 1; value < 11; ++value)
    h1.observe(value);
  auto buckets = h1.buckets();
  CAF_REQUIRE_EQUAL(buckets.size(), 4u);
  CHECK_EQ(buckets[0].count.value(), 2); // 1, 2
  CHECK_EQ(buckets[1].count.value(), 2); // 3, 4
  CHECK_EQ(buckets[2].count.value(), 4); // 5, 6, 7, 8
  CHECK_EQ(buckets[3].count.value(), 2); // 9, 10
  CHECK_EQ(h1.sum(), 55);
}