From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bilemail2.empirix.com (bilemail2.empirix.com [208.67.76.246]) by dpdk.org (Postfix) with ESMTP id 89F062C58 for ; Wed, 5 Oct 2016 15:26:32 +0200 (CEST) Received: from BILEMAIL1.empirix.com (10.17.8.30) by bilemail2.empirix.com (10.17.8.31) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Wed, 5 Oct 2016 09:26:31 -0400 Received: from BILEMAIL1.empirix.com ([fe80::f9e0:9293:2523:f021]) by bilemail1.empirix.com ([fe80::f9e0:9293:2523:f021%22]) with mapi id 15.00.1178.000; Wed, 5 Oct 2016 09:26:31 -0400 From: "Montorsi, Francesco" To: Olivier Matz , "dev@dpdk.org" Thread-Topic: [dpdk-dev] Proposal: enable redirection of DPDK logs from the user app Thread-Index: AdIeKK66V/qdjvS8QiaE91re7uFfpgAKvhEAAAaSYsAALYweAAAGUQ3Q Date: Wed, 5 Oct 2016 13:26:30 +0000 Message-ID: <348c536dca594a3fbd38137e2a5a29aa@bilemail1.empirix.com> References: <32054c5dd466431ebf99d84641c6313a@bilemail1.empirix.com> <4b3ed268f2584b4aaf251ba39f8c90bf@bilemail1.empirix.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.12.50.52] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] Proposal: enable redirection of DPDK logs from the user app X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Oct 2016 13:26:32 -0000 Hi Olivier, > On 10/04/2016 02:28 PM, Montorsi, Francesco wrote: > > Yes, but to be honest, that seems a troublesome solution for something > > as easy as logging a string; e.g. by using fopencookie() approach, you > > don't have the concept of "log message", you just provide a function > > that must write a block of bytes somewhere. > > Typically instead, you need to know where a log message starts and > > ends, to e.g., add prefixes/postfixes to it. >=20 > I'm not sure that true if you call setbuf(log_stream, NULL). >=20 > In that case, it looks easy to prefix / postfix messages with a fopencook= ie > callback like: >=20 > /* example on stdout */ > ssize_t > simple_write(void *c, const char *buf, size_t size) { > ssize_t ret1, ret2, ret3; >=20 > ret1 =3D fwrite("<", 1, 1, stdout); > if (ret1 =3D=3D 0) > return 0; > ret2 =3D fwrite(buf, size, 1, stdout); > if (ret2 =3D=3D 0) > return 0; > ret3 =3D fwrite(">", 1, 1, stdout); > if (ret3 =3D=3D 0) > return 0; > return ret1 + ret2 + ret3; > } >=20 I didn't know about setbuf()... but are we sure that in this way the simple= _write() function will always receive a full string? I mean: in the manpage= for setbuf() it says: "... When the first I/O operation occurs on a file, malloc(3) is called, an= d a buffer is obtained. .... If the argument buf is NULL, only the mode is = affected; a new buffer will be allocated on the next read or write operatio= n." But: is it true that 1 write operation corresponds to 1 vfprintf() call? Ma= ybe if you have a "long" a single vfprintf() call may translate to several = simple_write() calls... I don't know honestly. > > Indeed, most of the C/C++ (open source) libraries have some simple > > hook that allows the user to have more control on logging... I think > > DPDK should be no exception... :) >=20 > I understand that the current API is a bit more complex, but I don't feel= there > is any blocking issue to do what you want. What do you think? See above. Moreover, IMHO it would be much more user-friendly to have a sim= ple function callback to implement vs having to dig into fopencookie()+setb= uf()+etc etc .=20 > Also, I know you've said your patch needs some rework, but as you've also > said you are using it, maybe it would be useful for you to know: > - it makes use of a global variable 'log_buffer', shared by all the pthre= ads, > which can lead to crashes That's a good point. I will turn it into a __thread variable. Thanks for po= inting out this. > - it strips the log messages to 4095 chars Correct, but in my experience DPDK never creates such a long line of log me= ssage...=20 Francesco