Skip to content

Commit

Permalink
perf stat: Move common code in print_metric_headers()
Browse files Browse the repository at this point in the history
[ Upstream commit f4e55f8 ]

The struct perf_stat_output_ctx is set in a loop with the same values.
Move the code out of the loop and keep the loop minimal.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20221107213314.3239159-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Stable-dep-of: fdc7d60 ("perf stat: Fix --metric-only --json output")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
namhyung authored and gregkh committed Dec 31, 2022
1 parent 1b2a63c commit 8a9c05d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tools/perf/util/stat-display.c
Original file line number Diff line number Diff line change
Expand Up @@ -1130,11 +1130,16 @@ static void print_metric_headers(struct perf_stat_config *config,
struct evlist *evlist,
const char *prefix, bool no_indent)
{
struct perf_stat_output_ctx out;
struct evsel *counter;
struct outstate os = {
.fh = config->output
};
struct perf_stat_output_ctx out = {
.ctx = &os,
.print_metric = print_metric_header,
.new_line = new_line_metric,
.force_header = true,
};
bool first = true;

if (config->json_output && !config->interval)
Expand All @@ -1158,13 +1163,11 @@ static void print_metric_headers(struct perf_stat_config *config,
/* Print metrics headers only */
evlist__for_each_entry(evlist, counter) {
os.evsel = counter;
out.ctx = &os;
out.print_metric = print_metric_header;

if (!first && config->json_output)
fprintf(config->output, ", ");
first = false;
out.new_line = new_line_metric;
out.force_header = true;

perf_stat__print_shadow_stats(config, counter, 0,
0,
&out,
Expand Down

0 comments on commit 8a9c05d

Please sign in to comment.