From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 217FB1C07 for ; Wed, 28 Dec 2022 16:28:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D732C433EF; Wed, 28 Dec 2022 16:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1672244938; bh=nTMhsZi4WVkvFZvGKC1VL11sThIXjHmXx5Po1IJS24c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NQgMNJIiJhAoP4xzMbMAt5gfrhffu4zjFg7qRT3Kxehp6J2bZWGiaO39Imbp8QssK NUVjSx1N7j8wr9GhejTHyb8LZNHtognbpbAg07xyuXEVcvm7sDxrhbGkb2NOaZlt3f +Tdx3PD3z7XQyg9iNIbfoPaAO+iq3WHe6dEu3r5s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Namhyung Kim , Ian Rogers , Adrian Hunter , Ingo Molnar , James Clark , Jiri Olsa , Kan Liang , Peter Zijlstra , Xing Zhengjun , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.1 0765/1146] perf stat: Move common code in print_metric_headers() Date: Wed, 28 Dec 2022 15:38:24 +0100 Message-Id: <20221228144350.929663419@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221228144330.180012208@linuxfoundation.org> References: <20221228144330.180012208@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Namhyung Kim [ Upstream commit f4e55f88da923f39f0b76edc3da3c52d0b72d429 ] 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 Acked-by: Ian Rogers Cc: Adrian Hunter Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Peter Zijlstra Cc: Xing Zhengjun Link: https://lore.kernel.org/r/20221107213314.3239159-5-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo Stable-dep-of: fdc7d6082459 ("perf stat: Fix --metric-only --json output") Signed-off-by: Sasha Levin --- tools/perf/util/stat-display.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1130,11 +1130,16 @@ static void print_metric_headers(struct 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) @@ -1158,13 +1163,11 @@ static void print_metric_headers(struct /* 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,