]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf stat: Document and clarify outstate members
authorJames Clark <james.clark@linaro.org>
Tue, 12 Nov 2024 16:00:45 +0000 (16:00 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 26 Dec 2024 15:34:52 +0000 (12:34 -0300)
Not all of these are "state" so separate them into two sections. Rename
and document to make all clearer.

Signed-off-by: James Clark <james.clark@linaro.org>
Tested-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Link: https://lore.kernel.org/r/20241112160048.951213-6-james.clark@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/stat-display.c

index 8377e24602ddb4968c76f9a2e13653ecd125c3df..ba79f73e1cf5b426a1a117ecc32a6726448f3b14 100644 (file)
@@ -115,15 +115,29 @@ static void print_running_csv(struct perf_stat_config *config, u64 run, u64 ena)
                config->csv_sep, run, config->csv_sep, enabled_percent);
 }
 struct outstate {
-       FILE *fh;
+       /* Std mode: insert a newline before the next metric */
        bool newline;
+       /* JSON mode: track need for comma for a previous field or not */
        bool first;
+       /* Num CSV separators remaining to pad out when not all fields are printed */
+       int  csv_col_pad;
+
+       /*
+        * The following don't track state across fields, but are here as a shortcut to
+        * pass data to the print functions. The alternative would be to update the
+        * function signatures of the entire print stack to pass them through.
+        */
+       /* Place to output to */
+       FILE * const fh;
        /* Lines are timestamped in --interval-print mode */
        char timestamp[64];
-       int  nfields;
-       int  aggr_nr;
+       /* Num items aggregated in current line. See struct perf_stat_aggr.nr */
+       int aggr_nr;
+       /* Core/socket/die etc ID for the current line */
        struct aggr_cpu_id id;
+       /* Event for current line */
        struct evsel *evsel;
+       /* Cgroup for current line */
        struct cgroup *cgrp;
 };
 
@@ -473,7 +487,7 @@ static void new_line_csv(struct perf_stat_config *config, void *ctx)
        int i;
 
        __new_line_std_csv(config, os);
-       for (i = 0; i < os->nfields; i++)
+       for (i = 0; i < os->csv_col_pad; i++)
                fputs(config->csv_sep, os->fh);
 }
 
@@ -550,12 +564,12 @@ static void print_metricgroup_header_csv(struct perf_stat_config *config,
 
        if (!metricgroup_name) {
                /* Leave space for running and enabling */
-               for (i = 0; i < os->nfields - 2; i++)
+               for (i = 0; i < os->csv_col_pad - 2; i++)
                        fputs(config->csv_sep, os->fh);
                return;
        }
 
-       for (i = 0; i < os->nfields; i++)
+       for (i = 0; i < os->csv_col_pad; i++)
                fputs(config->csv_sep, os->fh);
        fprintf(config->output, "%s", metricgroup_name);
        new_line_csv(config, ctx);
@@ -837,7 +851,7 @@ static void printout(struct perf_stat_config *config, struct outstate *os,
                pm = config->metric_only ? print_metric_only_csv : print_metric_csv;
                nl = config->metric_only ? NULL : new_line_csv;
                pmh = print_metricgroup_header_csv;
-               os->nfields = 4 + (counter->cgrp ? 1 : 0);
+               os->csv_col_pad = 4 + (counter->cgrp ? 1 : 0);
        } else if (config->json_output) {
                pm = config->metric_only ? print_metric_only_json : print_metric_json;
                nl = config->metric_only ? NULL : new_line_json;