Skip to content

Commit

Permalink
Make use of time source type for throttling logs (#183)
Browse files Browse the repository at this point in the history
* Make use of time source type for throttling logs

Signed-off-by: Brian Ezequiel Marchi <brian.marchi65@gmail.com>
  • Loading branch information
BMarchi authored Oct 21, 2019
1 parent cfe98af commit e7eb74c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/rcutils/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extern "C"
#define RCUTILS_NS_TO_MS(nanoseconds) (nanoseconds / (1000LL * 1000LL))
/// Convenience macro to convert nanoseconds to microseconds.
#define RCUTILS_NS_TO_US(nanoseconds) (nanoseconds / 1000LL)
/// Convenience macro for rcutils_steady_time_now(rcutils_time_point_value_t *).
#define RCUTILS_STEADY_TIME rcutils_steady_time_now

/// A single point in time, measured in nanoseconds since the Unix epoch.
typedef int64_t rcutils_time_point_value_t;
Expand Down
5 changes: 3 additions & 2 deletions rcutils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@
skipfirst_doc_lines = [
'The first log call is being ignored but all subsequent calls are being processed.']
throttle_params = OrderedDict((
('time_source_type', 'The time source type of the time to be used'),
('get_time_point_value', 'Function that returns rcutils_ret_t and expects a '
'rcutils_time_point_value_t pointer.'),
('duration', 'The duration of the throttle interval'),
))
throttle_args = {
'condition_before': 'RCUTILS_LOG_CONDITION_THROTTLE_BEFORE(time_source_type, duration)',
'condition_before': 'RCUTILS_LOG_CONDITION_THROTTLE_BEFORE(get_time_point_value, duration)',
'condition_after': 'RCUTILS_LOG_CONDITION_THROTTLE_AFTER'}
throttle_doc_lines = [
'Log calls are being ignored if the last logged message is not longer ago than the specified '
Expand Down
4 changes: 2 additions & 2 deletions resource/logging_macros.h.em
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ typedef bool (* RclLogFilter)();
* \def RCUTILS_LOG_CONDITION_THROTTLE_BEFORE
* A macro initializing and checking the `throttle` condition.
*/
#define RCUTILS_LOG_CONDITION_THROTTLE_BEFORE(time_source_type, duration) { \
#define RCUTILS_LOG_CONDITION_THROTTLE_BEFORE(get_time_point_value, duration) { \
static rcutils_duration_value_t __rcutils_logging_duration = RCUTILS_MS_TO_NS((rcutils_duration_value_t)duration); \
static rcutils_time_point_value_t __rcutils_logging_last_logged = 0; \
rcutils_time_point_value_t __rcutils_logging_now = 0; \
bool __rcutils_logging_condition = true; \
if (rcutils_steady_time_now(&__rcutils_logging_now) != RCUTILS_RET_OK) { \
if (get_time_point_value(&__rcutils_logging_now) != RCUTILS_RET_OK) { \
rcutils_log( \
&__rcutils_logging_location, RCUTILS_LOG_SEVERITY_ERROR, "", \
"%s() at %s:%d getting current steady time failed\n", \
Expand Down

0 comments on commit e7eb74c

Please sign in to comment.