Skip to content

Commit 51677a8

Browse files
Fix metrics report, when top commands contain double quotes (#336)
* Remove double quotes from cmd * Correctly escape double quotes in metrics report
1 parent c600b98 commit 51677a8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tibanna/top.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ def write_to_csv(self, csv_file, metric='cpu', delimiter=',', colname_for_timest
231231
last_minute = 5
232232
with open(csv_file, 'w') as fo:
233233
# header
234-
fo.write(delimiter.join([colname_for_timestamps] + [Top.wrap_in_double_quotes(cmd) for cmd in self.commands]))
234+
# we have to escape any double quotes that are present in the cmd, before wrapping it in double quotes. Otherwise we
235+
# will get incorrect column counts when creating the metrics report.
236+
fo.write(delimiter.join([colname_for_timestamps] + [Top.wrap_in_double_quotes(cmd.replace('"', '""')) for cmd in self.commands]))
235237
fo.write('\n')
236238
# contents
237239
# skip timepoints earlier than timestamp_start

0 commit comments

Comments
 (0)