From: Arran Cudbard-Bell Date: Tue, 5 Mar 2024 18:11:31 +0000 (-0600) Subject: Print the actual states in assert messages for time tracking X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36104e0dbebf3f4ed694defb00e6c6b1d54d5328;p=thirdparty%2Ffreeradius-server.git Print the actual states in assert messages for time tracking --- diff --git a/src/lib/io/all.mk b/src/lib/io/all.mk index aa1fa0852b6..800a1b6c76a 100644 --- a/src/lib/io/all.mk +++ b/src/lib/io/all.mk @@ -12,6 +12,7 @@ SOURCES := \ queue.c \ ring_buffer.c \ schedule.c \ + time_tracking.c \ worker.c TGT_PREREQS := libfreeradius-util$(L) $(LIBFREERADIUS_SERVER) diff --git a/src/lib/io/time_tracking.c b/src/lib/io/time_tracking.c new file mode 100644 index 00000000000..0667f89b4c1 --- /dev/null +++ b/src/lib/io/time_tracking.c @@ -0,0 +1,34 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * $Id$ + * + * @brief Simple ring buffers for packet contents + * @file io/time_tracking.c + * + * @copyright 2024 Arran Cudbard-Bell (a.cudbardb@freeradius.org) + */ +RCSID("$Id$") + +#include + +fr_table_num_ordered_t fr_time_tracking_state_table[] = { + { L("STOPPED"), FR_TIME_TRACKING_STOPPED }, + { L("RUNNING"), FR_TIME_TRACKING_RUNNING }, + { L("YIELDED"), FR_TIME_TRACKING_YIELDED }, +}; +size_t fr_time_tracking_state_table_len = NUM_ELEMENTS(fr_time_tracking_state_table); diff --git a/src/lib/io/time_tracking.h b/src/lib/io/time_tracking.h index c3dfc909a76..2970c8df92f 100644 --- a/src/lib/io/time_tracking.h +++ b/src/lib/io/time_tracking.h @@ -31,8 +31,12 @@ extern "C" { #endif #include +#include #include +extern fr_table_num_ordered_t fr_time_tracking_state_table[]; +extern size_t fr_time_tracking_state_table_len; + typedef enum { FR_TIME_TRACKING_STOPPED = 0, //!< Time tracking is not running. FR_TIME_TRACKING_RUNNING, //!< We're currently tracking time in the @@ -148,7 +152,9 @@ static inline CC_HINT(nonnull) void fr_time_tracking_init(fr_time_tracking_t *tt static inline CC_HINT(nonnull(2)) void fr_time_tracking_start(fr_time_tracking_t *parent, fr_time_tracking_t *tt, fr_time_t now) { - fr_assert_msg(tt->state == FR_TIME_TRACKING_STOPPED, "Unexpected time tracking state state %i", tt->state); + + fr_assert_msg(tt->state == FR_TIME_TRACKING_STOPPED, "Unexpected time tracking state state %s", + fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "")); fr_assert(!tt->parent); ASSERT_ON_TIME_TRAVEL(tt, now); @@ -176,7 +182,8 @@ static inline CC_HINT(nonnull) void fr_time_tracking_push(fr_time_tracking_t *pa fr_assert(tt->parent); fr_assert(parent->parent == tt->parent); - fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %i", tt->state); + fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %s", + fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "")); run_time = fr_time_sub(now, tt->last_changed); tt->last_changed = parent->started = now; @@ -196,7 +203,8 @@ static inline CC_HINT(nonnull) void fr_time_tracking_pop(fr_time_tracking_t *tt, { fr_time_delta_t run_time; - fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %i", tt->state); + fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %s", + fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "")); fr_assert(tt->parent); run_time = fr_time_sub(now, tt->last_changed); @@ -219,7 +227,8 @@ static inline CC_HINT(nonnull) void fr_time_tracking_yield(fr_time_tracking_t *t ASSERT_ON_TIME_TRAVEL(tt, now); - fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %i", tt->state); + fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %s", + fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "")); tt->state = FR_TIME_TRACKING_YIELDED; tt->last_yielded = tt->last_changed = now; @@ -239,7 +248,8 @@ static inline CC_HINT(nonnull) void fr_time_tracking_resume(fr_time_tracking_t * ASSERT_ON_TIME_TRAVEL(tt, now); - fr_assert_msg(tt->state == FR_TIME_TRACKING_YIELDED, "Unexpected time tracking state state %i", tt->state); + fr_assert_msg(tt->state == FR_TIME_TRACKING_YIELDED, "Unexpected time tracking state state %s", + fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "")); tt->state = FR_TIME_TRACKING_RUNNING; tt->last_resumed = tt->last_changed = now; @@ -262,7 +272,8 @@ static inline void fr_time_tracking_end(fr_time_delta_t *predicted, { fr_time_delta_t run_time; - fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %i", tt->state); + fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %s", + fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "")); ASSERT_ON_TIME_TRAVEL(tt, now); tt->state = FR_TIME_TRACKING_STOPPED;