tracing: add RAM backend

If Zephyr is running on a coprocessor we might lack I/O
such as uart or usb to output tracing datas but we might
have gigabytes of RAM available.

This patch allows to output trace datas to a ram buffer, which then
may be retrieved using gdb.

e.g:
(gdb) dump binary memory channel0_0 <ram_tracing_start> \
<ram_tracing_end>

Signed-off-by: Julien Massot <julien.massot@iot.bzh>
This commit is contained in:
Julien Massot 2021-02-26 09:22:16 +01:00 committed by Anas Nashif
commit 80402f7f8b
4 changed files with 68 additions and 0 deletions

View file

@ -36,6 +36,12 @@ zephyr_sources_ifdef(
CONFIG_TRACING_BACKEND_POSIX CONFIG_TRACING_BACKEND_POSIX
tracing_backend_posix.c tracing_backend_posix.c
) )
zephyr_sources_ifdef(
CONFIG_TRACING_BACKEND_RAM
tracing_backend_ram.c
)
endif() endif()
zephyr_include_directories_ifdef( zephyr_include_directories_ifdef(

View file

@ -165,6 +165,21 @@ config TRACING_BACKEND_POSIX
help help
Use posix architecture to output tracing data to file system. Use posix architecture to output tracing data to file system.
config TRACING_BACKEND_RAM
bool "Enable RAM backend"
help
Use a ram buffer to output tracing data which can
be dumped to a file at runtime with a debugger.
See gdb dump binary memory documentation for example.
config RAM_TRACING_BUFFER_SIZE
int "Ram Tracing buffer size"
default 4096
depends on TRACING_BACKEND_RAM
help
Size of the RAM trace buffer. Trace will be discarded if the
length is exceeded.
endchoice endchoice
config TRACING_BACKEND_UART_NAME config TRACING_BACKEND_UART_NAME

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2021 IoT.bzh
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <ctype.h>
#include <kernel.h>
#include <string.h>
#include <tracing_core.h>
#include <tracing_buffer.h>
#include <tracing_backend.h>
uint8_t ram_tracing[CONFIG_RAM_TRACING_BUFFER_SIZE];
static uint32_t pos;
static bool buffer_full;
static void tracing_backend_ram_output(
const struct tracing_backend *backend,
uint8_t *data, uint32_t length)
{
if (buffer_full) {
return;
}
if ((pos + length) > CONFIG_RAM_TRACING_BUFFER_SIZE) {
buffer_full = true;
return;
}
memcpy(ram_tracing + pos, data, length);
pos += length;
}
static void tracing_backend_ram_init(void)
{
memset(ram_tracing, 0, CONFIG_RAM_TRACING_BUFFER_SIZE);
}
const struct tracing_backend_api tracing_backend_ram_api = {
.init = tracing_backend_ram_init,
.output = tracing_backend_ram_output
};
TRACING_BACKEND_DEFINE(tracing_backend_ram, tracing_backend_ram_api);

View file

@ -22,6 +22,8 @@
#define TRACING_BACKEND_NAME "tracing_backend_usb" #define TRACING_BACKEND_NAME "tracing_backend_usb"
#elif defined CONFIG_TRACING_BACKEND_POSIX #elif defined CONFIG_TRACING_BACKEND_POSIX
#define TRACING_BACKEND_NAME "tracing_backend_posix" #define TRACING_BACKEND_NAME "tracing_backend_posix"
#elif defined CONFIG_TRACING_BACKEND_RAM
#define TRACING_BACKEND_NAME "tracing_backend_ram"
#else #else
#define TRACING_BACKEND_NAME "" #define TRACING_BACKEND_NAME ""
#endif #endif