Commit 5f334d88 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf stat: Pass through 'struct outstate'

Now most of the print functions take a pointer to the struct outstate.
We have one in the evlist__print_counters() and pass it through the
child functions.
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20221123180208.2068936-13-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 01577597
...@@ -449,7 +449,7 @@ void iostat_print_metric(struct perf_stat_config *config, struct evsel *evsel, ...@@ -449,7 +449,7 @@ void iostat_print_metric(struct perf_stat_config *config, struct evsel *evsel,
void iostat_print_counters(struct evlist *evlist, void iostat_print_counters(struct evlist *evlist,
struct perf_stat_config *config, struct timespec *ts, struct perf_stat_config *config, struct timespec *ts,
char *prefix, iostat_print_counter_t print_cnt_cb) char *prefix, iostat_print_counter_t print_cnt_cb, void *arg)
{ {
void *perf_device = NULL; void *perf_device = NULL;
struct evsel *counter = evlist__first(evlist); struct evsel *counter = evlist__first(evlist);
...@@ -464,7 +464,7 @@ void iostat_print_counters(struct evlist *evlist, ...@@ -464,7 +464,7 @@ void iostat_print_counters(struct evlist *evlist,
iostat_prefix(evlist, config, prefix, ts); iostat_prefix(evlist, config, prefix, ts);
fprintf(config->output, "\n%s", prefix); fprintf(config->output, "\n%s", prefix);
} }
print_cnt_cb(config, counter, prefix); print_cnt_cb(config, counter, arg);
} }
fputc('\n', config->output); fputc('\n', config->output);
} }
...@@ -48,6 +48,7 @@ __weak void iostat_print_counters(struct evlist *evlist __maybe_unused, ...@@ -48,6 +48,7 @@ __weak void iostat_print_counters(struct evlist *evlist __maybe_unused,
struct perf_stat_config *config __maybe_unused, struct perf_stat_config *config __maybe_unused,
struct timespec *ts __maybe_unused, struct timespec *ts __maybe_unused,
char *prefix __maybe_unused, char *prefix __maybe_unused,
iostat_print_counter_t print_cnt_cb __maybe_unused) iostat_print_counter_t print_cnt_cb __maybe_unused,
void *arg __maybe_unused)
{ {
} }
...@@ -28,7 +28,7 @@ enum iostat_mode_t { ...@@ -28,7 +28,7 @@ enum iostat_mode_t {
extern enum iostat_mode_t iostat_mode; extern enum iostat_mode_t iostat_mode;
typedef void (*iostat_print_counter_t)(struct perf_stat_config *, struct evsel *, const char *); typedef void (*iostat_print_counter_t)(struct perf_stat_config *, struct evsel *, void *);
int iostat_prepare(struct evlist *evlist, struct perf_stat_config *config); int iostat_prepare(struct evlist *evlist, struct perf_stat_config *config);
int iostat_parse(const struct option *opt, const char *str, int iostat_parse(const struct option *opt, const char *str,
...@@ -42,6 +42,6 @@ void iostat_print_metric(struct perf_stat_config *config, struct evsel *evsel, ...@@ -42,6 +42,6 @@ void iostat_print_metric(struct perf_stat_config *config, struct evsel *evsel,
struct perf_stat_output_ctx *out); struct perf_stat_output_ctx *out);
void iostat_print_counters(struct evlist *evlist, void iostat_print_counters(struct evlist *evlist,
struct perf_stat_config *config, struct timespec *ts, struct perf_stat_config *config, struct timespec *ts,
char *prefix, iostat_print_counter_t print_cnt_cb); char *prefix, iostat_print_counter_t print_cnt_cb, void *arg);
#endif /* _IOSTAT_H */ #endif /* _IOSTAT_H */
...@@ -796,7 +796,7 @@ static void uniquify_counter(struct perf_stat_config *config, struct evsel *coun ...@@ -796,7 +796,7 @@ static void uniquify_counter(struct perf_stat_config *config, struct evsel *coun
static void print_counter_aggrdata(struct perf_stat_config *config, static void print_counter_aggrdata(struct perf_stat_config *config,
struct evsel *counter, int s, struct evsel *counter, int s,
const char *prefix) struct outstate *os)
{ {
FILE *output = config->output; FILE *output = config->output;
u64 ena, run, val; u64 ena, run, val;
...@@ -806,13 +806,10 @@ static void print_counter_aggrdata(struct perf_stat_config *config, ...@@ -806,13 +806,10 @@ static void print_counter_aggrdata(struct perf_stat_config *config,
struct aggr_cpu_id id = config->aggr_map->map[s]; struct aggr_cpu_id id = config->aggr_map->map[s];
double avg = aggr->counts.val; double avg = aggr->counts.val;
bool metric_only = config->metric_only; bool metric_only = config->metric_only;
struct outstate os = {
.fh = config->output, os->id = id;
.prefix = prefix ? prefix : "", os->nr = aggr->nr;
.id = id, os->evsel = counter;
.nr = aggr->nr,
.evsel = counter,
};
if (counter->supported && aggr->nr == 0) if (counter->supported && aggr->nr == 0)
return; return;
...@@ -824,8 +821,8 @@ static void print_counter_aggrdata(struct perf_stat_config *config, ...@@ -824,8 +821,8 @@ static void print_counter_aggrdata(struct perf_stat_config *config,
run = aggr->counts.run; run = aggr->counts.run;
if (!metric_only) { if (!metric_only) {
if (prefix) if (os->prefix)
fprintf(output, "%s", prefix); fprintf(output, "%s", os->prefix);
else if (config->summary && config->csv_output && else if (config->summary && config->csv_output &&
!config->no_csv_summary && !config->interval) !config->no_csv_summary && !config->interval)
fprintf(output, "%s%s", "summary", config->csv_sep); fprintf(output, "%s%s", "summary", config->csv_sep);
...@@ -833,7 +830,7 @@ static void print_counter_aggrdata(struct perf_stat_config *config, ...@@ -833,7 +830,7 @@ static void print_counter_aggrdata(struct perf_stat_config *config,
uval = val * counter->scale; uval = val * counter->scale;
printout(config, &os, uval, run, ena, avg, s); printout(config, os, uval, run, ena, avg, s);
if (!metric_only) if (!metric_only)
fputc('\n', output); fputc('\n', output);
...@@ -871,12 +868,9 @@ static void print_metric_end(struct perf_stat_config *config) ...@@ -871,12 +868,9 @@ static void print_metric_end(struct perf_stat_config *config)
static void print_aggr(struct perf_stat_config *config, static void print_aggr(struct perf_stat_config *config,
struct evlist *evlist, struct evlist *evlist,
const char *prefix) struct outstate *os)
{ {
struct evsel *counter; struct evsel *counter;
struct outstate os = {
.prefix = prefix,
};
int s; int s;
if (!config->aggr_map || !config->aggr_get_id) if (!config->aggr_map || !config->aggr_get_id)
...@@ -887,13 +881,13 @@ static void print_aggr(struct perf_stat_config *config, ...@@ -887,13 +881,13 @@ static void print_aggr(struct perf_stat_config *config,
* Without each counter has its own line. * Without each counter has its own line.
*/ */
for (s = 0; s < config->aggr_map->nr; s++) { for (s = 0; s < config->aggr_map->nr; s++) {
print_metric_begin(config, evlist, &os, s); print_metric_begin(config, evlist, os, s);
evlist__for_each_entry(evlist, counter) { evlist__for_each_entry(evlist, counter) {
if (counter->merged_stat) if (counter->merged_stat)
continue; continue;
print_counter_aggrdata(config, counter, s, prefix); print_counter_aggrdata(config, counter, s, os);
} }
print_metric_end(config); print_metric_end(config);
} }
...@@ -901,34 +895,31 @@ static void print_aggr(struct perf_stat_config *config, ...@@ -901,34 +895,31 @@ static void print_aggr(struct perf_stat_config *config,
static void print_aggr_cgroup(struct perf_stat_config *config, static void print_aggr_cgroup(struct perf_stat_config *config,
struct evlist *evlist, struct evlist *evlist,
const char *prefix) struct outstate *os)
{ {
struct evsel *counter, *evsel; struct evsel *counter, *evsel;
struct outstate os = {
.prefix = prefix,
};
int s; int s;
if (!config->aggr_map || !config->aggr_get_id) if (!config->aggr_map || !config->aggr_get_id)
return; return;
evlist__for_each_entry(evlist, evsel) { evlist__for_each_entry(evlist, evsel) {
if (os.cgrp == evsel->cgrp) if (os->cgrp == evsel->cgrp)
continue; continue;
os.cgrp = evsel->cgrp; os->cgrp = evsel->cgrp;
for (s = 0; s < config->aggr_map->nr; s++) { for (s = 0; s < config->aggr_map->nr; s++) {
print_metric_begin(config, evlist, &os, s); print_metric_begin(config, evlist, os, s);
evlist__for_each_entry(evlist, counter) { evlist__for_each_entry(evlist, counter) {
if (counter->merged_stat) if (counter->merged_stat)
continue; continue;
if (counter->cgrp != os.cgrp) if (counter->cgrp != os->cgrp)
continue; continue;
print_counter_aggrdata(config, counter, s, prefix); print_counter_aggrdata(config, counter, s, os);
} }
print_metric_end(config); print_metric_end(config);
} }
...@@ -936,7 +927,7 @@ static void print_aggr_cgroup(struct perf_stat_config *config, ...@@ -936,7 +927,7 @@ static void print_aggr_cgroup(struct perf_stat_config *config,
} }
static void print_counter(struct perf_stat_config *config, static void print_counter(struct perf_stat_config *config,
struct evsel *counter, const char *prefix) struct evsel *counter, struct outstate *os)
{ {
int s; int s;
...@@ -948,19 +939,16 @@ static void print_counter(struct perf_stat_config *config, ...@@ -948,19 +939,16 @@ static void print_counter(struct perf_stat_config *config,
return; return;
for (s = 0; s < config->aggr_map->nr; s++) { for (s = 0; s < config->aggr_map->nr; s++) {
print_counter_aggrdata(config, counter, s, prefix); print_counter_aggrdata(config, counter, s, os);
} }
} }
static void print_no_aggr_metric(struct perf_stat_config *config, static void print_no_aggr_metric(struct perf_stat_config *config,
struct evlist *evlist, struct evlist *evlist,
const char *prefix) struct outstate *os)
{ {
int all_idx; int all_idx;
struct perf_cpu cpu; struct perf_cpu cpu;
struct outstate os = {
.prefix = prefix,
};
perf_cpu_map__for_each_cpu(cpu, all_idx, evlist->core.user_requested_cpus) { perf_cpu_map__for_each_cpu(cpu, all_idx, evlist->core.user_requested_cpus) {
struct evsel *counter; struct evsel *counter;
...@@ -975,10 +963,10 @@ static void print_no_aggr_metric(struct perf_stat_config *config, ...@@ -975,10 +963,10 @@ static void print_no_aggr_metric(struct perf_stat_config *config,
if (counter_idx < 0) if (counter_idx < 0)
continue; continue;
os.evsel = counter; os->evsel = counter;
os.id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); os->id = aggr_cpu_id__cpu(cpu, /*data=*/NULL);
if (first) { if (first) {
print_metric_begin(config, evlist, &os, counter_idx); print_metric_begin(config, evlist, os, counter_idx);
first = false; first = false;
} }
val = ps->aggr[counter_idx].counts.val; val = ps->aggr[counter_idx].counts.val;
...@@ -986,7 +974,7 @@ static void print_no_aggr_metric(struct perf_stat_config *config, ...@@ -986,7 +974,7 @@ static void print_no_aggr_metric(struct perf_stat_config *config,
run = ps->aggr[counter_idx].counts.run; run = ps->aggr[counter_idx].counts.run;
uval = val * counter->scale; uval = val * counter->scale;
printout(config, &os, uval, run, ena, 1.0, counter_idx); printout(config, os, uval, run, ena, 1.0, counter_idx);
} }
if (!first) if (!first)
print_metric_end(config); print_metric_end(config);
...@@ -1304,7 +1292,7 @@ static void print_footer(struct perf_stat_config *config) ...@@ -1304,7 +1292,7 @@ static void print_footer(struct perf_stat_config *config)
} }
static void print_percore(struct perf_stat_config *config, static void print_percore(struct perf_stat_config *config,
struct evsel *counter, const char *prefix) struct evsel *counter, struct outstate *os)
{ {
bool metric_only = config->metric_only; bool metric_only = config->metric_only;
FILE *output = config->output; FILE *output = config->output;
...@@ -1315,7 +1303,7 @@ static void print_percore(struct perf_stat_config *config, ...@@ -1315,7 +1303,7 @@ static void print_percore(struct perf_stat_config *config,
return; return;
if (config->percore_show_thread) if (config->percore_show_thread)
return print_counter(config, counter, prefix); return print_counter(config, counter, os);
core_map = cpu_aggr_map__empty_new(config->aggr_map->nr); core_map = cpu_aggr_map__empty_new(config->aggr_map->nr);
if (core_map == NULL) { if (core_map == NULL) {
...@@ -1337,7 +1325,7 @@ static void print_percore(struct perf_stat_config *config, ...@@ -1337,7 +1325,7 @@ static void print_percore(struct perf_stat_config *config,
if (found) if (found)
continue; continue;
print_counter_aggrdata(config, counter, s, prefix); print_counter_aggrdata(config, counter, s, os);
core_map->map[c++] = core_id; core_map->map[c++] = core_id;
} }
...@@ -1348,30 +1336,28 @@ static void print_percore(struct perf_stat_config *config, ...@@ -1348,30 +1336,28 @@ static void print_percore(struct perf_stat_config *config,
} }
static void print_cgroup_counter(struct perf_stat_config *config, struct evlist *evlist, static void print_cgroup_counter(struct perf_stat_config *config, struct evlist *evlist,
const char *prefix) struct outstate *os)
{ {
struct evsel *counter; struct evsel *counter;
struct outstate os = {
.prefix = prefix,
};
evlist__for_each_entry(evlist, counter) { evlist__for_each_entry(evlist, counter) {
if (os.cgrp != counter->cgrp) { if (os->cgrp != counter->cgrp) {
if (os.cgrp != NULL) if (os->cgrp != NULL)
print_metric_end(config); print_metric_end(config);
os.cgrp = counter->cgrp; os->cgrp = counter->cgrp;
print_metric_begin(config, evlist, &os, /*aggr_idx=*/0); print_metric_begin(config, evlist, os, /*aggr_idx=*/0);
} }
print_counter(config, counter, prefix); print_counter(config, counter, os);
} }
if (os.cgrp) if (os->cgrp)
print_metric_end(config); print_metric_end(config);
} }
void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *config, void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *config,
struct target *_target, struct timespec *ts, int argc, const char **argv) struct target *_target, struct timespec *ts,
int argc, const char **argv)
{ {
bool metric_only = config->metric_only; bool metric_only = config->metric_only;
int interval = config->interval; int interval = config->interval;
...@@ -1397,34 +1383,34 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf ...@@ -1397,34 +1383,34 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf
case AGGR_SOCKET: case AGGR_SOCKET:
case AGGR_NODE: case AGGR_NODE:
if (config->cgroup_list) if (config->cgroup_list)
print_aggr_cgroup(config, evlist, os.prefix); print_aggr_cgroup(config, evlist, &os);
else else
print_aggr(config, evlist, os.prefix); print_aggr(config, evlist, &os);
break; break;
case AGGR_THREAD: case AGGR_THREAD:
case AGGR_GLOBAL: case AGGR_GLOBAL:
if (config->iostat_run) { if (config->iostat_run) {
iostat_print_counters(evlist, config, ts, buf, iostat_print_counters(evlist, config, ts, buf,
print_counter); (iostat_print_counter_t)print_counter, &os);
} else if (config->cgroup_list) { } else if (config->cgroup_list) {
print_cgroup_counter(config, evlist, os.prefix); print_cgroup_counter(config, evlist, &os);
} else { } else {
print_metric_begin(config, evlist, &os, /*aggr_idx=*/0); print_metric_begin(config, evlist, &os, /*aggr_idx=*/0);
evlist__for_each_entry(evlist, counter) { evlist__for_each_entry(evlist, counter) {
print_counter(config, counter, os.prefix); print_counter(config, counter, &os);
} }
print_metric_end(config); print_metric_end(config);
} }
break; break;
case AGGR_NONE: case AGGR_NONE:
if (metric_only) if (metric_only)
print_no_aggr_metric(config, evlist, os.prefix); print_no_aggr_metric(config, evlist, &os);
else { else {
evlist__for_each_entry(evlist, counter) { evlist__for_each_entry(evlist, counter) {
if (counter->percore) if (counter->percore)
print_percore(config, counter, os.prefix); print_percore(config, counter, &os);
else else
print_counter(config, counter, os.prefix); print_counter(config, counter, &os);
} }
} }
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment