6#ifndef __SOF_TRACE_TRACE_SOFLOGGER_H__
7#define __SOF_TRACE_TRACE_SOFLOGGER_H__
10#include <platform/trace/trace.h>
31#define _DECLARE_LOG_ENTRY(lvl, format, comp_class, n_params) \
32 __section(".static_log." #lvl) \
33 static const struct { \
35 uint32_t component_class; \
36 uint32_t params_num; \
38 uint32_t file_name_len; \
40 const char file_name[sizeof(RELATIVE_FILE)]; \
41 const char text[sizeof(format)]; \
47 sizeof(RELATIVE_FILE), \
53#define _TRACE_EVENT_MAX_ARGUMENT_COUNT 4
87#define trace_event_with_ids(class, ctx, id_1, id_2, format, ...) \
88 _trace_event_with_ids(LOG_LEVEL_INFO, class, ctx, id_1, id_2, \
89 format, ##__VA_ARGS__)
91#define trace_event_atomic_with_ids(class, ctx, id_1, id_2, format, ...) \
92 _trace_event_atomic_with_ids(LOG_LEVEL_INFO, class, ctx, id_1, id_2, \
93 format, ##__VA_ARGS__)
95#define trace_warn_with_ids(class, ctx, id_1, id_2, format, ...) \
96 _trace_event_with_ids(LOG_LEVEL_WARNING, class, ctx, id_1, id_2, \
97 format, ##__VA_ARGS__)
99#define trace_warn_atomic_with_ids(class, ctx, id_1, id_2, format, ...) \
100 _trace_event_atomic_with_ids(LOG_LEVEL_WARNING, class, \
102 format, ##__VA_ARGS__)
110typedef void (*
log_func_t)(
bool send_atomic,
const void *log_entry,
const struct tr_ctx *ctx,
111 uint32_t lvl, uint32_t id_1, uint32_t id_2,
int arg_count, va_list args);
114 uint32_t lvl, uint32_t id_1, uint32_t id_2,
int arg_count, va_list args);
116 uint32_t lvl, uint32_t id_1, uint32_t id_2,
int arg_count, va_list args);
122#define _trace_event_with_ids(lvl, class, ctx, id_1, id_2, format, ...) \
123 _log_message(trace_log_filtered, false, lvl, class, ctx, id_1, id_2, format, ##__VA_ARGS__)
125#define _trace_event_atomic_with_ids(lvl, class, ctx, id_1, id_2, format, ...) \
126 _log_message(trace_log_filtered, true, lvl, class, ctx, id_1, id_2, format, ##__VA_ARGS__)
147# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_INFO
149# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_DEBUG
152# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_ERROR
157 const struct tr_ctx *ctx,
const uint32_t lvl,
158 uint32_t id_1, uint32_t id_2,
int arg_count, ...);
167extern int host_trace_level;
169char *get_trace_class(uint32_t trace_class);
170#define _log_message(ignored_log_func, atomic, level, comp_class, ctx, id_1, id_2, format, ...) \
176 char slevel[5][4] = {"dis", "err", "wrn", "inf", "dbg"}; \
177 char *msg = "(%s:%d) " format; \
178 if (level <= host_trace_level) { \
179 gettimeofday(&tv, NULL); \
180 fprintf(stderr, "trace: [%ld.%6.6ld] <%s> ", tv.tv_sec, tv.tv_usec, \
182 fprintf(stderr, msg, strrchr(__FILE__, '/') + 1, \
183 __LINE__, ##__VA_ARGS__); \
184 fprintf(stderr, "\n"); \
188#define trace_point(x) do {} while (0)
192#define trace_point(x) platform_trace_point(x)
194#define BASE_LOG_ASSERT_FAIL_MSG \
195unsupported_amount_of_params_in_trace_event\
196_thrown_from_macro_BASE_LOG_in_trace_h
198#define CT_ASSERT(COND, MESSAGE) \
199 ((void)sizeof(char[1 - 2 * !(COND)]))
201#define trace_check_size_uint32(a) \
202 CT_ASSERT(sizeof(a) <= sizeof(uint32_t), "error: trace argument is bigger than a uint32_t");
204#define STATIC_ASSERT_ARG_SIZE(...) \
205 META_MAP(1, trace_check_size_uint32, __VA_ARGS__)
212#define _log_message(log_func, atomic, lvl, comp_class, ctx, id_1, id_2, format, ...) \
214 _DECLARE_LOG_ENTRY(lvl, format, comp_class, \
215 META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__)); \
216 STATIC_ASSERT_ARG_SIZE(__VA_ARGS__); \
217 STATIC_ASSERT(_TRACE_EVENT_MAX_ARGUMENT_COUNT >= \
218 META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
219 BASE_LOG_ASSERT_FAIL_MSG \
221 _log_sofdict(log_func, atomic, &log_entry, ctx, lvl, id_1, id_2, \
222 META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), ##__VA_ARGS__); \
223 _log_nodict(atomic, META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
224 lvl, format, ##__VA_ARGS__); \
231#define _log_nodict(atomic, arg_count, lvl, format, ...) \
233 if ((lvl) <= MTRACE_DUPLICATION_LEVEL) \
234 printk("%llu " format "\n", k_cycle_get_64(), \
238#define _log_nodict(atomic, n_args, lvl, format, ...)
245#define tracev_event_with_ids(class, ctx, id_1, id_2, format, ...) \
246 _trace_event_with_ids(LOG_LEVEL_VERBOSE, class, \
248 format, ##__VA_ARGS__)
250#define tracev_event_atomic_with_ids(class, ctx, id_1, id_2, format, ...) \
251 _trace_event_atomic_with_ids(LOG_LEVEL_VERBOSE, class, \
253 format, ##__VA_ARGS__)
256#define tracev_event_with_ids(class, ctx, id_1, id_2, format, ...) \
257 trace_unused(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
258#define tracev_event_atomic_with_ids(class, ctx, id_1, id_2, format, ...) \
259 trace_unused(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
266#define _trace_error_with_ids(class, ctx, id_1, id_2, format, ...) \
267 _log_message(trace_log_filtered, true, LOG_LEVEL_CRITICAL, class, ctx, id_1, \
268 id_2, format, ##__VA_ARGS__)
269#define trace_error_with_ids(class, ctx, id_1, id_2, format, ...) \
270 _trace_error_with_ids(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
271#define trace_error_atomic_with_ids(...) trace_error_with_ids(__VA_ARGS__)
275#define trace_error_with_ids(...) trace_event_with_ids(__VA_ARGS__)
276#define trace_error_atomic_with_ids(...) \
277 trace_event_atomic_with_ids(__VA_ARGS__)
292#define trace_dev_err(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
293 trace_error_with_ids(_TRACE_INV_CLASS, get_ctx_m(dev), \
294 get_id_m(dev), get_subid_m(dev), \
298#define trace_dev_warn(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
299 trace_warn_with_ids(_TRACE_INV_CLASS, get_ctx_m(dev), \
300 get_id_m(dev), get_subid_m(dev), \
304#define trace_dev_info(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
305 trace_event_with_ids(_TRACE_INV_CLASS, get_ctx_m(dev), \
306 get_id_m(dev), get_subid_m(dev), \
310#define trace_dev_dbg(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
311 tracev_event_with_ids(_TRACE_INV_CLASS, \
312 get_ctx_m(dev), get_id_m(dev), \
313 get_subid_m(dev), fmt, ##__VA_ARGS__)
317#define tr_err_atomic(ctx, fmt, ...) \
318 trace_error_atomic_with_ids(_TRACE_INV_CLASS, ctx, \
319 _TRACE_INV_ID, _TRACE_INV_ID, \
322#define tr_warn_atomic(ctx, fmt, ...) \
323 trace_warn_atomic_with_ids(_TRACE_INV_CLASS, ctx, \
324 _TRACE_INV_ID, _TRACE_INV_ID, \
327#define tr_info_atomic(ctx, fmt, ...) \
328 trace_event_atomic_with_ids(_TRACE_INV_CLASS, ctx, \
329 _TRACE_INV_ID, _TRACE_INV_ID, \
332#define tr_dbg_atomic(ctx, fmt, ...) \
333 tracev_event_atomic_with_ids(_TRACE_INV_CLASS, ctx, \
334 _TRACE_INV_ID, _TRACE_INV_ID, \
337#define tr_err(ctx, fmt, ...) \
338 trace_error_with_ids(_TRACE_INV_CLASS, ctx, \
339 _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
341#define tr_warn(ctx, fmt, ...) \
342 trace_warn_with_ids(_TRACE_INV_CLASS, ctx, \
343 _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
345#define tr_info(ctx, fmt, ...) \
346 trace_event_with_ids(_TRACE_INV_CLASS, ctx, \
347 _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
350#define tr_dbg(ctx, fmt, ...) \
351 tracev_event_with_ids(_TRACE_INV_CLASS, ctx, \
352 _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
363#define mtrace_printf(log_level, format_str, ...) \
365 STATIC_ASSERT(META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__) \
366 <= _TRACE_EVENT_MAX_ARGUMENT_COUNT, \
367 too_many_mtrace_printf_arguments); \
368 _DECLARE_LOG_ENTRY(log_level, format_str, _TRACE_INV_CLASS, \
369 META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__)); \
370 mtrace_dict_entry(true, (uint32_t)&log_entry, \
371 META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
struct sof * sof_get(void)
struct trace * trace
Definition sof.h:16
part of sof_ipc_trace_filter, ABI3.17
Definition trace.h:70
General firmware context.
Definition sof.h:44
struct trace * trace
Definition sof.h:61
Definition trace-soflogger.h:21
uint32_t uuid_id
type id, or 0 when not important
Definition trace-soflogger.h:22
int32_t log_level
new log level value
Definition trace-soflogger.h:25
int32_t pipe_id
pipeline id or -1 when not important
Definition trace-soflogger.h:24
int32_t comp_id
component id or -1 when not important
Definition trace-soflogger.h:23
uint32_t length
Definition tlv.h:1
void mtrace_event(const char *complete_packet, uint32_t length)
Posts a fully prepared log header + log entry.
void(* log_func_t)(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list args)
Definition trace-soflogger.h:110
void trace_flush_dma_to_mbox(void)
void trace_log_unfiltered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list args)
void mtrace_dict_entry(bool atomic_context, uint32_t log_entry_pointer, int n_args,...)
Appends one SOF dictionary entry and log statement to the ring buffer implementing the 'etrace' in sh...
void trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list args)
void trace_init(struct sof *sof)
void _log_sofdict(log_func_t sofdict_logf, bool atomic, const void *log_entry, const struct tr_ctx *ctx, const uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count,...)
struct sof_ipc_trace_filter_elem * trace_filter_fill(struct sof_ipc_trace_filter_elem *elem, struct sof_ipc_trace_filter_elem *end, struct trace_filter *filter)
int trace_filter_update(const struct trace_filter *elem)
static struct trace * trace_get(void)
Definition trace-soflogger.h:55