lkml.org 
[lkml]   [2021]   [Dec]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRE: [PATCH v2] Unbuffered output when pipe/tee to a file
    Date
    From: Arnaldo Carvalho de Melo
    > Sent: 09 December 2021 18:51
    ...
    > > diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
    > > index 8cb5a1c3489e..d92ae4efd2e6 100644
    > > --- a/tools/perf/tests/builtin-test.c
    > > +++ b/tools/perf/tests/builtin-test.c
    > > @@ -606,6 +606,9 @@ int cmd_test(int argc, const char **argv)
    > > if (ret < 0)
    > > return ret;
    > >
    > > + /* Unbuffered output */
    > > + setvbuf(stdout, NULL, _IONBF, 0);
    > > +

    You only want _IOLBF (line buffered).

    Otherwise you are likely to get a lot of write() system calls.
    Even multiple ones from the same printf().

    Although it can be better just to ensure there is a fflush(stdout)
    inside the loop.

    David

    -
    Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
    Registration No: 1397386 (Wales)

    \
     
     \ /
      Last update: 2021-12-11 18:11    [W:4.720 / U:0.012 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site