tools: Skip the csv header line in gonk-plot
- Switch print to _LOG statements.
- Also skip malformed lines in case of errors. The data may still be
usable in that case.
Change-Id: If5f83fb109e027a7217a6f1ceb0c6fac7f588faf
Reviewed-on: https://pigweed-review.googlesource.com/c/gonk/+/252372
Reviewed-by: Akira Baruah <akirabaruah@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Pigweed-Auto-Submit: Anthony DiGirolamo <tonymd@google.com>
Commit-Queue: Anthony DiGirolamo <tonymd@google.com>
Reviewed-by: Mary Xia <maryxia@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/tools/gonk_tools/plot.py b/tools/gonk_tools/plot.py
index ee47e6c..89d0122 100644
--- a/tools/gonk_tools/plot.py
+++ b/tools/gonk_tools/plot.py
@@ -62,13 +62,13 @@
# pylint: disable=too-many-locals
pw_cli.log.install()
- print(f'Input CSV: {input_csv}')
+ _LOG.info('Input CSV: %s', input_csv)
if output_svg:
- print(f'Output svg file: {output_svg}')
+ _LOG.info('Output svg file: %s', output_svg)
interactive_plotting = not (output_svg)
if interactive_plotting:
- print('No outputs specified; plotting interactively')
+ _LOG.info('No outputs specified; plotting interactively')
start_time: datetime | None = None
time_values = []
@@ -94,13 +94,31 @@
for line in f.readlines():
parts = [line.strip() for line in line.split(',')]
if len(parts) != csv_field_count:
- _LOG.warning('Unexpected number of CSV fields: %i', len(parts))
+ _LOG.warning(
+ 'Skipping line due to unexpected number of '
+ 'CSV fields: %i',
+ len(parts),
+ )
_LOG.warning('Fields: %s', parts)
_LOG.warning('Line: "%s"', line)
+ continue # Skip this line
# Extract the host timestamp
dtstr = parts[0]
- dt = datetime.strptime(dtstr, '%Y%m%d %H:%M:%S.%f')
+ try:
+ dt = datetime.strptime(dtstr, '%Y%m%d %H:%M:%S.%f')
+ except ValueError as err:
+ # Output a warning if this isn't the csv header line.
+ if not any(
+ channel_name in line for channel_name in get_channel_names()
+ ):
+ _LOG.warning(
+ 'Skipping line due to error parsing host time: ' '%s',
+ err,
+ )
+ _LOG.warning(' Line: "%s"', line)
+ continue # Skip this line
+
# Extract delta_micros
delta_micros = int(parts[1])
@@ -180,6 +198,7 @@
if output_svg:
plt.savefig(output_svg)
+ _LOG.info('Output svg saved: %s', output_svg.resolve())
if interactive_plotting:
plt.show()