[3/9] perf stat: Clear screen only if output file is a tty

Message ID 20221107213314.3239159-4-namhyung@kernel.org
State New
Headers
Series perf stat: Cleanup perf stat output display (v1) |

Commit Message

Namhyung Kim Nov. 7, 2022, 9:33 p.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.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/stat-display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Ian Rogers Nov. 8, 2022, 11:16 p.m. UTC | #1
On Mon, Nov 7, 2022 at 1:33 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.

Would it be more intuitive to warn if interval-clear is specified with a file?

Thanks,
Ian

> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/util/stat-display.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
> index 17d656566cd9..d4936a502560 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
> @@ -892,7 +892,7 @@ static void print_interval(struct perf_stat_config *config,
>         FILE *output = config->output;
>         static int num_print_interval;
>
> -       if (config->interval_clear)
> +       if (config->interval_clear && isatty(fileno(output)))
>                 puts(CONSOLE_CLEAR);
>
>         if (!config->iostat_run && !config->json_output)
> --
> 2.38.1.431.g37b22c650d-goog
>
  
Namhyung Kim Nov. 9, 2022, 6:02 p.m. UTC | #2
Hi Ian,

On Tue, Nov 8, 2022 at 3:16 PM Ian Rogers <irogers@google.com> wrote:
>
> On Mon, Nov 7, 2022 at 1:33 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.
>
> Would it be more intuitive to warn if interval-clear is specified with a file?

Makes sense, will change.

Thanks,
Namhyung
  

Patch

diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index 17d656566cd9..d4936a502560 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -892,7 +892,7 @@  static void print_interval(struct perf_stat_config *config,
 	FILE *output = config->output;
 	static int num_print_interval;
 
-	if (config->interval_clear)
+	if (config->interval_clear && isatty(fileno(output)))
 		puts(CONSOLE_CLEAR);
 
 	if (!config->iostat_run && !config->json_output)