Skip to content

Commit c419fad

Browse files
ktrzcinxlgirdwood
authored andcommitted
trace: Filter messages in runtime
Ability to change log level per UUID component improve user experience during debugging firmware. Threshold trace level defined in log message with value from trace context, where trece context is related with component instance (local or global instance). Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
1 parent 568ed16 commit c419fad

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/include/sof/trace/trace.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ void trace_on(void);
150150
void trace_off(void);
151151
void trace_init(struct sof *sof);
152152
void trace_log(bool send_atomic, const void *log_entry,
153-
const struct tr_ctx *ctx, uint32_t id_1, uint32_t id_2,
154-
int arg_count, ...);
153+
const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1,
154+
uint32_t id_2, int arg_count, ...);
155155

156156
#define _trace_event_with_ids(lvl, class, ctx, id_1, id_2, format, ...) \
157157
_log_message(false, lvl, class, ctx, id_1, id_2, \
@@ -201,7 +201,7 @@ do { \
201201
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
202202
BASE_LOG_ASSERT_FAIL_MSG \
203203
); \
204-
trace_log(atomic, &log_entry, ctx, id_1, id_2, \
204+
trace_log(atomic, &log_entry, ctx, lvl, id_1, id_2, \
205205
PP_NARG(__VA_ARGS__), ##__VA_ARGS__); \
206206
} while (0)
207207

src/trace/trace.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,22 @@ static inline void mtrace_event(const char *data, uint32_t length)
9696
}
9797
#endif /* CONFIG_TRACEM */
9898

99+
/**
100+
* \brief Runtime trace filtering
101+
* \param lvl log level (LOG_LEVEL_ ERROR, INFO, DEBUG ...)
102+
* \param uuid uuid address
103+
* \return false when trace is filtered out, otherwise true
104+
*/
105+
static inline bool trace_filter_pass(uint32_t lvl,
106+
const struct tr_ctx *ctx)
107+
{
108+
/* LOG_LEVEL_CRITICAL has low value, LOG_LEVEL_VERBOSE high */
109+
return lvl <= ctx->level;
110+
}
111+
99112
void trace_log(bool send_atomic, const void *log_entry,
100-
const struct tr_ctx *ctx, uint32_t id_1, uint32_t id_2,
101-
int arg_count, ...)
113+
const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1,
114+
uint32_t id_2, int arg_count, ...)
102115
{
103116
uint32_t data[MESSAGE_SIZE_DWORDS(_TRACE_EVENT_MAX_ARGUMENT_COUNT)];
104117
const int message_size = MESSAGE_SIZE(arg_count);
@@ -109,7 +122,7 @@ void trace_log(bool send_atomic, const void *log_entry,
109122
unsigned long flags;
110123
#endif /* CONFIG_TRACEM */
111124

112-
if (!trace->enable) {
125+
if (!trace->enable || !trace_filter_pass(lvl, ctx)) {
113126
platform_shared_commit(trace, sizeof(*trace));
114127
return;
115128
}

test/cmocka/src/common_mocks.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ void WEAK __panic(uint32_t p, char *filename, uint32_t linenum)
7676
}
7777

7878
void WEAK trace_log(bool send_atomic, const void *log_entry,
79-
const struct tr_ctx *ctx, uint32_t id_1, uint32_t id_2,
80-
int arg_count, ...)
79+
const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1,
80+
uint32_t id_2, int arg_count, ...)
8181
{
8282
(void) send_atomic;
8383
(void) log_entry;
8484
(void) ctx;
85+
(void) lvl;
8586
(void) id_1;
8687
(void) id_2;
8788
(void) arg_count;

0 commit comments

Comments
 (0)