userver: userver/utils/statistics/impl/histogram_bucket.hpp Source File
Loading...
Searching...
No Matches
histogram_bucket.hpp
1#pragma once
2
3#include <atomic>
4#include <cstddef>
5#include <cstdint>
6
7#include <userver/utils/span.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace utils::statistics {
12class Writer;
13class HistogramView;
14} // namespace utils::statistics
15
16namespace utils::statistics::impl::histogram {
17
18// The additional first HistogramBucket contains:
19// - size in 'upper_bound'
20// - inf count in 'counter'
21union BoundOrSize {
22 double bound;
23 std::size_t size;
24};
25
26struct Bucket final {
27 constexpr Bucket() noexcept = default;
28
29 Bucket(const Bucket& other) noexcept;
30 Bucket& operator=(const Bucket& other) noexcept;
31
32 BoundOrSize upper_bound{0.0};
33 std::atomic<std::uint64_t> counter{0};
34};
35
36void CopyBounds(Bucket* bucket_array, utils::span<const double> upper_bounds);
37
38void CopyBoundsAndValues(Bucket* destination_array, HistogramView source);
39
40void Account(Bucket* bucket_array, double value, std::uint64_t count) noexcept;
41
42void Add(Bucket* bucket_array, HistogramView other);
43
44void ResetMetric(Bucket* bucket_array) noexcept;
45
46HistogramView MakeView(const Bucket* bucket_array) noexcept;
47
48} // namespace utils::statistics::impl::histogram
49
50USERVER_NAMESPACE_END