shell: Improve handling of log messages

If burst of log messages was passed to the shell log
backend, it was likely that messages were lost because
shell had no means to control arrivals of log messages.

Added log message enqueueing timeout to the shell instance
to allow blocking logger thread if short-term arrival rate
exceeded shell capabilities.

Added kconfig option for setting log message queue size
and timeout in RTT and UART instances. Added section in
shell documentation which explains interaction between
the logger and shell instance acting as a logger backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2018-12-17 10:43:58 +01:00 committed by Carles Cufí
commit 08f0d93cbb
10 changed files with 87 additions and 20 deletions

View file

@ -452,18 +452,23 @@ extern void shell_print_stream(const void *user_ctx, const char *data,
*
* @param[in] _name Instance name.
* @param[in] _prompt Shell prompt string.
* @param[in] transport_iface Pointer to the transport interface.
* @param[in] log_queue_size Logger processing queue size.
* @param[in] _transport_iface Pointer to the transport interface.
* @param[in] _log_queue_size Logger processing queue size.
* @param[in] _log_timeout Logger thread timeout in milliseconds on full
* log queue. If queue is full logger thread is
* blocked for given amount of time before log
* message is dropped.
* @param[in] _shell_flag Shell output newline sequence.
*/
#define SHELL_DEFINE(_name, _prompt, transport_iface, \
log_queue_size, _shell_flag) \
#define SHELL_DEFINE(_name, _prompt, _transport_iface, \
_log_queue_size, _log_timeout, _shell_flag) \
static const struct shell _name; \
static struct shell_ctx UTIL_CAT(_name, _ctx); \
static char _name##prompt[CONFIG_SHELL_PROMPT_LENGTH + 1] = _prompt; \
static u8_t _name##_out_buffer[CONFIG_SHELL_PRINTF_BUFF_SIZE]; \
SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, \
CONFIG_SHELL_PRINTF_BUFF_SIZE); \
CONFIG_SHELL_PRINTF_BUFF_SIZE, \
_log_queue_size, _log_timeout); \
SHELL_HISTORY_DEFINE(_name, 128, 8);/*todo*/ \
SHELL_FPRINTF_DEFINE(_name##_fprintf, &_name, _name##_out_buffer, \
CONFIG_SHELL_PRINTF_BUFF_SIZE, \
@ -474,7 +479,7 @@ extern void shell_print_stream(const void *user_ctx, const char *data,
static struct k_thread _name##_thread; \
static const struct shell _name = { \
.prompt = _name##prompt, \
.iface = transport_iface, \
.iface = _transport_iface, \
.ctx = &UTIL_CAT(_name, _ctx), \
.history = SHELL_HISTORY_PTR(_name), \
.shell_flag = _shell_flag, \

View file

@ -37,6 +37,7 @@ struct shell_log_backend {
struct k_msgq *msgq;
const struct log_output *log_output;
struct shell_log_backend_control_block *control_block;
u32_t timeout;
};
/** @brief Prototype of function outputing processed data. */
@ -45,9 +46,12 @@ int shell_log_backend_output_func(u8_t *data, size_t length, void *ctx);
/** @def SHELL_LOG_BACKEND_DEFINE
* @brief Macro for creating instance of shell log backend.
*
* @param _name Shell name.
* @param _buf Output buffer.
* @param _size Output buffer size.
* @param _name Shell name.
* @param _buf Output buffer.
* @param _size Output buffer size.
* @param _queue_size Log message queue size.
* @param _timeout Timeout in milliseconds for pending on queue full.
* Message is dropped on timeout.
*/
/** @def SHELL_LOG_BACKEND_PTR
* @brief Macro for retrieving pointer to the instance of shell log backend.
@ -55,10 +59,10 @@ int shell_log_backend_output_func(u8_t *data, size_t length, void *ctx);
* @param _name Shell name.
*/
#if CONFIG_LOG
#define SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size) \
#define SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout) \
LOG_BACKEND_DEFINE(_name##_backend, log_backend_shell_api, false); \
K_MSGQ_DEFINE(_name##_msgq, sizeof(void *), \
CONFIG_SHELL_MAX_LOG_MSG_BUFFERED, sizeof(void *)); \
_queue_size, sizeof(void *)); \
LOG_OUTPUT_DEFINE(_name##_log_output, shell_log_backend_output_func, \
_buf, _size); \
static struct shell_log_backend_control_block _name##_control_block; \
@ -66,12 +70,13 @@ int shell_log_backend_output_func(u8_t *data, size_t length, void *ctx);
.backend = &_name##_backend, \
.msgq = &_name##_msgq, \
.log_output = &_name##_log_output, \
.control_block = &_name##_control_block \
.control_block = &_name##_control_block, \
.timeout = _timeout \
}
#define SHELL_LOG_BACKEND_PTR(_name) (&_name##_log_backend)
#else /* CONFIG_LOG */
#define SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size) /* empty */
#define SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout)
#define SHELL_LOG_BACKEND_PTR(_name) NULL
#endif /* CONFIG_LOG */