mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@kernel.org>,
	David Ahern <dsahern@gmail.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 08/26] perf stat: Move 'output' into struct perf_stat_config
Date: Thu,  6 Aug 2015 22:58:17 -0300	[thread overview]
Message-ID: <1438912715-4000-9-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1438912715-4000-1-git-send-email-acme@kernel.org>

From: Jiri Olsa <jolsa@kernel.org>

Moving 'output' into struct perf_stat_config. The point is to centralize
the base stat config so it could be used localy together with other stat
routines in other parts of perf code.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1437481927-29538-5-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-stat.c | 35 +++++++++++++++++++++++------------
 tools/perf/util/stat.h    |  1 +
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 3fb2865e519a..e3ea8b67703d 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -110,7 +110,6 @@ static int			big_num_opt			=  -1;
 static const char		*csv_sep			= NULL;
 static bool			csv_output			= false;
 static bool			group				= false;
-static FILE			*output				= NULL;
 static const char		*pre_cmd			= NULL;
 static const char		*post_cmd			= NULL;
 static bool			sync_run			= false;
@@ -305,7 +304,7 @@ static int process_counter(struct perf_evsel *counter)
 		update_stats(&ps->res_stats[i], count[i]);
 
 	if (verbose) {
-		fprintf(output, "%s: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n",
+		fprintf(stat_config.output, "%s: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n",
 			perf_evsel__name(counter), count[0], count[1], count[2]);
 	}
 
@@ -548,13 +547,13 @@ static int run_perf_stat(int argc, const char **argv)
 static void print_running(u64 run, u64 ena)
 {
 	if (csv_output) {
-		fprintf(output, "%s%" PRIu64 "%s%.2f",
+		fprintf(stat_config.output, "%s%" PRIu64 "%s%.2f",
 					csv_sep,
 					run,
 					csv_sep,
 					ena ? 100.0 * run / ena : 100.0);
 	} else if (run != ena) {
-		fprintf(output, "  (%.2f%%)", 100.0 * run / ena);
+		fprintf(stat_config.output, "  (%.2f%%)", 100.0 * run / ena);
 	}
 }
 
@@ -563,9 +562,9 @@ static void print_noise_pct(double total, double avg)
 	double pct = rel_stddev_stats(total, avg);
 
 	if (csv_output)
-		fprintf(output, "%s%.2f%%", csv_sep, pct);
+		fprintf(stat_config.output, "%s%.2f%%", csv_sep, pct);
 	else if (pct)
-		fprintf(output, "  ( +-%6.2f%% )", pct);
+		fprintf(stat_config.output, "  ( +-%6.2f%% )", pct);
 }
 
 static void print_noise(struct perf_evsel *evsel, double avg)
@@ -583,7 +582,7 @@ static void aggr_printout(struct perf_evsel *evsel, int id, int nr)
 {
 	switch (stat_config.aggr_mode) {
 	case AGGR_CORE:
-		fprintf(output, "S%d-C%*d%s%*d%s",
+		fprintf(stat_config.output, "S%d-C%*d%s%*d%s",
 			cpu_map__id_to_socket(id),
 			csv_output ? 0 : -8,
 			cpu_map__id_to_cpu(id),
@@ -593,7 +592,7 @@ static void aggr_printout(struct perf_evsel *evsel, int id, int nr)
 			csv_sep);
 		break;
 	case AGGR_SOCKET:
-		fprintf(output, "S%*d%s%*d%s",
+		fprintf(stat_config.output, "S%*d%s%*d%s",
 			csv_output ? 0 : -5,
 			id,
 			csv_sep,
@@ -602,12 +601,12 @@ static void aggr_printout(struct perf_evsel *evsel, int id, int nr)
 			csv_sep);
 			break;
 	case AGGR_NONE:
-		fprintf(output, "CPU%*d%s",
+		fprintf(stat_config.output, "CPU%*d%s",
 			csv_output ? 0 : -4,
 			perf_evsel__cpus(evsel)->map[id], csv_sep);
 		break;
 	case AGGR_THREAD:
-		fprintf(output, "%*s-%*d%s",
+		fprintf(stat_config.output, "%*s-%*d%s",
 			csv_output ? 0 : 16,
 			thread_map__comm(evsel->threads, id),
 			csv_output ? 0 : -8,
@@ -622,6 +621,7 @@ static void aggr_printout(struct perf_evsel *evsel, int id, int nr)
 
 static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg)
 {
+	FILE *output = stat_config.output;
 	double msecs = avg / 1e6;
 	const char *fmt_v, *fmt_n;
 	char name[25];
@@ -658,6 +658,7 @@ static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg)
 
 static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)
 {
+	FILE *output = stat_config.output;
 	double sc =  evsel->scale;
 	const char *fmt;
 	int cpu = cpu_map__id_to_cpu(id);
@@ -697,6 +698,7 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)
 
 static void print_aggr(char *prefix)
 {
+	FILE *output = stat_config.output;
 	struct perf_evsel *counter;
 	int cpu, cpu2, s, s2, id, nr;
 	double uval;
@@ -765,6 +767,7 @@ static void print_aggr(char *prefix)
 
 static void print_aggr_thread(struct perf_evsel *counter, char *prefix)
 {
+	FILE *output = stat_config.output;
 	int nthreads = thread_map__nr(counter->threads);
 	int ncpus = cpu_map__nr(counter->cpus);
 	int cpu, thread;
@@ -803,6 +806,7 @@ 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 *ps = counter->priv;
 	double avg = avg_stats(&ps->res_stats[0]);
 	int scaled = counter->counts->scaled;
@@ -854,6 +858,7 @@ static void print_counter_aggr(struct perf_evsel *counter, char *prefix)
  */
 static void print_counter(struct perf_evsel *counter, char *prefix)
 {
+	FILE *output = stat_config.output;
 	u64 ena, run, val;
 	double uval;
 	int cpu;
@@ -908,6 +913,7 @@ static void print_counter(struct perf_evsel *counter, char *prefix)
 
 static void print_interval(char *prefix, struct timespec *ts)
 {
+	FILE *output = stat_config.output;
 	static int num_print_interval;
 
 	sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep);
@@ -938,6 +944,7 @@ static void print_interval(char *prefix, struct timespec *ts)
 
 static void print_header(int argc, const char **argv)
 {
+	FILE *output = stat_config.output;
 	int i;
 
 	fflush(stdout);
@@ -967,6 +974,8 @@ static void print_header(int argc, const char **argv)
 
 static void print_footer(void)
 {
+	FILE *output = stat_config.output;
+
 	if (!null_run)
 		fprintf(output, "\n");
 	fprintf(output, " %17.9f seconds time elapsed",
@@ -1013,7 +1022,7 @@ static void print_counters(struct timespec *ts, int argc, const char **argv)
 	if (!interval && !csv_output)
 		print_footer();
 
-	fflush(output);
+	fflush(stat_config.output);
 }
 
 static volatile int signr = -1;
@@ -1322,6 +1331,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	};
 	int status = -EINVAL, run_idx;
 	const char *mode;
+	FILE *output = stderr;
 
 	setlocale(LC_ALL, "");
 
@@ -1332,7 +1342,6 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	argc = parse_options(argc, argv, options, stat_usage,
 		PARSE_OPT_STOP_AT_NON_OPTION);
 
-	output = stderr;
 	if (output_name && strcmp(output_name, "-"))
 		output = NULL;
 
@@ -1369,6 +1378,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 		}
 	}
 
+	stat_config.output = output;
+
 	if (csv_sep) {
 		csv_output = true;
 		if (!strcmp(csv_sep, "\\t"))
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index 0a1d83faa7b9..ed0e05829cb0 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -53,6 +53,7 @@ struct perf_counts {
 struct perf_stat_config {
 	enum aggr_mode	aggr_mode;
 	bool		scale;
+	FILE		*output;
 };
 
 static inline struct perf_counts_values*
-- 
2.1.0


  parent reply	other threads:[~2015-08-07  2:02 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-07  1:58 [GIT PULL 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 01/26] perf trace: Add total time column to summary Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 02/26] bpf: Use correct #ifdef controller for trace_call_bpf() Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 03/26] tracing, perf: Implement BPF programs attached to uprobes Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 04/26] perf tools: Introduce veprintf Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 05/26] perf tools: Add missing forward declaration of struct map to probe-event.h Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 06/26] perf stat: Introduce struct perf_stat_config Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 07/26] perf stat: Move 'scale' into " Arnaldo Carvalho de Melo
2015-08-07  1:58 ` Arnaldo Carvalho de Melo [this message]
2015-08-07  1:58 ` [PATCH 09/26] perf stat: Move 'interval' " Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 10/26] perf stat: Pass 'struct perf_stat_config' into process_counter() Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 11/26] perf stat: Move counter processing code into stat object Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 12/26] perf tools: Add empty Build files for architectures lacking them Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 13/26] perf tools: Add support for cycles, weight branch_info field Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 14/26] perf report: Add flag for non ANY branch mode Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 15/26] perf report: Add infrastructure for a cycles histogram Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 16/26] perf report: Add processing for cycle histograms Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 17/26] perf annotate: Compute IPC and basic block cycles Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 18/26] perf annotate: Finally display IPC and cycle accounting Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 19/26] perf top: Add branch annotation code to top Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 20/26] perf report: Display cycles in branch sort mode Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 21/26] perf tools xtensa: Add DWARF register names Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 22/26] perf auxtrace: Fix period type 'i' not working Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 23/26] perf tools: Fix perf-with-kcore handling of arguments containing spaces Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 24/26] perf tools: Add perf_pmu__format_bits() Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 25/26] perf tools: Validate config term maximum value Arnaldo Carvalho de Melo
2015-08-07  1:58 ` [PATCH 26/26] perf tools: Extend the event parser maximum error index Arnaldo Carvalho de Melo
2015-08-07  7:13 ` [GIT PULL 00/26] perf/core improvements and fixes Ingo Molnar

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=1438912715-4000-9-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /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

Powered by JetHome