Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Unified Diff: src/log-utils.h

Issue 5862002: Version 3.0.2. (Closed)
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ChangeLog ('K') | « src/log.cc ('k') | src/log-utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/log-utils.h
diff --git a/src/log-utils.h b/src/log-utils.h
index 719d37030e12d85ae521792f793973a2a489d45f..ffea9282cbac225499b2c8fb186b4c6a00f73639 100644
--- a/src/log-utils.h
+++ b/src/log-utils.h
@@ -176,6 +176,50 @@ class Log : public AllStatic {
friend class Logger;
friend class LogMessageBuilder;
+ friend class LogRecordCompressor;
+};
+
+
+// An utility class for performing backward reference compression
+// of string ends. It operates using a window of previous strings.
+class LogRecordCompressor {
+ public:
+ // 'window_size' is the size of backward lookup window.
+ explicit LogRecordCompressor(int window_size)
+ : buffer_(window_size + kNoCompressionWindowSize),
+ kMaxBackwardReferenceSize(
+ GetBackwardReferenceSize(window_size, Log::kMessageBufferSize)),
+ curr_(-1), prev_(-1) {
+ }
+
+ ~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:
+ // The minimum size of a buffer: a place needed for the current and
+ // the previous record. Since there is no place for precedessors of a previous
+ // record, it can't be compressed at all.
+ static const int kNoCompressionWindowSize = 2;
+
+ // Formatting strings for back references.
+ static const char* kLineBackwardReferenceFormat;
+ static const char* kBackwardReferenceFormat;
+
+ static int GetBackwardReferenceSize(int distance, int pos);
+
+ static void PrintBackwardReference(Vector<char> dest, int distance, int pos);
+
+ ScopedVector< Vector<const char> > buffer_;
+ const int kMaxBackwardReferenceSize;
+ int curr_;
+ int prev_;
};
@@ -200,14 +244,32 @@ class LogMessageBuilder BASE_EMBEDDED {
// Append a heap string.
void Append(String* str);
- // Appends an address.
+ // Appends an address, compressing it if needed by offsetting
+ // from Logger::last_address_.
void AppendAddress(Address addr);
+ // Appends an address, compressing it if needed.
+ void AppendAddress(Address addr, Address bias);
+
void AppendDetailed(String* str, bool show_impl_info);
// Append a portion of a string.
void AppendStringPart(const char* str, int len);
+ // Stores log message into compressor, returns true if the message
+ // was stored (i.e. doesn't repeat the previous one).
+ bool StoreInCompressor(LogRecordCompressor* compressor);
+
+ // Sets log message to a previous version of compressed message.
+ // Returns false, if there is no previous message.
+ bool RetrieveCompressedPrevious(LogRecordCompressor* compressor) {
+ return RetrieveCompressedPrevious(compressor, "");
+ }
+
+ // Does the same at the version without arguments, and sets a prefix.
+ bool RetrieveCompressedPrevious(LogRecordCompressor* compressor,
+ const char* prefix);
+
// Write the log message to the log file currently opened.
void WriteToLogFile();
« ChangeLog ('K') | « src/log.cc ('k') | src/log-utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698