subsys/logging: log_backend_rb: Clear memory, timestamps
Add option to clear memory slot before writing logs, making reading logs more easy. Add timestamp logging option Add option to enable timestamp for ring buffer backend. Timestamp may consume little memory we have for ring buffer. Add timestamp logging option Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This commit is contained in:
parent
47940a63d7
commit
c151f1768e
2 changed files with 49 additions and 16 deletions
|
@ -553,6 +553,19 @@ config LOG_BACKEND_RB_SLOT_SIZE
|
|||
Size of the message slot inside ring buffer. All log messages
|
||||
are split to similar sized logging slots.
|
||||
|
||||
config LOG_BACKEND_RB_CLEAR
|
||||
bool "Clear ring buffer slot"
|
||||
default y
|
||||
help
|
||||
Clearing ring buffer slot helps to write more easy tools to read logs
|
||||
on different platforms.
|
||||
|
||||
config LOG_BACKEND_RB_TIMESTAMP
|
||||
bool "Add timestamp to the log"
|
||||
default y
|
||||
help
|
||||
Add timestamp to the logging string.
|
||||
|
||||
endif # LOG_BACKEND_RB
|
||||
|
||||
config LOG_BACKEND_SHOW_COLOR
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <logging/log_core.h>
|
||||
#include <logging/log_msg.h>
|
||||
#include <logging/log_output.h>
|
||||
#include <sys/byteorder.h>
|
||||
#include <sys/ring_buffer.h>
|
||||
|
||||
static struct ring_buf ringbuf;
|
||||
|
@ -40,7 +41,6 @@ static void trace(const uint8_t *data, size_t length)
|
|||
static uint16_t log_id;
|
||||
volatile uint8_t *t, *region;
|
||||
int space;
|
||||
int i;
|
||||
|
||||
space = ring_buf_space_get(&ringbuf);
|
||||
if (space < CONFIG_LOG_BACKEND_RB_SLOT_SIZE) {
|
||||
|
@ -57,15 +57,23 @@ static void trace(const uint8_t *data, size_t length)
|
|||
region = t;
|
||||
|
||||
/* Add magic number at the beginning of the slot */
|
||||
*(uint16_t *)t = magic;
|
||||
sys_put_le16(magic, (uint8_t *)t);
|
||||
t += 2;
|
||||
|
||||
/* Add log id */
|
||||
*(uint16_t *)t = log_id++;
|
||||
sys_put_le16(log_id++, (uint8_t *)t);
|
||||
t += 2;
|
||||
|
||||
for (i = 0; i < MIN(length, CONFIG_LOG_BACKEND_RB_SLOT_SIZE - 4); i++) {
|
||||
*t++ = data[i];
|
||||
length = MIN(length, CONFIG_LOG_BACKEND_RB_SLOT_SIZE - 4);
|
||||
|
||||
memcpy((void *)t, data, length);
|
||||
t += length;
|
||||
|
||||
/* Clear logging slot */
|
||||
if (IS_ENABLED(CONFIG_LOG_BACKEND_RB_CLEAR) &&
|
||||
length < CONFIG_LOG_BACKEND_RB_SLOT_SIZE - 4) {
|
||||
memset((void *)t, 0,
|
||||
CONFIG_LOG_BACKEND_RB_SLOT_SIZE - 4 - length);
|
||||
}
|
||||
|
||||
SOC_DCACHE_FLUSH((void *)region, CONFIG_LOG_BACKEND_RB_SLOT_SIZE);
|
||||
|
@ -88,12 +96,16 @@ LOG_OUTPUT_DEFINE(log_output_rb, char_out, rb_log_buf, sizeof(rb_log_buf));
|
|||
static void put(const struct log_backend *const backend,
|
||||
struct log_msg *msg)
|
||||
{
|
||||
log_msg_get(msg);
|
||||
|
||||
uint32_t flags = LOG_OUTPUT_FLAG_LEVEL;
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
|
||||
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
|
||||
log_msg_get(msg);
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_BACKEND_RB_TIMESTAMP)) {
|
||||
flags |= LOG_OUTPUT_FLAG_TIMESTAMP;
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
|
||||
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
|
||||
}
|
||||
}
|
||||
|
||||
log_output_msg_process(&log_output_rb, msg, flags);
|
||||
|
@ -120,8 +132,12 @@ static void sync_string(const struct log_backend *const backend,
|
|||
uint32_t flags = LOG_OUTPUT_FLAG_LEVEL;
|
||||
uint32_t key;
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
|
||||
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
|
||||
if (IS_ENABLED(CONFIG_LOG_BACKEND_RB_TIMESTAMP)) {
|
||||
flags |= LOG_OUTPUT_FLAG_TIMESTAMP;
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
|
||||
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
|
||||
}
|
||||
}
|
||||
|
||||
key = irq_lock();
|
||||
|
@ -134,11 +150,15 @@ static void sync_hexdump(const struct log_backend *const backend,
|
|||
struct log_msg_ids src_level, uint32_t timestamp,
|
||||
const char *metadata, const uint8_t *data, uint32_t length)
|
||||
{
|
||||
uint32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;
|
||||
uint32_t flags = LOG_OUTPUT_FLAG_LEVEL;
|
||||
uint32_t key;
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
|
||||
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
|
||||
if (IS_ENABLED(CONFIG_LOG_BACKEND_RB_TIMESTAMP)) {
|
||||
flags |= LOG_OUTPUT_FLAG_TIMESTAMP;
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
|
||||
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
|
||||
}
|
||||
}
|
||||
|
||||
key = irq_lock();
|
||||
|
@ -147,7 +167,7 @@ static void sync_hexdump(const struct log_backend *const backend,
|
|||
irq_unlock(key);
|
||||
}
|
||||
|
||||
const struct log_backend_api log_backend_adsp_api = {
|
||||
const struct log_backend_api log_backend_rb_api = {
|
||||
.put = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : put,
|
||||
.put_sync_string = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ?
|
||||
sync_string : NULL,
|
||||
|
@ -158,4 +178,4 @@ const struct log_backend_api log_backend_adsp_api = {
|
|||
.dropped = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : dropped,
|
||||
};
|
||||
|
||||
LOG_BACKEND_DEFINE(log_backend_adsp, log_backend_adsp_api, true);
|
||||
LOG_BACKEND_DEFINE(log_backend_adsp, log_backend_rb_api, true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue