From ba8eadee2f8285db29140e72cc1f28559b474868 Mon Sep 17 00:00:00 2001 From: Wolfgang Hoenig Date: Thu, 5 Jan 2023 16:02:49 +0100 Subject: [PATCH] USD deck: parser and plotter improvements * config.txt parser: allow empty lines and lines with just comments * plot_events.py: fix error when only one event type is recorded --- src/deck/drivers/src/usddeck.c | 12 +++++++++--- tools/usdlog/plot_events.py | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/deck/drivers/src/usddeck.c b/src/deck/drivers/src/usddeck.c index 35506e3071..c49081b54a 100644 --- a/src/deck/drivers/src/usddeck.c +++ b/src/deck/drivers/src/usddeck.c @@ -416,7 +416,8 @@ TCHAR* f_gets_without_comments ( while (n < len - 1) { /* Read characters until buffer gets filled */ f_read(fp, &c, 1, &rc); if (rc != 1) { - break; + *p = 0; + return 0; /* When no data read (eof or error), return with error. */ } if (c == '\n') { if (isPureComment){ @@ -441,7 +442,7 @@ TCHAR* f_gets_without_comments ( } } *p = 0; - return n ? buff : 0; /* When no data read (eof or error), return with error. */ + return buff; } @@ -636,8 +637,13 @@ static void usdLogTask(void* prm) cfg->numBytes = 0; while (true) { line = f_gets_without_comments(readBuffer, sizeof(readBuffer), &logFile); - if (!line || strncmp(line, "on:", 3) == 0) + if (!line || strncmp(line, "on:", 3) == 0) { break; + } + // skip lines that do not have at least two characters (1 for group, 1 for '.', 1 for name) + if (strlen(line) <= 3) { + continue; + } char *group = line; char *name = 0; for (int i = 0; i < strlen(line); ++i) { diff --git a/tools/usdlog/plot_events.py b/tools/usdlog/plot_events.py index d707d5d8e3..889ba838da 100644 --- a/tools/usdlog/plot_events.py +++ b/tools/usdlog/plot_events.py @@ -31,13 +31,13 @@ def showAnnotation(data, sel): start_time = min(start_time, data['timestamp'][0]) # new figure - fig, ax = plt.subplots(len(data_usd.keys()),1,sharex=True) + fig, ax = plt.subplots(len(data_usd.keys()),1,sharex=True,squeeze=False) for k, (event_name, data) in enumerate(data_usd.items()): # print(k, event_name) t = (data['timestamp'] - start_time) / 1000 - ax[k].scatter(t, t*0) - ax[k].set_title(event_name) + ax[k,0].scatter(t, t*0) + ax[k,0].set_title(event_name) print(data.keys()) @@ -45,7 +45,7 @@ def showAnnotation(data, sel): crs.connect("add", functools.partial(showAnnotation, data)) - ax[-1].set_xlabel('Time [s]') + ax[-1,0].set_xlabel('Time [s]') plt.show()