Re: [PATCH] perf stat: fix default output file

From: Stephane Eranian
Date: Mon Jun 04 2012 - 03:31:19 EST


Ping?

On Tue, May 15, 2012 at 1:11 PM, Stephane Eranian <eranian@xxxxxxxxxx> wrote:
>
> The following commit:
>
> commit 56f3bae70638b33477a6015fd362ccfe354fd3ee
> Author: Jim Cromie <jim.cromie@xxxxxxxxx>
> 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@xxxxxxxxxx>
> ---
>
> 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) {
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/