Messages in this thread Patch in this message | | | From | Tom Zanussi <> | Subject | [RFC PATCH 1/7] perf: introduce special handling for pipe input/output | Date | Wed, 3 Mar 2010 01:05:23 -0600 |
| |
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
| |