userver
C++ Async Framework
Toggle main menu visibility
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
10
#
include
<
fmt
/
format
.
h
>
11
12
USERVER_NAMESPACE_BEGIN
13
14
namespace
utils
::
statistics
{
15
16
class
Writer;
17
18
namespace
impl::histogram {
19
struct
Bucket;
20
struct
Access;
21
}
// namespace impl::histogram
22
23
/// @ingroup userver_universal
24
///
25
/// @brief The non-owning reader API for "histogram" metrics.
26
///
27
/// @see utils::statistics::Histogram for details on semantics
28
///
29
/// HistogramView is cheap to copy, expected to be passed around by value.
30
class
HistogramView
final
{
31
public
:
32
// trivially copyable
33
constexpr
HistogramView(
const
HistogramView&)
noexcept
=
default
;
34
constexpr
HistogramView& operator=(
const
HistogramView&)
noexcept
=
default
;
35
36
/// Returns the number of "normal" (non-"infinity") buckets.
37
std::size_t
GetBucketCount
()
const
noexcept
;
38
39
/// Returns the upper bucket boundary for the given bucket.
40
double
GetUpperBoundAt
(std::size_t index)
const
;
41
42
/// Returns the occurrence count for the given bucket.
43
std::
uint64_t
GetValueAt
(std::size_t index)
const
;
44
45
/// Returns the occurrence count for the "infinity" bucket
46
/// (greater than the largest bucket boundary).
47
std::
uint64_t
GetValueAtInf
()
const
noexcept
;
48
49
/// Returns the sum of counts from all buckets.
50
std::
uint64_t
GetTotalCount
()
const
noexcept
;
51
52
/// Returns sum of values from the given bucket.
53
double
GetSumAt
(std::size_t index)
const
;
54
55
// Returns sum of values from the "infinity" bucket
56
/// (greater than the largest bucket boundary).
57
double
GetSumAtInf
()
const
noexcept
;
58
59
/// Returns sum of values from all buckets.
60
double
GetTotalSum
()
const
noexcept
;
61
62
private
:
63
friend
struct
impl::histogram::Access;
64
65
constexpr
explicit
HistogramView(
const
impl::histogram::Bucket& buckets)
noexcept
: buckets_(&buckets) {}
66
67
const
impl::histogram::Bucket* buckets_;
68
};
69
70
/// Compares equal if bounds are close and values are equal.
71
bool
operator
==(HistogramView lhs, HistogramView rhs)
noexcept
;
72
73
}
// namespace utils::statistics
74
75
USERVER_NAMESPACE_END
76
77
template
<>
78
struct
fmt
::
formatter
<USERVER_NAMESPACE::
utils
::
statistics
::HistogramView> {
79
constexpr
static
auto
parse(format_parse_context& ctx) {
return
ctx.begin(); }
80
81
template
<
typename
FormatCtx>
82
auto
format(USERVER_NAMESPACE::
utils
::
statistics
::HistogramView histogram, FormatCtx& ctx)
const
{
83
const
auto
bucket_count = histogram
.
GetBucketCount
(
)
;
84
for
(std::size_t i = 0; i < bucket_count; ++i) {
85
ctx.advance_to(fmt::format_to(ctx.out(),
"[{}]={}"
, histogram
.
GetUpperBoundAt
(
i
)
, histogram
.
GetValueAt
(
i
)
));
86
ctx.advance_to(fmt::format_to(ctx.out(),
","
));
87
}
88
ctx.advance_to(fmt::format_to(ctx.out(),
"[inf]={}"
, histogram
.
GetValueAtInf
(
)
));
89
return
ctx.out();
90
}
91
};
userver
utils
statistics
histogram_view.hpp
Generated on
for userver by
Doxygen
1.17.0