[Lldb-commits] [PATCH] D127986: [lldb] Support a buffered logging mode

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 16 13:58:39 PDT 2022


JDevlieghere added a comment.

In D127986#3590157 <https://reviews.llvm.org/D127986#3590157>, @clayborg wrote:

> The main questions is if we want --buffered for any log channel (file, callback, or circular). If we add a --circular flag, then we just let things accumulate in the LogHandler class.

That's wasn't a problem I was trying to solve personally, but if you think that would be useful I don't mind supporting it.

> The idea would be to add more stuff to the LogHandler base class to support this:

I don't think this has to (or even should) go into the base class. The idea behind the different handlers was to serve as an extension point. I think general buffering is a perfect example of that. The way I would implement that is by wrapping it into its own handler (e.g. `BufferedLogHandler`) which wraps around another Handler. The delegate handler can then be any of the existing handlers. The implementation would be pretty similar to what you described:

  class BufferedLogHandler : public LogHandler {
  public:
    void Emit(StringRef message) {
    if (m_buffer_size > 0) {
      if (m_buffer.size() + message.size() > m_buffer_size) {
        // If we exceed the buffer size, flush.
        m_delegate.Emit(m_buffer);
        m_delegate.DoEmit(message);
        m_buffer.clear();
      } else {
        // Buffer size not exceeded yet.
        m_buffer += message.str();
      }
    } else {
      DoEmit(message); 
    }
  }
  
  private:
    size_t m_buffer_size = 0;
    std::string m_buffer; 
    LogHandler m_delegate;
  };




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127986/new/

https://reviews.llvm.org/D127986



More information about the lldb-commits mailing list