Skip to content

Commit d7b535e

Browse files
ktrzcinxlgirdwood
authored andcommitted
logger: Add option to set timestamp precision
Shorten timestamp makes logger output more compact, it change: $ ./sof-logger -l sof-cnl.ldc -i dma_trace_1.bin TIMESTAMP DELTA C# COMPONENT LOCATION CONTENT [ 497588.489583] ( 497588.500000) c0 DMA .../intel/cavs/hda-dma.c:407 hda-dmac: 4 channel 6 -> get to: $ sof-logger -l sof-cnl.ldc -i dma_trace_1.bin -f0 TIMESTAMP DELTA C# COMPONENT LOCATION CONTENT [ 497588] ( 497588) c0 DMA .../intel/cavs/hda-dma.c:407 hda-dmac: 4 channel 6 -> get Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
1 parent 5469b1a commit d7b535e

3 files changed

Lines changed: 39 additions & 13 deletions

File tree

tools/logger/convert.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,18 @@ static double to_usecs(uint64_t time, double clk)
204204
}
205205

206206

207-
static inline void print_table_header(FILE *out_fd, int hide_location)
207+
static inline void print_table_header(FILE *out_fd, int hide_location,
208+
int float_precision)
208209
{
209-
fprintf(out_fd, "%18s %18s %2s %-18s",
210-
"TIMESTAMP", "DELTA", "C#", "COMPONENT");
210+
char time_fmt[32];
211+
212+
snprintf(time_fmt, sizeof(time_fmt), "%%%ds %%%ds ",
213+
float_precision + 12, float_precision + 12);
214+
fprintf(out_fd, time_fmt, "TIMESTAMP", "DELTA");
215+
fprintf(out_fd, "%2s %-18s ", "C#", "COMPONENT");
211216
if (!hide_location)
212-
fprintf(out_fd, " %-29s", "LOCATION");
213-
fprintf(out_fd, " %s\n", "CONTENT");
217+
fprintf(out_fd, "%-29s ", "LOCATION");
218+
fprintf(out_fd, "%s\n", "CONTENT");
214219

215220
fflush(out_fd);
216221
}
@@ -292,11 +297,12 @@ static void print_entry_params(FILE *out_fd,
292297
const struct snd_sof_uids_header *uids_dict,
293298
const struct log_entry_header *dma_log, const struct ldc_entry *entry,
294299
uint64_t last_timestamp, double clock, int use_colors, int raw_output,
295-
int hide_location)
300+
int hide_location, int float_precision)
296301
{
297302
char ids[TRACE_MAX_IDS_STR];
298303
float dt = to_usecs(dma_log->timestamp - last_timestamp, clock);
299304
struct proc_ldc_entry proc_entry;
305+
static char time_fmt[32];
300306

301307
if (raw_output)
302308
use_colors = 0;
@@ -312,7 +318,10 @@ static void print_entry_params(FILE *out_fd,
312318
ids[0] = '\0';
313319

314320
if (raw_output) {
315-
const char *entry_fmt = "%s%u %u %s%s%s %.6f %.6f ";
321+
const char *entry_fmt = "%s%u %u %s%s%s ";
322+
323+
snprintf(time_fmt, sizeof(time_fmt), "%%.%df %%.%df ",
324+
float_precision, float_precision);
316325

317326
fprintf(out_fd, entry_fmt,
318327
entry->header.level == use_colors ?
@@ -323,16 +332,20 @@ static void print_entry_params(FILE *out_fd,
323332
entry->header.component_class,
324333
dma_log->uid),
325334
raw_output && strlen(ids) ? "-" : "",
326-
ids,
327-
to_usecs(dma_log->timestamp, clock),
335+
ids);
336+
fprintf(out_fd, time_fmt, to_usecs(dma_log->timestamp, clock),
328337
dt);
329338
if (!hide_location)
330339
fprintf(out_fd, "(%s:%u) ",
331340
format_file_name(entry->file_name, raw_output),
332341
entry->header.line_idx);
333342
} else {
334343
/* timestamp */
335-
fprintf(out_fd, "%s[%16.6f] (%16.6f)%s ",
344+
snprintf(time_fmt, sizeof(time_fmt),
345+
"%%s[%%%d.%df] (%%%d.%df)%%s ",
346+
float_precision + 10, float_precision,
347+
float_precision + 10, float_precision);
348+
fprintf(out_fd, time_fmt,
336349
use_colors ? KGRN : "",
337350
to_usecs(dma_log->timestamp, clock), dt,
338351
use_colors ? KNRM : "");
@@ -505,7 +518,8 @@ static int fetch_entry(const struct convert_config *config,
505518
config->uids_dict,
506519
dma_log, &entry, *last_timestamp,
507520
config->clock, config->use_colors,
508-
config->raw_output, config->hide_location);
521+
config->raw_output, config->hide_location,
522+
config->float_precision);
509523
*last_timestamp = dma_log->timestamp;
510524

511525
/* set f_ldc file position to the beginning */
@@ -583,7 +597,8 @@ static int logger_read(const struct convert_config *config,
583597
uint64_t last_timestamp = 0;
584598

585599
if (!config->raw_output)
586-
print_table_header(config->out_fd, config->hide_location);
600+
print_table_header(config->out_fd, config->hide_location,
601+
config->float_precision);
587602

588603
if (config->serial_fd >= 0)
589604
/* Wait for CTRL-C */

tools/logger/convert.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct convert_config {
3838
int raw_output;
3939
int dump_ldc;
4040
int hide_location;
41+
int float_precision;
4142
struct snd_sof_uids_header *uids_dict;
4243
};
4344

tools/logger/logger.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static void usage(void)
5353
APP_NAME);
5454
fprintf(stdout, "%s:\t -L\t\t\tHide log location in source code\n",
5555
APP_NAME);
56+
fprintf(stdout, "%s:\t -f precision\t\t\tset timestamp precision\n",
57+
APP_NAME);
5658
fprintf(stdout, "%s:\t -d\t\t\tDump ldc information\n", APP_NAME);
5759
exit(0);
5860
}
@@ -160,8 +162,9 @@ int main(int argc, char *argv[])
160162
config.raw_output = 0;
161163
config.dump_ldc = 0;
162164
config.hide_location = 0;
165+
config.float_precision = 6;
163166

164-
while ((opt = getopt(argc, argv, "ho:i:l:ps:c:u:tev:rdL")) != -1) {
167+
while ((opt = getopt(argc, argv, "ho:i:l:ps:c:u:tev:rdLf:")) != -1) {
165168
switch (opt) {
166169
case 'o':
167170
config.out_file = optarg;
@@ -205,6 +208,13 @@ int main(int argc, char *argv[])
205208
case 'L':
206209
config.hide_location = 1;
207210
break;
211+
case 'f':
212+
config.float_precision = atoi(optarg);
213+
if (config.float_precision < 0) {
214+
usage();
215+
return -EINVAL;
216+
}
217+
break;
208218
case 'd':
209219
config.dump_ldc = 1;
210220
break;

0 commit comments

Comments
 (0)