public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Jiri Olsa <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: a.p.zijlstra@chello.nl, linux-kernel@vger.kernel.org,
	namhyung@kernel.org, eranian@google.com, tglx@linutronix.de,
	dsahern@gmail.com, mingo@kernel.org, adrian.hunter@intel.com,
	ak@linux.intel.com, jolsa@kernel.org, acme@redhat.com,
	hpa@zytor.com
Subject: [tip:perf/urgent] perf stat: Introduce print_counters function
Date: Mon, 29 Jun 2015 21:58:30 -0700	[thread overview]
Message-ID: <tip-d4f63a4741a808c0bf25d92884713008706fca16@git.kernel.org> (raw)
In-Reply-To: <1435310967-14570-22-git-send-email-jolsa@kernel.org>

Commit-ID:  d4f63a4741a808c0bf25d92884713008706fca16
Gitweb:     http://git.kernel.org/tip/d4f63a4741a808c0bf25d92884713008706fca16
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Fri, 26 Jun 2015 11:29:26 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 26 Jun 2015 12:00:50 -0300

perf stat: Introduce print_counters function

Centralize counters print code into single print_counters function.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1435310967-14570-22-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-stat.c | 127 +++++++++++++++++++++++-----------------------
 1 file changed, 64 insertions(+), 63 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 39a97ade..56dc888 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -67,10 +67,7 @@
 #define CNTR_NOT_SUPPORTED	"<not supported>"
 #define CNTR_NOT_COUNTED	"<not counted>"
 
-static void print_stat(int argc, const char **argv);
-static void print_counter_aggr(struct perf_evsel *counter, char *prefix);
-static void print_counter(struct perf_evsel *counter, char *prefix);
-static void print_aggr(char *prefix);
+static void print_counters(struct timespec *ts, int argc, const char **argv);
 
 /* Default events used for perf stat -T */
 static const char *transaction_attrs = {
@@ -365,53 +362,14 @@ static void read_counters(bool close)
 
 static void process_interval(void)
 {
-	static int num_print_interval;
-	struct perf_evsel *counter;
 	struct timespec ts, rs;
-	char prefix[64];
 
 	read_counters(false);
 
 	clock_gettime(CLOCK_MONOTONIC, &ts);
 	diff_timespec(&rs, &ts, &ref_time);
-	sprintf(prefix, "%6lu.%09lu%s", rs.tv_sec, rs.tv_nsec, csv_sep);
-
-	if (num_print_interval == 0 && !csv_output) {
-		switch (aggr_mode) {
-		case AGGR_SOCKET:
-			fprintf(output, "#           time socket cpus             counts %*s events\n", unit_width, "unit");
-			break;
-		case AGGR_CORE:
-			fprintf(output, "#           time core         cpus             counts %*s events\n", unit_width, "unit");
-			break;
-		case AGGR_NONE:
-			fprintf(output, "#           time CPU                counts %*s events\n", unit_width, "unit");
-			break;
-		case AGGR_GLOBAL:
-		default:
-			fprintf(output, "#           time             counts %*s events\n", unit_width, "unit");
-		}
-	}
-
-	if (++num_print_interval == 25)
-		num_print_interval = 0;
 
-	switch (aggr_mode) {
-	case AGGR_CORE:
-	case AGGR_SOCKET:
-		print_aggr(prefix);
-		break;
-	case AGGR_NONE:
-		evlist__for_each(evsel_list, counter)
-			print_counter(counter, prefix);
-		break;
-	case AGGR_GLOBAL:
-	default:
-		evlist__for_each(evsel_list, counter)
-			print_counter_aggr(counter, prefix);
-	}
-
-	fflush(output);
+	print_counters(&rs, 0, NULL);
 }
 
 static void handle_initial_delay(void)
@@ -901,9 +859,35 @@ static void print_counter(struct perf_evsel *counter, char *prefix)
 	}
 }
 
-static void print_stat(int argc, const char **argv)
+static void print_interval(char *prefix, struct timespec *ts)
+{
+	static int num_print_interval;
+
+	sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep);
+
+	if (num_print_interval == 0 && !csv_output) {
+		switch (aggr_mode) {
+		case AGGR_SOCKET:
+			fprintf(output, "#           time socket cpus             counts %*s events\n", unit_width, "unit");
+			break;
+		case AGGR_CORE:
+			fprintf(output, "#           time core         cpus             counts %*s events\n", unit_width, "unit");
+			break;
+		case AGGR_NONE:
+			fprintf(output, "#           time CPU                counts %*s events\n", unit_width, "unit");
+			break;
+		case AGGR_GLOBAL:
+		default:
+			fprintf(output, "#           time             counts %*s events\n", unit_width, "unit");
+		}
+	}
+
+	if (++num_print_interval == 25)
+		num_print_interval = 0;
+}
+
+static void print_header(int argc, const char **argv)
 {
-	struct perf_evsel *counter;
 	int i;
 
 	fflush(stdout);
@@ -929,36 +913,53 @@ static void print_stat(int argc, const char **argv)
 			fprintf(output, " (%d runs)", run_count);
 		fprintf(output, ":\n\n");
 	}
+}
+
+static void print_footer(void)
+{
+	if (!null_run)
+		fprintf(output, "\n");
+	fprintf(output, " %17.9f seconds time elapsed",
+			avg_stats(&walltime_nsecs_stats)/1e9);
+	if (run_count > 1) {
+		fprintf(output, "                                        ");
+		print_noise_pct(stddev_stats(&walltime_nsecs_stats),
+				avg_stats(&walltime_nsecs_stats));
+	}
+	fprintf(output, "\n\n");
+}
+
+static void print_counters(struct timespec *ts, int argc, const char **argv)
+{
+	struct perf_evsel *counter;
+	char buf[64], *prefix = NULL;
+
+	if (interval)
+		print_interval(prefix = buf, ts);
+	else
+		print_header(argc, argv);
 
 	switch (aggr_mode) {
 	case AGGR_CORE:
 	case AGGR_SOCKET:
-		print_aggr(NULL);
+		print_aggr(prefix);
 		break;
 	case AGGR_GLOBAL:
 		evlist__for_each(evsel_list, counter)
-			print_counter_aggr(counter, NULL);
+			print_counter_aggr(counter, prefix);
 		break;
 	case AGGR_NONE:
 		evlist__for_each(evsel_list, counter)
-			print_counter(counter, NULL);
+			print_counter(counter, prefix);
 		break;
 	default:
 		break;
 	}
 
-	if (!csv_output) {
-		if (!null_run)
-			fprintf(output, "\n");
-		fprintf(output, " %17.9f seconds time elapsed",
-				avg_stats(&walltime_nsecs_stats)/1e9);
-		if (run_count > 1) {
-			fprintf(output, "                                        ");
-			print_noise_pct(stddev_stats(&walltime_nsecs_stats),
-					avg_stats(&walltime_nsecs_stats));
-		}
-		fprintf(output, "\n\n");
-	}
+	if (!interval && !csv_output)
+		print_footer();
+
+	fflush(output);
 }
 
 static volatile int signr = -1;
@@ -1407,13 +1408,13 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 
 		status = run_perf_stat(argc, argv);
 		if (forever && status != -1) {
-			print_stat(argc, argv);
+			print_counters(NULL, argc, argv);
 			perf_stat__reset_stats();
 		}
 	}
 
 	if (!forever && status != -1 && !interval)
-		print_stat(argc, argv);
+		print_counters(NULL, argc, argv);
 
 	perf_evlist__free_stats(evsel_list);
 out:

  reply	other threads:[~2015-06-30  4:58 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-26  9:29 [PATCHv5 00/22] perf stat: Introduce --per-thread option Jiri Olsa
2015-06-26  9:29 ` [PATCH 01/22] perf thread_map: Introduce thread_map__reset function Jiri Olsa
2015-06-26 14:06   ` Arnaldo Carvalho de Melo
2015-06-30  4:52   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 02/22] perf tools: Add comm string into struct thread_map Jiri Olsa
2015-06-30  4:52   ` [tip:perf/urgent] perf thrad_map: Add comm string into array tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 03/22] perf tests: Add thread_map object tests Jiri Olsa
2015-06-30  4:53   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 04/22] perf stat: Introduce perf_counts function Jiri Olsa
2015-06-30  4:53   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 05/22] perf stat: Use xyarray for cpu evsel counts Jiri Olsa
2015-06-30  4:53   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 06/22] perf stat: Make stats work over the thread dimension Jiri Olsa
2015-06-30  4:54   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 07/22] perf stat: Rename struct perf_counts::cpu member to values Jiri Olsa
2015-06-30  4:54   ` [tip:perf/urgent] perf stat: Rename struct perf_counts:: cpu " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 08/22] perf stat: Introduce perf_evlist__reset_stats Jiri Olsa
2015-06-30  4:54   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 09/22] perf stat: Move perf_evsel__(alloc|free|reset)_stat_priv into stat object Jiri Olsa
2015-06-30  4:54   ` [tip:perf/urgent] perf stat: Move perf_evsel__(alloc|free|reset) _stat_priv " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 10/22] perf stat: Move perf_evsel__(alloc|free)_prev_raw_counts " Jiri Olsa
2015-06-30  4:55   ` [tip:perf/urgent] perf stat: Move perf_evsel__(alloc|free) _prev_raw_counts " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 11/22] perf stat: Move perf_evlist__(alloc|free|reset)_stats " Jiri Olsa
2015-06-30  4:55   ` [tip:perf/urgent] perf stat: Move perf_evlist__(alloc|free|reset) _stats " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 12/22] perf stat: Introduce perf_evsel__alloc_stats function Jiri Olsa
2015-06-30  4:55   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 13/22] perf stat: Introduce perf_evsel__read function Jiri Olsa
2015-06-30  4:56   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 14/22] perf stat: Introduce read_counters function Jiri Olsa
2015-06-30  4:56   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 15/22] perf stat: Separate counters reading and processing Jiri Olsa
2015-06-30  4:56   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 16/22] perf stat: Move zero_per_pkg into counter process code Jiri Olsa
2015-06-30  4:57   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 17/22] perf stat: Move perf_stat initialization " Jiri Olsa
2015-06-30  4:57   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 18/22] perf stat: Remove perf_evsel__read_cb function Jiri Olsa
2015-06-30  4:57   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 19/22] perf stat: Rename print_interval to process_interval Jiri Olsa
2015-06-30  4:57   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 20/22] perf stat: Using init_stats instead of memset Jiri Olsa
2015-06-30  4:58   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26  9:29 ` [PATCH 21/22] perf stat: Introduce print_counters function Jiri Olsa
2015-06-30  4:58   ` tip-bot for Jiri Olsa [this message]
2015-06-26  9:29 ` [PATCH 22/22] perf stat: Introduce --per-thread option Jiri Olsa
2015-06-30  4:58   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2015-06-26 15:06 ` [PATCHv5 00/22] " 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-d4f63a4741a808c0bf25d92884713008706fca16@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.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=namhyung@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox