FARGOS/VISTA Object Management Environment Core
..
|
Sliding window rate counter that takes O(1) time. More...
#include <rate_counter.hpp>
Public Member Functions | |
void | set_interval (uint64_t units) OME_ALWAYS_INLINE |
Set the size of the interval window in units of UNITS_PER_SECOND. More... | |
RateCounterForInterval (EVENT_COUNT_TYPE max_events, uint64_t units) | |
Construct an O(1) RateCounterForInterval object. More... | |
~RateCounterForInterval () | |
uint32_t | get_interval () const OME_ALWAYS_INLINE |
Get the length of the interval in units of UNITS_PER_SECOND. More... | |
uint32_t | get_interval_in_nanoseconds () const OME_ALWAYS_INLINE |
Get the length of the interval in nanoseconds. More... | |
EVENT_COUNT_TYPE | get_events_in_interval () const OME_ALWAYS_INLINE |
Get total number of events in the interval. More... | |
EVENT_COUNT_TYPE | get_maximum_rate () const OME_ALWAYS_INLINE |
Get the maximum permitted events per interval. More... | |
void | set_maximum_rate (EVENT_COUNT_TYPE max_events) OME_ALWAYS_INLINE |
Set the maximum permitted events per interval. More... | |
EVENT_COUNT_TYPE | add_events_to_slot (EVENT_COUNT_TYPE count=1, const struct timespec *now=nullptr) |
Add events to an interval. More... | |
Private Types | |
enum | { ONE_BILLION = 1000000000UL, NS_PER_UNITS = ONE_BILLION / UNITS_PER_SECOND } |
Private Attributes | |
EVENT_COUNT_TYPE * | event_slots |
storage for events-per-interval counters More... | |
EVENT_COUNT_TYPE | events_in_interval |
total events currently in the interval More... | |
EVENT_COUNT_TYPE | rate_threshold |
maximum permitted events in the interval More... | |
uint64_t | interval_in_units |
interval duration in UNITS_PER_SECOND More... | |
uint64_t | interval_in_nanoseconds |
interval duration in nanoseconds More... | |
uint64_t | interval_threshold_in_seconds |
coarse interval duration in seconds More... | |
struct timespec | last_time_used |
time of last recorded event More... | |
uint32_t | last_slot_used |
round-robin subscript for slot table More... | |
bool | changed_slot |
enables optimization if events are widely spaced More... | |
Sliding window rate counter that takes O(1) time.
EVENT_COUNT_TYPE | specifies the type to be used to hold the number of events within the interval. Typically this is an int32_t , but it might be a floating point or fixed-point value in some applications. |
UNITS_PER_SECOND | defines the granularity of the time units to be tracked. |
|
private |
|
inline |
Construct an O(1) RateCounterForInterval object.
max_events | specifies the maximum permissible events within an interval. |
units | specifies the length of the interval in units of UNITS_PER_SECOND. |
References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::event_slots, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::rate_threshold, and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_interval().
|
inline |
|
inline |
Add events to an interval.
count | specifies the number of events to be added. |
now | indicates the time associated with the events; if a null pointer is passed, the current time is assumed. |
References assignToZero(), RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::changed_slot, clock_gettime_via_tick(), RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::event_slots, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::events_in_interval, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_in_nanoseconds, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_in_units, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_threshold_in_seconds, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::last_slot_used, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::last_time_used, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::NS_PER_UNITS, OME_EXPECT_FALSE, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::ONE_BILLION, and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::rate_threshold.
|
inline |
Get total number of events in the interval.
References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::events_in_interval.
|
inline |
Get the length of the interval in units of UNITS_PER_SECOND.
References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_in_units.
|
inline |
Get the length of the interval in nanoseconds.
References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_in_nanoseconds.
|
inline |
Get the maximum permitted events per interval.
References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::rate_threshold.
|
inline |
Set the size of the interval window in units of UNITS_PER_SECOND.
units | specifies the duration of the interval in UNITS_PER_SECOND. |
References assignToZero(), RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::changed_slot, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::event_slots, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::events_in_interval, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_in_nanoseconds, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_in_units, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_threshold_in_seconds, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::last_slot_used, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::last_time_used, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::NS_PER_UNITS, and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::ONE_BILLION.
Referenced by RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::RateCounterForInterval().
|
inline |
Set the maximum permitted events per interval.
References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::rate_threshold.
|
private |
enables optimization if events are widely spaced
Referenced by RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::add_events_to_slot(), and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_interval().
|
private |
storage for events-per-interval counters
Referenced by RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::add_events_to_slot(), RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::RateCounterForInterval(), RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_interval(), and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::~RateCounterForInterval().
|
private |
total events currently in the interval
Referenced by RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::add_events_to_slot(), RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::get_events_in_interval(), and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_interval().
|
private |
interval duration in nanoseconds
Referenced by RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::add_events_to_slot(), RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::get_interval_in_nanoseconds(), and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_interval().
|
private |
interval duration in UNITS_PER_SECOND
Referenced by RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::add_events_to_slot(), RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::get_interval(), and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_interval().
|
private |
coarse interval duration in seconds
Referenced by RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::add_events_to_slot(), and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_interval().
|
private |
round-robin subscript for slot table
Referenced by RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::add_events_to_slot(), and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_interval().
|
private |
time of last recorded event
Referenced by RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::add_events_to_slot(), and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_interval().
|
private |
maximum permitted events in the interval
Referenced by RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::add_events_to_slot(), RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::get_maximum_rate(), RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::RateCounterForInterval(), and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_maximum_rate().
![]() | Generated: Fri Jul 31 2020 18:19:16
Support Information |