Skip to content

Commit ed60738

Browse files
james-c-linaroacmel
authored andcommitted
perf stat: Document and clarify outstate members
Not all of these are "state" so separate them into two sections. Rename and document to make all clearer. Signed-off-by: James Clark <[email protected]> Tested-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Tim Chen <[email protected]> Cc: Yicong Yang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent dd56668 commit ed60738

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

tools/perf/util/stat-display.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,29 @@ static void print_running_csv(struct perf_stat_config *config, u64 run, u64 ena)
115115
config->csv_sep, run, config->csv_sep, enabled_percent);
116116
}
117117
struct outstate {
118-
FILE *fh;
118+
/* Std mode: insert a newline before the next metric */
119119
bool newline;
120+
/* JSON mode: track need for comma for a previous field or not */
120121
bool first;
122+
/* Num CSV separators remaining to pad out when not all fields are printed */
123+
int csv_col_pad;
124+
125+
/*
126+
* The following don't track state across fields, but are here as a shortcut to
127+
* pass data to the print functions. The alternative would be to update the
128+
* function signatures of the entire print stack to pass them through.
129+
*/
130+
/* Place to output to */
131+
FILE * const fh;
121132
/* Lines are timestamped in --interval-print mode */
122133
char timestamp[64];
123-
int nfields;
124-
int aggr_nr;
134+
/* Num items aggregated in current line. See struct perf_stat_aggr.nr */
135+
int aggr_nr;
136+
/* Core/socket/die etc ID for the current line */
125137
struct aggr_cpu_id id;
138+
/* Event for current line */
126139
struct evsel *evsel;
140+
/* Cgroup for current line */
127141
struct cgroup *cgrp;
128142
};
129143

@@ -473,7 +487,7 @@ static void new_line_csv(struct perf_stat_config *config, void *ctx)
473487
int i;
474488

475489
__new_line_std_csv(config, os);
476-
for (i = 0; i < os->nfields; i++)
490+
for (i = 0; i < os->csv_col_pad; i++)
477491
fputs(config->csv_sep, os->fh);
478492
}
479493

@@ -550,12 +564,12 @@ static void print_metricgroup_header_csv(struct perf_stat_config *config,
550564

551565
if (!metricgroup_name) {
552566
/* Leave space for running and enabling */
553-
for (i = 0; i < os->nfields - 2; i++)
567+
for (i = 0; i < os->csv_col_pad - 2; i++)
554568
fputs(config->csv_sep, os->fh);
555569
return;
556570
}
557571

558-
for (i = 0; i < os->nfields; i++)
572+
for (i = 0; i < os->csv_col_pad; i++)
559573
fputs(config->csv_sep, os->fh);
560574
fprintf(config->output, "%s", metricgroup_name);
561575
new_line_csv(config, ctx);
@@ -837,7 +851,7 @@ static void printout(struct perf_stat_config *config, struct outstate *os,
837851
pm = config->metric_only ? print_metric_only_csv : print_metric_csv;
838852
nl = config->metric_only ? NULL : new_line_csv;
839853
pmh = print_metricgroup_header_csv;
840-
os->nfields = 4 + (counter->cgrp ? 1 : 0);
854+
os->csv_col_pad = 4 + (counter->cgrp ? 1 : 0);
841855
} else if (config->json_output) {
842856
pm = config->metric_only ? print_metric_only_json : print_metric_json;
843857
nl = config->metric_only ? NULL : new_line_json;

0 commit comments

Comments
 (0)