userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
percentile_format_json.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/utils/statistics/percentile_format_json.hpp
4
/// @brief JSON formatting helpers for percentile metrics
5
6
#
include
<
initializer_list
>
7
8
#
include
<
userver
/
formats
/
json
/
value_builder
.
hpp
>
9
#
include
<
userver
/
utils
/
assert
.
hpp
>
10
#
include
<
userver
/
utils
/
statistics
/
metadata
.
hpp
>
11
#
include
<
userver
/
utils
/
statistics
/
percentile
.
hpp
>
12
13
USERVER_NAMESPACE_BEGIN
14
15
namespace
utils
::
statistics
{
16
17
std::string GetPercentileFieldName(
double
perc);
18
19
template
<
typename
T>
20
formats::
json
::ValueBuilder PercentileToJson(
const
T& perc, std::initializer_list<
double
> percents) {
21
static_assert
(
22
requires
(
const
T& t) { t.GetPercentile(0.0); },
23
"T must specify T::GetPercentile(double) returning "
24
"json-serializable value"
25
);
26
formats::
json
::ValueBuilder result;
27
for
(
const
double
percent : percents) {
28
result
[
GetPercentileFieldName(percent)
]
= perc.GetPercentile(percent);
29
}
30
utils
::
statistics
::
SolomonChildrenAreLabelValues
(
result
,
"percentile"
)
;
31
return
result;
32
}
33
34
template
<
typename
T>
35
formats::
json
::ValueBuilder PercentileToJson(
const
T& perc) {
36
return
PercentileToJson(perc, {0, 50, 90, 95, 98, 99, 99.6, 99.9, 100});
37
}
38
39
}
// namespace utils::statistics
40
41
USERVER_NAMESPACE_END
userver
utils
statistics
percentile_format_json.hpp
Generated on
for userver by
Doxygen
1.17.0