Flow 2.0.0
Flow project: Full implementation reference.
Namespaces | Enumerations | Functions
stat_fwd.hpp File Reference
#include <boost/type_traits/type_identity.hpp>
#include <atomic>
#include <iosfwd>
#include <string>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  flow
 Catch-all namespace for the Flow project: A collection of various production-quality modules written in modern C++17, originally by ygoldfel.
 
namespace  flow::util
 Flow module containing miscellaneous general-use facilities that don't fit into any other Flow module.
 
namespace  flow::util::stat
 Sub-module of flow::util providing lightweight facilities for working with simple structs of stat counters/gauges/etc.
 

Enumerations

enum class  flow::util::stat::Stat_type { flow::util::stat::S_ACCUMULATOR , flow::util::stat::S_GAUGE , flow::util::stat::S_HI_WMARK }
 Describes an individual member of a Stat_set, as decided by the user (you) via FLOW_UTIL_STAT_DECLARE(). More...
 

Functions

template<typename T >
const T & flow::util::stat::load (const T &val)
 Default load(stats.m_val) that simply return stats.m_val. More...
 
template<typename T >
T flow::util::stat::load (const std::atomic< T > &val)
 load(stats.m_val) that loads a copy of the value stored inside an atomic<T> stats.m_val. More...
 
template<typename T >
void flow::util::stat::store (T *target_val, const boost::type_identity_t< T > &val)
 Default store(&target_stats.m_val, val) that simply assigns *target_val = val. More...
 
template<typename T >
void flow::util::stat::store (std::atomic< T > *target_val, boost::type_identity_t< T > val)
 store(&target_stats.m_val, val) that stores a copy of val into an atomic<T> target_stats.m_val. More...
 
template<typename T >
void flow::util::stat::fetch_add (T *target_val, const boost::type_identity_t< T > &addend_val)
 Default fetch_add(&target_stats.m_val, addend_val) that simply applies *target_val += addend_val. More...
 
template<typename T >
T flow::util::stat::fetch_add (std::atomic< T > *target_val, boost::type_identity_t< T > addend_val)
 fetch_add(&target_stats.m_val, addend_val) that increments by addend_val value inside atomic<T> target_stats.m_val and returns the pre-change value. More...
 
template<typename T >
void flow::util::stat::fetch_sub (T *target_val, const boost::type_identity_t< T > &subtrahend_val)
 Default fetch_sub(&target_stats.m_val, _val) that simply applies *target_val -= subtrahend_val. More...
 
template<typename T >
T flow::util::stat::fetch_sub (std::atomic< T > *target_val, boost::type_identity_t< T > subtrahend_val)
 fetch_sub(&target_stats.m_val, subtrahend_val) that decrements by subtrahend_val value inside atomic<T> target_stats.m_val and returns the pre-change value. More...
 
template<typename T >
T flow::util::stat::exchange (std::atomic< T > *target_val, boost::type_identity_t< T > val)
 Equivalent to target_val->exchange(val, memory_order_relaxed); sets *target_val to val and returns the pre-change value. More...
 
template<typename T >
void flow::util::stat::update_hi_wmark (T *target_val, const boost::type_identity_t< T > &val)
 Default update_hi_wmark(&target_stats.m_val, val) that updates *target_val to val if and only if the latter exceeds the former. More...
 
template<typename T >
void flow::util::stat::update_hi_wmark (std::atomic< T > *target_val, boost::type_identity_t< T > val)
 update_hi_wmark(&target_stats.m_val, val) that stores copy of val value inside atomic<T> target_stats.m_val if and only if the latter is less-than the former. More...
 
template<typename T >
void flow::util::stat::reset (T *target_val, const T &fresh_val)
 Executes store(*target_val, load(fresh_val)). More...
 
void flow::util::stat::reset (Histogram_counter *target_val, const Histogram_counter &fresh_val)
 Executes target_val->clear(), where *target_val is a Histogram_counter. More...
 
template<typename Stat_set >
void flow::util::stat::stats_to_ostream (std::ostream &os, const Stat_set &stats)
 Outputs a human-readable representation of all declared stats in stats to the given ostream. More...
 
template<typename Stat_set , typename... Ctor_args>
std::vector< std::string > flow::util::stat::stats_field_names (Ctor_args &&... ctor_args)
 Returns the names of all declared stats of the given Stat_set type, in declaration order: the same names, in the same order, as in stats_to_ostream() output. More...
 
template<typename Stat_set >
void flow::util::stat::stats_reset (Stat_set *target_stats, const Stat_set &fresh_stats)
 With the help of a freshly-initialized Stat_set, resets the target Stat_set so as to immediately begin a fresh measurement period. More...
 
template<typename Stat_set >
void flow::util::stat::stats_assign (Stat_set *target_stats, const Stat_set &src_stats)
 Given a source Stat_set, makes the target Stat_set equal to the former. More...
 
template<typename Stat_set >
void flow::util::stat::stats_aggregate_one (Stat_set *target_stats, const Stat_set &src_stats)
 Aggregates the values from src_stats into *target_stats, in-place. More...
 
template<typename Stat_set , typename It >
void flow::util::stat::stats_aggregate (Stat_set *target_stats, const It &src_stats_begin, const It &src_stats_end)
 Aggregates N source Stat_sets – drawn from the iterator range [src_stats_begin, src_stats_end) – into *target_stats. More...
 
template<typename Stat_set , typename It >
void flow::util::stat::stats_sum (Stat_set *target_stats, const It &src_stats_begin, const It &src_stats_end)
 Equivalent to stats_aggregate() as-if every stat, regardless of its actual stat::Stat_type, is an ACCUMULATOR; that is simply computes the sum via += or equivalent. More...
 
template<typename Stat_set , typename It >
void flow::util::stat::stats_aggregate_shards (Stat_set *target_stats, const It &src_stats_begin, const It &src_stats_end, const Stat_set *fresh_stats_from_0_shards)
 Sharded-stats consumption: Aggregates N source Stat_sets, interpreted as shards of the aggregated whole – drawn from the iterator range [src_stats_begin, src_stats_end) – into *target_stats. More...
 
template<typename Stat_set , typename It >
void flow::util::stat::stats_reset_shard_aggregate (Stat_set *target_stats, const It &src_stats_begin, const It &src_stats_end, const Stat_set &fresh_stats_from_0_shards)
 Reset-stats companion to stats_aggregate_shards(); together the two functions provide support for the (TL-)sharded stat-collection pattern. More...
 
template<typename Stat_set >
void flow::util::stat::stats_since_reset_state (Stat_set *target_stats, Stat_set *reset_state)
 Intended for situations where the source of stat readings – including ACCUMULATORs and not just GAUGEs – is not by continuous sampling but rather by querying a data source (such as a library with its own stats outputs), this obtains a view of *target_stats (also placed back into *target_stats destructively) relative to a past reference point, *reset_state. More...
 
template<typename Stat_set >
void flow::util::stat::stats_mark_reset_state (Stat_set *target_stats)
 Sets each HI_WMARK-declared stat-member in *target_stats to its gauged-stat's current value in *target_stats; required for stats_since_reset_state() algorithm; may be useful otherwise as well. More...
 
template<typename Stat_set >
Stat_set_printable< Stat_set > flow::util::stat::print (const Stat_set &stats)
 Returns a lightweight proxy object that, when streamed via operator<<, pretty-prints the given Stat_set using stats_to_ostream(). More...
 
template<typename Stat_set >
std::ostream & flow::util::stat::operator<< (std::ostream &os, const Stat_set_printable< Stat_set > &printable)
 Prints string representation of the given printable.m_stats to the given ostream via stats_to_ostream(). More...
 
std::ostream & flow::util::stat::operator<< (std::ostream &os, const Histogram_counter &val)
 Prints string representation of the given Histogram_counter to the given ostream. More...