[6/9] perf stat: Do not indent headers for JSON

Message ID 20221107213314.3239159-7-namhyung@kernel.org
State New
Headers
Series perf stat: Cleanup perf stat output display (v1) |

Commit Message

Namhyung Kim Nov. 7, 2022, 9:33 p.m. UTC
  Currently --metric-only with --json indents header lines.  This is not
needed for JSON.

  $ perf stat -aA --metric-only -j true
        {"unit" : "GHz"}{"unit" : "insn per cycle"}{"unit" : "branch-misses of all branches"}
  {"cpu" : "0", {"metric-value" : "0.101"}{"metric-value" : "0.86"}{"metric-value" : "1.91"}
  {"cpu" : "1", {"metric-value" : "0.102"}{"metric-value" : "0.87"}{"metric-value" : "2.02"}
  {"cpu" : "2", {"metric-value" : "0.085"}{"metric-value" : "1.02"}{"metric-value" : "1.69"}
  ...

Note that the other lines are broken JSON, but it will be handled later.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/stat-display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Ian Rogers Nov. 8, 2022, 11:20 p.m. UTC | #1
On Mon, Nov 7, 2022 at 1:33 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Currently --metric-only with --json indents header lines.  This is not
> needed for JSON.
>
>   $ perf stat -aA --metric-only -j true
>         {"unit" : "GHz"}{"unit" : "insn per cycle"}{"unit" : "branch-misses of all branches"}
>   {"cpu" : "0", {"metric-value" : "0.101"}{"metric-value" : "0.86"}{"metric-value" : "1.91"}
>   {"cpu" : "1", {"metric-value" : "0.102"}{"metric-value" : "0.87"}{"metric-value" : "2.02"}
>   {"cpu" : "2", {"metric-value" : "0.085"}{"metric-value" : "1.02"}{"metric-value" : "1.69"}
>   ...
>
> Note that the other lines are broken JSON, but it will be handled later.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/util/stat-display.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
> index 515fb6db3d67..25f67fb37f6d 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
> @@ -851,7 +851,7 @@ static void print_metric_headers(struct perf_stat_config *config,
>         if (prefix && !config->json_output)
>                 fprintf(config->output, "%s", prefix);
>
> -       if (!config->csv_output && !no_indent)
> +       if (!config->csv_output && !config->json_output && !no_indent)
>                 fprintf(config->output, "%*s",
>                         aggr_header_lens[config->aggr_mode], "");
>         if (config->csv_output) {
> --
> 2.38.1.431.g37b22c650d-goog
>
  

Patch

diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index 515fb6db3d67..25f67fb37f6d 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -851,7 +851,7 @@  static void print_metric_headers(struct perf_stat_config *config,
 	if (prefix && !config->json_output)
 		fprintf(config->output, "%s", prefix);
 
-	if (!config->csv_output && !no_indent)
+	if (!config->csv_output && !config->json_output && !no_indent)
 		fprintf(config->output, "%*s",
 			aggr_header_lens[config->aggr_mode], "");
 	if (config->csv_output) {