diff options
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; |