[PATCH v1 2/3] perf stat: Don't write "started on" for json output

From: Ian Rogers
Date: Tue Apr 04 2023 - 13:12:17 EST


Json files don't support comments. Disable the "started on" comment
when writing json output to file.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/builtin-stat.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 7ef565ae7265..330f00497e6e 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2272,8 +2272,10 @@ int cmd_stat(int argc, const char **argv)
perror("failed to create output file");
return -1;
}
- clock_gettime(CLOCK_REALTIME, &tm);
- fprintf(output, "# started on %s\n", ctime(&tm.tv_sec));
+ if (!stat_config.json_output) {
+ clock_gettime(CLOCK_REALTIME, &tm);
+ fprintf(output, "# started on %s\n", ctime(&tm.tv_sec));
+ }
} else if (output_fd > 0) {
mode = append_file ? "a" : "w";
output = fdopen(output_fd, mode);
--
2.40.0.348.gf938b09366-goog