aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/stat-shadow.c
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2017-08-31 15:40:28 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-09-13 08:49:12 -0400
commitbba49af87393ebc8960bf8abdcbb9af53bf1aba1 (patch)
tree35042c51d2182f6905a84e2d84cba4bd5002ca06 /tools/perf/util/stat-shadow.c
parent3ba36d3620d08be31f5ee9ae20abb9bf3bdeb05a (diff)
perf stat: Factor out generic metric printing
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. v2: Fix indentation Signed-off-by: Andi Kleen <ak@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: http://lkml.kernel.org/r/20170831194036.30146-4-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/stat-shadow.c')
-rw-r--r--tools/perf/util/stat-shadow.c69
1 files changed, 42 insertions, 27 deletions
diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index a04cf56d3517..96aa6cbf24d6 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,
627 out->print_metric(out->ctx, NULL, "%4.0f", "SMI#", smi_num); 627 out->print_metric(out->ctx, NULL, "%4.0f", "SMI#", smi_num);
628} 628}
629 629
630static void generic_metric(const char *metric_expr,
631 struct perf_evsel **metric_events,
632 char *name,
633 const char *metric_name,
634 double avg,
635 int cpu,
636 int ctx,
637 struct perf_stat_output_ctx *out)
638{
639 print_metric_t print_metric = out->print_metric;
640 struct parse_ctx pctx;
641 double ratio;
642 int i;
643 void *ctxp = out->ctx;
644
645 expr__ctx_init(&pctx);
646 expr__add_id(&pctx, name, avg);
647 for (i = 0; metric_events[i]; i++) {
648 struct saved_value *v;
649
650 v = saved_value_lookup(metric_events[i], cpu, ctx, false);
651 if (!v)
652 break;
653 expr__add_id(&pctx, metric_events[i]->name, avg_stats(&v->stats));
654 }
655 if (!metric_events[i]) {
656 const char *p = metric_expr;
657
658 if (expr__parse(&ratio, &pctx, &p) == 0)
659 print_metric(ctxp, NULL, "%8.1f",
660 metric_name ?
661 metric_name :
662 out->force_header ? name : "",
663 ratio);
664 else
665 print_metric(ctxp, NULL, NULL, "", 0);
666 } else
667 print_metric(ctxp, NULL, NULL, "", 0);
668}
669
630void perf_stat__print_shadow_stats(struct perf_evsel *evsel, 670void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
631 double avg, int cpu, 671 double avg, int cpu,
632 struct perf_stat_output_ctx *out) 672 struct perf_stat_output_ctx *out)
@@ -819,33 +859,8 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
819 else 859 else
820 print_metric(ctxp, NULL, NULL, name, 0); 860 print_metric(ctxp, NULL, NULL, name, 0);
821 } else if (evsel->metric_expr) { 861 } else if (evsel->metric_expr) {
822 struct parse_ctx pctx; 862 generic_metric(evsel->metric_expr, evsel->metric_events, evsel->name,
823 int i; 863 evsel->metric_name, avg, cpu, ctx, out);
824
825 expr__ctx_init(&pctx);
826 expr__add_id(&pctx, evsel->name, avg);
827 for (i = 0; evsel->metric_events[i]; i++) {
828 struct saved_value *v;
829
830 v = saved_value_lookup(evsel->metric_events[i], cpu, ctx, false);
831 if (!v)
832 break;
833 expr__add_id(&pctx, evsel->metric_events[i]->name,
834 avg_stats(&v->stats));
835 }
836 if (!evsel->metric_events[i]) {
837 const char *p = evsel->metric_expr;
838
839 if (expr__parse(&ratio, &pctx, &p) == 0)
840 print_metric(ctxp, NULL, "%8.1f",
841 evsel->metric_name ?
842 evsel->metric_name :
843 out->force_header ? evsel->name : "",
844 ratio);
845 else
846 print_metric(ctxp, NULL, NULL, "", 0);
847 } else
848 print_metric(ctxp, NULL, NULL, "", 0);
849 } else if (runtime_nsecs_stats[cpu].n != 0) { 864 } else if (runtime_nsecs_stats[cpu].n != 0) {
850 char unit = 'M'; 865 char unit = 'M';
851 char unit_buf[10]; 866 char unit_buf[10];