Skip to content

Commit e289245

Browse files
committed
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 6aa98d9 commit e289245

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

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
}
@@ -319,11 +324,12 @@ static void print_entry_params(FILE *out_fd,
319324
const struct snd_sof_uids_header *uids_dict,
320325
const struct log_entry_header *dma_log, const struct ldc_entry *entry,
321326
uint64_t last_timestamp, double clock, int use_colors, int raw_output,
322-
int hide_location)
327+
int hide_location, int float_precision)
323328
{
324329
char ids[TRACE_MAX_IDS_STR];
325330
float dt = to_usecs(dma_log->timestamp - last_timestamp, clock);
326331
struct proc_ldc_entry proc_entry;
332+
static char time_fmt[32];
327333

328334
if (raw_output)
329335
use_colors = 0;
@@ -339,7 +345,10 @@ static void print_entry_params(FILE *out_fd,
339345
ids[0] = '\0';
340346

341347
if (raw_output) {
342-
const char *entry_fmt = "%s%u %u %s%s%s %.6f %.6f ";
348+
const char *entry_fmt = "%s%u %u %s%s%s ";
349+
350+
snprintf(time_fmt, sizeof(time_fmt), "%%.%df %%.%df ",
351+
float_precision, float_precision);
343352

344353
fprintf(out_fd, entry_fmt,
345354
entry->header.level == use_colors ?
@@ -350,16 +359,20 @@ static void print_entry_params(FILE *out_fd,
350359
entry->header.component_class,
351360
dma_log->uid),
352361
raw_output && strlen(ids) ? "-" : "",
353-
ids,
354-
to_usecs(dma_log->timestamp, clock),
362+
ids);
363+
fprintf(out_fd, time_fmt, to_usecs(dma_log->timestamp, clock),
355364
dt);
356365
if (!hide_location)
357366
fprintf(out_fd, "(%s:%u) ",
358367
format_file_name(entry->file_name, raw_output),
359368
entry->header.line_idx);
360369
} else {
361370
/* timestamp */
362-
fprintf(out_fd, "%s[%16.6f] (%16.6f)%s ",
371+
snprintf(time_fmt, sizeof(time_fmt),
372+
"%%s[%%%d.%df] (%%%d.%df)%%s ",
373+
float_precision + 10, float_precision,
374+
float_precision + 10, float_precision);
375+
fprintf(out_fd, time_fmt,
363376
use_colors ? KGRN : "",
364377
to_usecs(dma_log->timestamp, clock), dt,
365378
use_colors ? KNRM : "");
@@ -532,7 +545,8 @@ static int fetch_entry(const struct convert_config *config,
532545
config->uids_dict,
533546
dma_log, &entry, *last_timestamp,
534547
config->clock, config->use_colors,
535-
config->raw_output, config->hide_location);
548+
config->raw_output, config->hide_location,
549+
config->float_precision);
536550
*last_timestamp = dma_log->timestamp;
537551

538552
/* set f_ldc file position to the beginning */
@@ -610,7 +624,8 @@ static int logger_read(const struct convert_config *config,
610624
uint64_t last_timestamp = 0;
611625

612626
if (!config->raw_output)
613-
print_table_header(config->out_fd, config->hide_location);
627+
print_table_header(config->out_fd, config->hide_location,
628+
config->float_precision);
614629

615630
if (config->serial_fd >= 0)
616631
/* 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)