All of lore.kernel.org
 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 36/43] perf stat report: Add report command
Date: Thu, 17 Dec 2015 16:47:17 -0300	[thread overview]
Message-ID: <1450381644-25674-37-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1450381644-25674-1-git-send-email-acme@kernel.org>

From: Jiri Olsa <jolsa@kernel.org>

Adding 'perf stat report' command support. ATM it only processes attr
events and display nothing.

Reported-by: Kan Liang <kan.liang@intel.com>
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/1446734469-11352-12-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-stat.txt | 12 +++++++
 tools/perf/builtin-stat.c              | 61 +++++++++++++++++++++++++++++++---
 2 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 70eee1c2c444..95f492828657 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -11,6 +11,7 @@ SYNOPSIS
 'perf stat' [-e <EVENT> | --event=EVENT] [-a] <command>
 'perf stat' [-e <EVENT> | --event=EVENT] [-a] -- <command> [<options>]
 'perf stat' [-e <EVENT> | --event=EVENT] [-a] record [-o file] -- <command> [<options>]
+'perf stat' report [-i file]
 
 DESCRIPTION
 -----------
@@ -26,6 +27,9 @@ OPTIONS
 record::
 	See STAT RECORD.
 
+report::
+	See STAT REPORT.
+
 -e::
 --event=::
 	Select the PMU event. Selection can be:
@@ -170,6 +174,14 @@ Stores stat data into perf data file.
 --output file::
 Output file name.
 
+STAT REPORT
+-----------
+Reads and reports stat data from perf data file.
+
+-i file::
+--input file::
+Input file name.
+
 
 EXAMPLES
 --------
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 575e2535ea03..abba49b847d2 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -60,6 +60,8 @@
 #include "util/thread_map.h"
 #include "util/counts.h"
 #include "util/session.h"
+#include "util/tool.h"
+#include "asm/bug.h"
 
 #include <stdlib.h>
 #include <sys/prctl.h>
@@ -132,6 +134,7 @@ struct perf_stat {
 	struct perf_data_file	 file;
 	struct perf_session	*session;
 	u64			 bytes_written;
+	struct perf_tool	 tool;
 };
 
 static struct perf_stat		perf_stat;
@@ -1041,8 +1044,8 @@ static void print_header(int argc, const char **argv)
 		else if (target.cpu_list)
 			fprintf(output, "\'CPU(s) %s", target.cpu_list);
 		else if (!target__has_task(&target)) {
-			fprintf(output, "\'%s", argv[0]);
-			for (i = 1; i < argc; i++)
+			fprintf(output, "\'%s", argv ? argv[0] : "pipe");
+			for (i = 1; argv && (i < argc); i++)
 				fprintf(output, " %s", argv[i]);
 		} else if (target.pid)
 			fprintf(output, "process id \'%s", target.pid);
@@ -1527,6 +1530,55 @@ static int __cmd_record(int argc, const char **argv)
 	return argc;
 }
 
+static const char * const report_usage[] = {
+	"perf stat report [<options>]",
+	NULL,
+};
+
+static struct perf_stat perf_stat = {
+	.tool = {
+		.attr		= perf_event__process_attr,
+	},
+};
+
+static int __cmd_report(int argc, const char **argv)
+{
+	struct perf_session *session;
+	const struct option options[] = {
+	OPT_STRING('i', "input", &input_name, "file", "input file name"),
+	OPT_END()
+	};
+	struct stat st;
+	int ret;
+
+	argc = parse_options(argc, argv, options, report_usage, 0);
+
+	if (!input_name || !strlen(input_name)) {
+		if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))
+			input_name = "-";
+		else
+			input_name = "perf.data";
+	}
+
+	perf_stat.file.path = input_name;
+	perf_stat.file.mode = PERF_DATA_MODE_READ;
+
+	session = perf_session__new(&perf_stat.file, false, &perf_stat.tool);
+	if (session == NULL)
+		return -1;
+
+	perf_stat.session  = session;
+	stat_config.output = stderr;
+	evsel_list         = session->evlist;
+
+	ret = perf_session__process_events(session);
+	if (ret)
+		return ret;
+
+	perf_session__delete(session);
+	return 0;
+}
+
 int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 {
 	const char * const stat_usage[] = {
@@ -1537,7 +1589,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	const char *mode;
 	FILE *output = stderr;
 	unsigned int interval;
-	const char * const stat_subcommands[] = { "record" };
+	const char * const stat_subcommands[] = { "record", "report" };
 
 	setlocale(LC_ALL, "");
 
@@ -1553,7 +1605,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 		argc = __cmd_record(argc, argv);
 		if (argc < 0)
 			return -1;
-	}
+	} else if (argc && !strncmp(argv[0], "rep", 3))
+		return __cmd_report(argc, argv);
 
 	interval = stat_config.interval;
 
-- 
2.1.0


  parent reply	other threads:[~2015-12-17 19:53 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-17 19:46 [GIT PULL 00/43] perf/core new feature: 'perf stat record/report' Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 01/43] perf thread_map: Add thread_map user level event Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 02/43] perf thread_map: Add thread_map event sythesize function Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 03/43] perf thread_map: Add thread_map__new_event function Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 04/43] perf thread_map: Add perf_event__fprintf_thread_map function Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 05/43] perf cpu_map: Add cpu_map user level event Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 06/43] perf cpu_map: Add cpu_map event synthesize function Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 07/43] perf cpu_map: Add cpu_map__new_event function Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 08/43] perf cpu_map: Add perf_event__fprintf_cpu_map function Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 09/43] perf tools: Add stat config user level event Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 10/43] perf tools: Add stat config event synthesize function Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 11/43] perf tools: Add stat config event read function Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 12/43] perf tools: Add stat user level event Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 13/43] perf tools: Add stat event synthesize function Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 14/43] perf tools: Add stat event read function Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 15/43] perf tools: Add stat round user level event Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 16/43] perf tools: Add stat round event synthesize function Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 17/43] perf tools: Add stat events fprintf functions Arnaldo Carvalho de Melo
2015-12-17 19:46 ` [PATCH 18/43] perf tools: Add event_update user level event Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 19/43] perf tools: Add event_update event unit type Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 20/43] perf tools: Add event_update event scale type Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 21/43] perf tools: Add event_update event name type Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 22/43] perf tools: Add event_update event cpus type Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 23/43] perf tools: Add perf_event__fprintf_event_update function Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 24/43] perf report: Display newly added events in raw dump Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 25/43] perf tools: Introduce stat perf.data header feature Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 26/43] perf stat record: Add record command Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 27/43] perf stat record: Initialize record features Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 28/43] perf stat record: Synthesize stat record data Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 29/43] perf evlist: Export id_add_fd() Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 30/43] perf stat record: Store events IDs in perf data file Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 31/43] perf stat record: Add pipe support for record command Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 32/43] perf stat record: Write stat events on record Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 33/43] perf stat record: Write stat round " Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 34/43] perf stat record: Do not allow record with multiple runs mode Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 35/43] perf stat record: Synthesize event update events Arnaldo Carvalho de Melo
2015-12-17 19:47 ` Arnaldo Carvalho de Melo [this message]
2015-12-17 19:47 ` [PATCH 37/43] perf stat report: Process cpu/threads maps Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 38/43] perf stat report: Process stat config event Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 39/43] perf stat report: Add support to initialize aggr_map from file Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 40/43] perf stat report: Move csv_sep initialization before report command Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 41/43] perf stat report: Process stat and stat round events Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 42/43] perf stat report: Process event update events Arnaldo Carvalho de Melo
2015-12-17 19:47 ` [PATCH 43/43] perf stat report: Allow to override aggr_mode Arnaldo Carvalho de Melo
2015-12-18  8:48 ` [GIT PULL 00/43] perf/core new feature: 'perf stat record/report' Ingo Molnar
2015-12-18  8:55   ` Ingo Molnar
2015-12-18 10:11     ` Jiri Olsa

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=1450381644-25674-37-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.