Commit 2cfaa853 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf tools: Factor out prepare_metric function

Factoring out prepare_metric function so it can be used in test
interface coming in following changes.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Acked-by: default avatarIan Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200602214741.1218986-10-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent f78ac00a
...@@ -730,25 +730,16 @@ static void print_smi_cost(struct perf_stat_config *config, ...@@ -730,25 +730,16 @@ static void print_smi_cost(struct perf_stat_config *config,
out->print_metric(config, out->ctx, NULL, "%4.0f", "SMI#", smi_num); out->print_metric(config, out->ctx, NULL, "%4.0f", "SMI#", smi_num);
} }
static void generic_metric(struct perf_stat_config *config, static int prepare_metric(struct evsel **metric_events,
const char *metric_expr, struct expr_parse_ctx *pctx,
struct evsel **metric_events,
char *name,
const char *metric_name,
const char *metric_unit,
int runtime,
int cpu, int cpu,
struct perf_stat_output_ctx *out,
struct runtime_stat *st) struct runtime_stat *st)
{ {
print_metric_t print_metric = out->print_metric; double scale;
struct expr_parse_ctx pctx;
double ratio, scale;
int i;
void *ctxp = out->ctx;
char *n, *pn; char *n, *pn;
int i;
expr__ctx_init(&pctx); expr__ctx_init(pctx);
for (i = 0; metric_events[i]; i++) { for (i = 0; metric_events[i]; i++) {
struct saved_value *v; struct saved_value *v;
struct stats *stats; struct stats *stats;
...@@ -771,7 +762,7 @@ static void generic_metric(struct perf_stat_config *config, ...@@ -771,7 +762,7 @@ static void generic_metric(struct perf_stat_config *config,
n = strdup(metric_events[i]->name); n = strdup(metric_events[i]->name);
if (!n) if (!n)
return; return -ENOMEM;
/* /*
* This display code with --no-merge adds [cpu] postfixes. * This display code with --no-merge adds [cpu] postfixes.
* These are not supported by the parser. Remove everything * These are not supported by the parser. Remove everything
...@@ -782,11 +773,35 @@ static void generic_metric(struct perf_stat_config *config, ...@@ -782,11 +773,35 @@ static void generic_metric(struct perf_stat_config *config,
*pn = 0; *pn = 0;
if (metric_total) if (metric_total)
expr__add_id(&pctx, n, metric_total); expr__add_id(pctx, n, metric_total);
else else
expr__add_id(&pctx, n, avg_stats(stats)*scale); expr__add_id(pctx, n, avg_stats(stats)*scale);
} }
return i;
}
static void generic_metric(struct perf_stat_config *config,
const char *metric_expr,
struct evsel **metric_events,
char *name,
const char *metric_name,
const char *metric_unit,
int runtime,
int cpu,
struct perf_stat_output_ctx *out,
struct runtime_stat *st)
{
print_metric_t print_metric = out->print_metric;
struct expr_parse_ctx pctx;
double ratio, scale;
int i;
void *ctxp = out->ctx;
i = prepare_metric(metric_events, &pctx, cpu, st);
if (i < 0)
return;
if (!metric_events[i]) { if (!metric_events[i]) {
if (expr__parse(&ratio, &pctx, metric_expr, runtime) == 0) { if (expr__parse(&ratio, &pctx, metric_expr, runtime) == 0) {
char *unit; char *unit;
......
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