userver: utils::statistics::MetricValue Class Reference
Loading...
Searching...
No Matches
utils::statistics::MetricValue Class Referencefinal

#include <userver/utils/statistics/metric_value.hpp>

Detailed Description

The value of a metric.

Cheap to copy, expected to be passed around by value.

A histogram is stored only as a utils::statistics::HistogramView. Its backing storage has to be kept alive separately.

Definition at line 27 of file metric_value.hpp.

Public Types

using RawType = std::variant<std::int64_t, double, Rate, HistogramView>

Public Member Functions

constexpr MetricValue () noexcept
 Creates an unspecified metric value.
 MetricValue (const MetricValue &)=default
MetricValue & operator= (const MetricValue &)=default
bool EqualsNumerically (const MetricValue &other) const noexcept
 Numeric comparison of two metric values.
std::int64_t AsInt () const
 Retrieve the value of an integer metric.
double AsFloat () const
 Retrieve the value of a floating-point metric.
Rate AsRate () const
 Retrieve the value of a utils::statistics::Rate metric.
bool IsRate () const noexcept
 Returns whether metric is a utils::statistics::Rate metric.
HistogramView AsHistogram () const
 Retrieve the value of a utils::statistics::HistogramView metric.
bool IsHistogram () const noexcept
 Returns whether metric is a utils::statistics::HistogramView metric.
template<typename VisitorFunc>
decltype(auto) Visit (VisitorFunc visitor) const
 Calls visitor with the stored value.
constexpr MetricValue (std::int64_t value) noexcept
constexpr MetricValue (double value) noexcept
constexpr MetricValue (Rate value) noexcept
constexpr MetricValue (HistogramView value) noexcept

Member Typedef Documentation

◆ RawType

using utils::statistics::MetricValue::RawType = std::variant<std::int64_t, double, Rate, HistogramView>

Definition at line 29 of file metric_value.hpp.

Constructor & Destructor Documentation

◆ MetricValue() [1/5]

utils::statistics::MetricValue::MetricValue ( )
inlineconstexprnoexcept

Creates an unspecified metric value.

Definition at line 32 of file metric_value.hpp.

◆ MetricValue() [2/5]

utils::statistics::MetricValue::MetricValue ( std::int64_t value)
inlineconstexprnoexcept

Constructs utils::statistics::MetricValue for tests.

Definition at line 36 of file metric_value.hpp.

◆ MetricValue() [3/5]

utils::statistics::MetricValue::MetricValue ( double value)
inlineconstexprnoexcept

Definition at line 38 of file metric_value.hpp.

◆ MetricValue() [4/5]

utils::statistics::MetricValue::MetricValue ( Rate value)
inlineconstexprnoexcept

Definition at line 40 of file metric_value.hpp.

◆ MetricValue() [5/5]

utils::statistics::MetricValue::MetricValue ( HistogramView value)
inlineconstexprnoexcept

Definition at line 42 of file metric_value.hpp.

Member Function Documentation

◆ AsFloat()

double utils::statistics::MetricValue::AsFloat ( ) const
inline

Retrieve the value of a floating-point metric.

Exceptions
std::exceptionon type mismatch.

Definition at line 71 of file metric_value.hpp.

◆ AsHistogram()

HistogramView utils::statistics::MetricValue::AsHistogram ( ) const
inline

Retrieve the value of a utils::statistics::HistogramView metric.

Exceptions
std::exceptionon type mismatch.

Definition at line 82 of file metric_value.hpp.

◆ AsInt()

std::int64_t utils::statistics::MetricValue::AsInt ( ) const
inline

Retrieve the value of an integer metric.

Exceptions
std::exceptionon type mismatch.

Definition at line 67 of file metric_value.hpp.

◆ AsRate()

Rate utils::statistics::MetricValue::AsRate ( ) const
inline

Retrieve the value of a utils::statistics::Rate metric.

Exceptions
std::exceptionon type mismatch.

Definition at line 75 of file metric_value.hpp.

◆ EqualsNumerically()

bool utils::statistics::MetricValue::EqualsNumerically ( const MetricValue & other) const
noexcept

Numeric comparison of two metric values.

std::int64_t, double and utils::statistics::Rate compare as numbers: 4, 4.0 and Rate{4} are equal. A fractional double is not equal to a truncated integer. An integer that is not exactly representable as double is not equal to the rounded value.

utils::statistics::HistogramView compares as a histogram, via utils::statistics::operator==(HistogramView,HistogramView). Bucket sums are ignored. A histogram is not equal to a number.

◆ IsHistogram()

bool utils::statistics::MetricValue::IsHistogram ( ) const
inlinenoexcept

Returns whether metric is a utils::statistics::HistogramView metric.

Definition at line 85 of file metric_value.hpp.

◆ IsRate()

bool utils::statistics::MetricValue::IsRate ( ) const
inlinenoexcept

Returns whether metric is a utils::statistics::Rate metric.

Definition at line 78 of file metric_value.hpp.

◆ Visit()

template<typename VisitorFunc>
decltype(auto) utils::statistics::MetricValue::Visit ( VisitorFunc visitor) const
inline

Calls visitor with the stored value.

The argument has one of these types:

Returns
Whatever visitor returns.

Definition at line 97 of file metric_value.hpp.

◆ operator!=

bool operator!= ( const MetricValue & lhs,
const MetricValue & rhs )
friend

Definition at line 51 of file metric_value.hpp.

◆ operator==

bool operator== ( const MetricValue & lhs,
const MetricValue & rhs )
friend

Definition at line 49 of file metric_value.hpp.


The documentation for this class was generated from the following file: