Index: src/log-utils.h |
diff --git a/src/log-utils.h b/src/log-utils.h |
index 2e8b3a36478d7681c12a032f5b603a0bd134ff9e..73ed7cf4aba1758733a3ead609aca3b698ae0260 100644 |
--- a/src/log-utils.h |
+++ b/src/log-utils.h |
@@ -88,6 +88,45 @@ class LogDynamicBuffer { |
}; |
+// An utility class for performing backward reference compression |
+// of string ends. It operates using a window of previous strings. |
+class LogRecordCompressor { |
+ public: |
+ explicit LogRecordCompressor(int window_size_) |
+ : buffer_(window_size_), curr_(-1), prev_(-1) { |
+ // Must have place for the current record and the previous. |
+ ASSERT(window_size_ >= 2); |
+ } |
+ ~LogRecordCompressor(); |
+ |
+ // Fills vector with a compressed version of the previous record. |
+ // Returns false if there is no previous record. |
+ bool RetrievePreviousCompressed(Vector<char>* prev_record); |
+ |
+ // Stores a record if it differs from a previous one (or there's no previous). |
+ // Returns true, if the record has been stored. |
+ bool Store(const Vector<const char>& record); |
+ |
+ private: |
+ // Record field separator. It is assumed that it can't appear |
+ // inside a field (a simplified version of CSV format). |
+ static const char kFieldSeparator = ','; |
+ |
+ // Formatting string for back references. |
+ static const char* kBackwardReferenceFormat; |
+ |
+ // A boundary value. If current record only differs in |
+ // kUncompressibleBound chars, don't compress it. |
+ // The value must be greater than the length of maximum |
+ // projected backward reference length. |
+ static const intptr_t kUncompressibleBound = 10; |
+ |
+ ScopedVector< Vector<const char> > buffer_; |
+ int curr_; |
+ int prev_; |
+}; |
+ |
+ |
// Functions and data for performing output of log messages. |
class Log : public AllStatic { |
public: |
@@ -169,6 +208,12 @@ class Log : public AllStatic { |
// mutex_ should be acquired before using it. |
static char* message_buffer_; |
+ // Size of buffer used for record compression. |
+ static const int kRecordCompressorWindow = 6; |
+ |
+ // An utility object for compressing repeated parts of records. |
+ static LogRecordCompressor* record_compressor_; |
+ |
friend class LogMessageBuilder; |
}; |
@@ -196,6 +241,19 @@ class LogMessageBuilder BASE_EMBEDDED { |
void AppendDetailed(String* str, bool show_impl_info); |
+ // Stores log message into compressor, returns true if the message |
+ // was stored (i.e. doesn't repeat the previous one). If log compression is |
+ // disabled, does nothing and returns true. |
+ bool StoreInCompressor(); |
+ |
+ // Sets log message to a previous version of compressed message. |
+ // Returns false, if there is no previous message. If log compression |
+ // is disabled, does nothing and retuns true. |
+ bool RetrieveCompressedPrevious() { return RetrieveCompressedPrevious(""); } |
+ |
+ // Does the same at the version without arguments, and sets a prefix. |
+ bool RetrieveCompressedPrevious(const char* prefix); |
+ |
// Write the log message to the log file currently opened. |
void WriteToLogFile(); |