logging: Add dropped messages notification to backends
Extended backend interface to allow notifying backend that log messages has been dropped due to insufficient internal buffer size. Notification contains number of log messages dropped since last notification. It is optional for a backend to implement handler. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
f7f31b1e13
commit
a211c42a29
2 changed files with 40 additions and 1 deletions
|
@ -29,6 +29,7 @@ struct log_backend_api {
|
|||
void (*put)(const struct log_backend *const backend,
|
||||
struct log_msg *msg);
|
||||
|
||||
void (*dropped)(const struct log_backend *const backend, u32_t cnt);
|
||||
void (*panic)(const struct log_backend *const backend);
|
||||
void (*init)(void);
|
||||
};
|
||||
|
@ -94,7 +95,25 @@ static inline void log_backend_put(const struct log_backend *const backend,
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Function for reconfiguring backend to panic mode.
|
||||
* @brief Notify backend about dropped log messages.
|
||||
*
|
||||
* Function is optional.
|
||||
*
|
||||
* @param[in] backend Pointer to the backend instance.
|
||||
* @param[in] cnt Number of dropped logs since last notification.
|
||||
*/
|
||||
static inline void log_backend_dropped(const struct log_backend *const backend,
|
||||
u32_t cnt)
|
||||
{
|
||||
assert(backend);
|
||||
|
||||
if (backend->api->dropped) {
|
||||
backend->api->dropped(backend, cnt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reconfigure backend to panic mode.
|
||||
*
|
||||
* @param[in] backend Pointer to the backend instance.
|
||||
*/
|
||||
|
|
|
@ -36,6 +36,7 @@ static atomic_t initialized;
|
|||
static bool panic_mode;
|
||||
static bool backend_attached;
|
||||
static atomic_t buffered_cnt;
|
||||
static atomic_t dropped_cnt;
|
||||
static k_tid_t proc_tid;
|
||||
|
||||
static u32_t dummy_timestamp(void);
|
||||
|
@ -389,11 +390,26 @@ static void msg_process(struct log_msg *msg, bool bypass)
|
|||
log_backend_put(backend, msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
atomic_inc(&dropped_cnt);
|
||||
}
|
||||
|
||||
log_msg_put(msg);
|
||||
}
|
||||
|
||||
void dropped_notify(void)
|
||||
{
|
||||
u32_t dropped = atomic_set(&dropped_cnt, 0);
|
||||
|
||||
for (int i = 0; i < log_backend_count_get(); i++) {
|
||||
struct log_backend const *backend = log_backend_get(i);
|
||||
|
||||
if (log_backend_is_active(backend)) {
|
||||
log_backend_dropped(backend, dropped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool log_process(bool bypass)
|
||||
{
|
||||
struct log_msg *msg;
|
||||
|
@ -411,6 +427,10 @@ bool log_process(bool bypass)
|
|||
msg_process(msg, bypass);
|
||||
}
|
||||
|
||||
if (!bypass && dropped_cnt) {
|
||||
dropped_notify();
|
||||
}
|
||||
|
||||
return (log_list_head_peek(&list) != NULL);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue