From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@kernel.org>
Cc: 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>,
Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Subject: [PATCH 16/19] perf stat: Factor out prefix display
Date: Mon, 14 Nov 2022 15:02:24 -0800 [thread overview]
Message-ID: <20221114230227.1255976-17-namhyung@kernel.org> (raw)
In-Reply-To: <20221114230227.1255976-1-namhyung@kernel.org>
The prefix is needed for interval mode to print timestamp at the
beginning of each line. But the it's tricky for the metric only
mode since it doesn't print every evsel and combines the metrics
into a single line.
So it needed to pass 'first' argument to print_counter_aggrdata()
to determine if the current event is being printed at first. This
makes the code hard to read.
Let's move the logic out of the function and do it in the outer
print loop. This would enable further cleanups later.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/stat-display.c | 43 ++++++++++++----------------------
1 file changed, 15 insertions(+), 28 deletions(-)
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index 73cf898060c0..bb40ed29300d 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -805,8 +805,7 @@ static void uniquify_counter(struct perf_stat_config *config, struct evsel *coun
static void print_counter_aggrdata(struct perf_stat_config *config,
struct evsel *counter, int s,
- char *prefix, bool metric_only,
- bool *first)
+ char *prefix, bool metric_only)
{
FILE *output = config->output;
u64 ena, run, val;
@@ -825,10 +824,6 @@ static void print_counter_aggrdata(struct perf_stat_config *config,
ena = aggr->counts.ena;
run = aggr->counts.run;
- if (*first && metric_only) {
- *first = false;
- aggr_printout(config, counter, id, aggr->nr);
- }
if (prefix && !metric_only)
fprintf(output, "%s", prefix);
@@ -849,7 +844,6 @@ static void print_aggr(struct perf_stat_config *config,
FILE *output = config->output;
struct evsel *counter;
int s;
- bool first;
if (!config->aggr_map || !config->aggr_get_id)
return;
@@ -860,21 +854,23 @@ static void print_aggr(struct perf_stat_config *config,
*/
for (s = 0; s < config->aggr_map->nr; s++) {
if (metric_only) {
+ struct perf_stat_aggr *aggr;
+ struct aggr_cpu_id id = config->aggr_map->map[s];
+
if (prefix)
fprintf(output, "%s", prefix);
- else if (config->summary && !config->no_csv_summary &&
- config->csv_output && !config->interval)
- fprintf(output, "%16s%s", "summary", config->csv_sep);
+
+ counter = evlist__first(evlist);
+ aggr = &counter->stats->aggr[s];
+ aggr_printout(config, counter, id, aggr->nr);
}
- first = true;
evlist__for_each_entry(evlist, counter) {
if (counter->merged_stat)
continue;
- print_counter_aggrdata(config, counter, s,
- prefix, metric_only,
- &first);
+ print_counter_aggrdata(config, counter, s, prefix,
+ metric_only);
}
if (metric_only)
fputc('\n', output);
@@ -885,7 +881,6 @@ static void print_counter(struct perf_stat_config *config,
struct evsel *counter, char *prefix)
{
bool metric_only = config->metric_only;
- bool first = false;
int s;
/* AGGR_THREAD doesn't have config->aggr_get_id */
@@ -896,9 +891,8 @@ static void print_counter(struct perf_stat_config *config,
return;
for (s = 0; s < config->aggr_map->nr; s++) {
- print_counter_aggrdata(config, counter, s,
- prefix, metric_only,
- &first);
+ print_counter_aggrdata(config, counter, s, prefix,
+ metric_only);
}
}
@@ -1260,7 +1254,6 @@ static void print_percore(struct perf_stat_config *config,
FILE *output = config->output;
struct cpu_aggr_map *core_map;
int s, c, i;
- bool first = true;
if (!config->aggr_map || !config->aggr_get_id)
return;
@@ -1288,11 +1281,7 @@ static void print_percore(struct perf_stat_config *config,
if (found)
continue;
- if (prefix && metric_only)
- fprintf(output, "%s", prefix);
-
- print_counter_aggrdata(config, counter, s,
- prefix, metric_only, &first);
+ print_counter_aggrdata(config, counter, s, prefix, metric_only);
core_map->map[c++] = core_id;
}
@@ -1319,10 +1308,6 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf
}
print_header(config, _target, evlist, argc, argv);
- if (metric_only) {
- if (config->aggr_mode == AGGR_GLOBAL && prefix && !config->iostat_run)
- fprintf(config->output, "%s", prefix);
- }
switch (config->aggr_mode) {
case AGGR_CORE:
@@ -1337,6 +1322,8 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf
iostat_print_counters(evlist, config, ts, prefix = buf,
print_counter);
else {
+ if (prefix && metric_only)
+ fprintf(config->output, "%s", prefix);
evlist__for_each_entry(evlist, counter) {
print_counter(config, counter, prefix);
}
--
2.38.1.493.g58b659f92b-goog
next prev parent reply other threads:[~2022-11-14 23:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-14 23:02 [PATCHSET 00/19] perf stat: Improve perf stat output (v1) Namhyung Kim
2022-11-14 23:02 ` [PATCH 01/19] perf stat: Clear screen only if output file is a tty Namhyung Kim
2022-11-14 23:02 ` [PATCH 02/19] perf stat: Split print_running() function Namhyung Kim
2022-11-14 23:02 ` [PATCH 03/19] perf stat: Split print_noise_pct() function Namhyung Kim
2022-11-14 23:02 ` [PATCH 04/19] perf stat: Split print_cgroup() function Namhyung Kim
2022-11-14 23:02 ` [PATCH 05/19] perf stat: Split aggr_printout() function Namhyung Kim
2022-11-14 23:02 ` [PATCH 06/19] perf stat: Factor out print_counter_value() function Namhyung Kim
2022-11-14 23:02 ` [PATCH 07/19] perf stat: Handle bad events in abs_printout() Namhyung Kim
2022-11-14 23:02 ` [PATCH 08/19] perf stat: Add before_metric argument Namhyung Kim
2022-11-14 23:02 ` [PATCH 09/19] perf stat: Align cgroup names Namhyung Kim
2022-11-14 23:02 ` [PATCH 10/19] perf stat: Split print_metric_headers() function Namhyung Kim
2022-11-14 23:02 ` [PATCH 11/19] perf stat: Factor out prepare_interval() Namhyung Kim
2022-11-14 23:02 ` [PATCH 12/19] perf stat: Cleanup interval print alignment Namhyung Kim
2022-11-14 23:02 ` [PATCH 13/19] perf stat: Remove impossible condition Namhyung Kim
2022-11-14 23:02 ` [PATCH 14/19] perf stat: Rework header display Namhyung Kim
2022-11-14 23:02 ` [PATCH 15/19] perf stat: Move condition to print_footer() Namhyung Kim
2022-11-14 23:02 ` Namhyung Kim [this message]
2022-11-14 23:02 ` [PATCH 17/19] perf stat: Factor out print_metric_{begin,end}() Namhyung Kim
2022-11-14 23:02 ` [PATCH 18/19] perf stat: Support --for-each-cgroup and --metric-only Namhyung Kim
2022-11-14 23:02 ` [PATCH 19/19] perf stat: Add print_aggr_cgroup() for --for-each-cgroup and --topdown Namhyung Kim
2022-11-15 14:04 ` [PATCHSET 00/19] perf stat: Improve perf stat output (v1) Arnaldo Carvalho de Melo
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=20221114230227.1255976-17-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=atrajeev@linux.vnet.ibm.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=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
all inboxes | Powered by JetHome®