mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Zanussi <tzanussi@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@elte.hu, fweisbec@gmail.com, rostedt@goodmis.org,
	k-keiichi@bx.jp.nec.com
Subject: [RFC PATCH 1/7] perf: introduce special handling for pipe input/output
Date: Wed,  3 Mar 2010 01:05:23 -0600	[thread overview]
Message-ID: <1267599929-8310-2-git-send-email-tzanussi@gmail.com> (raw)
In-Reply-To: <1267599929-8310-1-git-send-email-tzanussi@gmail.com>

Adds special treatment for stdin/stdout - if the user specifies '-o -'
to perf record or '-i -' to perf report et al, the intent is that the
event stream be written to stdout or read from stdin rather than a
disk file.

This initial patch just handles parsing the cmdline for those modes
and setting a couple variables to be used by the code in later
patches.

Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
---
 tools/perf/builtin-record.c |   10 ++++++++--
 tools/perf/builtin-report.c |    3 ++-
 tools/perf/util/session.c   |   10 ++++++++++
 tools/perf/util/session.h   |    1 +
 4 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 771533c..4fe87e3 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -35,6 +35,7 @@ static unsigned int		page_size;
 static unsigned int		mmap_pages			=    128;
 static int			freq				=   1000;
 static int			output;
+static int			pipe_output			=      0;
 static const char		*output_name			= "perf.data";
 static int			group				=      0;
 static unsigned int		realtime_prio			=      0;
@@ -431,7 +432,9 @@ static int __cmd_record(int argc, const char **argv)
 		exit(-1);
 	}
 
-	if (!stat(output_name, &st) && st.st_size) {
+	if (!strcmp(output_name, "-"))
+		pipe_output = 1;
+	else if (!stat(output_name, &st) && st.st_size) {
 		if (!force) {
 			if (!append_file) {
 				pr_err("Error, output file %s exists, use -A "
@@ -456,7 +459,10 @@ static int __cmd_record(int argc, const char **argv)
 	else
 		flags |= O_TRUNC;
 
-	output = open(output_name, flags, S_IRUSR|S_IWUSR);
+	if (pipe_output)
+		output = STDOUT_FILENO;
+	else
+		output = open(output_name, flags, S_IRUSR | S_IWUSR);
 	if (output < 0) {
 		perror("failed to create output file");
 		exit(-1);
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index cfc655d..ca12efa 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -359,7 +359,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
 {
 	argc = parse_options(argc, argv, options, report_usage, 0);
 
-	setup_pager();
+	if (strcmp(input_name, "-") != 0)
+		setup_pager();
 
 	if (symbol__init() < 0)
 		return -1;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 0de7258..dd1e923 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -14,6 +14,16 @@ static int perf_session__open(struct perf_session *self, bool force)
 {
 	struct stat input_stat;
 
+	if (!strcmp(self->filename, "-")) {
+		self->fd_pipe = true;
+		self->fd = STDIN_FILENO;
+
+		if (perf_header__read(&self->header, self->fd) < 0)
+			pr_err("incompatible file format");
+
+		return 0;
+	}
+
 	self->fd = open(self->filename, O_RDONLY);
 	if (self->fd < 0) {
 		pr_err("failed to open file: %s", self->filename);
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 31950fc..dbfb74a 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -26,6 +26,7 @@ struct perf_session {
 	u64			sample_type;
 	struct ref_reloc_sym	ref_reloc_sym;
 	int			fd;
+	bool			fd_pipe;
 	int			cwdlen;
 	char			*cwd;
 	char filename[0];
-- 
1.6.4.GIT


  reply	other threads:[~2010-03-03  7:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-03  7:05 [RFC PATCH 0/7] perf: 'live mode' Tom Zanussi
2010-03-03  7:05 ` Tom Zanussi [this message]
2010-03-03  7:05 ` [RFC PATCH 2/7] perf: add pipe-specific header read/write and event processing code Tom Zanussi
2010-03-27  3:14   ` Frederic Weisbecker
2010-03-27 22:57     ` Arnaldo Carvalho de Melo
2010-03-27 23:05       ` Arnaldo Carvalho de Melo
2010-03-27 23:12         ` Frederic Weisbecker
2010-03-28  0:15           ` Arnaldo Carvalho de Melo
2010-03-03  7:05 ` [RFC PATCH 3/7] perf: convert perf header attrs into attr events Tom Zanussi
2010-03-03  7:05 ` [RFC PATCH 4/7] perf: convert perf event types into event type events Tom Zanussi
2010-03-03  7:05 ` [RFC PATCH 5/7] perf: convert perf tracing data into a tracing_data event Tom Zanussi
2010-03-03  7:05 ` [RFC PATCH 6/7] perf: convert perf header build_ids into build_id events Tom Zanussi
2010-03-03  7:05 ` [RFC PATCH 7/7] perf trace/scripting: rwtop and sctop scripts Tom Zanussi
2010-03-04 11:18 ` [RFC PATCH 0/7] perf: 'live mode' Ingo Molnar
2010-03-27 23:00   ` Arnaldo Carvalho de Melo
2010-03-28  5:04     ` Tom Zanussi
2010-03-27  0:57 ` Frederic Weisbecker

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=1267599929-8310-2-git-send-email-tzanussi@gmail.com \
    --to=tzanussi@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=k-keiichi@bx.jp.nec.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome