lkml.org 
[lkml]   [2022]   [Nov]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 10/19] perf stat: Split print_metric_headers() function
Date
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 <namhyung@kernel.org>
---
tools/perf/util/stat-display.c | 52 ++++++++++++++++++++++++----------
1 file 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);

--
2.38.1.493.g58b659f92b-goog
\
 
 \ /
  Last update: 2022-11-15 00:04    [W:0.120 / U:0.044 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site