linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] perf tools: Support -x for perf stat report
@ 2020-11-01  6:31 Andi Kleen
  2020-11-01  9:24 ` Jiri Olsa
  0 siblings, 1 reply; 2+ messages in thread
From: Andi Kleen @ 2020-11-01  6:31 UTC (permalink / raw)
  To: acme; +Cc: jolsa, linux-kernel, Andi Kleen, Andi Kleen

Add support for the -x, option to enable CSV output with perf stat
report. Useful to parse the information with other programs.

% perf stat record --quiet -a -I 1000 sleep 5
% perf stat report -x,
     1.000838672,4003.55,msec,cpu-clock,4003548736,100.00,,
     1.000838672,11243,,context-switches,4003631885,100.00,0.003,M/sec
     1.000838672,1682,,cpu-migrations,4003672150,100.00,0.420,K/sec
     1.000838672,13244,,page-faults,4003697471,100.00,0.003,M/sec
     1.000838672,2953214077,,cycles,4003715495,100.00,0.738,GHz
     1.000838672,4380820799,,instructions,4003738270,100.00,1.48,insn per cycle
     1.000838672,809865653,,branches,4003760616,100.00,202.287,M/sec
     1.000838672,12439843,,branch-misses,4003780785,100.00,1.54,of all branches
...

Signed-off-by: Andi Kleen <ak@linux.intel.com>

---

v2: Fix default output (Jiri). Also handle \t as special value like the
original parser (Andi)
v3: Use DEFAULT_SEPARATOR
---
 tools/perf/builtin-stat.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 743fe47e7a88..9fcc7351ce43 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1988,6 +1988,8 @@ static int __cmd_report(int argc, const char **argv)
 		     "aggregate counts per numa node", AGGR_NODE),
 	OPT_SET_UINT('A', "no-aggr", &perf_stat.aggr_mode,
 		     "disable CPU count aggregation", AGGR_NONE),
+	OPT_STRING('x', "field-separator", &stat_config.csv_sep, "separator",
+		   "print counts with custom separator"),
 	OPT_END()
 	};
 	struct stat st;
@@ -2002,6 +2004,13 @@ static int __cmd_report(int argc, const char **argv)
 			input_name = "perf.data";
 	}
 
+	if (strcmp(stat_config.csv_sep, DEFAULT_SEPARATOR)) {
+		stat_config.csv_output = true;
+		if (!strcmp(stat_config.csv_sep, "\\t"))
+			stat_config.csv_sep = "\t";
+		stat_config.big_num = false;
+	}
+
 	perf_stat.data.path = input_name;
 	perf_stat.data.mode = PERF_DATA_MODE_READ;
 
-- 
2.28.0


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

* Re: [PATCH v3] perf tools: Support -x for perf stat report
  2020-11-01  6:31 [PATCH v3] perf tools: Support -x for perf stat report Andi Kleen
@ 2020-11-01  9:24 ` Jiri Olsa
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Olsa @ 2020-11-01  9:24 UTC (permalink / raw)
  To: Andi Kleen; +Cc: acme, jolsa, linux-kernel, Andi Kleen

On Sat, Oct 31, 2020 at 11:31:33PM -0700, Andi Kleen wrote:
> Add support for the -x, option to enable CSV output with perf stat
> report. Useful to parse the information with other programs.
> 
> % perf stat record --quiet -a -I 1000 sleep 5
> % perf stat report -x,
>      1.000838672,4003.55,msec,cpu-clock,4003548736,100.00,,
>      1.000838672,11243,,context-switches,4003631885,100.00,0.003,M/sec
>      1.000838672,1682,,cpu-migrations,4003672150,100.00,0.420,K/sec
>      1.000838672,13244,,page-faults,4003697471,100.00,0.003,M/sec
>      1.000838672,2953214077,,cycles,4003715495,100.00,0.738,GHz
>      1.000838672,4380820799,,instructions,4003738270,100.00,1.48,insn per cycle
>      1.000838672,809865653,,branches,4003760616,100.00,202.287,M/sec
>      1.000838672,12439843,,branch-misses,4003780785,100.00,1.54,of all branches
> ...
> 
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> 
> ---
> 
> v2: Fix default output (Jiri). Also handle \t as special value like the
> original parser (Andi)
> v3: Use DEFAULT_SEPARATOR

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

> ---
>  tools/perf/builtin-stat.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 743fe47e7a88..9fcc7351ce43 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -1988,6 +1988,8 @@ static int __cmd_report(int argc, const char **argv)
>  		     "aggregate counts per numa node", AGGR_NODE),
>  	OPT_SET_UINT('A', "no-aggr", &perf_stat.aggr_mode,
>  		     "disable CPU count aggregation", AGGR_NONE),
> +	OPT_STRING('x', "field-separator", &stat_config.csv_sep, "separator",
> +		   "print counts with custom separator"),
>  	OPT_END()
>  	};
>  	struct stat st;
> @@ -2002,6 +2004,13 @@ static int __cmd_report(int argc, const char **argv)
>  			input_name = "perf.data";
>  	}
>  
> +	if (strcmp(stat_config.csv_sep, DEFAULT_SEPARATOR)) {
> +		stat_config.csv_output = true;
> +		if (!strcmp(stat_config.csv_sep, "\\t"))
> +			stat_config.csv_sep = "\t";
> +		stat_config.big_num = false;
> +	}
> +
>  	perf_stat.data.path = input_name;
>  	perf_stat.data.mode = PERF_DATA_MODE_READ;
>  
> -- 
> 2.28.0
> 


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

end of thread, other threads:[~2020-11-01  9:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-01  6:31 [PATCH v3] perf tools: Support -x for perf stat report Andi Kleen
2020-11-01  9:24 ` 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).