[05/11] perf stat: Clear screen only if output file is a tty

Message ID 20221112032244.1077370-6-namhyung@kernel.org
State New
Headers
Series perf stat: Cleanup perf stat output display (v2) |

Commit Message

Namhyung Kim Nov. 12, 2022, 3:22 a.m. UTC
  The --interval-clear option makes perf stat to clear the terminal at
each interval.  But it doesn't need to clear the screen when it saves
to a file.  Make it fail when it's enabled with the output options.

  $ perf stat -I 1 --interval-clear -o myfile true
  --interval-clear does not work with output

   Usage: perf stat [<options>] [<command>]

      -o, --output <file>   output file name
          --log-fd <n>      log output to fd, instead of stderr
          --interval-clear  clear screen in between new interval

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/builtin-stat.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Ian Rogers Nov. 14, 2022, 6:19 p.m. UTC | #1
On Fri, Nov 11, 2022 at 7:22 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> The --interval-clear option makes perf stat to clear the terminal at
> each interval.  But it doesn't need to clear the screen when it saves
> to a file.  Make it fail when it's enabled with the output options.
>
>   $ perf stat -I 1 --interval-clear -o myfile true
>   --interval-clear does not work with output
>
>    Usage: perf stat [<options>] [<command>]
>
>       -o, --output <file>   output file name
>           --log-fd <n>      log output to fd, instead of stderr
>           --interval-clear  clear screen in between new interval
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/builtin-stat.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index d5e1670bca20..1d79801f4e84 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -2403,6 +2403,14 @@ int cmd_stat(int argc, const char **argv)
>                 }
>         }
>
> +       if (stat_config.interval_clear && !isatty(fileno(output))) {
> +               fprintf(stderr, "--interval-clear does not work with output\n");
> +               parse_options_usage(stat_usage, stat_options, "o", 1);
> +               parse_options_usage(NULL, stat_options, "log-fd", 0);
> +               parse_options_usage(NULL, stat_options, "interval-clear", 0);
> +               return -1;
> +       }
> +
>         stat_config.output = output;
>
>         /*
> --
> 2.38.1.493.g58b659f92b-goog
>
  

Patch

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index d5e1670bca20..1d79801f4e84 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2403,6 +2403,14 @@  int cmd_stat(int argc, const char **argv)
 		}
 	}
 
+	if (stat_config.interval_clear && !isatty(fileno(output))) {
+		fprintf(stderr, "--interval-clear does not work with output\n");
+		parse_options_usage(stat_usage, stat_options, "o", 1);
+		parse_options_usage(NULL, stat_options, "log-fd", 0);
+		parse_options_usage(NULL, stat_options, "interval-clear", 0);
+		return -1;
+	}
+
 	stat_config.output = output;
 
 	/*