On Tue, Apr 08, 2008 at 09:57:42PM -0500, Dean Luick wrote:
> On Wed, Apr 09, 2008 at 10:52:05AM +1000, David Gibson wrote:
> > On Tue, Apr 08, 2008 at 02:16:11PM -0500, Dean Luick wrote:
> > > When running on multiple hosts with output coalesced, it is useful to
> > > be able to isolate messages from individual processes.  This patch adds
> > > the ability to add the string "[hostname:pid] " to all messages emitted
> > > by libhugetlbfs.  Display this additional information by setting the
> > > environment variable HUGETLB_VERBOSE_ID to anything but "no".
> > > 
> > > This change uses a GNU extension of CPP that will eat a preceeding
> > > comma when using ##__VA_ARGS__ and __VA_ARGS__ is empty.
> > 
> > [snip]
> > >  static int initialized;
> > > +static char hostname[64];
> > > +
> > > +char *__hugetlbfs_host_info(char *buf, int size)
> > > +{
> > > + if (hostname[0] == 0)   /* empty -- not set */
> > > +         return "";
> > > +
> > > + snprintf(buf, size, "[%s:%d] ", hostname, getpid());
> > > + buf[size-1] = 0;        /* make sure it is null terminated */
> > > + return buf;
> > > +}
> > 
> > Marshalling the prefix into a string buffer like this before printing
> > it is ugly and unnecessary.  Just printf() the hostname and pid
> > directly to the log stream.
> 
> Are you suggesting that each line be compromised of possibly two
> prints?  The optinal header, then the "regular" line?
> 
> If so, then that won't work.  That was the first thing I tried.
> The marshalling is necessary to prevent the two prints from mixing
> with other parallel prints.  The whole message must be printed using
> one print.  E.g.  If using two printfs, instead of this:
> 
>       [hostname1:pid1] message 1
>       [hostname2:pid2] message 2
> 
> You sometimes get:
> 
>       [hostname1:pid1][hostname2:pid2]
>       message 1
>       message 2
> 
> It gets a lot worse with more hosts and processes.
> 
> Obviously, this depends a lot on how the stderr output of each of
> the processes is merged.  I can conceive of some smart merge that
> examines each input stream and holds until it sees a newline.
> However, I have yet to see one that works that way.  At least here :-(.

Ugh.  I did think about concurrency, but not hard enough.  I thought
stdio buffering would save us, but of course buffering is typically
turned off for stderr.  Although even with the one fprintf(), I don't
believe it's guaranteed that the write will be atomic, it probably
will be in practice though.

But... there's no reason using one fprintf() requires you to
marshal it this way.  You can just do:

        fprintf("libhugetlbfs [%s:%d]: " fmt, hostname, getpid(), \
                ##__VA_ARGS__)

I'd prefer that the the "libhugetlbfs" string comes first, too -
that's important if messages from the library are interspersed with
error output from the program itself.

I don't think the HUGETLB_VERBOSE_ID option is particularly useful.
Just include the extra information always.

-- 
David Gibson                    | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
                                | _way_ _around_!
http://www.ozlabs.org/~dgibson

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to