linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Jiri Olsa <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: hpa@zytor.com, peterz@infradead.org, dsahern@gmail.com,
	linux-kernel@vger.kernel.org, namhyung@kernel.org,
	andi@firstfloor.org, tglx@linutronix.de, acme@redhat.com,
	jolsa@kernel.org, mingo@kernel.org,
	alexander.shishkin@linux.intel.com
Subject: [tip:perf/core] perf stat: Move 'run_count' to 'struct perf_stat_config'
Date: Thu, 6 Sep 2018 06:35:16 -0700	[thread overview]
Message-ID: <tip-d97ae04b3d5263be242a6a9f9eef6422fc86326a@git.kernel.org> (raw)
In-Reply-To: <20180830063252.23729-28-jolsa@kernel.org>

Commit-ID:  d97ae04b3d5263be242a6a9f9eef6422fc86326a
Gitweb:     https://git.kernel.org/tip/d97ae04b3d5263be242a6a9f9eef6422fc86326a
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Thu, 30 Aug 2018 08:32:36 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 30 Aug 2018 15:52:23 -0300

perf stat: Move 'run_count' to 'struct perf_stat_config'

Move the static 'run_count' variable to 'struct perf_stat_config', so
that it can be passed around and used outside the 'perf stat' command.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180830063252.23729-28-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-stat.c | 39 ++++++++++++++++++++-------------------
 tools/perf/util/stat.h    |  1 +
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 11741f3a8342..1276596840c9 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -147,7 +147,6 @@ typedef int (*aggr_get_id_t)(struct cpu_map *m, int cpu);
 
 #define METRIC_ONLY_LEN 20
 
-static int			run_count			=  1;
 static volatile pid_t		child_pid			= -1;
 static bool			null_run			=  false;
 static int			detailed_run			=  0;
@@ -200,6 +199,7 @@ static struct perf_stat_config stat_config = {
 	.aggr_mode	= AGGR_GLOBAL,
 	.scale		= true,
 	.unit_width	= 4, /* strlen("unit") */
+	.run_count	= 1,
 };
 
 static bool is_duration_time(struct perf_evsel *evsel)
@@ -686,7 +686,7 @@ static void print_noise(struct perf_stat_config *config,
 {
 	struct perf_stat_evsel *ps;
 
-	if (run_count == 1)
+	if (config->run_count == 1)
 		return;
 
 	ps = evsel->stats;
@@ -1620,8 +1620,8 @@ static void print_header(struct perf_stat_config *config,
 			fprintf(output, "thread id \'%s", _target->tid);
 
 		fprintf(output, "\'");
-		if (run_count > 1)
-			fprintf(output, " (%d runs)", run_count);
+		if (config->run_count > 1)
+			fprintf(output, " (%d runs)", config->run_count);
 		fprintf(output, ":\n\n");
 	}
 }
@@ -1634,7 +1634,8 @@ static int get_precision(double num)
 	return lround(ceil(-log10(num)));
 }
 
-static void print_table(FILE *output, int precision, double avg)
+static void print_table(struct perf_stat_config *config,
+			FILE *output, int precision, double avg)
 {
 	char tmp[64];
 	int idx, indent = 0;
@@ -1645,7 +1646,7 @@ static void print_table(FILE *output, int precision, double avg)
 
 	fprintf(output, "%*s# Table of individual measurements:\n", indent, "");
 
-	for (idx = 0; idx < run_count; idx++) {
+	for (idx = 0; idx < config->run_count; idx++) {
 		double run = (double) walltime_run[idx] / NSEC_PER_SEC;
 		int h, n = 1 + abs((int) (100.0 * (run - avg)/run) / 5);
 
@@ -1675,7 +1676,7 @@ static void print_footer(struct perf_stat_config *config)
 	if (!null_run)
 		fprintf(output, "\n");
 
-	if (run_count == 1) {
+	if (config->run_count == 1) {
 		fprintf(output, " %17.9f seconds time elapsed", avg);
 
 		if (ru_display) {
@@ -1695,7 +1696,7 @@ static void print_footer(struct perf_stat_config *config)
 		int precision = get_precision(sd) + 2;
 
 		if (walltime_run_table)
-			print_table(output, precision, avg);
+			print_table(config, output, precision, avg);
 
 		fprintf(output, " %17.*f +- %.*f seconds time elapsed",
 			precision, avg, precision, sd);
@@ -1886,7 +1887,7 @@ static const struct option stat_options[] = {
 	OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"),
 	OPT_INCR('v', "verbose", &verbose,
 		    "be more verbose (show counter open errors, etc)"),
-	OPT_INTEGER('r', "repeat", &run_count,
+	OPT_INTEGER('r', "repeat", &stat_config.run_count,
 		    "repeat command and print average + stddev (max: 100, forever: 0)"),
 	OPT_BOOLEAN(0, "table", &walltime_run_table,
 		    "display details about each run (only with -r option)"),
@@ -2484,7 +2485,7 @@ static int __cmd_record(int argc, const char **argv)
 	if (output_name)
 		data->file.path = output_name;
 
-	if (run_count != 1 || forever) {
+	if (stat_config.run_count != 1 || forever) {
 		pr_err("Cannot use -r option with perf stat record.\n");
 		return -1;
 	}
@@ -2792,12 +2793,12 @@ int cmd_stat(int argc, const char **argv)
 		goto out;
 	}
 
-	if (stat_config.metric_only && run_count > 1) {
+	if (stat_config.metric_only && stat_config.run_count > 1) {
 		fprintf(stderr, "--metric-only is not supported with -r\n");
 		goto out;
 	}
 
-	if (walltime_run_table && run_count <= 1) {
+	if (walltime_run_table && stat_config.run_count <= 1) {
 		fprintf(stderr, "--table is only supported with -r\n");
 		parse_options_usage(stat_usage, stat_options, "r", 1);
 		parse_options_usage(NULL, stat_options, "table", 0);
@@ -2853,20 +2854,20 @@ int cmd_stat(int argc, const char **argv)
 	 * Display user/system times only for single
 	 * run and when there's specified tracee.
 	 */
-	if ((run_count == 1) && target__none(&target))
+	if ((stat_config.run_count == 1) && target__none(&target))
 		ru_display = true;
 
-	if (run_count < 0) {
+	if (stat_config.run_count < 0) {
 		pr_err("Run count must be a positive number\n");
 		parse_options_usage(stat_usage, stat_options, "r", 1);
 		goto out;
-	} else if (run_count == 0) {
+	} else if (stat_config.run_count == 0) {
 		forever = true;
-		run_count = 1;
+		stat_config.run_count = 1;
 	}
 
 	if (walltime_run_table) {
-		walltime_run = zalloc(run_count * sizeof(walltime_run[0]));
+		walltime_run = zalloc(stat_config.run_count * sizeof(walltime_run[0]));
 		if (!walltime_run) {
 			pr_err("failed to setup -r option");
 			goto out;
@@ -2994,8 +2995,8 @@ int cmd_stat(int argc, const char **argv)
 	signal(SIGABRT, skip_signal);
 
 	status = 0;
-	for (run_idx = 0; forever || run_idx < run_count; run_idx++) {
-		if (run_count != 1 && verbose > 0)
+	for (run_idx = 0; forever || run_idx < stat_config.run_count; run_idx++) {
+		if (stat_config.run_count != 1 && verbose > 0)
 			fprintf(output, "[ perf stat: executing run #%d ... ]\n",
 				run_idx + 1);
 
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index 2dc66e0ba4b8..351a36f5f5b0 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -100,6 +100,7 @@ struct perf_stat_config {
 	unsigned int		 initial_delay;
 	unsigned int		 unit_width;
 	int			 times;
+	int			 run_count;
 	struct runtime_stat	*stats;
 	int			 stats_num;
 	const char		*csv_sep;

  reply	other threads:[~2018-09-06 13:35 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-30  6:32 [PATCH 00/43] perf stat: Make some of the stat code generic Jiri Olsa
2018-08-30  6:32 ` [PATCH 01/43] perf stat: Use evsel->threads in create_perf_stat_counter Jiri Olsa
2018-09-06 13:21   ` [tip:perf/core] perf stat: Use evsel->threads in create_perf_stat_counter() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 02/43] perf stat: Move initial_delay into struct perf_stat_config Jiri Olsa
2018-09-06 13:21   ` [tip:perf/core] perf stat: Move 'initial_delay' to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 03/43] perf stat: Move no_inherit into struct perf_stat_config Jiri Olsa
2018-09-06 13:22   ` [tip:perf/core] perf stat: Move 'no_inherit' to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 04/43] perf stat: Use local config arg for scale in create_perf_stat_counter Jiri Olsa
2018-09-06 13:22   ` [tip:perf/core] perf stat: Use local config arg for scale in create_perf_stat_counter() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 05/43] perf stat: Add identifier flag into struct stat_opts Jiri Olsa
2018-09-06 13:23   ` [tip:perf/core] perf stat: Add 'identifier' flag to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 06/43] perf tools: Switch session argument to evlist in perf_event__synthesize_attrs Jiri Olsa
2018-09-06 13:23   ` [tip:perf/core] perf tools: Switch 'session' argument to 'evlist' in perf_event__synthesize_attrs() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 07/43] perf tools: Add perf_evsel__store_ids function Jiri Olsa
2018-09-06 13:24   ` [tip:perf/core] perf evsel: Introduce perf_evsel__store_ids() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 08/43] perf stat: Move create_perf_stat_counter into stat.c Jiri Olsa
2018-09-06 13:24   ` [tip:perf/core] perf stat: Move create_perf_stat_counter() to stat.c tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 09/43] perf stat: Rename is_pipe argument to attrs perf_stat_synthesize_config Jiri Olsa
2018-09-06 13:25   ` [tip:perf/core] perf stat: Rename 'is_pipe' argument to 'attrs' in perf_stat_synthesize_config() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 10/43] perf stat: Add struct perf_stat_config argument to perf_stat_synthesize_config Jiri Olsa
2018-09-06 13:26   ` [tip:perf/core] perf stat: Add 'struct perf_stat_config' argument to perf_stat_synthesize_config() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 11/43] perf stat: Add struct perf_tool argument to perf_stat_synthesize_config Jiri Olsa
2018-09-06 13:26   ` [tip:perf/core] perf stat: Add 'struct perf_tool' argument to perf_stat_synthesize_config() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 12/43] perf stat: Add struct perf_evlist argument to perf_stat_synthesize_config Jiri Olsa
2018-09-06 13:27   ` [tip:perf/core] perf stat: Add 'struct perf_evlist' argument to perf_stat_synthesize_config() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 13/43] perf stat: Add perf_event__handler_t argument to perf_stat_synthesize_config Jiri Olsa
2018-09-06 13:27   ` [tip:perf/core] perf stat: Add 'perf_event__handler_t' argument to perf_stat_synthesize_config() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 14/43] perf stat: Move perf_stat_synthesize_config into stat.c Jiri Olsa
2018-09-06 13:28   ` [tip:perf/core] perf stat: Move perf_stat_synthesize_config() to stat.c tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 15/43] perf stat: Add perf_evlist__print_counters function Jiri Olsa
2018-09-06 13:28   ` [tip:perf/core] perf stat: Introduce perf_evlist__print_counters() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 16/43] perf stat: Move STAT_RECORD out of perf_evlist__print_counters Jiri Olsa
2018-09-06 13:29   ` [tip:perf/core] perf stat: Move STAT_RECORD out of perf_evlist__print_counters() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 17/43] perf stat: Add stat_config argument to perf_evlist__print_counters Jiri Olsa
2018-09-06 13:29   ` [tip:perf/core] perf stat: Add 'struct perf_stat_config' argument to perf_evlist__print_counters() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 18/43] perf stat: Pass stat_config argument to local print functions Jiri Olsa
2018-09-06 13:30   ` [tip:perf/core] perf stat: Pass 'struct perf_stat_config' " tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 19/43] perf stat: Pass stat_config argument to global " Jiri Olsa
2018-09-06 13:30   ` [tip:perf/core] perf stat: Pass a 'struct perf_stat_config' " tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 20/43] perf stat: Move csv_* into struct perf_stat_config Jiri Olsa
2018-09-06 13:31   ` [tip:perf/core] perf stat: Move csv_* to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 21/43] perf stat: Move interval_clear into struct perf_stat_config Jiri Olsa
2018-09-06 13:31   ` [tip:perf/core] perf stat: Move 'interval_clear' to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 22/43] perf stat: Move metric_only into struct perf_stat_config Jiri Olsa
2018-09-06 13:32   ` [tip:perf/core] perf stat: Move 'metric_only' to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 23/43] perf stat: Move unit_width into struct perf_stat_config Jiri Olsa
2018-09-06 13:33   ` [tip:perf/core] perf stat: Move 'unit_width' to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 24/43] perf stat: Add target argument to perf_evlist__print_counters Jiri Olsa
2018-09-06 13:33   ` [tip:perf/core] perf stat: Add 'target' argument to perf_evlist__print_counters() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 25/43] perf stat: Pass evlist argument to print functions Jiri Olsa
2018-09-06 13:34   ` [tip:perf/core] perf stat: Pass 'evlist' " tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 26/43] perf stat: Use evsel->evlist instead of evsel_list in collect_all_aliases Jiri Olsa
2018-09-06 13:34   ` [tip:perf/core] perf stat: Use 'evsel->evlist' instead of 'evsel_list' in collect_all_aliases() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 27/43] perf stat: Move run_count into struct perf_stat_config Jiri Olsa
2018-09-06 13:35   ` tip-bot for Jiri Olsa [this message]
2018-08-30  6:32 ` [PATCH 28/43] perf stat: Move metric_only_len " Jiri Olsa
2018-09-06 13:35   ` [tip:perf/core] perf stat: Move 'metric_only_len' to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 29/43] perf stat: Pass stat_config to first_shadow_cpu Jiri Olsa
2018-09-06 13:36   ` [tip:perf/core] perf stat: Pass 'struct perf_stat_config' to first_shadow_cpu() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 30/43] perf stat: Pass evlist to aggr_update_shadow Jiri Olsa
2018-09-06 13:37   ` [tip:perf/core] perf stat: Pass 'evlist' to aggr_update_shadow() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 31/43] perf stat: Add walltime_nsecs_stats pointer into struct perf_stat_config Jiri Olsa
2018-09-06 13:37   ` [tip:perf/core] perf stat: Add 'walltime_nsecs_stats' pointer to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 32/43] perf stat: Move null_run into struct perf_stat_config Jiri Olsa
2018-09-06 13:38   ` [tip:perf/core] perf stat: Move 'null_run' to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 33/43] perf stat: Move print_free_counters_hint into struct perf_stat_config Jiri Olsa
2018-09-06 13:38   ` [tip:perf/core] perf stat: Move 'print_free_counters_hint' to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 34/43] perf stat: Move print_mixed_hw_group_error into struct perf_stat_config Jiri Olsa
2018-09-06 13:39   ` [tip:perf/core] perf stat: Move 'print_mixed_hw_group_error' to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 35/43] perf stat: Move ru_* data into struct perf_stat_config Jiri Olsa
2018-09-06 13:39   ` [tip:perf/core] perf stat: Move ru_* data to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 36/43] perf stat: Move *_aggr_* data into struct perf_stat_config Jiri Olsa
2018-09-06 13:40   ` [tip:perf/core] perf stat: Move *_aggr_* data to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 37/43] perf stat: Do not use glovab evsel_list in print functions Jiri Olsa
2018-09-06 13:40   ` [tip:perf/core] perf stat: Do not use the global 'evsel_list' " tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 38/43] perf stat: Move big_num data into struct perf_stat_config Jiri Olsa
2018-09-06 13:41   ` [tip:perf/core] perf stat: Move 'big_num' data to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 39/43] perf stat: Move no_merge data into struct perf_stat_config Jiri Olsa
2018-09-06 13:42   ` [tip:perf/core] perf stat: Move 'no_merge' data to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 40/43] perf stat: Propagate struct target arg to sort_aggr_thread Jiri Olsa
2018-09-06 13:42   ` [tip:perf/core] perf stat: Propagate 'struct target' arg to sort_aggr_thread() tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 41/43] perf stat: Move walltime_* data into struct perf_stat_config Jiri Olsa
2018-09-06 13:43   ` [tip:perf/core] perf stat: Move 'walltime_*' data to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 42/43] perf stat: Move metric_events into struct perf_stat_config Jiri Olsa
2018-09-06 13:43   ` [tip:perf/core] perf stat: Move 'metric_events' to 'struct perf_stat_config' tip-bot for Jiri Olsa
2018-08-30  6:32 ` [PATCH 43/43] perf stat: Move display functions into stat-display.c Jiri Olsa
2018-09-06 13:44   ` [tip:perf/core] perf stat: Move the display functions to stat-display.c tip-bot for Jiri Olsa
2018-08-30 17:54 ` [PATCH 00/43] perf stat: Make some of the stat code generic 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-d97ae04b3d5263be242a6a9f9eef6422fc86326a@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andi@firstfloor.org \
    --cc=dsahern@gmail.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=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).