diff --git a/tools/logger/convert.c b/tools/logger/convert.c index dc9cd3a39219..f8465d2fbe79 100644 --- a/tools/logger/convert.c +++ b/tools/logger/convert.c @@ -204,11 +204,19 @@ static double to_usecs(uint64_t time, double clk) } -static inline void print_table_header(FILE *out_fd) +static inline void print_table_header(FILE *out_fd, int hide_location, + int float_precision) { - fprintf(out_fd, "%18s %18s %2s %-18s %-29s %s\n", - "TIMESTAMP", "DELTA", "C#", "COMPONENT", "LOCATION", - "CONTENT"); + char time_fmt[32]; + + snprintf(time_fmt, sizeof(time_fmt), "%%%ds %%%ds ", + float_precision + 12, float_precision + 12); + fprintf(out_fd, time_fmt, "TIMESTAMP", "DELTA"); + fprintf(out_fd, "%2s %-18s ", "C#", "COMPONENT"); + if (!hide_location) + fprintf(out_fd, "%-29s ", "LOCATION"); + fprintf(out_fd, "%s\n", "CONTENT"); + fflush(out_fd); } @@ -315,11 +323,13 @@ static char *format_file_name(char *file_name_raw, int full_name) static void print_entry_params(FILE *out_fd, const struct snd_sof_uids_header *uids_dict, const struct log_entry_header *dma_log, const struct ldc_entry *entry, - uint64_t last_timestamp, double clock, int use_colors, int raw_output) + uint64_t last_timestamp, double clock, int use_colors, int raw_output, + int hide_location, int float_precision) { char ids[TRACE_MAX_IDS_STR]; float dt = to_usecs(dma_log->timestamp - last_timestamp, clock); struct proc_ldc_entry proc_entry; + static char time_fmt[32]; if (raw_output) use_colors = 0; @@ -335,7 +345,10 @@ static void print_entry_params(FILE *out_fd, ids[0] = '\0'; if (raw_output) { - const char *entry_fmt = "%s%u %u %s%s%s %.6f %.6f (%s:%u) "; + const char *entry_fmt = "%s%u %u %s%s%s "; + + snprintf(time_fmt, sizeof(time_fmt), "%%.%df %%.%df ", + float_precision, float_precision); fprintf(out_fd, entry_fmt, entry->header.level == use_colors ? @@ -346,14 +359,20 @@ static void print_entry_params(FILE *out_fd, entry->header.component_class, dma_log->uid), raw_output && strlen(ids) ? "-" : "", - ids, - to_usecs(dma_log->timestamp, clock), - dt, - format_file_name(entry->file_name, raw_output), - entry->header.line_idx); + ids); + fprintf(out_fd, time_fmt, to_usecs(dma_log->timestamp, clock), + dt); + if (!hide_location) + fprintf(out_fd, "(%s:%u) ", + format_file_name(entry->file_name, raw_output), + entry->header.line_idx); } else { /* timestamp */ - fprintf(out_fd, "%s[%16.6f] (%16.6f)%s ", + snprintf(time_fmt, sizeof(time_fmt), + "%%s[%%%d.%df] (%%%d.%df)%%s ", + float_precision + 10, float_precision, + float_precision + 10, float_precision); + fprintf(out_fd, time_fmt, use_colors ? KGRN : "", to_usecs(dma_log->timestamp, clock), dt, use_colors ? KNRM : ""); @@ -371,9 +390,10 @@ static void print_entry_params(FILE *out_fd, use_colors ? KNRM : ""); /* location */ - fprintf(out_fd, "%24s:%-4u ", - format_file_name(entry->file_name, raw_output), - entry->header.line_idx); + if (!hide_location) + fprintf(out_fd, "%24s:%-4u ", + format_file_name(entry->file_name, raw_output), + entry->header.line_idx); /* level name */ fprintf(out_fd, "%s%s", @@ -525,7 +545,8 @@ static int fetch_entry(const struct convert_config *config, config->uids_dict, dma_log, &entry, *last_timestamp, config->clock, config->use_colors, - config->raw_output); + config->raw_output, config->hide_location, + config->float_precision); *last_timestamp = dma_log->timestamp; /* set f_ldc file position to the beginning */ @@ -603,7 +624,8 @@ static int logger_read(const struct convert_config *config, uint64_t last_timestamp = 0; if (!config->raw_output) - print_table_header(config->out_fd); + print_table_header(config->out_fd, config->hide_location, + config->float_precision); if (config->serial_fd >= 0) /* Wait for CTRL-C */ diff --git a/tools/logger/convert.h b/tools/logger/convert.h index 2ae64d4c412e..e63e8fd9882a 100644 --- a/tools/logger/convert.h +++ b/tools/logger/convert.h @@ -37,6 +37,8 @@ struct convert_config { int serial_fd; int raw_output; int dump_ldc; + int hide_location; + int float_precision; struct snd_sof_uids_header *uids_dict; }; diff --git a/tools/logger/logger.c b/tools/logger/logger.c index e67f2ca82b41..6263fa6e59f3 100644 --- a/tools/logger/logger.c +++ b/tools/logger/logger.c @@ -51,6 +51,10 @@ static void usage(void) fprintf(stdout, "%s:\t -r\t\t\tLess formatted output for " "chained log processors\n", APP_NAME); + fprintf(stdout, "%s:\t -L\t\t\tHide log location in source code\n", + APP_NAME); + fprintf(stdout, "%s:\t -f precision\t\t\tset timestamp precision\n", + APP_NAME); fprintf(stdout, "%s:\t -d\t\t\tDump ldc information\n", APP_NAME); exit(0); } @@ -157,8 +161,10 @@ int main(int argc, char *argv[]) config.serial_fd = -EINVAL; config.raw_output = 0; config.dump_ldc = 0; + config.hide_location = 0; + config.float_precision = 6; - while ((opt = getopt(argc, argv, "ho:i:l:ps:c:u:tev:rd")) != -1) { + while ((opt = getopt(argc, argv, "ho:i:l:ps:c:u:tev:rdLf:")) != -1) { switch (opt) { case 'o': config.out_file = optarg; @@ -199,6 +205,16 @@ int main(int argc, char *argv[]) config.version_fw = 1; config.version_file = optarg; break; + case 'L': + config.hide_location = 1; + break; + case 'f': + config.float_precision = atoi(optarg); + if (config.float_precision < 0) { + usage(); + return -EINVAL; + } + break; case 'd': config.dump_ldc = 1; break;