diff options
author | Tom Zanussi <tzanussi@gmail.com> | 2010-04-02 00:59:16 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-04-14 05:56:06 -0400 |
commit | 529870e37473a9fc609078f03cc5b4148cf06a87 (patch) | |
tree | d0ab94e0895dbf1e27292c1c654e316c808d8f07 /tools/perf/builtin-record.c | |
parent | 8dc58101f2c838355d44402aa77646649d10dbec (diff) |
perf record: Introduce special handling for pipe output
Adds special treatment for stdout - if the user specifies '-o -'
to perf record, the intent is that the event stream be written
to stdout rather than to a disk file.
Also, redirect stdout of forked child to stderr - in pipe mode,
stdout of the forked child interferes with the stdout perf
stream, so redirect it to stderr where it can still be seen but
won't be mixed in with the perf output.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: fweisbec@gmail.com
Cc: rostedt@goodmis.org
Cc: k-keiichi@bx.jp.nec.com
Cc: acme@ghostprotocols.net
LKML-Reference: <1270184365-8281-3-git-send-email-tzanussi@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/builtin-record.c')
-rw-r--r-- | tools/perf/builtin-record.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index d060fc50c8a..d4464f7fcea 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -35,6 +35,7 @@ static unsigned int page_size; | |||
35 | static unsigned int mmap_pages = 128; | 35 | static unsigned int mmap_pages = 128; |
36 | static int freq = 1000; | 36 | static int freq = 1000; |
37 | static int output; | 37 | static int output; |
38 | static int pipe_output = 0; | ||
38 | static const char *output_name = "perf.data"; | 39 | static const char *output_name = "perf.data"; |
39 | static int group = 0; | 40 | static int group = 0; |
40 | static unsigned int realtime_prio = 0; | 41 | static unsigned int realtime_prio = 0; |
@@ -449,7 +450,9 @@ static int __cmd_record(int argc, const char **argv) | |||
449 | exit(-1); | 450 | exit(-1); |
450 | } | 451 | } |
451 | 452 | ||
452 | if (!stat(output_name, &st) && st.st_size) { | 453 | if (!strcmp(output_name, "-")) |
454 | pipe_output = 1; | ||
455 | else if (!stat(output_name, &st) && st.st_size) { | ||
453 | if (!force) { | 456 | if (!force) { |
454 | if (!append_file) { | 457 | if (!append_file) { |
455 | pr_err("Error, output file %s exists, use -A " | 458 | pr_err("Error, output file %s exists, use -A " |
@@ -474,7 +477,10 @@ static int __cmd_record(int argc, const char **argv) | |||
474 | else | 477 | else |
475 | flags |= O_TRUNC; | 478 | flags |= O_TRUNC; |
476 | 479 | ||
477 | output = open(output_name, flags, S_IRUSR|S_IWUSR); | 480 | if (pipe_output) |
481 | output = STDOUT_FILENO; | ||
482 | else | ||
483 | output = open(output_name, flags, S_IRUSR | S_IWUSR); | ||
478 | if (output < 0) { | 484 | if (output < 0) { |
479 | perror("failed to create output file"); | 485 | perror("failed to create output file"); |
480 | exit(-1); | 486 | exit(-1); |
@@ -513,6 +519,8 @@ static int __cmd_record(int argc, const char **argv) | |||
513 | } | 519 | } |
514 | 520 | ||
515 | if (!child_pid) { | 521 | if (!child_pid) { |
522 | if (pipe_output) | ||
523 | dup2(2, 1); | ||
516 | close(child_ready_pipe[0]); | 524 | close(child_ready_pipe[0]); |
517 | close(go_pipe[1]); | 525 | close(go_pipe[1]); |
518 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); | 526 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); |
@@ -564,7 +572,11 @@ static int __cmd_record(int argc, const char **argv) | |||
564 | open_counters(cpumap[i]); | 572 | open_counters(cpumap[i]); |
565 | } | 573 | } |
566 | 574 | ||
567 | if (file_new) { | 575 | if (pipe_output) { |
576 | err = perf_header__write_pipe(output); | ||
577 | if (err < 0) | ||
578 | return err; | ||
579 | } else if (file_new) { | ||
568 | err = perf_header__write(&session->header, output, false); | 580 | err = perf_header__write(&session->header, output, false); |
569 | if (err < 0) | 581 | if (err < 0) |
570 | return err; | 582 | return err; |