From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
linux-perf-users@vger.kernel.org,
Kan Liang <kan.liang@linux.intel.com>,
Zhengjun Xing <zhengjun.xing@linux.intel.com>,
James Clark <james.clark@arm.com>
Subject: Re: [PATCH 5/9] perf stat: Fix --metric-only --json output
Date: Tue, 8 Nov 2022 17:45:04 -0300 [thread overview]
Message-ID: <Y2q/0LNDCspN0Tm8@kernel.org> (raw)
In-Reply-To: <20221107213314.3239159-6-namhyung@kernel.org>
Em Mon, Nov 07, 2022 at 01:33:10PM -0800, Namhyung Kim escreveu:
> Currently it prints all metric headers for JSON output. But actually it
> skips some metrics with valid_only_metric(). So the output looks like:
>
> $ perf stat --metric-only --json true
> {"unit" : "CPUs utilized", "unit" : "/sec", "unit" : "/sec", "unit" : "/sec", "unit" : "GHz", "unit" : "insn per cycle", "unit" : "/sec", "unit" : "branch-misses of all branches"}
> {"metric-value" : "3.861"}{"metric-value" : "0.79"}{"metric-value" : "3.04"}
>
> As you can see there are 8 units in the header but only 3 metric-values
> are there. It should skip the unused headers as well. Also each unit
> should be printed as a separate object like metric values.
>
> With this patch:
>
> $ perf stat --metric-only --json true
> {"unit" : "GHz"}{"unit" : "insn per cycle"}{"unit" : "branch-misses of all branches"}
> {"metric-value" : "4.166"}{"metric-value" : "0.73"}{"metric-value" : "2.96"}
Can we get a Fixes tag for this one?
- Arnaldo
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/util/stat-display.c | 22 +++-------------------
> 1 file changed, 3 insertions(+), 19 deletions(-)
>
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
> index 115477461224..515fb6db3d67 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
> @@ -430,12 +430,12 @@ static void print_metric_header(struct perf_stat_config *config,
> os->evsel->priv != os->evsel->evlist->selected->priv)
> return;
>
> - if (!valid_only_metric(unit) && !config->json_output)
> + if (!valid_only_metric(unit))
> return;
> unit = fixunit(tbuf, os->evsel, unit);
>
> if (config->json_output)
> - fprintf(os->fh, "\"unit\" : \"%s\"", unit);
> + fprintf(os->fh, "{\"unit\" : \"%s\"}", unit);
> else if (config->csv_output)
> fprintf(os->fh, "%s%s", unit, config->csv_sep);
> else
> @@ -847,10 +847,6 @@ static void print_metric_headers(struct perf_stat_config *config,
> .new_line = new_line_metric,
> .force_header = true,
> };
> - bool first = true;
> -
> - if (config->json_output && !config->interval)
> - fprintf(config->output, "{");
>
> if (prefix && !config->json_output)
> fprintf(config->output, "%s", prefix);
> @@ -871,18 +867,12 @@ static void print_metric_headers(struct perf_stat_config *config,
> evlist__for_each_entry(evlist, counter) {
> os.evsel = counter;
>
> - if (!first && config->json_output)
> - fprintf(config->output, ", ");
> - first = false;
> -
> perf_stat__print_shadow_stats(config, counter, 0,
> 0,
> &out,
> &config->metric_events,
> &rt_stat);
> }
> - if (config->json_output)
> - fprintf(config->output, "}");
> fputc('\n', config->output);
> }
>
> @@ -954,14 +944,8 @@ static void print_interval(struct perf_stat_config *config,
> }
> }
>
> - if ((num_print_interval == 0 || config->interval_clear)
> - && metric_only && !config->json_output)
> + if ((num_print_interval == 0 || config->interval_clear) && metric_only)
> print_metric_headers(config, evlist, " ", true);
> - if ((num_print_interval == 0 || config->interval_clear)
> - && metric_only && config->json_output) {
> - fprintf(output, "{");
> - print_metric_headers(config, evlist, " ", true);
> - }
> if (++num_print_interval == 25)
> num_print_interval = 0;
> }
> --
> 2.38.1.431.g37b22c650d-goog
--
- Arnaldo
next prev parent reply other threads:[~2022-11-08 20:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-07 21:33 [PATCHSET 0/9] perf stat: Cleanup perf stat output display (v1) Namhyung Kim
2022-11-07 21:33 ` [PATCH 1/9] perf stat: Fix crash with --per-node --metric-only in CSV mode Namhyung Kim
2022-11-08 20:50 ` Arnaldo Carvalho de Melo
2022-11-07 21:33 ` [PATCH 2/9] perf stat: Increase metric length to align outputs Namhyung Kim
2022-11-08 23:14 ` Ian Rogers
2022-11-07 21:33 ` [PATCH 3/9] perf stat: Clear screen only if output file is a tty Namhyung Kim
2022-11-08 23:16 ` Ian Rogers
2022-11-09 18:02 ` Namhyung Kim
2022-11-07 21:33 ` [PATCH 4/9] perf stat: Move common code in print_metric_headers() Namhyung Kim
2022-11-08 23:19 ` Ian Rogers
2022-11-09 18:04 ` Namhyung Kim
2022-11-07 21:33 ` [PATCH 5/9] perf stat: Fix --metric-only --json output Namhyung Kim
2022-11-08 20:45 ` Arnaldo Carvalho de Melo [this message]
2022-11-08 22:07 ` Namhyung Kim
2022-11-09 18:33 ` Arnaldo Carvalho de Melo
2022-11-09 1:26 ` Ian Rogers
2022-11-07 21:33 ` [PATCH 6/9] perf stat: Do not indent headers for JSON Namhyung Kim
2022-11-08 23:20 ` Ian Rogers
2022-11-07 21:33 ` [PATCH 7/9] perf stat: Add header for interval in JSON output Namhyung Kim
2022-11-08 23:22 ` Ian Rogers
2022-11-07 21:33 ` [PATCH 8/9] perf stat: Fix condition in print_interval() Namhyung Kim
2022-11-08 23:23 ` Ian Rogers
2022-11-07 21:33 ` [PATCH 9/9] perf stat: Consolidate condition to print metrics Namhyung Kim
2022-11-08 23:23 ` Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y2q/0LNDCspN0Tm8@kernel.org \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@arm.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=zhengjun.xing@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).