Go to the documentation of this file. 1 #ifndef _RATE_COUNTER_HPP_
2 #define _RATE_COUNTER_HPP_ "$Id: rate_counter.hpp 454 2020-07-23 20:22:23Z geoff $"
67 if (UNITS_PER_SECOND == 1) {
146 const struct timespec *now =
nullptr)
148 struct timespec system_time;
149 const struct timespec *current_time;
151 if (now !=
nullptr) {
155 current_time = &system_time;
158 int64_t delta_secs = current_time->tv_sec -
last_time_used.tv_sec;
159 int64_t delta_ns = current_time->tv_nsec -
last_time_used.tv_nsec;
181 for(uint_fast32_t i =
static_cast<uint_fast32_t
>(delta); i > 0; --i) {
@ NS_PER_UNITS
Definition: rate_counter.hpp:43
int clock_gettime_via_tick(struct timespec *result, bool force) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Definition: tick_time.h:290
uint32_t last_slot_used
round-robin subscript for slot table
Definition: rate_counter.hpp:52
struct timespec last_time_used
time of last recorded event
Definition: rate_counter.hpp:51
uint32_t get_interval() const OME_ALWAYS_INLINE
Get the length of the interval in units of UNITS_PER_SECOND.
Definition: rate_counter.hpp:105
EVENT_COUNT_TYPE get_maximum_rate() const OME_ALWAYS_INLINE
Get the maximum permitted events per interval.
Definition: rate_counter.hpp:123
EVENT_COUNT_TYPE get_events_in_interval() const OME_ALWAYS_INLINE
Get total number of events in the interval.
Definition: rate_counter.hpp:117
EVENT_COUNT_TYPE events_in_interval
total events currently in the interval
Definition: rate_counter.hpp:46
EVENT_COUNT_TYPE * event_slots
storage for events-per-interval counters
Definition: rate_counter.hpp:45
EVENT_COUNT_TYPE add_events_to_slot(EVENT_COUNT_TYPE count=1, const struct timespec *now=nullptr)
Add events to an interval.
Definition: rate_counter.hpp:145
const char srcID[]
Definition: catSym.c:17
RateCounterForInterval< int64_t > RateCounter64
Definition: rate_counter.hpp:202
RateCounterForInterval< int32_t > RateCounter
Definition: rate_counter.hpp:199
uint64_t interval_in_nanoseconds
interval duration in nanoseconds
Definition: rate_counter.hpp:49
~RateCounterForInterval()
Definition: rate_counter.hpp:98
const char srcID[] OME_USED
Definition: tick_time.cpp:24
void set_interval(uint64_t units) OME_ALWAYS_INLINE
Set the size of the interval window in units of UNITS_PER_SECOND.
Definition: rate_counter.hpp:64
RateCounterForInterval(EVENT_COUNT_TYPE max_events, uint64_t units)
Construct an O(1) RateCounterForInterval object.
Definition: rate_counter.hpp:91
Compiler-specific macros to provide performance-related hints.
#define OME_EXPECT_FALSE(expr)
Annotation macro for conditional expression expected to be false.
Definition: compiler_hints.h:540
#define OME_ALWAYS_INLINE
Tell the compiler to alway inline a function, regardless of optimization level.
Definition: compiler_hints.h:364
uint64_t interval_threshold_in_seconds
coarse interval duration in seconds
Definition: rate_counter.hpp:50
uint32_t get_interval_in_nanoseconds() const OME_ALWAYS_INLINE
Get the length of the interval in nanoseconds.
Definition: rate_counter.hpp:111
bool changed_slot
enables optimization if events are widely spaced
Definition: rate_counter.hpp:53
FARGOS CPU tick routines.
EVENT_COUNT_TYPE rate_threshold
maximum permitted events in the interval
Definition: rate_counter.hpp:47
void set_maximum_rate(EVENT_COUNT_TYPE max_events) OME_ALWAYS_INLINE
Set the maximum permitted events per interval.
Definition: rate_counter.hpp:129
void assignToZero(int32_t &n) OME_ALWAYS_INLINE
Assigns 0 to a 32-bit integer.
Definition: assignToZero.hpp:48
uint64_t interval_in_units
interval duration in UNITS_PER_SECOND
Definition: rate_counter.hpp:48
@ ONE_BILLION
Definition: rate_counter.hpp:42
Sliding window rate counter that takes O(1) time.
Definition: rate_counter.hpp:39