All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Andi Kleen <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: ak@linux.intel.com, acme@redhat.com, hpa@zytor.com,
	tglx@linutronix.de, linux-kernel@vger.kernel.org,
	jolsa@kernel.org, mingo@kernel.org
Subject: [tip:perf/core] perf stat: Factor out callback for collecting event values
Date: Fri, 24 Mar 2017 11:46:58 -0700	[thread overview]
Message-ID: <tip-fbe51fba82901fd15d3e0a068388fcd7d02dc047@git.kernel.org> (raw)
In-Reply-To: <20170320201711.14142-2-andi@firstfloor.org>

Commit-ID:  fbe51fba82901fd15d3e0a068388fcd7d02dc047
Gitweb:     http://git.kernel.org/tip/fbe51fba82901fd15d3e0a068388fcd7d02dc047
Author:     Andi Kleen <ak@linux.intel.com>
AuthorDate: Mon, 20 Mar 2017 13:16:59 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 21 Mar 2017 16:03:39 -0300

perf stat: Factor out callback for collecting event values

To be used in next patch to support automatic summing of alias events.

v2: Move check for bad results to next patch
v3: Remove trivial addition.
v4: Use perf_evsel__cpus instead of evsel->cpus

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170320201711.14142-2-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-stat.c | 103 +++++++++++++++++++++++++++++++++++-----------
 1 file changed, 80 insertions(+), 23 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index f53f449..5c13a0f 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1182,11 +1182,46 @@ static void aggr_update_shadow(void)
 	}
 }
 
+static void collect_data(struct perf_evsel *counter,
+			    void (*cb)(struct perf_evsel *counter, void *data,
+				       bool first),
+			    void *data)
+{
+	cb(counter, data, true);
+}
+
+struct aggr_data {
+	u64 ena, run, val;
+	int id;
+	int nr;
+	int cpu;
+};
+
+static void aggr_cb(struct perf_evsel *counter, void *data, bool first)
+{
+	struct aggr_data *ad = data;
+	int cpu, s2;
+
+	for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
+		struct perf_counts_values *counts;
+
+		s2 = aggr_get_id(perf_evsel__cpus(counter), cpu);
+		if (s2 != ad->id)
+			continue;
+		if (first)
+			ad->nr++;
+		counts = perf_counts(counter->counts, cpu, 0);
+		ad->val += counts->val;
+		ad->ena += counts->ena;
+		ad->run += counts->run;
+	}
+}
+
 static void print_aggr(char *prefix)
 {
 	FILE *output = stat_config.output;
 	struct perf_evsel *counter;
-	int cpu, s, s2, id, nr;
+	int s, id, nr;
 	double uval;
 	u64 ena, run, val;
 	bool first;
@@ -1201,23 +1236,20 @@ static void print_aggr(char *prefix)
 	 * Without each counter has its own line.
 	 */
 	for (s = 0; s < aggr_map->nr; s++) {
+		struct aggr_data ad;
 		if (prefix && metric_only)
 			fprintf(output, "%s", prefix);
 
-		id = aggr_map->map[s];
+		ad.id = id = aggr_map->map[s];
 		first = true;
 		evlist__for_each_entry(evsel_list, counter) {
-			val = ena = run = 0;
-			nr = 0;
-			for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
-				s2 = aggr_get_id(perf_evsel__cpus(counter), cpu);
-				if (s2 != id)
-					continue;
-				val += perf_counts(counter->counts, cpu, 0)->val;
-				ena += perf_counts(counter->counts, cpu, 0)->ena;
-				run += perf_counts(counter->counts, cpu, 0)->run;
-				nr++;
-			}
+			ad.val = ad.ena = ad.run = 0;
+			ad.nr = 0;
+			collect_data(counter, aggr_cb, &ad);
+			nr = ad.nr;
+			ena = ad.ena;
+			run = ad.run;
+			val = ad.val;
 			if (first && metric_only) {
 				first = false;
 				aggr_printout(counter, id, nr);
@@ -1261,6 +1293,21 @@ static void print_aggr_thread(struct perf_evsel *counter, char *prefix)
 	}
 }
 
+struct caggr_data {
+	double avg, avg_enabled, avg_running;
+};
+
+static void counter_aggr_cb(struct perf_evsel *counter, void *data,
+			    bool first __maybe_unused)
+{
+	struct caggr_data *cd = data;
+	struct perf_stat_evsel *ps = counter->priv;
+
+	cd->avg += avg_stats(&ps->res_stats[0]);
+	cd->avg_enabled += avg_stats(&ps->res_stats[1]);
+	cd->avg_running += avg_stats(&ps->res_stats[2]);
+}
+
 /*
  * Print out the results of a single counter:
  * aggregated counts in system-wide mode
@@ -1268,23 +1315,30 @@ static void print_aggr_thread(struct perf_evsel *counter, char *prefix)
 static void print_counter_aggr(struct perf_evsel *counter, char *prefix)
 {
 	FILE *output = stat_config.output;
-	struct perf_stat_evsel *ps = counter->priv;
-	double avg = avg_stats(&ps->res_stats[0]);
 	double uval;
-	double avg_enabled, avg_running;
+	struct caggr_data cd = { .avg = 0.0 };
 
-	avg_enabled = avg_stats(&ps->res_stats[1]);
-	avg_running = avg_stats(&ps->res_stats[2]);
+	collect_data(counter, counter_aggr_cb, &cd);
 
 	if (prefix && !metric_only)
 		fprintf(output, "%s", prefix);
 
-	uval = avg * counter->scale;
-	printout(-1, 0, counter, uval, prefix, avg_running, avg_enabled, avg);
+	uval = cd.avg * counter->scale;
+	printout(-1, 0, counter, uval, prefix, cd.avg_running, cd.avg_enabled, cd.avg);
 	if (!metric_only)
 		fprintf(output, "\n");
 }
 
+static void counter_cb(struct perf_evsel *counter, void *data,
+		       bool first __maybe_unused)
+{
+	struct aggr_data *ad = data;
+
+	ad->val += perf_counts(counter->counts, ad->cpu, 0)->val;
+	ad->ena += perf_counts(counter->counts, ad->cpu, 0)->ena;
+	ad->run += perf_counts(counter->counts, ad->cpu, 0)->run;
+}
+
 /*
  * Print out the results of a single counter:
  * does not use aggregated count in system-wide
@@ -1297,9 +1351,12 @@ static void print_counter(struct perf_evsel *counter, char *prefix)
 	int cpu;
 
 	for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
-		val = perf_counts(counter->counts, cpu, 0)->val;
-		ena = perf_counts(counter->counts, cpu, 0)->ena;
-		run = perf_counts(counter->counts, cpu, 0)->run;
+		struct aggr_data ad = { .cpu = cpu };
+
+		collect_data(counter, counter_cb, &ad);
+		val = ad.val;
+		ena = ad.ena;
+		run = ad.run;
 
 		if (prefix)
 			fprintf(output, "%s", prefix);

  reply	other threads:[~2017-03-24 18:48 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-20 20:16 perf: Improve support for uncore JSON event lists Andi Kleen
2017-03-20 20:16 ` [PATCH 01/13] perf, tools, stat: Factor out callback for collecting event values Andi Kleen
2017-03-24 18:46   ` tip-bot for Andi Kleen [this message]
2017-03-20 20:17 ` [PATCH 02/13] perf, tools, stat: Collapse identically named events Andi Kleen
2017-03-24 18:47   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 03/13] perf, tools, stat: Handle partially bad results with merging Andi Kleen
2017-03-24 18:48   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 04/13] perf, tools: Factor out PMU matching in parser Andi Kleen
2017-03-24 18:48   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 05/13] perf, tools: Expand PMU events by prefix match Andi Kleen
2017-03-24 18:49   ` [tip:perf/core] perf pmu: " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 06/13] perf, tools: Special case uncore_ prefix Andi Kleen
2017-03-24 18:49   ` [tip:perf/core] perf pmu: " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 07/13] perf, tools: Add a simple expression parser for JSON Andi Kleen
2017-03-21 19:14   ` Arnaldo Carvalho de Melo
2017-03-21 19:15     ` Arnaldo Carvalho de Melo
2017-03-21 22:08       ` Build errors, was " Arnaldo Carvalho de Melo
2017-03-24 18:50   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 08/13] perf, tools: Update Intel uncore JSON event files Andi Kleen
2017-03-24 18:50   ` [tip:perf/core] perf vendor events intel: " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 09/13] perf, tools: Support MetricExpr header in JSON event list Andi Kleen
2017-03-24 18:51   ` [tip:perf/core] perf pmu: " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 10/13] perf, tools, stat: Output JSON MetricExpr metric Andi Kleen
2017-03-21 14:48   ` Jiri Olsa
2017-03-21 15:45     ` Andi Kleen
2017-03-21 19:42       ` Arnaldo Carvalho de Melo
2017-03-21 19:49         ` Andi Kleen
2017-03-24 18:51   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 11/13] perf, tools, list: Support printing MetricExpr with --debug Andi Kleen
2017-03-24 18:52   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 12/13] perf, tools: Add support for MetricName JSON attribute Andi Kleen
2017-03-24 18:53   ` [tip:perf/core] perf pmu: " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 13/13] perf, tools, list: Move extra details printing to new option Andi Kleen
2017-03-24 18:53   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-21 14:48 ` perf: Improve support for uncore JSON event lists Jiri Olsa
2017-03-21 19:53   ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-fbe51fba82901fd15d3e0a068388fcd7d02dc047@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.