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 :-(.

What I sent was best compromise that I could come up with.


Dean

Dean Luick
Cray Inc.

-------------------------------------------------------------------------
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