[LLVMdev] [PATCH] Circular Buffered Debug Stream
David Greene
dag at cray.com
Mon Dec 21 12:20:14 PST 2009
On Monday 21 December 2009 13:40, Chris Lattner wrote:
> >> Now that I understand the model :) I don't see why you need to fiddle
> >> with the underlying buffering of TheStream. In the dbgs() use case,
> >> the underlying stream will be errs() which is already unbuffered.
> >
> > Might circular_raw_ostream be used with other streams at some point?
>
> In that case, setting the underlying stream to unbuffered seems even more
> dangerous. The client who sets up the buffers has both the power and the
> knowledge to set the streams up correctly when the streams are created.
Fair enough. I'll make the change. I was simply following what we did
for formatted_raw_ostream. It seems a bit wasteful to do buffering on
both streams.
> > + /// flushBuffer - Dump the contents of the buffer to Stream.
> > + ///
> > + void flushBuffer(void) {
> > + // Write the older portion of the buffer.
> > + TheStream->write(Cur, BufferArray + BufferSize - Cur);
> > + // Write the newer portion of the buffer.
> > + TheStream->write(BufferArray, Cur - BufferArray);
> > + Cur = BufferArray;
> > + }
>
> Is this correct in the case when the circular buffer hasn't completely
> filled yet?
Hmm...Depends on what's "correct." :) You'll get a bunch of garbage
output but I don't think it should fault or anything. I don't think
there's a way of knowing whether the buffer got filled all the way to
the end unless we add another member variable. In practice, it will
almost always be filled.
> > +void circular_raw_ostream::flushBufferWithBanner(void) {
> > + if (BufferSize != 0) {
> > + // Write out the buffer
> > + const char *msg = "*** Log Output ***\n";
>
> This is not generic. If you really want something like this, the string to
> print should be provided to the ctor.
Ok.
Attached an updated patch.
-Dave
-------------- next part --------------
A non-text attachment was scrubbed...
Name: circular_raw_ostream.patch
Type: text/x-diff
Size: 6986 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091221/3d60c638/attachment.patch>
More information about the llvm-dev
mailing list