[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221114230227.1255976-7-namhyung@kernel.org>
Date: Mon, 14 Nov 2022 15:02:14 -0800
From: Namhyung Kim <namhyung@...nel.org>
To: Arnaldo Carvalho de Melo <acme@...nel.org>,
Jiri Olsa <jolsa@...nel.org>
Cc: Ingo Molnar <mingo@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
LKML <linux-kernel@...r.kernel.org>,
Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>,
linux-perf-users@...r.kernel.org,
Kan Liang <kan.liang@...ux.intel.com>,
Zhengjun Xing <zhengjun.xing@...ux.intel.com>,
James Clark <james.clark@....com>,
Athira Jajeev <atrajeev@...ux.vnet.ibm.com>
Subject: [PATCH 06/19] perf stat: Factor out print_counter_value() function
And split it for each output mode like others. I believe it makes the
code simpler and more intuitive. Now abs_printout() becomes just to
call sub-functions.
Signed-off-by: Namhyung Kim <namhyung@...nel.org>
---
tools/perf/util/stat-display.c | 81 ++++++++++++++++++++++------------
1 file changed, 53 insertions(+), 28 deletions(-)
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index ed421f6d512f..a72c7442ff3d 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -517,46 +517,71 @@ static void print_metric_header(struct perf_stat_config *config,
fprintf(os->fh, "%*s ", config->metric_only_len, unit);
}
-static void abs_printout(struct perf_stat_config *config,
- struct aggr_cpu_id id, int nr, struct evsel *evsel, double avg)
+static void print_counter_value_std(struct perf_stat_config *config,
+ struct evsel *evsel, double avg)
{
FILE *output = config->output;
double sc = evsel->scale;
const char *fmt;
- if (config->csv_output) {
- fmt = floor(sc) != sc ? "%.2f%s" : "%.0f%s";
- } else {
- if (config->big_num)
- fmt = floor(sc) != sc ? "%'18.2f%s" : "%'18.0f%s";
- else
- fmt = floor(sc) != sc ? "%18.2f%s" : "%18.0f%s";
- }
+ if (config->big_num)
+ fmt = floor(sc) != sc ? "%'18.2f " : "%'18.0f ";
+ else
+ fmt = floor(sc) != sc ? "%18.2f " : "%18.0f ";
- aggr_printout(config, evsel, id, nr);
+ fprintf(output, fmt, avg);
- if (config->json_output)
- fprintf(output, "\"counter-value\" : \"%f\", ", avg);
- else
- fprintf(output, fmt, avg, config->csv_sep);
+ if (evsel->unit)
+ fprintf(output, "%-*s ", config->unit_width, evsel->unit);
- if (config->json_output) {
- if (evsel->unit) {
- fprintf(output, "\"unit\" : \"%s\", ",
- evsel->unit);
- }
- } else {
- if (evsel->unit)
- fprintf(output, "%-*s%s",
- config->csv_output ? 0 : config->unit_width,
- evsel->unit, config->csv_sep);
- }
+ fprintf(output, "%-*s", 32, evsel__name(evsel));
+}
+static void print_counter_value_csv(struct perf_stat_config *config,
+ struct evsel *evsel, double avg)
+{
+ FILE *output = config->output;
+ double sc = evsel->scale;
+ const char *sep = config->csv_sep;
+ const char *fmt = floor(sc) != sc ? "%.2f%s" : "%.0f%s";
+
+ fprintf(output, fmt, avg, sep);
+
+ if (evsel->unit)
+ fprintf(output, "%s%s", evsel->unit, sep);
+
+ fprintf(output, "%s", evsel__name(evsel));
+}
+
+static void print_counter_value_json(struct perf_stat_config *config,
+ struct evsel *evsel, double avg)
+{
+ FILE *output = config->output;
+
+ fprintf(output, "\"counter-value\" : \"%f\", ", avg);
+
+ if (evsel->unit)
+ fprintf(output, "\"unit\" : \"%s\", ", evsel->unit);
+
+ fprintf(output, "\"event\" : \"%s\", ", evsel__name(evsel));
+}
+
+static void print_counter_value(struct perf_stat_config *config,
+ struct evsel *evsel, double avg)
+{
if (config->json_output)
- fprintf(output, "\"event\" : \"%s\", ", evsel__name(evsel));
+ print_counter_value_json(config, evsel, avg);
+ else if (config->csv_output)
+ print_counter_value_csv(config, evsel, avg);
else
- fprintf(output, "%-*s", config->csv_output ? 0 : 32, evsel__name(evsel));
+ print_counter_value_std(config, evsel, avg);
+}
+static void abs_printout(struct perf_stat_config *config,
+ struct aggr_cpu_id id, int nr, struct evsel *evsel, double avg)
+{
+ aggr_printout(config, evsel, id, nr);
+ print_counter_value(config, evsel, avg);
print_cgroup(config, evsel);
}
--
2.38.1.493.g58b659f92b-goog
Powered by blists - more mailing lists