Re: [PATCH 1/2] perf stat: add -l <N> option to redirect stderr elsewhere

From: Jim Cromie
Date: Fri Sep 02 2011 - 14:04:36 EST


On Fri, Sep 2, 2011 at 8:35 AM, Arnaldo Carvalho de Melo
<acme@xxxxxxxxxxxxxxxxxx> wrote:
> Em Thu, Sep 01, 2011 at 03:58:13PM -0600, Jim Cromie escreveu:
>> On Sat, May 21, 2011 at 2:41 PM, Arnaldo Carvalho de Melo
>> <acme@xxxxxxxxxxxxxxxxxx> wrote:
>> > Em Sat, May 21, 2011 at 12:34:18PM +0200, Ingo Molnar escreveu:
>> >> * Jim Cromie <jim.cromie@xxxxxxxxx> wrote:
>> >>
>> >> > This perf stat option emulates valgrind's --log-fd option, allowing the
>> >> > user to send perf results elsewhere, and leaving stderr for use by the
>> >> > program under test.
>> >> >
>> >> >   3>results perf stat -l 3 -- <cmd>
>> >> >
>> >> > The perl distro's make test.valgrind target uses valgrinds --log-fd
>> >> > option, I've adapted it to invoke perf also, and tested this patch there.
>> >> >
>> >> > Signed-off-by: Jim Cromie <jim.cromie@xxxxxxxxx>
>> >>
>> >> Makes sense!
>> >>
>> >> Arnaldo, if you are fine with it, do you want to pick it up - or should i? If
>> >> you pick it up:
>> >>
>> >> Acked-by: Ingo Molnar <mingo@xxxxxxx>
>> >
>> > Its ok with me:
>> >
>> > Acked-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
>> >
>> > I will pick it this weekend, if you don't merge it till then.
>
>> Did this ever happen ?
>> Can you point me to the git-url where it did/will end up ?
>
> Fell thru the cracks, then Stephane implemented --output:
>
> http://git.kernel.org/?p=linux/kernel/git/tip/linux-tip.git;a=commitdiff;h=4aa9015f8bfd2c8d7cc33a360275b71a9d708b37
>
> That introduces an output FILE pointer as in your patch (logfp), so I
> adjusted your patch, that ended up like below. I removed -l and made it
> --log-fd, just like valgrind and added the Documentation bits about the
> new cmdline option, ok?
>

absolutely.
theres one comment I added (just above output_fd decl)
that mentions -I, it should be updated to --log-fd

And probably --output and --log-fd should be mutually exclusive.

> I'll look at the other 3 patch series that came after, will fix up and
> post here for your consideration.

those are the output format refactoring ?

ah, your new message just arrived.
I'll take another go at them..
thanks

>
> - Arnaldo
>
> diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
> index 08394c4..b6bfd1e 100644
> --- a/tools/perf/Documentation/perf-stat.txt
> +++ b/tools/perf/Documentation/perf-stat.txt
> @@ -101,6 +101,9 @@ Print the output into the designated file.
>  --append::
>  Append to the output file designated with the -o option. Ignored if -o is not specified.
>
> +--log-fd::
> +Log output to fd, instead of stderr.

stderr / outputfile ??

> +
>  EXAMPLES
>  --------
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index bec64a9..c991d66 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -196,6 +196,8 @@ static bool                 csv_output                      = false;
>  static bool                    group                           = false;
>  static const char              *output_name                    = NULL;
>  static FILE                    *output                         = NULL;
> +/* stderr by default, override with -l */

with --log-fd

> +static int                     output_fd                       = 2;
>
>  static volatile int done = 0;
>
> @@ -1080,6 +1082,8 @@ static const struct option options[] = {
>        OPT_STRING('o', "output", &output_name, "file",
>                    "output file name"),
>        OPT_BOOLEAN(0, "append", &append_file, "append to the output file"),
> +       OPT_INTEGER(0, "log-fd", &output_fd,
> +                   "log output to fd, instead of stderr"),
>        OPT_END()
>  };
>
> @@ -1177,6 +1181,12 @@ 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) {
> +               output = fdopen(output_fd, "w");
> +               if (!output) {
> +                       perror("Failed opening logfd");
> +                       return -errno;
> +               }
>        }
>
>        if (csv_sep)
>
--
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/