tracing: ctf: adapt ctf implementation to tracing infrastructure

Adapt ctf implementation to tracing infrastructure.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
This commit is contained in:
Wentong Wu 2020-02-01 02:29:20 +08:00 committed by Anas Nashif
commit 10a669ea87
9 changed files with 42 additions and 191 deletions

View file

@ -81,13 +81,6 @@ config SDL_DISPLAY
endif # DISPLAY
if TRACING_CTF
config TRACING_CTF_BOTTOM_POSIX
default y
endif # TRACING_CTF
if FLASH
config FLASH_SIMULATOR

View file

@ -133,8 +133,7 @@ internally and statically at compile-time in the bottom-layer.
How to Activate?
================
Make sure :option:`CONFIG_TRACING_CTF` is set to ``y`` (:option:`CONFIG_TRACING_CTF_BOTTOM_POSIX`
is selected by default when using ``BOARD_NATIVE_POSIX``).
Make sure :option:`CONFIG_TRACING_CTF` is set to ``y``
How to Use?

View file

@ -433,16 +433,14 @@ config TRACING_CTF
select THREAD_MONITOR
select TRACING
help
Enable tracing to a Common Trace Format stream. In order to use it a
CTF bottom layer should be selected, such as TRACING_CTF_BOTTOM_POSIX.
Enable tracing to a Common Trace Format stream.
config TRACING_CTF_BOTTOM_POSIX
bool "CTF backend for the native_posix port, using a file in the host filesystem"
depends on TRACING_CTF
depends on ARCH_POSIX
config TRACING_CTF_TIMESTAMP
bool "Enable CTF internal timestamp"
default y
help
Enable POSIX backend for CTF tracing. It will output the CTF stream to a
file using fwrite.
Timestamp prefix will be added to the beginning of CTF
event internally.
source "subsys/debug/Kconfig.segger"

View file

@ -10,5 +10,3 @@ zephyr_library_include_directories(
)
zephyr_include_directories(.)
add_subdirectory_ifdef(CONFIG_TRACING_CTF_BOTTOM_POSIX bottoms/posix)

View file

@ -1,4 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
zephyr_include_directories(.)
zephyr_sources(ctf_bottom.c)

View file

@ -1,58 +0,0 @@
/*
* Copyright (c) 2018 Oticon A/S
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "ctf_bottom.h"
#include "soc.h"
#include "cmdline.h" /* native_posix command line options header */
#include <arch/posix/posix_trace.h>
ctf_bottom_ctx_t ctf_bottom;
void ctf_bottom_configure(void)
{
if (ctf_bottom.pathname == NULL) {
ctf_bottom.pathname = "channel0_0";
}
ctf_bottom.ostream = fopen(ctf_bottom.pathname, "wb");
if (ctf_bottom.ostream == NULL) {
posix_print_error_and_exit("CTF trace: "
"Problem opening file %s.\n",
ctf_bottom.pathname);
}
}
void ctf_bottom_start(void)
{
}
/* command line option to specify ctf output file */
void add_ctf_option(void)
{
static struct args_struct_t ctf_options[] = {
/*
* Fields:
* manual, mandatory, switch,
* option_name, var_name ,type,
* destination, callback,
* description
*/
{ .manual = false,
.is_mandatory = false,
.is_switch = false,
.option = "ctf-path",
.name = "file_name",
.type = 's',
.dest = (void *)&ctf_bottom.pathname,
.call_when_found = NULL,
.descript = "File name for CTF tracing output." },
ARG_TABLE_ENDMARKER
};
native_add_command_line_opts(ctf_options);
}
NATIVE_TASK(add_ctf_option, PRE_BOOT_1, 1);

View file

@ -1,76 +0,0 @@
/*
* Copyright (c) 2018 Oticon A/S
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef SUBSYS_DEBUG_TRACING_BOTTOMS_POSIX_CTF_BOTTOM_H
#define SUBSYS_DEBUG_TRACING_BOTTOMS_POSIX_CTF_BOTTOM_H
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <zephyr/types.h>
#include <ctf_map.h>
/* Obtain a field's size at compile-time.
* Internal to this bottom-layer.
*/
#define CTF_BOTTOM_INTERNAL_FIELD_SIZE(x) + sizeof(x)
/* Append a field to current event-packet.
* Internal to this bottom-layer.
*/
#define CTF_BOTTOM_INTERNAL_FIELD_APPEND(x) \
{ \
memcpy(epacket_cursor, &(x), sizeof(x)); \
epacket_cursor += sizeof(x); \
}
/* Gather fields to a contiguous event-packet, then atomically emit.
* Used by middle-layer.
*/
#define CTF_BOTTOM_FIELDS(...) \
{ \
u8_t epacket[0 MAP(CTF_BOTTOM_INTERNAL_FIELD_SIZE, ##__VA_ARGS__)]; \
u8_t *epacket_cursor = &epacket[0]; \
\
MAP(CTF_BOTTOM_INTERNAL_FIELD_APPEND, ##__VA_ARGS__) \
ctf_bottom_emit(epacket, sizeof(epacket)); \
}
/* No need for locking when ctf_bottom_emit does POSIX fwrite(3) which is thread
* safe. Used by middle-layer.
*/
#define CTF_BOTTOM_LOCK() { /* empty */ }
#define CTF_BOTTOM_UNLOCK() { /* empty */ }
/* On native_posix board, the code must sample time by itself.
* Used by middle-layer.
*/
#define CTF_BOTTOM_TIMESTAMPED_INTERNALLY
typedef struct {
const char *pathname;
FILE *ostream;
} ctf_bottom_ctx_t;
extern ctf_bottom_ctx_t ctf_bottom;
/* Configure initializes ctf_bottom context and opens the IO channel */
void ctf_bottom_configure(void);
/* Start a new trace stream */
void ctf_bottom_start(void);
/* Emit IO in system-specific way */
static inline void ctf_bottom_emit(const void *ptr, size_t size)
{
/* Simplest possible example is atomic fwrite */
fwrite(ptr, size, 1, ctf_bottom.ostream);
}
#endif /* SUBSYS_DEBUG_TRACING_BOTTOMS_POSIX_CTF_BOTTOM_H */

View file

@ -6,9 +6,8 @@
#include <zephyr.h>
#include <kernel_structs.h>
#include <init.h>
#include <kernel_internal.h>
#include "ctf_top.h"
#include <ctf_top.h>
void sys_trace_thread_switched_out(void)
{
@ -142,14 +141,3 @@ void sys_trace_end_call(unsigned int id)
{
ctf_top_end_call(id);
}
static int ctf_top_init(struct device *arg)
{
ARG_UNUSED(arg);
ctf_bottom_configure();
ctf_bottom_start();
return 0;
}
SYS_INIT(ctf_top_init, PRE_KERNEL_1, 0);

View file

@ -9,37 +9,51 @@
#include <stddef.h>
#include <string.h>
#include <ctf_bottom.h>
#include <ctf_map.h>
#include <debug/tracing_format.h>
/* Limit strings to 20 bytes to optimize bandwidth */
#define CTF_MAX_STRING_LEN 20
/* Optionally enter into a critical region, decided by bottom layer */
#define CTF_CRITICAL_REGION(x) \
{ \
CTF_BOTTOM_LOCK(); \
x; \
CTF_BOTTOM_UNLOCK(); \
/*
* Obtain a field's size at compile-time.
*/
#define CTF_INTERNAL_FIELD_SIZE(x) + sizeof(x)
/*
* Append a field to current event-packet.
*/
#define CTF_INTERNAL_FIELD_APPEND(x) \
{ \
memcpy(epacket_cursor, &(x), sizeof(x)); \
epacket_cursor += sizeof(x); \
}
/*
* Gather fields to a contiguous event-packet, then atomically emit.
*/
#define CTF_GATHER_FIELDS(...) \
{ \
u8_t epacket[0 MAP(CTF_INTERNAL_FIELD_SIZE, ##__VA_ARGS__)]; \
u8_t *epacket_cursor = &epacket[0]; \
\
MAP(CTF_INTERNAL_FIELD_APPEND, ##__VA_ARGS__) \
tracing_format_raw_data(epacket, sizeof(epacket)); \
}
#ifdef CTF_BOTTOM_TIMESTAMPED_EXTERNALLY
/* Emit CTF event using the bottom-level IO mechanics */
#define CTF_EVENT(...) \
{ \
CTF_CRITICAL_REGION(CTF_BOTTOM_FIELDS(__VA_ARGS__)) \
}
#endif /* CTF_BOTTOM_TIMESTAMPED_EXTERNALLY */
#ifdef CTF_BOTTOM_TIMESTAMPED_INTERNALLY
/* Emit CTF event using the bottom-level IO mechanics. Prefix by sample time */
#ifdef CONFIG_TRACING_CTF_TIMESTAMP
#define CTF_EVENT(...) \
{ \
const u32_t tstamp = k_cycle_get_32(); \
CTF_CRITICAL_REGION(CTF_BOTTOM_FIELDS(tstamp, __VA_ARGS__)) \
\
CTF_GATHER_FIELDS(tstamp, __VA_ARGS__) \
}
#endif /* CTF_BOTTOM_TIMESTAMPED_INTERNALLY */
#else
#define CTF_EVENT(...) \
{ \
CTF_GATHER_FIELDS(__VA_ARGS__) \
}
#endif
/* Anonymous compound literal with 1 member. Legal since C99.
* This permits us to take the address of literals, like so:
@ -52,7 +66,6 @@
*/
#define CTF_LITERAL(type, value) ((type) { (type)(value) })
typedef enum {
CTF_EVENT_THREAD_SWITCHED_OUT = 0x10,
CTF_EVENT_THREAD_SWITCHED_IN = 0x11,