]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf bench: Use unbuffered output when pipe/tee'ing to a file
authorSohaib Mohamed <sohaib.amhmd@gmail.com>
Fri, 19 Nov 2021 06:14:08 +0000 (08:14 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 16 Dec 2021 15:18:11 +0000 (12:18 -0300)
The output of 'perf bench' gets buffered when I pipe it to a file or to
tee, in such a way that I can see it only at the end.

E.g.

  $ perf bench internals synthesize -t
  < output comes out fine after each test run >

  $ perf bench internals synthesize -t | tee file.txt
  < output comes out only at the end of all tests >

This patch resolves this issue for 'bench' and 'test' subcommands.

See, also:

  $ perf bench mem all | tee file.txt
  $ perf bench sched all | tee file.txt
  $ perf bench internals all -t | tee file.txt
  $ perf bench internals all | tee file.txt

Committer testing:

It really gets staggered, i.e. outputs in bursts, when the buffer fills
up and has to be drained to make up space for more output.

Suggested-by: Riccardo Mancini <rickyman7@gmail.com>
Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Ian Rogers <irogers@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20211119061409.78004-1-sohaib.amhmd@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-bench.c
tools/perf/tests/builtin-test.c

index d0895162c2ba6411539f2a411ba77d528756f21e..d291f3a8af5f290ffcb9aa7d4afdd54ce2f7be93 100644 (file)
@@ -226,7 +226,6 @@ static void run_collection(struct collection *coll)
                if (!bench->fn)
                        break;
                printf("# Running %s/%s benchmark...\n", coll->name, bench->name);
-               fflush(stdout);
 
                argv[1] = bench->name;
                run_bench(coll->name, bench->name, bench->fn, 1, argv);
@@ -247,6 +246,9 @@ int cmd_bench(int argc, const char **argv)
        struct collection *coll;
        int ret = 0;
 
+       /* Unbuffered output */
+       setvbuf(stdout, NULL, _IONBF, 0);
+
        if (argc < 2) {
                /* No collection specified. */
                print_usage();
@@ -300,7 +302,6 @@ int cmd_bench(int argc, const char **argv)
 
                        if (bench_format == BENCH_FORMAT_DEFAULT)
                                printf("# Running '%s/%s' benchmark:\n", coll->name, bench->name);
-                       fflush(stdout);
                        ret = run_bench(coll->name, bench->name, bench->fn, argc-1, argv+1);
                        goto end;
                }
index f1e6d2a3a578651cd893ec53ff0a93d255580fe4..1fb9f2a11d63999b7b3dead866c2cc5c6bdd0cad 100644 (file)
@@ -607,6 +607,9 @@ int cmd_test(int argc, const char **argv)
         if (ret < 0)
                 return ret;
 
+       /* Unbuffered output */
+       setvbuf(stdout, NULL, _IONBF, 0);
+
        argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0);
        if (argc >= 1 && !strcmp(argv[0], "list"))
                return perf_test__list(argc - 1, argv + 1);