diff options
author | Franck Bui-Huu <fbuihuu@gmail.com> | 2011-01-16 11:14:45 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-01-24 07:58:27 -0500 |
commit | d7065adb9b4f3384c2615f0a3dbdb6c3aae1eb18 (patch) | |
tree | 2547ed90722723a9039bbbc3d4f1519d4908db79 /tools | |
parent | e80711ca8512c8586da0c3e18e2f1caf73c88731 (diff) |
perf record: auto detect when stdout is a pipe
This patch gives the ability to 'perf record' to detect when its stdout
has been redirected to a pipe. There's now no more need to add '-o -'
switch in this case.
However '-o <path>' option has always precedence, that is if specified
and stdout has been connected via a pipe then the output will go into
the specified output.
LKML-Reference: <m3ipxo966i.fsf@gmail.com>
Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/builtin-record.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 45a3689f9ed6..1346d4230bc0 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -48,7 +48,7 @@ static unsigned int user_freq = UINT_MAX; | |||
48 | static int freq = 1000; | 48 | static int freq = 1000; |
49 | static int output; | 49 | static int output; |
50 | static int pipe_output = 0; | 50 | static int pipe_output = 0; |
51 | static const char *output_name = "perf.data"; | 51 | static const char *output_name = NULL; |
52 | static int group = 0; | 52 | static int group = 0; |
53 | static int realtime_prio = 0; | 53 | static int realtime_prio = 0; |
54 | static bool nodelay = false; | 54 | static bool nodelay = false; |
@@ -497,18 +497,26 @@ static int __cmd_record(int argc, const char **argv) | |||
497 | exit(-1); | 497 | exit(-1); |
498 | } | 498 | } |
499 | 499 | ||
500 | if (!strcmp(output_name, "-")) | 500 | if (!output_name) { |
501 | pipe_output = 1; | 501 | if (!fstat(STDOUT_FILENO, &st) && S_ISFIFO(st.st_mode)) |
502 | else if (!stat(output_name, &st) && st.st_size) { | 502 | pipe_output = 1; |
503 | if (write_mode == WRITE_FORCE) { | 503 | else |
504 | char oldname[PATH_MAX]; | 504 | output_name = "perf.data"; |
505 | snprintf(oldname, sizeof(oldname), "%s.old", | 505 | } |
506 | output_name); | 506 | if (output_name) { |
507 | unlink(oldname); | 507 | if (!strcmp(output_name, "-")) |
508 | rename(output_name, oldname); | 508 | pipe_output = 1; |
509 | else if (!stat(output_name, &st) && st.st_size) { | ||
510 | if (write_mode == WRITE_FORCE) { | ||
511 | char oldname[PATH_MAX]; | ||
512 | snprintf(oldname, sizeof(oldname), "%s.old", | ||
513 | output_name); | ||
514 | unlink(oldname); | ||
515 | rename(output_name, oldname); | ||
516 | } | ||
517 | } else if (write_mode == WRITE_APPEND) { | ||
518 | write_mode = WRITE_FORCE; | ||
509 | } | 519 | } |
510 | } else if (write_mode == WRITE_APPEND) { | ||
511 | write_mode = WRITE_FORCE; | ||
512 | } | 520 | } |
513 | 521 | ||
514 | flags = O_CREAT|O_RDWR; | 522 | flags = O_CREAT|O_RDWR; |