10#include "utility/module.hpp"
11#include "concurrency/module.hpp"
12#include "time_stamp_count.hpp"
23namespace hi::inline
v1 {
36 hilet lock = std::scoped_lock(_mutex);
37 hilet& map_ = _map.get_or_make();
38 hilet it = map_.find(name);
39 if (it == map_.cend()) {
54 operator uint64_t() const noexcept
56 return _total_count.load(std::memory_order::relaxed);
59 static void log() noexcept
61 hilet lock = std::scoped_lock(_mutex);
63 for (
hilet & [
string, counter ] : _map.get_or_make()) {
69 static void log_header() noexcept;
73 void log(
std::
string const& tag) noexcept;
75 uint64_t operator++() noexcept
77 return _total_count.fetch_add(1, std::memory_order::relaxed) + 1;
80 uint64_t operator++(
int)
noexcept
82 return _total_count.fetch_add(1, std::memory_order::relaxed);
85 uint64_t operator--() noexcept
87 return _total_count.fetch_sub(1, std::memory_order::relaxed) + 1;
90 uint64_t operator--(
int)
noexcept
92 return _total_count.fetch_sub(1, std::memory_order::relaxed);
99 _total_count.fetch_add(1, std::memory_order::relaxed);
100 fetch_max(_duration_max, duration, std::memory_order::relaxed);
101 fetch_min(_duration_min, duration, std::memory_order::relaxed);
107 _duration_avg.fetch_add(duration, std::memory_order::relaxed);
116 constinit static inline unfair_mutex_impl<false> _mutex;
132template<fixed_
string Tag>
137 hilet lock = std::scoped_lock(_mutex);
144template<fixed_
string Tag>
149 return detail::counter::get_if(name);
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:184
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
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:26
static counter * get_if(std::string const &name) noexcept
Get the named counter.
Definition counters.hpp:34
void add_duration(uint64_t duration) noexcept
Add a duration.
Definition counters.hpp:97
Definition counters.hpp:133