aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNamhyung Kim <[email protected]>2022-11-14 15:02:18 -0800
committerArnaldo Carvalho de Melo <[email protected]>2022-11-16 09:51:22 -0300
commitb2d9832e00a0d93ad6127fa8ccf2b8e0cfe67397 (patch)
treee6accb80257984cc83dec02fde3f04010d97e65b
parent8d500292bd55c05130c96f6e84cc3e6ba3ebed99 (diff)
perf stat: Split print_metric_headers() function
The print_metric_headers() shows metric headers a little bit for each mode. Split it out to make the code clearer. Signed-off-by: Namhyung Kim <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Athira Jajeev <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Xing Zhengjun <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
-rw-r--r--tools/perf/util/stat-display.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index e66f766a3d78..bb2791459f5f 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -924,6 +924,37 @@ static const char *aggr_header_csv[] = {
[AGGR_GLOBAL] = ""
};
+static void print_metric_headers_std(struct perf_stat_config *config,
+ const char *prefix, bool no_indent)
+{
+ if (prefix)
+ fprintf(config->output, "%s", prefix);
+ if (!no_indent) {
+ fprintf(config->output, "%*s",
+ aggr_header_lens[config->aggr_mode], "");
+ }
+}
+
+static void print_metric_headers_csv(struct perf_stat_config *config,
+ const char *prefix,
+ bool no_indent __maybe_unused)
+{
+ if (prefix)
+ fprintf(config->output, "%s", prefix);
+ if (config->interval)
+ fputs("time,", config->output);
+ if (!config->iostat_run)
+ fputs(aggr_header_csv[config->aggr_mode], config->output);
+}
+
+static void print_metric_headers_json(struct perf_stat_config *config,
+ const char *prefix __maybe_unused,
+ bool no_indent __maybe_unused)
+{
+ if (config->interval)
+ fputs("{\"unit\" : \"sec\"}", config->output);
+}
+
static void print_metric_headers(struct perf_stat_config *config,
struct evlist *evlist,
const char *prefix, bool no_indent)
@@ -939,22 +970,13 @@ static void print_metric_headers(struct perf_stat_config *config,
.force_header = true,
};
- if (prefix && !config->json_output)
- fprintf(config->output, "%s", prefix);
+ if (config->json_output)
+ print_metric_headers_json(config, prefix, no_indent);
+ else if (config->csv_output)
+ print_metric_headers_csv(config, prefix, no_indent);
+ else
+ print_metric_headers_std(config, prefix, no_indent);
- if (!config->csv_output && !config->json_output && !no_indent)
- fprintf(config->output, "%*s",
- aggr_header_lens[config->aggr_mode], "");
- if (config->csv_output) {
- if (config->interval)
- fputs("time,", config->output);
- if (!config->iostat_run)
- fputs(aggr_header_csv[config->aggr_mode], config->output);
- }
- if (config->json_output) {
- if (config->interval)
- fputs("{\"unit\" : \"sec\"}", config->output);
- }
if (config->iostat_run)
iostat_print_header_prefix(config);