userver: userver/utils/statistics/histogram_view.hpp Source File
Loading...
Searching...
No Matches
histogram_view.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/utils/statistics/histogram_view.hpp
4/// @brief @copybrief utils::statistics::HistogramView
5
6#include <cstddef>
7#include <cstdint>
8#include <type_traits>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace utils::statistics {
13
14class Writer;
15
16namespace impl::histogram {
17struct Bucket;
18struct Access;
19} // namespace impl::histogram
20
21/// @brief The non-owning reader API for "histogram" metrics.
22///
23/// @see utils::statistics::Histogram for details on semantics
24///
25/// HistogramView is cheap to copy, expected to be passed around by value.
26class HistogramView final {
27 public:
28 // trivially copyable
29 HistogramView(const HistogramView&) noexcept = default;
30 HistogramView& operator=(const HistogramView&) noexcept = default;
31
32 /// Returns the number of "normal" (non-"infinity") buckets.
33 std::size_t GetBucketCount() const noexcept;
34
35 /// Returns the upper bucket boundary for the given bucket.
36 double GetUpperBoundAt(std::size_t index) const;
37
38 /// Returns the occurrence count for the given bucket.
39 std::uint64_t GetValueAt(std::size_t index) const;
40
41 /// Returns the occurrence count for the "infinity" bucket
42 /// (greater than the largest bucket boundary).
43 std::uint64_t GetValueAtInf() const noexcept;
44
45 /// Returns the sum of counts from all buckets.
46 std::uint64_t GetTotalCount() const noexcept;
47
48 private:
49 friend struct impl::histogram::Access;
50
51 explicit HistogramView(const impl::histogram::Bucket* buckets) noexcept;
52
53 const impl::histogram::Bucket* buckets_;
54};
55
56/// Compares equal if bounds are close and values are equal.
57bool operator==(HistogramView lhs, HistogramView rhs) noexcept;
58
59/// @overload
60bool operator!=(HistogramView lhs, HistogramView rhs) noexcept;
61
62} // namespace utils::statistics
63
64USERVER_NAMESPACE_END