27 RCSIDH(time_tracking_h,
"$Id: 2970c8df92ff346efcd2653682027e99efa750d3 $")
33 #include <freeradius-devel/util/debug.h>
34 #include <freeradius-devel/util/table.h>
35 #include <freeradius-devel/util/time.h>
89 #define ASSERT_ON_TIME_TRAVEL(_tt, _now) \
91 fr_assert(fr_time_lteq((_tt)->last_changed, (_now))); \
92 fr_assert(fr_time_lteq((_tt)->started, (_now))); \
93 fr_assert(fr_time_lteq((_tt)->ended, (_now))); \
94 fr_assert(fr_time_lteq((_tt)->last_yielded, (_now))); \
95 fr_assert(fr_time_lteq((_tt)->last_resumed, (_now))); \
101 #define UPDATE_PARENT_START_TIME(_tt, _now) \
103 fr_time_tracking_t *_parent; \
104 for (_parent = (_tt)->parent; _parent; _parent = _parent->parent) { \
105 _parent->started = _now; \
106 _parent->last_changed = _now; \
113 #define UPDATE_PARENT_RUN_TIME(_tt, _run_time, _event, _now) \
115 fr_time_tracking_t *_parent; \
116 for (_parent = (_tt)->parent; _parent; _parent = _parent->parent) { \
117 _parent->_event = _now; \
118 _parent->last_changed = _now; \
119 _parent->running_total = fr_time_delta_add(_parent->running_total, _run_time); \
126 #define UPDATE_PARENT_WAIT_TIME(_tt, _wait_time, _event, _now) \
128 fr_time_tracking_t *_parent; \
129 for (_parent = (_tt)->parent; _parent; _parent = _parent->parent){ \
130 _parent->_event = _now; \
131 _parent->last_changed = _now; \
132 _parent->waiting_total = fr_time_delta_add(_parent->waiting_total, _wait_time); \
141 memset(tt, 0,
sizeof(*tt));
163 tt->started = tt->last_changed = tt->last_resumed = now;
262 #define RTT(_old, _new) fr_time_delta_wrap((fr_time_delta_unwrap(_new) + (fr_time_delta_unwrap(_old) * (IALPHA - 1))) / IALPHA)
301 #define DPRINT_TIME(_x) fprintf(fp, "\t" #_x " = %"PRIu64"\n", fr_time_unwrap(tt->_x))
302 #define DPRINT(_x) fprintf(fp, "\t" #_x " = %"PRIu64"\n", fr_time_delta_unwrap(tt->_x))
#define fr_assert_msg(_x, _msg,...)
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code...
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
An element in an arbitrarily ordered array of name to num mappings.
static fr_time_delta_t fr_time_delta_add(fr_time_delta_t a, fr_time_delta_t b)
#define fr_time_delta_ispos(_a)
#define fr_time_sub(_a, _b)
Subtract one time from another.
A time delta, a difference in time measured in nanoseconds.
fr_time_t last_changed
last time we changed a field
size_t fr_time_tracking_state_table_len
@ FR_TIME_TRACKING_YIELDED
We're currently tracking time in the yielded state.
@ FR_TIME_TRACKING_STOPPED
Time tracking is not running.
@ FR_TIME_TRACKING_RUNNING
We're currently tracking time in the running state.
fr_time_tracking_state_t state
What state we're currently in.
static void fr_time_tracking_yield(fr_time_tracking_t *tt, fr_time_t now)
Transition to the yielded state, recording the time we just spent running.
fr_time_t last_resumed
Last time this tracked entity or a child resumed;.
static void fr_time_tracking_end(fr_time_delta_t *predicted, fr_time_tracking_t *tt, fr_time_t now)
End time tracking for this entity.
fr_table_num_ordered_t fr_time_tracking_state_table[]
#define UPDATE_PARENT_WAIT_TIME(_tt, _wait_time, _event, _now)
Update total wait time up the list of parents.
#define UPDATE_PARENT_START_TIME(_tt, _now)
Set the last time a tracked entity started in its list of parents.
fr_time_t started
Last time this tracked entity or a child entered the running state, or entered a time tracked parent.
static void fr_time_tracking_init(fr_time_tracking_t *tt)
Initialise a time tracking structure.
static void fr_time_tracking_pop(fr_time_tracking_t *tt, fr_time_t now)
Tracked entity left a tracked nested code area.
fr_time_delta_t waiting_total
total time spent waiting
fr_time_delta_t running_total
total time spent running
fr_time_t ended
Last time this tracked entity or a child left the running state, or popped a time tracked parent.
static void fr_time_tracking_start(fr_time_tracking_t *parent, fr_time_tracking_t *tt, fr_time_t now)
Start time tracking for a tracked entity.
static void fr_time_tracking_resume(fr_time_tracking_t *tt, fr_time_t now)
Track that a request resumed.
fr_time_t last_yielded
Last time this tracked entity or a child yielded.
fr_time_tracking_t * parent
To update with our time tracking data when tracking is complete.
#define ASSERT_ON_TIME_TRAVEL(_tt, _now)
We use a monotonic time source.
#define UPDATE_PARENT_RUN_TIME(_tt, _run_time, _event, _now)
Update total run time up the list of parents.
static void fr_time_tracking_push(fr_time_tracking_t *parent, fr_time_tracking_t *tt, fr_time_t now)
Tracked entity entered a deeper time tracked code area.
static void fr_time_tracking_debug(fr_time_tracking_t *tt, FILE *fp)
Print debug information about the time tracking structure.