diff --git a/tools/logger/convert.c b/tools/logger/convert.c index 5f8e3c91a562..741ee5e4a85e 100644 --- a/tools/logger/convert.c +++ b/tools/logger/convert.c @@ -5,6 +5,7 @@ // Author: Bartosz Kokoszko // Artur Kloniecki +#include #include #include #include @@ -387,9 +388,30 @@ static void print_entry_params(const struct log_entry_header *dma_log, if (raw_output) use_colors = 0; + /* Something somewhere went wrong */ if (dt < 0 || dt > 1000.0 * 1000.0 * 1000.0) dt = NAN; + static int entry_number = 1; + static uint64_t timestamp_origin; + + /* The first entry: + * - is never shown with a relative TIMESTAMP (to itself!?) + * - shows a zero DELTA + */ + if (entry_number == 1) { + entry_number++; + assert(last_timestamp == 0); + /* Display absolute (and random) timestamps */ + timestamp_origin = 0; + dt = 0; + } else if (entry_number == 2) { + entry_number++; + if (global_config->relative_timestamps == 1) + /* Switch to relative timestamps from now on. */ + timestamp_origin = last_timestamp; + } /* We don't need the exact entry_number after 3 */ + if (dma_log->id_0 != INVALID_TRACE_ID && dma_log->id_1 != INVALID_TRACE_ID) sprintf(ids, "%d.%d", (dma_log->id_0 & TRACE_IDS_MASK), @@ -413,7 +435,8 @@ static void print_entry_params(const struct log_entry_header *dma_log, raw_output && strlen(ids) ? "-" : "", ids); if (time_precision >= 0) - fprintf(out_fd, time_fmt, to_usecs(dma_log->timestamp), dt); + fprintf(out_fd, time_fmt, + to_usecs(dma_log->timestamp - timestamp_origin), dt); if (!hide_location) fprintf(out_fd, "(%s:%u) ", format_file_name(entry->file_name, raw_output), @@ -431,7 +454,7 @@ static void print_entry_params(const struct log_entry_header *dma_log, time_precision + 10, time_precision); fprintf(out_fd, time_fmt, use_colors ? KGRN : "", - to_usecs(dma_log->timestamp), dt, + to_usecs(dma_log->timestamp - timestamp_origin), dt, use_colors ? KNRM : ""); } diff --git a/tools/logger/convert.h b/tools/logger/convert.h index 36c30ef93447..607e5e59e049 100644 --- a/tools/logger/convert.h +++ b/tools/logger/convert.h @@ -40,6 +40,7 @@ struct convert_config { int raw_output; int dump_ldc; int hide_location; + int relative_timestamps; int time_precision; struct snd_sof_uids_header *uids_dict; struct snd_sof_logs_header *logs_header; diff --git a/tools/logger/logger.c b/tools/logger/logger.c index 9d2826910ff8..a64158693e75 100644 --- a/tools/logger/logger.c +++ b/tools/logger/logger.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,11 @@ static void usage(void) APP_NAME); fprintf(stdout, "%s:\t -L\t\t\tHide log location in source code\n", APP_NAME); + fprintf(stdout, + "%s:\t -e 0/1\t\t\tTimestamps relative to first entry seen. Defaults to\n", + APP_NAME); + fprintf(stdout, "%s:\t\t\t\tabsolute when -r(aw), relative otherwise.\n", + APP_NAME); fprintf(stdout, "%s:\t -f precision\t\tSet timestamp precision\n", APP_NAME); fprintf(stdout, "%s:\t -g\t\t\tHide timestamp\n", @@ -162,7 +168,7 @@ static int append_filter_config(struct convert_config *config, const char *input int main(int argc, char *argv[]) { - static const char optstring[] = "ho:i:l:ps:c:u:tv:rd:Lf:gF:n"; + static const char optstring[] = "ho:i:l:ps:c:u:tv:rd:Le:f:gF:n"; struct convert_config config; unsigned int baud = 0; const char *snapshot_file = 0; @@ -187,6 +193,7 @@ int main(int argc, char *argv[]) config.dump_ldc = 0; config.hide_location = 0; config.time_precision = 6; + config.relative_timestamps = INT_MAX; /* unspecified */ config.filter_config = NULL; while ((opt = getopt(argc, argv, optstring)) != -1) { @@ -232,6 +239,16 @@ int main(int argc, char *argv[]) case 'L': config.hide_location = 1; break; + case 'e': { + int i = atoi(optarg); + + if (i < 0 || 1 < i) { + fprintf(stderr, "%s: invalid option: -e %s\n", + APP_NAME, optarg); + return -EINVAL; + } + config.relative_timestamps = i; + } case 'f': config.time_precision = atoi(optarg); if (config.time_precision < 0) { @@ -286,7 +303,8 @@ int main(int argc, char *argv[]) if (config.version_fw) { config.version_fd = fopen(config.version_file, "rb"); if (!config.version_fd) { - fprintf(stderr, "error: Unable to open version file %s\n", + fprintf(stderr, + "error: Unable to open version file %s, check permissions\n", config.version_file); ret = errno; goto out; @@ -309,6 +327,10 @@ int main(int argc, char *argv[]) if (config.trace) config.in_file = "/sys/kernel/debug/sof/trace"; + /* Default value when -e is not specified */ + if (config.relative_timestamps == INT_MAX) + config.relative_timestamps = config.raw_output ? 0 : 1; + /* default option with no infile is to dump errors/debug data */ if (!config.in_file && !config.dump_ldc) config.in_file = "/sys/kernel/debug/sof/etrace"; @@ -324,7 +346,8 @@ int main(int argc, char *argv[]) } else if (config.in_file) { config.in_fd = fopen(config.in_file, "rb"); if (!config.in_fd) { - fprintf(stderr, "error: Unable to open in file %s\n", + fprintf(stderr, + "error: Unable to open in file %s, check permissions\n", config.in_file); ret = errno; goto out;