11#include "fixed_string.hpp"
12#include "time_stamp_count.hpp"
14#include "unfair_mutex.hpp"
24namespace hi::inline
v1 {
37 hilet lock = std::scoped_lock(_mutex);
38 hilet& map_ = _map.get_or_make();
39 hilet it = map_.find(name);
40 if (it == map_.cend()) {
55 operator uint64_t() const noexcept
57 return _total_count.load(std::memory_order::relaxed);
60 static void log() noexcept
62 hilet lock = std::scoped_lock(_mutex);
64 for (
hilet & [
string, counter ] : _map.get_or_make()) {
70 static void log_header() noexcept;
74 void log(
std::
string const& tag) noexcept;
76 uint64_t operator++() noexcept
78 return _total_count.fetch_add(1, std::memory_order::relaxed) + 1;
81 uint64_t operator++(
int)
noexcept
83 return _total_count.fetch_add(1, std::memory_order::relaxed);
86 uint64_t operator--() noexcept
88 return _total_count.fetch_sub(1, std::memory_order::relaxed) + 1;
91 uint64_t operator--(
int)
noexcept
93 return _total_count.fetch_sub(1, std::memory_order::relaxed);
100 _total_count.fetch_add(1, std::memory_order::relaxed);
101 fetch_max(_duration_max, duration, std::memory_order::relaxed);
102 fetch_min(_duration_min, duration, std::memory_order::relaxed);
108 _duration_avg.fetch_add(duration, std::memory_order::relaxed);
133template<fixed_
string Tag>
138 hilet lock = std::scoped_lock(_mutex);
145template<fixed_
string Tag>
150 return detail::counter::get_if(name);
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:87
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
Functions and macros for handling architectural difference between compilers, CPUs and operating syst...
DOXYGEN BUG.
Definition algorithm.hpp:15
T fetch_max(std::atomic< T > &lhs, T rhs, std::memory_order order) noexcept
Lock-free fetch-then-max operation on an atomic.
Definition atomic.hpp:22
T fetch_min(std::atomic< T > &lhs, T rhs, std::memory_order order) noexcept
Lock-free fetch-then-min operation on an atomic.
Definition atomic.hpp:36
Definition counters.hpp:27
static counter * get_if(std::string const &name) noexcept
Get the named counter.
Definition counters.hpp:35
void add_duration(uint64_t duration) noexcept
Add a duration.
Definition counters.hpp:98
Definition counters.hpp:134
An unfair mutex This is a fast implementation of a mutex which does not fairly arbitrate between mult...
Definition unfair_mutex.hpp:33