Skip to content

Commit 93cf630

Browse files
Marcin Makatlauda
authored andcommitted
logger: support for uuid address as entry parameter
Log entry format is scanned by the logger and if %s is found, then corresponding parameter is interpreted as address of static uuid entry. The original address is replaced by formatted uuid namen and value, painted in blue, before fprintf() is called. Signed-off-by: Marcin Maka <marcin.maka@linux.intel.com>
1 parent f3e80af commit 93cf630

File tree

2 files changed

+101
-8
lines changed

2 files changed

+101
-8
lines changed

tools/logger/convert.c

Lines changed: 100 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,89 @@ struct ldc_entry {
4141
uint32_t *params;
4242
};
4343

44+
struct proc_ldc_entry {
45+
int subst_mask;
46+
struct ldc_entry_header header;
47+
char *file_name;
48+
char *text;
49+
uintptr_t params[TRACE_MAX_PARAMS_COUNT];
50+
};
51+
52+
static const char *BAD_PTR_STR = "<bad uid ptr %x>";
53+
54+
const char *format_uid(const struct snd_sof_uids_header *uids_dict,
55+
uint32_t uid_ptr,
56+
int use_colors)
57+
{
58+
char *str;
59+
60+
if (uid_ptr < uids_dict->base_address ||
61+
uid_ptr >= uids_dict->base_address + uids_dict->data_length) {
62+
str = calloc(1, strlen(BAD_PTR_STR) + 1 + 6);
63+
sprintf(str, BAD_PTR_STR, uid_ptr);
64+
} else {
65+
const struct sof_uuid *uid_val = (const struct sof_uuid *)
66+
((uint8_t *)uids_dict + uids_dict->data_offset +
67+
uid_ptr - uids_dict->base_address);
68+
69+
str = calloc(1, (use_colors ? strlen(KBLU) : 0) + 1 +
70+
36 + 1 + *(uint32_t *)(uid_val + 1) + 1 +
71+
(use_colors ? strlen(KNRM) : 0));
72+
sprintf(str, "%s%s <%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x>%s",
73+
use_colors ? KBLU : "",
74+
(const char *)(uid_val + 1) + 4,
75+
uid_val->a, uid_val->b, uid_val->c,
76+
uid_val->d[0], uid_val->d[1], uid_val->d[2],
77+
uid_val->d[3], uid_val->d[4], uid_val->d[5],
78+
uid_val->d[6], uid_val->d[7],
79+
use_colors ? KNRM : "");
80+
}
81+
return str;
82+
}
83+
84+
static void process_params(struct proc_ldc_entry *pe,
85+
const struct ldc_entry *e,
86+
const struct snd_sof_uids_header *uids_dict,
87+
int use_colors)
88+
{
89+
const char *p = e->text;
90+
const char *t_end = p + strlen(e->text);
91+
unsigned int par_bit = 1;
92+
int i;
93+
94+
pe->subst_mask = 0;
95+
pe->header = e->header;
96+
pe->file_name = e->file_name;
97+
pe->text = e->text;
98+
99+
/* scan the text for possible replacements */
100+
while ((p = strchr(p, '%'))) {
101+
if (p < t_end - 1 && *(p + 1) == 's')
102+
pe->subst_mask += par_bit;
103+
par_bit <<= 1;
104+
++p;
105+
}
106+
107+
for (i = 0; i < e->header.params_num; i++) {
108+
pe->params[i] = e->params[i];
109+
if (pe->subst_mask & (1 << i))
110+
pe->params[i] = (uintptr_t)format_uid(uids_dict,
111+
e->params[i],
112+
use_colors);
113+
}
114+
}
115+
116+
static void free_proc_ldc_entry(struct proc_ldc_entry *pe)
117+
{
118+
int i;
119+
120+
for (i = 0; i < TRACE_MAX_PARAMS_COUNT; i++) {
121+
if (pe->subst_mask & (1 << i))
122+
free((void *)pe->params[i]);
123+
pe->params[i] = 0;
124+
}
125+
}
126+
44127
static double to_usecs(uint64_t time, double clk)
45128
{
46129
/* trace timestamp uses CPU system clock at default 25MHz ticks */
@@ -164,6 +247,10 @@ static void print_entry_params(FILE *out_fd,
164247
{
165248
char ids[TRACE_MAX_IDS_STR];
166249
float dt = to_usecs(dma_log->timestamp - last_timestamp, clock);
250+
struct proc_ldc_entry proc_entry;
251+
252+
if (raw_output)
253+
use_colors = 0;
167254

168255
if (dt < 0 || dt > 1000.0 * 1000.0 * 1000.0)
169256
dt = NAN;
@@ -222,25 +309,30 @@ static void print_entry_params(FILE *out_fd,
222309
get_level_name(entry->header.level));
223310
}
224311

225-
switch (entry->header.params_num) {
312+
process_params(&proc_entry, entry, uids_dict, use_colors);
313+
314+
switch (proc_entry.header.params_num) {
226315
case 0:
227-
fprintf(out_fd, "%s", entry->text);
316+
fprintf(out_fd, "%s", proc_entry.text);
228317
break;
229318
case 1:
230-
fprintf(out_fd, entry->text, entry->params[0]);
319+
fprintf(out_fd, proc_entry.text, proc_entry.params[0]);
231320
break;
232321
case 2:
233-
fprintf(out_fd, entry->text, entry->params[0], entry->params[1]);
322+
fprintf(out_fd, proc_entry.text, proc_entry.params[0],
323+
proc_entry.params[1]);
234324
break;
235325
case 3:
236-
fprintf(out_fd, entry->text, entry->params[0], entry->params[1],
237-
entry->params[2]);
326+
fprintf(out_fd, proc_entry.text, proc_entry.params[0],
327+
proc_entry.params[1], proc_entry.params[2]);
238328
break;
239329
case 4:
240-
fprintf(out_fd, entry->text, entry->params[0], entry->params[1],
241-
entry->params[2], entry->params[3]);
330+
fprintf(out_fd, proc_entry.text, proc_entry.params[0],
331+
proc_entry.params[1], proc_entry.params[2],
332+
proc_entry.params[3]);
242333
break;
243334
}
335+
free_proc_ldc_entry(&proc_entry);
244336
fprintf(out_fd, "%s\n", use_colors ? KNRM : "");
245337
fflush(out_fd);
246338
}

tools/logger/convert.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define KRED "\x1B[31m"
1919
#define KGRN "\x1B[32m"
2020
#define KYEL "\x1B[33m"
21+
#define KBLU "\x1B[34m"
2122

2223
struct convert_config {
2324
const char *out_file;

0 commit comments

Comments
 (0)