The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
time_tracking.h File Reference
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/table.h>
#include <freeradius-devel/util/time.h>
+ Include dependency graph for time_tracking.h:

Go to the source code of this file.

Data Structures

struct  fr_time_tracking_s
 

Macros

#define ASSERT_ON_TIME_TRAVEL(_tt, _now)
 We use a monotonic time source. More...
 
#define DPRINT(_x)   fprintf(fp, "\t" #_x " = %"PRIu64"\n", fr_time_delta_unwrap(tt->_x))
 
#define DPRINT_TIME(_x)   fprintf(fp, "\t" #_x " = %"PRIu64"\n", fr_time_unwrap(tt->_x))
 
#define IALPHA   (8)
 
#define RTT(_old, _new)   fr_time_delta_wrap((fr_time_delta_unwrap(_new) + (fr_time_delta_unwrap(_old) * (IALPHA - 1))) / IALPHA)
 
#define UPDATE_PARENT_RUN_TIME(_tt, _run_time, _event, _now)
 Update total run time up the list of parents. More...
 
#define UPDATE_PARENT_START_TIME(_tt, _now)
 Set the last time a tracked entity started in its list of parents. More...
 
#define UPDATE_PARENT_WAIT_TIME(_tt, _wait_time, _event, _now)
 Update total wait time up the list of parents. More...
 

Typedefs

typedef struct fr_time_tracking_s fr_time_tracking_t
 A structure to track the time spent processing a request. More...
 

Enumerations

enum  fr_time_tracking_state_t {
  FR_TIME_TRACKING_STOPPED = 0 ,
  FR_TIME_TRACKING_RUNNING ,
  FR_TIME_TRACKING_YIELDED
}
 

Functions

static void fr_time_tracking_debug (fr_time_tracking_t *tt, FILE *fp)
 Print debug information about the time tracking structure. More...
 
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. More...
 
static void fr_time_tracking_init (fr_time_tracking_t *tt)
 Initialise a time tracking structure. More...
 
static void fr_time_tracking_pop (fr_time_tracking_t *tt, fr_time_t now)
 Tracked entity left a tracked nested code area. More...
 
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. More...
 
static void fr_time_tracking_resume (fr_time_tracking_t *tt, fr_time_t now)
 Track that a request resumed. More...
 
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. More...
 
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. More...
 

Variables

fr_table_num_ordered_t fr_time_tracking_state_table []
 
size_t fr_time_tracking_state_table_len
 

Data Structure Documentation

◆ fr_time_tracking_s

struct fr_time_tracking_s

Definition at line 60 of file time_tracking.h.

+ Collaboration diagram for fr_time_tracking_s:
Data Fields
fr_time_t ended Last time this tracked entity or a child left the running state, or popped a time tracked parent.
fr_time_t last_changed last time we changed a field
fr_time_t last_resumed Last time this tracked entity or a child 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.
fr_time_delta_t running_total total time spent running
fr_time_t started Last time this tracked entity or a child entered the running state, or entered a time tracked parent.
fr_time_tracking_state_t state What state we're currently in.

only used for the leaf node.

fr_time_delta_t waiting_total total time spent waiting

Macro Definition Documentation

◆ ASSERT_ON_TIME_TRAVEL

#define ASSERT_ON_TIME_TRAVEL (   _tt,
  _now 
)
Value:
do { \
fr_assert(fr_time_lteq((_tt)->last_changed, (_now))); \
fr_assert(fr_time_lteq((_tt)->started, (_now))); \
fr_assert(fr_time_lteq((_tt)->ended, (_now))); \
fr_assert(fr_time_lteq((_tt)->last_yielded, (_now))); \
fr_assert(fr_time_lteq((_tt)->last_resumed, (_now))); \
} while(0)
#define fr_time_lteq(_a, _b)
Definition: time.h:240

We use a monotonic time source.

Definition at line 89 of file time_tracking.h.

◆ DPRINT

#define DPRINT (   _x)    fprintf(fp, "\t" #_x " = %"PRIu64"\n", fr_time_delta_unwrap(tt->_x))

◆ DPRINT_TIME

#define DPRINT_TIME (   _x)    fprintf(fp, "\t" #_x " = %"PRIu64"\n", fr_time_unwrap(tt->_x))

◆ IALPHA

#define IALPHA   (8)

Definition at line 261 of file time_tracking.h.

◆ RTT

#define RTT (   _old,
  _new 
)    fr_time_delta_wrap((fr_time_delta_unwrap(_new) + (fr_time_delta_unwrap(_old) * (IALPHA - 1))) / IALPHA)

Definition at line 262 of file time_tracking.h.

◆ UPDATE_PARENT_RUN_TIME

#define UPDATE_PARENT_RUN_TIME (   _tt,
  _run_time,
  _event,
  _now 
)
Value:
do { \
fr_time_tracking_t *_parent; \
for (_parent = (_tt)->parent; _parent; _parent = _parent->parent) { \
_parent->_event = _now; \
_parent->last_changed = _now; \
_parent->running_total = fr_time_delta_add(_parent->running_total, _run_time); \
} \
} while (0)
static fr_time_delta_t fr_time_delta_add(fr_time_delta_t a, fr_time_delta_t b)
Definition: time.h:255
static fr_slen_t parent
Definition: pair.h:844

Update total run time up the list of parents.

Definition at line 113 of file time_tracking.h.

◆ UPDATE_PARENT_START_TIME

#define UPDATE_PARENT_START_TIME (   _tt,
  _now 
)
Value:
do { \
fr_time_tracking_t *_parent; \
for (_parent = (_tt)->parent; _parent; _parent = _parent->parent) { \
_parent->started = _now; \
_parent->last_changed = _now; \
} \
} while (0)

Set the last time a tracked entity started in its list of parents.

Definition at line 101 of file time_tracking.h.

◆ UPDATE_PARENT_WAIT_TIME

#define UPDATE_PARENT_WAIT_TIME (   _tt,
  _wait_time,
  _event,
  _now 
)
Value:
do { \
fr_time_tracking_t *_parent; \
for (_parent = (_tt)->parent; _parent; _parent = _parent->parent){ \
_parent->_event = _now; \
_parent->last_changed = _now; \
_parent->waiting_total = fr_time_delta_add(_parent->waiting_total, _wait_time); \
} \
} while (0)

Update total wait time up the list of parents.

Definition at line 126 of file time_tracking.h.

Typedef Documentation

◆ fr_time_tracking_t

A structure to track the time spent processing a request.

The same structure is used by threads to track when they are running / waiting. The functions modifying fr_time_tracking_t all take an explicit "when" parameter. This parameter allows the thread to update a requests tracking structure, and then use that same fr_time_t to update the threads tracking structure.

While fr_time() is fast, it is also called very often. We should therefore be careful to call it only when necessary.

Definition at line 38 of file time_tracking.h.

Enumeration Type Documentation

◆ fr_time_tracking_state_t

Enumerator
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_YIELDED 

We're currently tracking time in the yielded state.

Definition at line 40 of file time_tracking.h.

Function Documentation

◆ fr_time_tracking_debug()

static void fr_time_tracking_debug ( fr_time_tracking_t tt,
FILE *  fp 
)
inlinestatic

Print debug information about the time tracking structure.

Parameters
[in]ttthe time tracking structure
[in]fpthe file where the debug output is printed.

Definition at line 299 of file time_tracking.h.

+ Here is the caller graph for this function:

◆ fr_time_tracking_end()

static void fr_time_tracking_end ( fr_time_delta_t predicted,
fr_time_tracking_t tt,
fr_time_t  now 
)
inlinestatic

End time tracking for this entity.

Parameters
[in,out]predictedUpdate our prediction of how long requests should run for.
[in]ttthe time tracking structure.
[in]nowthe current time.

Definition at line 270 of file time_tracking.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_tracking_init()

static void fr_time_tracking_init ( fr_time_tracking_t tt)
inlinestatic

Initialise a time tracking structure.

Definition at line 139 of file time_tracking.h.

◆ fr_time_tracking_pop()

static void fr_time_tracking_pop ( fr_time_tracking_t tt,
fr_time_t  now 
)
inlinestatic

Tracked entity left a tracked nested code area.

Updates parent to point to the current time tracking parent.

Parameters
[in]ttthe time tracked entity.
[in]nowthe current time.

Definition at line 202 of file time_tracking.h.

+ Here is the call graph for this function:

◆ fr_time_tracking_push()

static void fr_time_tracking_push ( fr_time_tracking_t parent,
fr_time_tracking_t tt,
fr_time_t  now 
)
inlinestatic

Tracked entity entered a deeper time tracked code area.

Parameters
[in]parentwe entered. Must be a direct descendent of the current tt->parent.
[in]ttthe time tracked entity.
[in]nowthe current time.

Definition at line 177 of file time_tracking.h.

+ Here is the call graph for this function:

◆ fr_time_tracking_resume()

static void fr_time_tracking_resume ( fr_time_tracking_t tt,
fr_time_t  now 
)
inlinestatic

Track that a request resumed.

Parameters
[in]ttthe time tracked entity.
[in]nowthe current time.

Definition at line 245 of file time_tracking.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_tracking_start()

static void fr_time_tracking_start ( fr_time_tracking_t parent,
fr_time_tracking_t tt,
fr_time_t  now 
)
inlinestatic

Start time tracking for a tracked entity.

Should be called when the tracked entity starts running.

Parameters
[in]parentto update when time tracking ends.
[in]ttthe time tracked entity.
[in]nowthe current time.

Definition at line 152 of file time_tracking.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_tracking_yield()

static void fr_time_tracking_yield ( fr_time_tracking_t tt,
fr_time_t  now 
)
inlinestatic

Transition to the yielded state, recording the time we just spent running.

Parameters
[in]ttthe time tracked entity.
[in]nowthe current time.

Definition at line 224 of file time_tracking.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ fr_time_tracking_state_table

fr_table_num_ordered_t fr_time_tracking_state_table[]
extern

Definition at line 29 of file time_tracking.c.

◆ fr_time_tracking_state_table_len

size_t fr_time_tracking_state_table_len
extern

Definition at line 34 of file time_tracking.c.