Commit 0ce5aa02 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf stat: Move 'metric_only' to 'struct perf_stat_config'

Move the static 'metric_only' variable to 'struct perf_stat_config', so
it can be passed around and used outside the 'perf stat' command.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180830063252.23729-23-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 132c6ba3
...@@ -163,7 +163,6 @@ static const char *post_cmd = NULL; ...@@ -163,7 +163,6 @@ static const char *post_cmd = NULL;
static bool sync_run = false; static bool sync_run = false;
static unsigned int unit_width = 4; /* strlen("unit") */ static unsigned int unit_width = 4; /* strlen("unit") */
static bool forever = false; static bool forever = false;
static bool metric_only = false;
static bool force_metric_only = false; static bool force_metric_only = false;
static bool no_merge = false; static bool no_merge = false;
static bool walltime_run_table = false; static bool walltime_run_table = false;
...@@ -1013,7 +1012,7 @@ static void printout(struct perf_stat_config *config, int id, int nr, ...@@ -1013,7 +1012,7 @@ static void printout(struct perf_stat_config *config, int id, int nr,
print_metric_t pm = print_metric_std; print_metric_t pm = print_metric_std;
new_line_t nl; new_line_t nl;
if (metric_only) { if (config->metric_only) {
nl = new_line_metric; nl = new_line_metric;
if (config->csv_output) if (config->csv_output)
pm = print_metric_only_csv; pm = print_metric_only_csv;
...@@ -1022,7 +1021,7 @@ static void printout(struct perf_stat_config *config, int id, int nr, ...@@ -1022,7 +1021,7 @@ static void printout(struct perf_stat_config *config, int id, int nr,
} else } else
nl = new_line_std; nl = new_line_std;
if (config->csv_output && !metric_only) { if (config->csv_output && !config->metric_only) {
static int aggr_fields[] = { static int aggr_fields[] = {
[AGGR_GLOBAL] = 0, [AGGR_GLOBAL] = 0,
[AGGR_THREAD] = 1, [AGGR_THREAD] = 1,
...@@ -1039,7 +1038,7 @@ static void printout(struct perf_stat_config *config, int id, int nr, ...@@ -1039,7 +1038,7 @@ static void printout(struct perf_stat_config *config, int id, int nr,
os.nfields++; os.nfields++;
} }
if (run == 0 || ena == 0 || counter->counts->scaled == -1) { if (run == 0 || ena == 0 || counter->counts->scaled == -1) {
if (metric_only) { if (config->metric_only) {
pm(config, &os, NULL, "", "", 0); pm(config, &os, NULL, "", "", 0);
return; return;
} }
...@@ -1077,7 +1076,7 @@ static void printout(struct perf_stat_config *config, int id, int nr, ...@@ -1077,7 +1076,7 @@ static void printout(struct perf_stat_config *config, int id, int nr,
return; return;
} }
if (!metric_only) if (!config->metric_only)
abs_printout(config, id, nr, counter, uval); abs_printout(config, id, nr, counter, uval);
out.print_metric = pm; out.print_metric = pm;
...@@ -1085,7 +1084,7 @@ static void printout(struct perf_stat_config *config, int id, int nr, ...@@ -1085,7 +1084,7 @@ static void printout(struct perf_stat_config *config, int id, int nr,
out.ctx = &os; out.ctx = &os;
out.force_header = false; out.force_header = false;
if (config->csv_output && !metric_only) { if (config->csv_output && !config->metric_only) {
print_noise(config, counter, noise); print_noise(config, counter, noise);
print_running(config, run, ena); print_running(config, run, ena);
} }
...@@ -1093,7 +1092,7 @@ static void printout(struct perf_stat_config *config, int id, int nr, ...@@ -1093,7 +1092,7 @@ static void printout(struct perf_stat_config *config, int id, int nr,
perf_stat__print_shadow_stats(config, counter, uval, perf_stat__print_shadow_stats(config, counter, uval,
first_shadow_cpu(counter, id), first_shadow_cpu(counter, id),
&out, &metric_events, st); &out, &metric_events, st);
if (!config->csv_output && !metric_only) { if (!config->csv_output && !config->metric_only) {
print_noise(config, counter, noise); print_noise(config, counter, noise);
print_running(config, run, ena); print_running(config, run, ena);
} }
...@@ -1225,6 +1224,7 @@ static void aggr_cb(struct perf_evsel *counter, void *data, bool first) ...@@ -1225,6 +1224,7 @@ static void aggr_cb(struct perf_evsel *counter, void *data, bool first)
static void print_aggr(struct perf_stat_config *config, static void print_aggr(struct perf_stat_config *config,
char *prefix) char *prefix)
{ {
bool metric_only = config->metric_only;
FILE *output = config->output; FILE *output = config->output;
struct perf_evsel *counter; struct perf_evsel *counter;
int s, id, nr; int s, id, nr;
...@@ -1388,6 +1388,7 @@ static void counter_aggr_cb(struct perf_evsel *counter, void *data, ...@@ -1388,6 +1388,7 @@ static void counter_aggr_cb(struct perf_evsel *counter, void *data,
static void print_counter_aggr(struct perf_stat_config *config, static void print_counter_aggr(struct perf_stat_config *config,
struct perf_evsel *counter, char *prefix) struct perf_evsel *counter, char *prefix)
{ {
bool metric_only = config->metric_only;
FILE *output = config->output; FILE *output = config->output;
double uval; double uval;
struct caggr_data cd = { .avg = 0.0 }; struct caggr_data cd = { .avg = 0.0 };
...@@ -1540,6 +1541,7 @@ static void print_metric_headers(struct perf_stat_config *config, ...@@ -1540,6 +1541,7 @@ static void print_metric_headers(struct perf_stat_config *config,
static void print_interval(struct perf_stat_config *config, static void print_interval(struct perf_stat_config *config,
char *prefix, struct timespec *ts) char *prefix, struct timespec *ts)
{ {
bool metric_only = config->metric_only;
FILE *output = config->output; FILE *output = config->output;
static int num_print_interval; static int num_print_interval;
...@@ -1716,6 +1718,7 @@ perf_evlist__print_counters(struct perf_evlist *evlist, ...@@ -1716,6 +1718,7 @@ perf_evlist__print_counters(struct perf_evlist *evlist,
struct timespec *ts, struct timespec *ts,
int argc, const char **argv) int argc, const char **argv)
{ {
bool metric_only = config->metric_only;
int interval = config->interval; int interval = config->interval;
struct perf_evsel *counter; struct perf_evsel *counter;
char buf[64], *prefix = NULL; char buf[64], *prefix = NULL;
...@@ -1843,7 +1846,7 @@ static int enable_metric_only(const struct option *opt __maybe_unused, ...@@ -1843,7 +1846,7 @@ static int enable_metric_only(const struct option *opt __maybe_unused,
const char *s __maybe_unused, int unset) const char *s __maybe_unused, int unset)
{ {
force_metric_only = true; force_metric_only = true;
metric_only = !unset; stat_config.metric_only = !unset;
return 0; return 0;
} }
...@@ -1922,7 +1925,7 @@ static const struct option stat_options[] = { ...@@ -1922,7 +1925,7 @@ static const struct option stat_options[] = {
"aggregate counts per thread", AGGR_THREAD), "aggregate counts per thread", AGGR_THREAD),
OPT_UINTEGER('D', "delay", &stat_config.initial_delay, OPT_UINTEGER('D', "delay", &stat_config.initial_delay,
"ms to wait before starting measurement after program start"), "ms to wait before starting measurement after program start"),
OPT_CALLBACK_NOOPT(0, "metric-only", &metric_only, NULL, OPT_CALLBACK_NOOPT(0, "metric-only", &stat_config.metric_only, NULL,
"Only print computed metrics. No raw values", enable_metric_only), "Only print computed metrics. No raw values", enable_metric_only),
OPT_BOOLEAN(0, "topdown", &topdown_run, OPT_BOOLEAN(0, "topdown", &topdown_run,
"measure topdown level 1 statistics"), "measure topdown level 1 statistics"),
...@@ -2345,7 +2348,7 @@ static int add_default_attributes(void) ...@@ -2345,7 +2348,7 @@ static int add_default_attributes(void)
if (pmu_have_event("msr", "aperf") && if (pmu_have_event("msr", "aperf") &&
pmu_have_event("msr", "smi")) { pmu_have_event("msr", "smi")) {
if (!force_metric_only) if (!force_metric_only)
metric_only = true; stat_config.metric_only = true;
err = parse_events(evsel_list, smi_cost_attrs, &errinfo); err = parse_events(evsel_list, smi_cost_attrs, &errinfo);
} else { } else {
fprintf(stderr, "To measure SMI cost, it needs " fprintf(stderr, "To measure SMI cost, it needs "
...@@ -2376,7 +2379,7 @@ static int add_default_attributes(void) ...@@ -2376,7 +2379,7 @@ static int add_default_attributes(void)
} }
if (!force_metric_only) if (!force_metric_only)
metric_only = true; stat_config.metric_only = true;
if (topdown_filter_events(topdown_attrs, &str, if (topdown_filter_events(topdown_attrs, &str,
arch_topdown_check_group(&warn)) < 0) { arch_topdown_check_group(&warn)) < 0) {
pr_err("Out of memory\n"); pr_err("Out of memory\n");
...@@ -2776,12 +2779,12 @@ int cmd_stat(int argc, const char **argv) ...@@ -2776,12 +2779,12 @@ int cmd_stat(int argc, const char **argv)
goto out; goto out;
} }
if (metric_only && stat_config.aggr_mode == AGGR_THREAD) { if (stat_config.metric_only && stat_config.aggr_mode == AGGR_THREAD) {
fprintf(stderr, "--metric-only is not supported with --per-thread\n"); fprintf(stderr, "--metric-only is not supported with --per-thread\n");
goto out; goto out;
} }
if (metric_only && run_count > 1) { if (stat_config.metric_only && run_count > 1) {
fprintf(stderr, "--metric-only is not supported with -r\n"); fprintf(stderr, "--metric-only is not supported with -r\n");
goto out; goto out;
} }
......
...@@ -93,6 +93,7 @@ struct perf_stat_config { ...@@ -93,6 +93,7 @@ struct perf_stat_config {
bool identifier; bool identifier;
bool csv_output; bool csv_output;
bool interval_clear; bool interval_clear;
bool metric_only;
FILE *output; FILE *output;
unsigned int interval; unsigned int interval;
unsigned int timeout; unsigned int timeout;
......
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