LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Jiri Olsa <jolsa@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	David Ahern <dsahern@gmail.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 06/52] perf stat: Add --table option to display time of each run
Date: Wed,  2 May 2018 12:18:56 -0300	[thread overview]
Message-ID: <20180502151942.20542-7-acme@kernel.org> (raw)
In-Reply-To: <20180502151942.20542-1-acme@kernel.org>

From: Jiri Olsa <jolsa@kernel.org>

Add --table option to display time for each run (-r option), like:

  $ perf stat --null -r 5 --table perf bench sched pipe

   Performance counter stats for './perf bench sched pipe' (5 runs):

             # Table of individual measurements:
             5.379 (-0.176)
             5.243 (-0.311)
             5.238 (-0.317)
             5.536 (-0.019)
             6.377 (+0.823)

             # Final result:
             5.555 +- 0.213 seconds time elapsed  ( +-  3.83% )

Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180423090823.32309-8-jolsa@kernel.org
[ Document the new option in 'perf stat's man page ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-stat.txt | 16 ++++++++++
 tools/perf/builtin-stat.c              | 56 +++++++++++++++++++++++++++++++---
 tools/perf/util/stat.h                 |  3 +-
 3 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index e6c3b4e555c2..72a2414513bd 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -116,6 +116,22 @@ Do not aggregate counts across all monitored CPUs.
 print counts using a CSV-style output to make it easy to import directly into
 spreadsheets. Columns are separated by the string specified in SEP.
 
+--table:: Display time for each run (-r option), in a table format, e.g.:
+
+  $ perf stat --null -r 5 --table perf bench sched pipe
+
+   Performance counter stats for 'perf bench sched pipe' (5 runs):
+
+             # Table of individual measurements:
+             5.379 (-0.176)
+             5.243 (-0.311)
+             5.238 (-0.317)
+             5.536 (-0.019)
+             6.377 (+0.823)
+
+             # Final result:
+             5.555 +- 0.213 seconds time elapsed  ( +-  3.83% )
+
 -G name::
 --cgroup name::
 monitor only in the container (cgroup) called "name". This option is available only
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 3a94647ef6bc..72553937c010 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -164,6 +164,7 @@ static bool			forever				= false;
 static bool			metric_only			= false;
 static bool			force_metric_only		= false;
 static bool			no_merge			= false;
+static bool			walltime_run_table		= false;
 static struct timespec		ref_time;
 static struct cpu_map		*aggr_map;
 static aggr_get_id_t		aggr_get_id;
@@ -173,6 +174,7 @@ static const char		*output_name;
 static int			output_fd;
 static int			print_free_counters_hint;
 static int			print_mixed_hw_group_error;
+static u64			*walltime_run;
 
 struct perf_stat {
 	bool			 record;
@@ -569,7 +571,7 @@ static struct perf_evsel *perf_evsel__reset_weak_group(struct perf_evsel *evsel)
 	return leader;
 }
 
-static int __run_perf_stat(int argc, const char **argv)
+static int __run_perf_stat(int argc, const char **argv, int run_idx)
 {
 	int interval = stat_config.interval;
 	int times = stat_config.times;
@@ -752,6 +754,9 @@ static int __run_perf_stat(int argc, const char **argv)
 
 	t1 = rdclock();
 
+	if (walltime_run_table)
+		walltime_run[run_idx] = t1 - t0;
+
 	update_stats(&walltime_nsecs_stats, t1 - t0);
 
 	/*
@@ -766,7 +771,7 @@ static int __run_perf_stat(int argc, const char **argv)
 	return WEXITSTATUS(status);
 }
 
-static int run_perf_stat(int argc, const char **argv)
+static int run_perf_stat(int argc, const char **argv, int run_idx)
 {
 	int ret;
 
@@ -779,7 +784,7 @@ static int run_perf_stat(int argc, const char **argv)
 	if (sync_run)
 		sync();
 
-	ret = __run_perf_stat(argc, argv);
+	ret = __run_perf_stat(argc, argv, run_idx);
 	if (ret)
 		return ret;
 
@@ -1772,6 +1777,27 @@ static int get_precision(double num)
 	return lround(ceil(-log10(num)));
 }
 
+static void print_table(FILE *output, int precision, double avg)
+{
+	char tmp[64];
+	int idx, indent = 0;
+
+	scnprintf(tmp, 64, " %17.*f", precision, avg);
+	while (tmp[indent] == ' ')
+		indent++;
+
+	fprintf(output, "%*s# Table of individual measurements:\n", indent, "");
+
+	for (idx = 0; idx < run_count; idx++) {
+		double run = (double) walltime_run[idx] / NSEC_PER_SEC;
+
+		fprintf(output, " %17.*f (%+.*f)\n",
+			precision, run, precision, run - avg);
+	}
+
+	fprintf(output, "\n%*s# Final result:\n", indent, "");
+}
+
 static void print_footer(void)
 {
 	double avg = avg_stats(&walltime_nsecs_stats) / NSEC_PER_SEC;
@@ -1791,6 +1817,9 @@ static void print_footer(void)
 		 */
 		int precision = get_precision(sd) + 2;
 
+		if (walltime_run_table)
+			print_table(output, precision, avg);
+
 		fprintf(output, " %17.*f +- %.*f seconds time elapsed",
 			precision, avg, precision, sd);
 
@@ -1970,6 +1999,8 @@ static const struct option stat_options[] = {
 		    "be more verbose (show counter open errors, etc)"),
 	OPT_INTEGER('r', "repeat", &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)"),
 	OPT_BOOLEAN('n', "null", &null_run,
 		    "null run - dont start any counters"),
 	OPT_INCR('d', "detailed", &detailed_run,
@@ -2861,6 +2892,13 @@ int cmd_stat(int argc, const char **argv)
 		goto out;
 	}
 
+	if (walltime_run_table && 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);
+		goto out;
+	}
+
 	if (output_fd < 0) {
 		fprintf(stderr, "argument to --log-fd must be a > 0\n");
 		parse_options_usage(stat_usage, stat_options, "log-fd", 0);
@@ -2915,6 +2953,14 @@ int cmd_stat(int argc, const char **argv)
 		run_count = 1;
 	}
 
+	if (walltime_run_table) {
+		walltime_run = zalloc(run_count * sizeof(walltime_run[0]));
+		if (!walltime_run) {
+			pr_err("failed to setup -r option");
+			goto out;
+		}
+	}
+
 	if ((stat_config.aggr_mode == AGGR_THREAD) &&
 		!target__has_task(&target)) {
 		if (!target.system_wide || target.cpu_list) {
@@ -3030,7 +3076,7 @@ int cmd_stat(int argc, const char **argv)
 			fprintf(output, "[ perf stat: executing run #%d ... ]\n",
 				run_idx + 1);
 
-		status = run_perf_stat(argc, argv);
+		status = run_perf_stat(argc, argv, run_idx);
 		if (forever && status != -1) {
 			print_counters(NULL, argc, argv);
 			perf_stat__reset_stats();
@@ -3078,6 +3124,8 @@ int cmd_stat(int argc, const char **argv)
 	perf_stat__exit_aggr_mode();
 	perf_evlist__free_stats(evsel_list);
 out:
+	free(walltime_run);
+
 	if (smi_cost && smi_reset)
 		sysfs__write_int(FREEZE_ON_SMI_PATH, 0);
 
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index 8f56ba4fd258..36efb986f7fc 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -7,8 +7,7 @@
 #include "xyarray.h"
 #include "rblist.h"
 
-struct stats
-{
+struct stats {
 	double n, mean, M2;
 	u64 max, min;
 };
-- 
2.14.3

  parent reply	other threads:[~2018-05-02 15:33 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-02 15:18 [GIT PULL 00/52] perf/core improvements and fixes Arnaldo Carvalho de Melo
2018-05-02 15:18 ` [PATCH 01/52] perf buildid-cache: Support --list option Arnaldo Carvalho de Melo
2018-05-02 15:18 ` [PATCH 02/52] perf buildid-cache: Support --purge-all option Arnaldo Carvalho de Melo
2018-05-02 15:18 ` [PATCH 03/52] perf check-headers.sh: Simplify arguments passing Arnaldo Carvalho de Melo
2018-05-02 15:18 ` [PATCH 04/52] perf check-headers.sh: Add support to check 2 independent files Arnaldo Carvalho de Melo
2018-05-02 15:18 ` [PATCH 05/52] perf stat: Display time in precision based on std deviation Arnaldo Carvalho de Melo
2018-05-02 15:18 ` Arnaldo Carvalho de Melo [this message]
2018-05-02 15:18 ` [PATCH 07/52] perf stat: Display length strings of each run for --table option Arnaldo Carvalho de Melo
2018-05-02 15:18 ` [PATCH 08/52] perf top: Use __map__is_kernel() Arnaldo Carvalho de Melo
2018-05-02 15:18 ` [PATCH 09/52] perf symbols: Use __map__is_kernel() instead of ad-hoc equivalent code Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 10/52] perf dso: Add dso__has_symbols() method Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 11/52] perf map: Introduce map__has_symbols() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 12/52] perf thread: Introduce thread__find_map() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 13/52] perf tests: Let 'perf test list' display subtests Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 14/52] perf thread: Introduce thread__find_symbol() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 15/52] perf script: Use thread__find_symbol() instead of ad-hoc equivalent Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 16/52] perf thread: Make thread__find_map() return the map Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 17/52] perf thread: Make thread__find_symbol() return the symbol searched Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 18/52] perf map: Shorten map_groups__find_by_name() signature Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 19/52] perf Documentation: Support for asciidoctor Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 20/52] perf machine: Introduce machine__kernel_maps() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 21/52] perf machine: Shorten machine__load_kallsyms() signature Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 22/52] perf machine: Remove needless map_type from machine__load_vmlinux_path() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 23/52] perf tests vmlinux-kallsyms: Use machine__find_kernel_function(_by_name) Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 24/52] perf tests vmlinux-kallsyms: Use map__for_each_symbol() instead of open coded equivalent Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 25/52] perf map: Shorten map_groups__find() signature Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 26/52] perf ui stdio: Use map_groups__fprintf() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 27/52] perf symbols: Shorten dso__(first|last)_symbol() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 28/52] tools lib symbols: Introduce kallsyms__is_function() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 29/52] perf tools: Use kallsyms__is_function() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 30/52] perf symbols: Unexport symbol_type__is_a() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 31/52] perf map: Remove enum_type arg to map_groups__first() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 32/52] perf symbols: Remove map_type arg from dso__find_symbol() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 33/52] perf thread: Remove addr_type arg from thread__find_cpumode_addr_location() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 34/52] perf machine: Use machine__find_kernel_function() instead of open coded version Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 35/52] perf thread: Ditch __thread__find_symbol() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 36/52] perf thread: Make thread__find_map() search all maps Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 37/52] perf map: Remove map_type arg from map_groups__find() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 38/52] perf symbols: Store the ELF symbol type in the symbol struct Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 39/52] perf machine: Set PROT_EXEC for executable PERF_RECORD_MMAP records Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 40/52] perf sort: Use mmap->prot on "dcacheline" formatting Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 41/52] perf symbols: No need to special case MAP__FUNCTION in fixup Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 42/52] perf symbols: Use symbol type instead of map->type Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 43/52] perf map: Use map->prot in place of type==MAP__FUNCTION Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 44/52] perf symbols: " Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 45/52] perf symbols: Unify symbol maps Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 46/52] perf symbols: Remove needless goto Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 47/52] perf symbols: Split kernel symbol processing from dso__load_sym() Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 48/52] perf symbols: Remove unused dso__load_all_kallsyms() 'map' parameter Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 49/52] perf symbols: kallsyms__delta() needs the kmap, not the map Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 50/52] perf symbols: Move split_kallsyms to struct map_groups Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 51/52] perf tools: Fix spelling mistake: "builid" -> "buildid" Arnaldo Carvalho de Melo
2018-05-02 15:19 ` [PATCH 52/52] perf machine: Ditch find_kernel_function variants 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=20180502151942.20542-7-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=williams@redhat.com \
    --subject='Re: [PATCH 06/52] perf stat: Add --table option to display time of each run' \
    /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

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).