提交 d7065adb 编写于 作者: F Franck Bui-Huu 提交者: Arnaldo Carvalho de Melo

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: NFranck Bui-Huu <fbuihuu@gmail.com>
Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 e80711ca
...@@ -48,7 +48,7 @@ static unsigned int user_freq = UINT_MAX; ...@@ -48,7 +48,7 @@ static unsigned int user_freq = UINT_MAX;
static int freq = 1000; static int freq = 1000;
static int output; static int output;
static int pipe_output = 0; static int pipe_output = 0;
static const char *output_name = "perf.data"; static const char *output_name = NULL;
static int group = 0; static int group = 0;
static int realtime_prio = 0; static int realtime_prio = 0;
static bool nodelay = false; static bool nodelay = false;
...@@ -497,18 +497,26 @@ static int __cmd_record(int argc, const char **argv) ...@@ -497,18 +497,26 @@ static int __cmd_record(int argc, const char **argv)
exit(-1); exit(-1);
} }
if (!strcmp(output_name, "-")) if (!output_name) {
pipe_output = 1; if (!fstat(STDOUT_FILENO, &st) && S_ISFIFO(st.st_mode))
else if (!stat(output_name, &st) && st.st_size) { pipe_output = 1;
if (write_mode == WRITE_FORCE) { else
char oldname[PATH_MAX]; output_name = "perf.data";
snprintf(oldname, sizeof(oldname), "%s.old", }
output_name); if (output_name) {
unlink(oldname); if (!strcmp(output_name, "-"))
rename(output_name, oldname); pipe_output = 1;
else if (!stat(output_name, &st) && st.st_size) {
if (write_mode == WRITE_FORCE) {
char oldname[PATH_MAX];
snprintf(oldname, sizeof(oldname), "%s.old",
output_name);
unlink(oldname);
rename(output_name, oldname);
}
} else if (write_mode == WRITE_APPEND) {
write_mode = WRITE_FORCE;
} }
} else if (write_mode == WRITE_APPEND) {
write_mode = WRITE_FORCE;
} }
flags = O_CREAT|O_RDWR; flags = O_CREAT|O_RDWR;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册