* [PATCH] perf-record: auto detect when stdout is a pipe
@ 2011-01-16 16:14 Franck Bui-Huu
2011-01-17 17:27 ` Arnaldo Carvalho de Melo
2011-01-26 7:23 ` [tip:perf/core] perf record: " tip-bot for Franck Bui-Huu
0 siblings, 2 replies; 4+ messages in thread
From: Franck Bui-Huu @ 2011-01-16 16:14 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo; +Cc: linux-kernel
From: Franck Bui-Huu <fbuihuu@gmail.com>
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.
Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
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 7069bd3..4f86354 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -46,7 +46,7 @@ static unsigned int user_freq = UINT_MAX;
static int freq = 1000;
static int output;
static int pipe_output = 0;
-static const char *output_name = "perf.data";
+static const char *output_name = NULL;
static int group = 0;
static int realtime_prio = 0;
static bool raw_samples = false;
@@ -562,18 +562,26 @@ static int __cmd_record(int argc, const char **argv)
exit(-1);
}
- if (!strcmp(output_name, "-"))
- 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);
+ if (!output_name) {
+ if (!fstat(STDOUT_FILENO, &st) && S_ISFIFO(st.st_mode))
+ pipe_output = 1;
+ else
+ output_name = "perf.data";
+ }
+ if (output_name) {
+ if (!strcmp(output_name, "-"))
+ 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;
--
1.7.3.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] perf-record: auto detect when stdout is a pipe
2011-01-16 16:14 [PATCH] perf-record: auto detect when stdout is a pipe Franck Bui-Huu
@ 2011-01-17 17:27 ` Arnaldo Carvalho de Melo
2011-01-17 18:16 ` Franck Bui-Huu
2011-01-26 7:23 ` [tip:perf/core] perf record: " tip-bot for Franck Bui-Huu
1 sibling, 1 reply; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2011-01-17 17:27 UTC (permalink / raw)
To: Franck Bui-Huu; +Cc: linux-kernel
Em Sun, Jan 16, 2011 at 05:14:45PM +0100, Franck Bui-Huu escreveu:
> From: Franck Bui-Huu <fbuihuu@gmail.com>
>
> 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.
>
I guess we could have that in perf report as well? I.e. if stdin is a
FIFO...
Thanks, applied,
- Arnaldo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf-record: auto detect when stdout is a pipe
2011-01-17 17:27 ` Arnaldo Carvalho de Melo
@ 2011-01-17 18:16 ` Franck Bui-Huu
0 siblings, 0 replies; 4+ messages in thread
From: Franck Bui-Huu @ 2011-01-17 18:16 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo; +Cc: linux-kernel
On 01/17/2011 06:27 PM, Arnaldo Carvalho de Melo wrote:
> Em Sun, Jan 16, 2011 at 05:14:45PM +0100, Franck Bui-Huu escreveu:
>> From: Franck Bui-Huu <fbuihuu@gmail.com>
>>
>> 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.
>>
>
> I guess we could have that in perf report as well? I.e. if stdin is a
> FIFO...
>
Yes, I noticed that too, perf-script is also a candidate.
I'll do.
Franck
^ permalink raw reply [flat|nested] 4+ messages in thread
* [tip:perf/core] perf record: auto detect when stdout is a pipe
2011-01-16 16:14 [PATCH] perf-record: auto detect when stdout is a pipe Franck Bui-Huu
2011-01-17 17:27 ` Arnaldo Carvalho de Melo
@ 2011-01-26 7:23 ` tip-bot for Franck Bui-Huu
1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Franck Bui-Huu @ 2011-01-26 7:23 UTC (permalink / raw)
To: linux-tip-commits; +Cc: acme, linux-kernel, hpa, mingo, fbuihuu, tglx
Commit-ID: d7065adb9b4f3384c2615f0a3dbdb6c3aae1eb18
Gitweb: http://git.kernel.org/tip/d7065adb9b4f3384c2615f0a3dbdb6c3aae1eb18
Author: Franck Bui-Huu <fbuihuu@gmail.com>
AuthorDate: Sun, 16 Jan 2011 17:14:45 +0100
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 24 Jan 2011 10:58:27 -0200
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>
---
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 45a3689..1346d42 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -48,7 +48,7 @@ static unsigned int user_freq = UINT_MAX;
static int freq = 1000;
static int output;
static int pipe_output = 0;
-static const char *output_name = "perf.data";
+static const char *output_name = NULL;
static int group = 0;
static int realtime_prio = 0;
static bool nodelay = false;
@@ -497,18 +497,26 @@ static int __cmd_record(int argc, const char **argv)
exit(-1);
}
- if (!strcmp(output_name, "-"))
- 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);
+ if (!output_name) {
+ if (!fstat(STDOUT_FILENO, &st) && S_ISFIFO(st.st_mode))
+ pipe_output = 1;
+ else
+ output_name = "perf.data";
+ }
+ if (output_name) {
+ if (!strcmp(output_name, "-"))
+ 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;
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-01-26 7:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-16 16:14 [PATCH] perf-record: auto detect when stdout is a pipe Franck Bui-Huu
2011-01-17 17:27 ` Arnaldo Carvalho de Melo
2011-01-17 18:16 ` Franck Bui-Huu
2011-01-26 7:23 ` [tip:perf/core] perf record: " tip-bot for Franck Bui-Huu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.