linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] perf stat: Print topology/time headers with --metric-only
@ 2016-05-20 19:50 Andi Kleen
  2016-05-20 19:50 ` [PATCH 2/2] perf stat: Add missing aggregation headers for --metric-only CSV Andi Kleen
  2016-05-21 11:17 ` [PATCH 1/2] perf stat: Print topology/time headers with --metric-only Jiri Olsa
  0 siblings, 2 replies; 4+ messages in thread
From: Andi Kleen @ 2016-05-20 19:50 UTC (permalink / raw)
  To: acme; +Cc: jolsa, linux-kernel, Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

When --metric-only is enabled there were no headers for the topology
in interval mode.  Also when headers were printed they were
on a separate line.

Before:

$ perf stat  --metric-only  -A -I 1000 -a
     1.001038376       frontend cycles idle insn per cycle       stalled cycles per insn branch-misses of all branches
     1.001038376 CPU0     123.54%               0.23                5.29                    7.61%
     1.001038376 CPU1     137.78%               0.24                5.13                   10.07%
     1.001038376 CPU2      64.48%               0.22                5.50                    6.84%

After:

$ perf stat  --metric-only  -A -I 1000 -a
     1.001111114 CPU0      82.46%               0.32                2.60                    7.64%
     1.001111114 CPU1     126.63%               0.02               42.83                    0.15%
     1.001111114 CPU2     193.54%               0.32                2.59                    6.92%

v2: Move all headers on a single line
Reported-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/builtin-stat.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 7c5c50b61b28..790eeea335cc 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1311,7 +1311,7 @@ static int aggr_header_lens[] = {
 	[AGGR_GLOBAL] = 0,
 };
 
-static void print_metric_headers(char *prefix)
+static void print_metric_headers(const char *prefix, bool no_indent)
 {
 	struct perf_stat_output_ctx out;
 	struct perf_evsel *counter;
@@ -1322,7 +1322,7 @@ static void print_metric_headers(char *prefix)
 	if (prefix)
 		fprintf(stat_config.output, "%s", prefix);
 
-	if (!csv_output)
+	if (!csv_output && !no_indent)
 		fprintf(stat_config.output, "%*s",
 			aggr_header_lens[stat_config.aggr_mode], "");
 
@@ -1347,28 +1347,40 @@ static void print_interval(char *prefix, struct timespec *ts)
 
 	sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep);
 
-	if (num_print_interval == 0 && !csv_output && !metric_only) {
+	if (num_print_interval == 0 && !csv_output) {
 		switch (stat_config.aggr_mode) {
 		case AGGR_SOCKET:
-			fprintf(output, "#           time socket cpus             counts %*s events\n", unit_width, "unit");
+			fprintf(output, "#           time socket cpus");
+			if (!metric_only)
+				fprintf(output, "             counts %*s events\n", unit_width, "unit");
 			break;
 		case AGGR_CORE:
-			fprintf(output, "#           time core         cpus             counts %*s events\n", unit_width, "unit");
+			fprintf(output, "#           time core         cpus");
+			if (!metric_only)
+				fprintf(output, "             counts %*s events\n", unit_width, "unit");
 			break;
 		case AGGR_NONE:
-			fprintf(output, "#           time CPU                counts %*s events\n", unit_width, "unit");
+			fprintf(output, "#           time CPU");
+			if (!metric_only)
+				fprintf(output, "                counts %*s events\n", unit_width, "unit");
 			break;
 		case AGGR_THREAD:
-			fprintf(output, "#           time             comm-pid                  counts %*s events\n", unit_width, "unit");
+			fprintf(output, "#           time             comm-pid");
+			if (!metric_only)
+				fprintf(output, "                  counts %*s events\n", unit_width, "unit");
 			break;
 		case AGGR_GLOBAL:
 		default:
-			fprintf(output, "#           time             counts %*s events\n", unit_width, "unit");
+			fprintf(output, "#           time");
+			if (!metric_only)
+				fprintf(output, "             counts %*s events\n", unit_width, "unit");
 		case AGGR_UNSET:
 			break;
 		}
 	}
 
+	if (num_print_interval == 0 && metric_only)
+		print_metric_headers(" ", true);
 	if (++num_print_interval == 25)
 		num_print_interval = 0;
 }
@@ -1437,8 +1449,8 @@ static void print_counters(struct timespec *ts, int argc, const char **argv)
 	if (metric_only) {
 		static int num_print_iv;
 
-		if (num_print_iv == 0)
-			print_metric_headers(prefix);
+		if (num_print_iv == 0 && !interval)
+			print_metric_headers(prefix, false);
 		if (num_print_iv++ == 25)
 			num_print_iv = 0;
 		if (stat_config.aggr_mode == AGGR_GLOBAL && prefix)
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] perf stat: Add missing aggregation headers for --metric-only CSV
  2016-05-20 19:50 [PATCH 1/2] perf stat: Print topology/time headers with --metric-only Andi Kleen
@ 2016-05-20 19:50 ` Andi Kleen
  2016-05-21 11:19   ` Jiri Olsa
  2016-05-21 11:17 ` [PATCH 1/2] perf stat: Print topology/time headers with --metric-only Jiri Olsa
  1 sibling, 1 reply; 4+ messages in thread
From: Andi Kleen @ 2016-05-20 19:50 UTC (permalink / raw)
  To: acme; +Cc: jolsa, linux-kernel, Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

When in CSV mode --metric-only outputs an header, unlike the other
modes. Previously it did not properly print headers for the
aggregation columns, so the headers were actually shifted against
the real values.

Fix this here by outputting the correct headers for CSV.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/builtin-stat.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 790eeea335cc..5d295da0e41c 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1311,6 +1311,14 @@ static int aggr_header_lens[] = {
 	[AGGR_GLOBAL] = 0,
 };
 
+static const char *aggr_header_csv[] = {
+	[AGGR_CORE] = "core,cpus,",
+	[AGGR_SOCKET] = "socket,cpus",
+	[AGGR_NONE] = "cpu,",
+	[AGGR_THREAD] = "comm-pid,",
+	[AGGR_GLOBAL] = ""
+};
+
 static void print_metric_headers(const char *prefix, bool no_indent)
 {
 	struct perf_stat_output_ctx out;
@@ -1325,6 +1333,12 @@ static void print_metric_headers(const char *prefix, bool no_indent)
 	if (!csv_output && !no_indent)
 		fprintf(stat_config.output, "%*s",
 			aggr_header_lens[stat_config.aggr_mode], "");
+	if (csv_output) {
+		if (stat_config.interval)
+			fputs("time,", stat_config.output);
+		fputs(aggr_header_csv[stat_config.aggr_mode],
+			stat_config.output);
+	}
 
 	/* Print metrics headers only */
 	evlist__for_each(evsel_list, counter) {
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] perf stat: Print topology/time headers with --metric-only
  2016-05-20 19:50 [PATCH 1/2] perf stat: Print topology/time headers with --metric-only Andi Kleen
  2016-05-20 19:50 ` [PATCH 2/2] perf stat: Add missing aggregation headers for --metric-only CSV Andi Kleen
@ 2016-05-21 11:17 ` Jiri Olsa
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Olsa @ 2016-05-21 11:17 UTC (permalink / raw)
  To: Andi Kleen; +Cc: acme, jolsa, linux-kernel, Andi Kleen

On Fri, May 20, 2016 at 12:50:14PM -0700, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
> 
> When --metric-only is enabled there were no headers for the topology
> in interval mode.  Also when headers were printed they were
> on a separate line.
> 
> Before:
> 
> $ perf stat  --metric-only  -A -I 1000 -a
>      1.001038376       frontend cycles idle insn per cycle       stalled cycles per insn branch-misses of all branches
>      1.001038376 CPU0     123.54%               0.23                5.29                    7.61%
>      1.001038376 CPU1     137.78%               0.24                5.13                   10.07%
>      1.001038376 CPU2      64.48%               0.22                5.50                    6.84%
> 
> After:
> 
> $ perf stat  --metric-only  -A -I 1000 -a
>      1.001111114 CPU0      82.46%               0.32                2.60                    7.64%
>      1.001111114 CPU1     126.63%               0.02               42.83                    0.15%
>      1.001111114 CPU2     193.54%               0.32                2.59                    6.92%
> 
> v2: Move all headers on a single line

changelog is wrong

[jolsa@ibm-x3650m4-01 perf]$ sudo ./perf stat  --metric-only  -A -I 1000 -a
#           time CPU frontend cycles idle backend cycles idle  insn per cycle       stalled cycles per insn branch-misses of all branches 
     1.003232468 CPU0      69.13%             56.43%                0.31                2.20                    0.01%                      
     1.003232468 CPU1      69.13%             56.23%                0.31                2.20                    0.00%                      
     1.003232468 CPU2      69.11%             56.27%                0.32                2.19                    0.00%                      

otherwise

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] perf stat: Add missing aggregation headers for --metric-only CSV
  2016-05-20 19:50 ` [PATCH 2/2] perf stat: Add missing aggregation headers for --metric-only CSV Andi Kleen
@ 2016-05-21 11:19   ` Jiri Olsa
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Olsa @ 2016-05-21 11:19 UTC (permalink / raw)
  To: Andi Kleen; +Cc: acme, jolsa, linux-kernel, Andi Kleen

On Fri, May 20, 2016 at 12:50:15PM -0700, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
> 
> When in CSV mode --metric-only outputs an header, unlike the other
> modes. Previously it did not properly print headers for the
> aggregation columns, so the headers were actually shifted against
> the real values.
> 
> Fix this here by outputting the correct headers for CSV.
> 
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
>  tools/perf/builtin-stat.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 790eeea335cc..5d295da0e41c 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -1311,6 +1311,14 @@ static int aggr_header_lens[] = {
>  	[AGGR_GLOBAL] = 0,
>  };
>  
> +static const char *aggr_header_csv[] = {
> +	[AGGR_CORE] = "core,cpus,",
> +	[AGGR_SOCKET] = "socket,cpus",
> +	[AGGR_NONE] = "cpu,",
> +	[AGGR_THREAD] = "comm-pid,",
> +	[AGGR_GLOBAL] = ""
> +};

please indent properly, otherwise

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-05-21 11:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-20 19:50 [PATCH 1/2] perf stat: Print topology/time headers with --metric-only Andi Kleen
2016-05-20 19:50 ` [PATCH 2/2] perf stat: Add missing aggregation headers for --metric-only CSV Andi Kleen
2016-05-21 11:19   ` Jiri Olsa
2016-05-21 11:17 ` [PATCH 1/2] perf stat: Print topology/time headers with --metric-only Jiri Olsa

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