diff options
author | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2016-12-14 17:24:54 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2016-12-14 18:00:52 +0100 |
commit | 725698a4f15b9403620951961984b68ed4148992 (patch) | |
tree | 23cff9a72220210f33f47c736e7242fec69de3ee /include/osmocom/core | |
parent | 6a13e7f563e3983c51363704bd2a65e691bafc3e (diff) |
fsm: log caller's source for events and state changes, not fsm.c lines
When looking at log output, it is not interesting to see that a state
transition's petty details are implemented in fsm.c. Rather log the *caller's*
source file and line that caused an event, state change and cascading events.
To that end, introduce LOGPSRC() absorbing the guts of LOGP(), to be able to
explicitly pass the source file and line information.
Prepend an underscore to the function names of osmo_fsm_inst_state_chg(),
osmo_fsm_inst_dispatch() and osmo_fsm_inst_term(), and add file and line
arguments to them. Provide the previous names as macros that insert the
caller's __BASE_FILE__ and __LINE__ constants for the new arguments. Hence no
calling code needs to be changed.
In fsm.c, add LOGPFSMSRC to call LOGPSRC, and add LOGPFSMLSRC, and use them in
above _osmo_fsm_inst_* functions.
In addition, in _osmo_fsm_inst_term(), pass the caller's source file and line
on to nested event dispatches, so showing where a cascade originated from.
Change-Id: Iae72aba7bbf99e19dd584ccabea5867210650dcd
Diffstat (limited to 'include/osmocom/core')
-rw-r--r-- | include/osmocom/core/fsm.h | 41 | ||||
-rw-r--r-- | include/osmocom/core/logging.h | 27 |
2 files changed, 58 insertions, 10 deletions
diff --git a/include/osmocom/core/fsm.h b/include/osmocom/core/fsm.h index 026ed01a..77072ef8 100644 --- a/include/osmocom/core/fsm.h +++ b/include/osmocom/core/fsm.h @@ -131,11 +131,40 @@ const char *osmo_fsm_event_name(struct osmo_fsm *fsm, uint32_t event); const char *osmo_fsm_inst_name(struct osmo_fsm_inst *fi); const char *osmo_fsm_state_name(struct osmo_fsm *fsm, uint32_t state); -int osmo_fsm_inst_state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, - unsigned long timeout_secs, int T); -int osmo_fsm_inst_dispatch(struct osmo_fsm_inst *fi, uint32_t event, void *data); - -void osmo_fsm_inst_term(struct osmo_fsm_inst *fi, - enum osmo_fsm_term_cause cause, void *data); +/*! \brief perform a state change of the given FSM instance + * + * This is a macro that calls _osmo_fsm_inst_state_chg() with the given + * parameters as well as the caller's source file and line number for logging + * purposes. See there for documentation. + */ +#define osmo_fsm_inst_state_chg(fi, new_state, timeout_secs, T) \ + _osmo_fsm_inst_state_chg(fi, new_state, timeout_secs, T, \ + __BASE_FILE__, __LINE__) +int _osmo_fsm_inst_state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, + unsigned long timeout_secs, int T, + const char *file, int line); + +/*! \brief dispatch an event to an osmocom finite state machine instance + * + * This is a macro that calls _osmo_fsm_inst_dispatch() with the given + * parameters as well as the caller's source file and line number for logging + * purposes. See there for documentation. + */ +#define osmo_fsm_inst_dispatch(fi, event, data) \ + _osmo_fsm_inst_dispatch(fi, event, data, __BASE_FILE__, __LINE__) +int _osmo_fsm_inst_dispatch(struct osmo_fsm_inst *fi, uint32_t event, void *data, + const char *file, int line); + +/*! \brief Terminate FSM instance with given cause + * + * This is a macro that calls _osmo_fsm_inst_term() with the given parameters + * as well as the caller's source file and line number for logging purposes. + * See there for documentation. + */ +#define osmo_fsm_inst_term(fi, cause, data) \ + _osmo_fsm_inst_term(fi, cause, data, __BASE_FILE__, __LINE__) +void _osmo_fsm_inst_term(struct osmo_fsm_inst *fi, + enum osmo_fsm_term_cause cause, void *data, + const char *file, int line); /*! @} */ diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index 1ca348a2..fe9ae93f 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -55,10 +55,7 @@ void logp(int subsys, const char *file, int line, int cont, const char *format, * \param[in] args variable argument list */ #define LOGP(ss, level, fmt, args...) \ - do { \ - if (log_check_level(ss, level)) \ - logp2(ss, level, __BASE_FILE__, __LINE__, 0, fmt, ##args); \ - } while(0) + LOGPSRC(ss, level, NULL, 0, fmt, ## args) /*! \brief Continue a log message through the Osmocom logging framework * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) @@ -72,6 +69,28 @@ void logp(int subsys, const char *file, int line, int cont, const char *format, logp2(ss, level, __BASE_FILE__, __LINE__, 1, fmt, ##args); \ } while(0) +/*! \brief Log through the Osmocom logging framework with explicit source. + * If caller_file is passed as NULL, __BASE_FILE__ and __LINE__ are used + * instead of caller_file and caller_line (so that this macro here defines + * both cases in the same place, and to catch cases where callers fail to pass + * a non-null filename string). + * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) + * \param[in] level logging level (e.g. \ref LOGL_NOTICE) + * \param[in] caller_file caller's source file string (e.g. __BASE_FILE__) + * \param[in] caller_line caller's source line nr (e.g. __LINE__) + * \param[in] fmt format string + * \param[in] args variable argument list + */ +#define LOGPSRC(ss, level, caller_file, caller_line, fmt, args...) \ + do { \ + if (log_check_level(ss, level)) {\ + if (caller_file) \ + logp2(ss, level, caller_file, caller_line, 0, fmt, ##args); \ + else \ + logp2(ss, level, __BASE_FILE__, __LINE__, 0, fmt, ##args); \ + }\ + } while(0) + /*! \brief different log levels */ #define LOGL_DEBUG 1 /*!< \brief debugging information */ #define LOGL_INFO 3 /*!< \brief general information */ |