Re: [PATCH v2 12/19] perf, tools, stat: Factor out generic metric printing
From: Jiri Olsa
Date: Mon Aug 28 2017 - 05:19:52 EST
On Fri, Aug 11, 2017 at 04:26:27PM -0700, Andi Kleen wrote:
SNIP
> +static void generic_metric(const char *metric_expr,
> + struct perf_evsel **metric_events,
> + char *name,
> + const char *metric_name,
> + double avg,
> + int cpu,
> + int ctx,
> + struct perf_stat_output_ctx *out)
> +{
> + print_metric_t print_metric = out->print_metric;
> + struct parse_ctx pctx;
> + double ratio;
> + int i;
> + void *ctxp = out->ctx;
> +
> + expr__ctx_init(&pctx);
> + expr__add_id(&pctx, name, avg);
> + for (i = 0; metric_events[i]; i++) {
> + struct saved_value *v;
> +
> + v = saved_value_lookup(metric_events[i], cpu, ctx, false);
> + if (!v)
> + break;
> + expr__add_id(&pctx, metric_events[i]->name, avg_stats(&v->stats));
> + }
> + if (!metric_events[i]) {
> + const char *p = metric_expr;
> +
> + if (expr__parse(&ratio, &pctx, &p) == 0)
> + print_metric(ctxp, NULL, "%8.1f",
> + metric_name ?
> + metric_name :
> + out->force_header ? name : "",
nit, missing tab ^^^
jirka