Re: [PATCH v2 12/19] perf, tools, stat: Factor out generic metric printing
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(); > + expr__add_id(, 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(, metric_events[i]->name, > avg_stats(>stats)); > + } > + if (!metric_events[i]) { > + const char *p = metric_expr; > + > + if (expr__parse(, , ) == 0) > + print_metric(ctxp, NULL, "%8.1f", > + metric_name ? > + metric_name : > + out->force_header ? name : "", nit, missing tab ^^^ jirka
Re: [PATCH v2 12/19] perf, tools, stat: Factor out generic metric printing
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(); > + expr__add_id(, 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(, metric_events[i]->name, > avg_stats(>stats)); > + } > + if (!metric_events[i]) { > + const char *p = metric_expr; > + > + if (expr__parse(, , ) == 0) > + print_metric(ctxp, NULL, "%8.1f", > + metric_name ? > + metric_name : > + out->force_header ? name : "", nit, missing tab ^^^ jirka
[PATCH v2 12/19] perf, tools, stat: Factor out generic metric printing
From: Andi KleenThe perf stat shadow metric printing already supports generic metrics. Factor out the code doing that into a separate function that can be re-used in a later patch. No behavior changes. Signed-off-by: Andi Kleen --- tools/perf/util/stat-shadow.c | 69 ++- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index a04cf56d3517..b6cbb6e67167 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -627,6 +627,46 @@ static void print_smi_cost(int cpu, struct perf_evsel *evsel, out->print_metric(out->ctx, NULL, "%4.0f", "SMI#", smi_num); } +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(); + expr__add_id(, 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(, metric_events[i]->name, avg_stats(>stats)); + } + if (!metric_events[i]) { + const char *p = metric_expr; + + if (expr__parse(, , ) == 0) + print_metric(ctxp, NULL, "%8.1f", + metric_name ? + metric_name : + out->force_header ? name : "", + ratio); + else + print_metric(ctxp, NULL, NULL, "", 0); + } else + print_metric(ctxp, NULL, NULL, "", 0); +} + void perf_stat__print_shadow_stats(struct perf_evsel *evsel, double avg, int cpu, struct perf_stat_output_ctx *out) @@ -819,33 +859,8 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel, else print_metric(ctxp, NULL, NULL, name, 0); } else if (evsel->metric_expr) { - struct parse_ctx pctx; - int i; - - expr__ctx_init(); - expr__add_id(, evsel->name, avg); - for (i = 0; evsel->metric_events[i]; i++) { - struct saved_value *v; - - v = saved_value_lookup(evsel->metric_events[i], cpu, ctx, false); - if (!v) - break; - expr__add_id(, evsel->metric_events[i]->name, -avg_stats(>stats)); - } - if (!evsel->metric_events[i]) { - const char *p = evsel->metric_expr; - - if (expr__parse(, , ) == 0) - print_metric(ctxp, NULL, "%8.1f", - evsel->metric_name ? - evsel->metric_name : - out->force_header ? evsel->name : "", - ratio); - else - print_metric(ctxp, NULL, NULL, "", 0); - } else - print_metric(ctxp, NULL, NULL, "", 0); + generic_metric(evsel->metric_expr, evsel->metric_events, evsel->name, + evsel->metric_name, avg, cpu, ctx, out); } else if (runtime_nsecs_stats[cpu].n != 0) { char unit = 'M'; char unit_buf[10]; -- 2.9.4
[PATCH v2 12/19] perf, tools, stat: Factor out generic metric printing
From: Andi Kleen The perf stat shadow metric printing already supports generic metrics. Factor out the code doing that into a separate function that can be re-used in a later patch. No behavior changes. Signed-off-by: Andi Kleen --- tools/perf/util/stat-shadow.c | 69 ++- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index a04cf56d3517..b6cbb6e67167 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -627,6 +627,46 @@ static void print_smi_cost(int cpu, struct perf_evsel *evsel, out->print_metric(out->ctx, NULL, "%4.0f", "SMI#", smi_num); } +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(); + expr__add_id(, 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(, metric_events[i]->name, avg_stats(>stats)); + } + if (!metric_events[i]) { + const char *p = metric_expr; + + if (expr__parse(, , ) == 0) + print_metric(ctxp, NULL, "%8.1f", + metric_name ? + metric_name : + out->force_header ? name : "", + ratio); + else + print_metric(ctxp, NULL, NULL, "", 0); + } else + print_metric(ctxp, NULL, NULL, "", 0); +} + void perf_stat__print_shadow_stats(struct perf_evsel *evsel, double avg, int cpu, struct perf_stat_output_ctx *out) @@ -819,33 +859,8 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel, else print_metric(ctxp, NULL, NULL, name, 0); } else if (evsel->metric_expr) { - struct parse_ctx pctx; - int i; - - expr__ctx_init(); - expr__add_id(, evsel->name, avg); - for (i = 0; evsel->metric_events[i]; i++) { - struct saved_value *v; - - v = saved_value_lookup(evsel->metric_events[i], cpu, ctx, false); - if (!v) - break; - expr__add_id(, evsel->metric_events[i]->name, -avg_stats(>stats)); - } - if (!evsel->metric_events[i]) { - const char *p = evsel->metric_expr; - - if (expr__parse(, , ) == 0) - print_metric(ctxp, NULL, "%8.1f", - evsel->metric_name ? - evsel->metric_name : - out->force_header ? evsel->name : "", - ratio); - else - print_metric(ctxp, NULL, NULL, "", 0); - } else - print_metric(ctxp, NULL, NULL, "", 0); + generic_metric(evsel->metric_expr, evsel->metric_events, evsel->name, + evsel->metric_name, avg, cpu, ctx, out); } else if (runtime_nsecs_stats[cpu].n != 0) { char unit = 'M'; char unit_buf[10]; -- 2.9.4