Commit eee41e6b authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim

perf stat: Pass fewer metric arguments

Pass metric_expr and evsel rather than specific variables from the
struct, thereby reducing the number of arguments. This will enable
later fixes.

To reduce the size of the diff, local variables are added to match the
previous parameter names. This isn't done in the case of "name" as
evsel->name is more intention revealing. A whitespace issue is also
addressed.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Kaige Ye <ye@kaige.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: John Garry <john.g.garry@oracle.com>
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240221070754.4163916-1-irogers@google.com
parent 659663f0
...@@ -355,11 +355,12 @@ static void print_nsecs(struct perf_stat_config *config, ...@@ -355,11 +355,12 @@ static void print_nsecs(struct perf_stat_config *config,
print_metric(config, ctxp, NULL, NULL, "CPUs utilized", 0); print_metric(config, ctxp, NULL, NULL, "CPUs utilized", 0);
} }
static int prepare_metric(struct evsel **metric_events, static int prepare_metric(const struct metric_expr *mexp,
struct metric_ref *metric_refs,
struct expr_parse_ctx *pctx, struct expr_parse_ctx *pctx,
int aggr_idx) int aggr_idx)
{ {
struct evsel * const *metric_events = mexp->metric_events;
struct metric_ref *metric_refs = mexp->metric_refs;
int i; int i;
for (i = 0; metric_events[i]; i++) { for (i = 0; metric_events[i]; i++) {
...@@ -436,18 +437,18 @@ static int prepare_metric(struct evsel **metric_events, ...@@ -436,18 +437,18 @@ static int prepare_metric(struct evsel **metric_events,
} }
static void generic_metric(struct perf_stat_config *config, static void generic_metric(struct perf_stat_config *config,
const char *metric_expr, struct metric_expr *mexp,
const char *metric_threshold, struct evsel *evsel,
struct evsel **metric_events,
struct metric_ref *metric_refs,
char *name,
const char *metric_name,
const char *metric_unit,
int runtime,
int aggr_idx, int aggr_idx,
struct perf_stat_output_ctx *out) struct perf_stat_output_ctx *out)
{ {
print_metric_t print_metric = out->print_metric; print_metric_t print_metric = out->print_metric;
const char *metric_name = mexp->metric_name;
const char *metric_expr = mexp->metric_expr;
const char *metric_threshold = mexp->metric_threshold;
const char *metric_unit = mexp->metric_unit;
struct evsel * const *metric_events = mexp->metric_events;
int runtime = mexp->runtime;
struct expr_parse_ctx *pctx; struct expr_parse_ctx *pctx;
double ratio, scale, threshold; double ratio, scale, threshold;
int i; int i;
...@@ -462,7 +463,7 @@ static void generic_metric(struct perf_stat_config *config, ...@@ -462,7 +463,7 @@ static void generic_metric(struct perf_stat_config *config,
pctx->sctx.user_requested_cpu_list = strdup(config->user_requested_cpu_list); pctx->sctx.user_requested_cpu_list = strdup(config->user_requested_cpu_list);
pctx->sctx.runtime = runtime; pctx->sctx.runtime = runtime;
pctx->sctx.system_wide = config->system_wide; pctx->sctx.system_wide = config->system_wide;
i = prepare_metric(metric_events, metric_refs, pctx, aggr_idx); i = prepare_metric(mexp, pctx, aggr_idx);
if (i < 0) { if (i < 0) {
expr__ctx_free(pctx); expr__ctx_free(pctx);
return; return;
...@@ -497,18 +498,18 @@ static void generic_metric(struct perf_stat_config *config, ...@@ -497,18 +498,18 @@ static void generic_metric(struct perf_stat_config *config,
print_metric(config, ctxp, color, "%8.2f", print_metric(config, ctxp, color, "%8.2f",
metric_name ? metric_name ?
metric_name : metric_name :
out->force_header ? name : "", out->force_header ? evsel->name : "",
ratio); ratio);
} }
} else { } else {
print_metric(config, ctxp, color, /*unit=*/NULL, print_metric(config, ctxp, color, /*unit=*/NULL,
out->force_header ? out->force_header ?
(metric_name ? metric_name : name) : "", 0); (metric_name ?: evsel->name) : "", 0);
} }
} else { } else {
print_metric(config, ctxp, color, /*unit=*/NULL, print_metric(config, ctxp, color, /*unit=*/NULL,
out->force_header ? out->force_header ?
(metric_name ? metric_name : name) : "", 0); (metric_name ?: evsel->name) : "", 0);
} }
expr__ctx_free(pctx); expr__ctx_free(pctx);
...@@ -523,7 +524,7 @@ double test_generic_metric(struct metric_expr *mexp, int aggr_idx) ...@@ -523,7 +524,7 @@ double test_generic_metric(struct metric_expr *mexp, int aggr_idx)
if (!pctx) if (!pctx)
return NAN; return NAN;
if (prepare_metric(mexp->metric_events, mexp->metric_refs, pctx, aggr_idx) < 0) if (prepare_metric(mexp, pctx, aggr_idx) < 0)
goto out; goto out;
if (expr__parse(&ratio, pctx, mexp->metric_expr)) if (expr__parse(&ratio, pctx, mexp->metric_expr))
...@@ -625,10 +626,7 @@ void *perf_stat__print_shadow_stats_metricgroup(struct perf_stat_config *config, ...@@ -625,10 +626,7 @@ void *perf_stat__print_shadow_stats_metricgroup(struct perf_stat_config *config,
if ((*num)++ > 0) if ((*num)++ > 0)
out->new_line(config, ctxp); out->new_line(config, ctxp);
generic_metric(config, mexp->metric_expr, mexp->metric_threshold, generic_metric(config, mexp, evsel, aggr_idx, out);
mexp->metric_events, mexp->metric_refs, evsel->name,
mexp->metric_name, mexp->metric_unit, mexp->runtime,
aggr_idx, out);
} }
return NULL; return NULL;
......
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