* [PATCH] perf stat: fix default output file
@ 2012-05-15 11:11 Stephane Eranian
2012-06-04 7:31 ` Stephane Eranian
2012-06-15 19:11 ` [tip:perf/urgent] perf stat: Fix " tip-bot for Stephane Eranian
0 siblings, 2 replies; 3+ messages in thread
From: Stephane Eranian @ 2012-05-15 11:11 UTC (permalink / raw)
To: linux-kernel; +Cc: acme, peterz, mingo, dsahern, jim.cromie
The following commit:
commit 56f3bae70638b33477a6015fd362ccfe354fd3ee
Author: Jim Cromie <jim.cromie@gmail.com>
Date: Wed Sep 7 17:14:00 2011 -0600
perf stat: Add --log-fd <N> option to redirect stderr elsewhere
introduced a bug in the way perf stat outputs the results by default, i.e.,
without the --log-fd or --output option. It would default to writing to
file descriptor 0, i.e., stdin. Writing to stdin is allowed and is equivalent
to writing to stdout. However, there is a major difference for any script that
was already capturing the output of perf stat via redirection:
perf stat >/tmp/log .... or perf stat 2>/tmp/log ....
They would not capture anything anymore. They would have to do:
perf stat 0>/tmp/log ...
This breaks compatibility with existing scripts and does not look very
natural.
This patch fixes the problem by looking at output_fd only when it
was modified by user (> 0). It also checks that the value if positive.
Passing --log-fd 0 is ignored.
I would also argue that defaulting to stderr for the results is not
the right thing to do, though this patch does not address this specific
issue.
Signed-off-by: Stephane Eranian <eranian@google.com>
---
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 36603e4..56e6040 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1179,6 +1179,12 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
fprintf(stderr, "cannot use both --output and --log-fd\n");
usage_with_options(stat_usage, options);
}
+
+ if (output_fd < 0) {
+ fprintf(stderr, "argument to --log-fd must be a > 0\n");
+ usage_with_options(stat_usage, options);
+ }
+
if (!output) {
struct timespec tm;
mode = append_file ? "a" : "w";
@@ -1190,7 +1196,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
}
clock_gettime(CLOCK_REALTIME, &tm);
fprintf(output, "# started on %s\n", ctime(&tm.tv_sec));
- } else if (output_fd != 2) {
+ } else if (output_fd > 0) {
mode = append_file ? "a" : "w";
output = fdopen(output_fd, mode);
if (!output) {
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] perf stat: fix default output file
2012-05-15 11:11 [PATCH] perf stat: fix default output file Stephane Eranian
@ 2012-06-04 7:31 ` Stephane Eranian
2012-06-15 19:11 ` [tip:perf/urgent] perf stat: Fix " tip-bot for Stephane Eranian
1 sibling, 0 replies; 3+ messages in thread
From: Stephane Eranian @ 2012-06-04 7:31 UTC (permalink / raw)
To: linux-kernel; +Cc: acme, peterz, mingo, dsahern, jim.cromie
Ping?
On Tue, May 15, 2012 at 1:11 PM, Stephane Eranian <eranian@google.com> wrote:
>
> The following commit:
>
> commit 56f3bae70638b33477a6015fd362ccfe354fd3ee
> Author: Jim Cromie <jim.cromie@gmail.com>
> Date: Wed Sep 7 17:14:00 2011 -0600
>
> perf stat: Add --log-fd <N> option to redirect stderr elsewhere
>
> introduced a bug in the way perf stat outputs the results by default, i.e.,
> without the --log-fd or --output option. It would default to writing to
> file descriptor 0, i.e., stdin. Writing to stdin is allowed and is equivalent
> to writing to stdout. However, there is a major difference for any script that
> was already capturing the output of perf stat via redirection:
>
> perf stat >/tmp/log .... or perf stat 2>/tmp/log ....
>
> They would not capture anything anymore. They would have to do:
> perf stat 0>/tmp/log ...
>
> This breaks compatibility with existing scripts and does not look very
> natural.
>
> This patch fixes the problem by looking at output_fd only when it
> was modified by user (> 0). It also checks that the value if positive.
> Passing --log-fd 0 is ignored.
>
> I would also argue that defaulting to stderr for the results is not
> the right thing to do, though this patch does not address this specific
> issue.
>
> Signed-off-by: Stephane Eranian <eranian@google.com>
> ---
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 36603e4..56e6040 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -1179,6 +1179,12 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
> fprintf(stderr, "cannot use both --output and --log-fd\n");
> usage_with_options(stat_usage, options);
> }
> +
> + if (output_fd < 0) {
> + fprintf(stderr, "argument to --log-fd must be a > 0\n");
> + usage_with_options(stat_usage, options);
> + }
> +
> if (!output) {
> struct timespec tm;
> mode = append_file ? "a" : "w";
> @@ -1190,7 +1196,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
> }
> clock_gettime(CLOCK_REALTIME, &tm);
> fprintf(output, "# started on %s\n", ctime(&tm.tv_sec));
> - } else if (output_fd != 2) {
> + } else if (output_fd > 0) {
> mode = append_file ? "a" : "w";
> output = fdopen(output_fd, mode);
> if (!output) {
^ permalink raw reply [flat|nested] 3+ messages in thread* [tip:perf/urgent] perf stat: Fix default output file
2012-05-15 11:11 [PATCH] perf stat: fix default output file Stephane Eranian
2012-06-04 7:31 ` Stephane Eranian
@ 2012-06-15 19:11 ` tip-bot for Stephane Eranian
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Stephane Eranian @ 2012-06-15 19:11 UTC (permalink / raw)
To: linux-tip-commits
Cc: acme, linux-kernel, eranian, hpa, mingo, peterz, jim.cromie,
dsahern, tglx, mingo
Commit-ID: fc3e4d077d5c7a7bc1ad5bc143895b4e070e5a8b
Gitweb: http://git.kernel.org/tip/fc3e4d077d5c7a7bc1ad5bc143895b4e070e5a8b
Author: Stephane Eranian <eranian@google.com>
AuthorDate: Tue, 15 May 2012 13:11:11 +0200
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 11 Jun 2012 11:20:21 -0300
perf stat: Fix default output file
The following commit:
commit 56f3bae70638b33477a6015fd362ccfe354fd3ee
Author: Jim Cromie <jim.cromie@gmail.com>
Date: Wed Sep 7 17:14:00 2011 -0600
perf stat: Add --log-fd <N> option to redirect stderr elsewhere
introduced a bug in the way perf stat outputs the results by default,
i.e., without the --log-fd or --output option. It would default to
writing to file descriptor 0, i.e., stdin. Writing to stdin is allowed
and is equivalent to writing to stdout. However, there is a major
difference for any script that was already capturing the output of perf
stat via redirection:
perf stat >/tmp/log .... or perf stat 2>/tmp/log ....
They would not capture anything anymore. They would have to do:
perf stat 0>/tmp/log ...
This breaks compatibility with existing scripts and does not look very
natural.
This patch fixes the problem by looking at output_fd only when it was
modified by user (> 0). It also checks that the value if positive.
Passing --log-fd 0 is ignored.
I would also argue that defaulting to stderr for the results is not the
right thing to do, though this patch does not address this specific
issue.
Signed-off-by: Stephane Eranian <eranian@google.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Jim Cromie <jim.cromie@gmail.com>
Link: http://lkml.kernel.org/r/20120515111111.GA9870@quad
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-stat.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 2625899..07b5c77 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1179,6 +1179,12 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
fprintf(stderr, "cannot use both --output and --log-fd\n");
usage_with_options(stat_usage, options);
}
+
+ if (output_fd < 0) {
+ fprintf(stderr, "argument to --log-fd must be a > 0\n");
+ usage_with_options(stat_usage, options);
+ }
+
if (!output) {
struct timespec tm;
mode = append_file ? "a" : "w";
@@ -1190,7 +1196,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
}
clock_gettime(CLOCK_REALTIME, &tm);
fprintf(output, "# started on %s\n", ctime(&tm.tv_sec));
- } else if (output_fd != 2) {
+ } else if (output_fd > 0) {
mode = append_file ? "a" : "w";
output = fdopen(output_fd, mode);
if (!output) {
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-06-15 19:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-15 11:11 [PATCH] perf stat: fix default output file Stephane Eranian
2012-06-04 7:31 ` Stephane Eranian
2012-06-15 19:11 ` [tip:perf/urgent] perf stat: Fix " tip-bot for Stephane Eranian
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.