|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <memory> |
| 4 | + |
| 5 | +#include <userver/utils/span.hpp> |
| 6 | +#include <userver/utils/statistics/fwd.hpp> |
| 7 | +#include <userver/utils/statistics/histogram_view.hpp> |
| 8 | + |
| 9 | +/// @file userver/utils/statistics/histogram_aggregator.hpp |
| 10 | +/// @brief @copybrief utils::statistics::HistogramAggregator |
| 11 | + |
| 12 | +USERVER_NAMESPACE_BEGIN |
| 13 | + |
| 14 | +namespace utils::statistics { |
| 15 | + |
| 16 | +/// @brief Used to aggregate multiple utils::statistics::Histogram metrics. |
| 17 | +/// |
| 18 | +/// Usage example: |
| 19 | +/// @snippet utils/statistics/histogram_test.cpp HistogramAggregator |
| 20 | +class HistogramAggregator final { |
| 21 | + public: |
| 22 | + explicit HistogramAggregator(utils::span<const double> upper_bounds); |
| 23 | + |
| 24 | + HistogramAggregator(HistogramAggregator&&) noexcept; |
| 25 | + HistogramAggregator& operator=(HistogramAggregator&&) noexcept; |
| 26 | + ~HistogramAggregator(); |
| 27 | + |
| 28 | + /// @brief Add the other histogram to the current one. |
| 29 | + /// |
| 30 | + /// Bucket borders in `this` and `other` must be either identical, or bucket |
| 31 | + /// borders in `this` must be a strict subset of bucket borders in `other`. |
| 32 | + /// |
| 33 | + /// Writes to `*this` are non-atomic. |
| 34 | + void Add(HistogramView other); |
| 35 | + |
| 36 | + /// Allows reading the histogram. |
| 37 | + HistogramView GetView() const& noexcept; |
| 38 | + |
| 39 | + /// @cond |
| 40 | + // Store Histogram in a variable before taking a view on it. |
| 41 | + HistogramView GetView() && noexcept = delete; |
| 42 | + /// @endcond |
| 43 | + |
| 44 | + private: |
| 45 | + std::unique_ptr<impl::histogram::Bucket[]> buckets_; |
| 46 | +}; |
| 47 | + |
| 48 | +/// Metric serialization support for HistogramAggregator. |
| 49 | +void DumpMetric(Writer& writer, const HistogramAggregator& histogram); |
| 50 | + |
| 51 | +} // namespace utils::statistics |
| 52 | + |
| 53 | +USERVER_NAMESPACE_END |
0 commit comments