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

Side by Side Diff: src/log-utils.h

Issue 125114: Involve more log compression techniques. (Closed)
Patch Set: Created 11 years, 6 months 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 unified diff | Download patch
« no previous file with comments | « src/log.cc ('k') | src/log-utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const char* seal_; 81 const char* seal_;
82 const int seal_size_; 82 const int seal_size_;
83 ScopedVector<char*> blocks_; 83 ScopedVector<char*> blocks_;
84 int write_pos_; 84 int write_pos_;
85 int block_index_; 85 int block_index_;
86 int block_write_pos_; 86 int block_write_pos_;
87 bool is_sealed_; 87 bool is_sealed_;
88 }; 88 };
89 89
90 90
91 // An utility class for performing backward reference compression
92 // of string ends. It operates using a window of previous strings.
93 class LogRecordCompressor {
94 public:
95 // 'window_size' is the size of backward lookup window.
96 // 'start_pos' is the length of string prefix that must be left uncompressed.
97 LogRecordCompressor(int window_size, int start_pos)
98 : buffer_(window_size), start_pos_(start_pos), curr_(-1), prev_(-1) {
99 // Must have place for the current record and the previous.
100 ASSERT(window_size >= 2);
101 }
102 ~LogRecordCompressor();
103
104 // Fills vector with a compressed version of the previous record.
105 // Returns false if there is no previous record.
106 bool RetrievePreviousCompressed(Vector<char>* prev_record);
107
108 // Stores a record if it differs from a previous one (or there's no previous).
109 // Returns true, if the record has been stored.
110 bool Store(const Vector<const char>& record);
111
112 private:
113 // Record field separator. It is assumed that it can't appear
114 // inside a field (a simplified version of CSV format).
115 static const char kFieldSeparator = ',';
116
117 // Formatting string for back references.
118 static const char* kBackwardReferenceFormat;
119
120 // A boundary value. If current record only differs in
121 // kUncompressibleBound chars, don't compress it.
122 // The value must be greater than the length of maximum
123 // projected backward reference length.
124 static const intptr_t kUncompressibleBound = 10;
125
126 ScopedVector< Vector<const char> > buffer_;
127 const int start_pos_;
128 int curr_;
129 int prev_;
130 };
131
132
133 // Functions and data for performing output of log messages. 91 // Functions and data for performing output of log messages.
134 class Log : public AllStatic { 92 class Log : public AllStatic {
135 public: 93 public:
136 // Opens stdout for logging. 94 // Opens stdout for logging.
137 static void OpenStdout(); 95 static void OpenStdout();
138 96
139 // Opens file for logging. 97 // Opens file for logging.
140 static void OpenFile(const char* name); 98 static void OpenFile(const char* name);
141 99
142 // Opens memory buffer for logging. 100 // Opens memory buffer for logging.
143 static void OpenMemoryBuffer(); 101 static void OpenMemoryBuffer();
144 102
145 // Disables logging, but preserves acquired resources. 103 // Disables logging, but preserves acquired resources.
146 static void stop() { is_stopped_ = true; } 104 static void stop() { is_stopped_ = true; }
147 105
148 // Frees all resources acquired in Open... functions. 106 // Frees all resources acquired in Open... functions.
149 static void Close(); 107 static void Close();
150 108
151 // See description in include/v8.h. 109 // See description in include/v8.h.
152 static int GetLogLines(int from_pos, char* dest_buf, int max_size); 110 static int GetLogLines(int from_pos, char* dest_buf, int max_size);
153 111
154 // Returns whether logging is enabled. 112 // Returns whether logging is enabled.
155 static bool IsEnabled() { 113 static bool IsEnabled() {
156 return !is_stopped_ && (output_handle_ != NULL || output_buffer_ != NULL); 114 return !is_stopped_ && (output_handle_ != NULL || output_buffer_ != NULL);
157 } 115 }
158 116
159 // Size of buffer used for record compression.
160 static const int kRecordCompressorWindow = 6;
161
162 private: 117 private:
163 typedef int (*WritePtr)(const char* msg, int length); 118 typedef int (*WritePtr)(const char* msg, int length);
164 119
165 // Initialization function called from Open... functions. 120 // Initialization function called from Open... functions.
166 static void Init(); 121 static void Init();
167 122
168 // Write functions assume that mutex_ is acquired by the caller. 123 // Write functions assume that mutex_ is acquired by the caller.
169 static WritePtr Write; 124 static WritePtr Write;
170 125
171 // Implementation of writing to a log file. 126 // Implementation of writing to a log file.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // access to the formatting buffer and the log file or log memory buffer. 162 // access to the formatting buffer and the log file or log memory buffer.
208 static Mutex* mutex_; 163 static Mutex* mutex_;
209 164
210 // Size of buffer used for formatting log messages. 165 // Size of buffer used for formatting log messages.
211 static const int kMessageBufferSize = 2048; 166 static const int kMessageBufferSize = 2048;
212 167
213 // Buffer used for formatting log messages. This is a singleton buffer and 168 // Buffer used for formatting log messages. This is a singleton buffer and
214 // mutex_ should be acquired before using it. 169 // mutex_ should be acquired before using it.
215 static char* message_buffer_; 170 static char* message_buffer_;
216 171
217 // An utility object for compressing repeated parts of records.
218 static LogRecordCompressor* record_compressor_;
219
220 static const char* kCompressedTickEventName;
221
222 friend class LogMessageBuilder; 172 friend class LogMessageBuilder;
173 friend class LogRecordCompressor;
223 }; 174 };
224 175
225 176
177 // An utility class for performing backward reference compression
178 // of string ends. It operates using a window of previous strings.
179 class LogRecordCompressor {
180 public:
181 // 'window_size' is the size of backward lookup window.
182 explicit LogRecordCompressor(int window_size)
183 : buffer_(window_size + kNoCompressionWindowSize),
184 kMaxBackwardReferenceSize(
185 GetBackwardReferenceSize(window_size, Log::kMessageBufferSize)),
186 curr_(-1), prev_(-1) {
187 }
188
189 ~LogRecordCompressor();
190
191 // Fills vector with a compressed version of the previous record.
192 // Returns false if there is no previous record.
193 bool RetrievePreviousCompressed(Vector<char>* prev_record);
194
195 // Stores a record if it differs from a previous one (or there's no previous).
196 // Returns true, if the record has been stored.
197 bool Store(const Vector<const char>& record);
198
199 private:
200 // The minimum size of a buffer: a place needed for the current and
201 // the previous record. Since there is no place for precedessors of a previous
202 // record, it can't be compressed at all.
203 static const int kNoCompressionWindowSize = 2;
204
205 // Formatting strings for back references.
206 static const char* kLineBackwardReferenceFormat;
207 static const char* kBackwardReferenceFormat;
208
209 static int GetBackwardReferenceSize(int distance, int pos);
210
211 static void PrintBackwardReference(Vector<char> dest, int distance, int pos);
212
213 ScopedVector< Vector<const char> > buffer_;
214 const int kMaxBackwardReferenceSize;
215 int curr_;
216 int prev_;
217 };
218
219
226 // Utility class for formatting log messages. It fills the message into the 220 // Utility class for formatting log messages. It fills the message into the
227 // static buffer in Log. 221 // static buffer in Log.
228 class LogMessageBuilder BASE_EMBEDDED { 222 class LogMessageBuilder BASE_EMBEDDED {
229 public: 223 public:
230 // Create a message builder starting from position 0. This acquires the mutex 224 // Create a message builder starting from position 0. This acquires the mutex
231 // in the log as well. 225 // in the log as well.
232 explicit LogMessageBuilder(); 226 explicit LogMessageBuilder();
233 ~LogMessageBuilder() { } 227 ~LogMessageBuilder() { }
234 228
235 // Append string data to the log message. 229 // Append string data to the log message.
236 void Append(const char* format, ...); 230 void Append(const char* format, ...);
237 231
238 // Append string data to the log message. 232 // Append string data to the log message.
239 void Append(const char* format, va_list args); 233 void Append(const char* format, va_list args);
240 234
241 // Append a character to the log message. 235 // Append a character to the log message.
242 void Append(const char c); 236 void Append(const char c);
243 237
244 // Append a heap string. 238 // Append a heap string.
245 void Append(String* str); 239 void Append(String* str);
246 240
241 // Appends an address, compressing it if needed by offsetting
242 // from Logger::last_address_.
243 void AppendAddress(Address addr);
244
245 // Appends an address, compressing it if needed.
246 void AppendAddress(Address addr, Address bias);
247
247 void AppendDetailed(String* str, bool show_impl_info); 248 void AppendDetailed(String* str, bool show_impl_info);
248 249
249 // Stores log message into compressor, returns true if the message 250 // Stores log message into compressor, returns true if the message
250 // was stored (i.e. doesn't repeat the previous one). If log compression is 251 // was stored (i.e. doesn't repeat the previous one).
251 // disabled, does nothing and returns true. 252 bool StoreInCompressor(LogRecordCompressor* compressor);
252 bool StoreInCompressor();
253 253
254 // Sets log message to a previous version of compressed message. 254 // Sets log message to a previous version of compressed message.
255 // Returns false, if there is no previous message. If log compression 255 // Returns false, if there is no previous message.
256 // is disabled, does nothing and retuns true. 256 bool RetrieveCompressedPrevious(LogRecordCompressor* compressor) {
257 bool RetrieveCompressedPrevious() { return RetrieveCompressedPrevious(""); } 257 return RetrieveCompressedPrevious(compressor, "");
258 }
258 259
259 // Does the same at the version without arguments, and sets a prefix. 260 // Does the same at the version without arguments, and sets a prefix.
260 bool RetrieveCompressedPrevious(const char* prefix); 261 bool RetrieveCompressedPrevious(LogRecordCompressor* compressor,
262 const char* prefix);
261 263
262 // Write the log message to the log file currently opened. 264 // Write the log message to the log file currently opened.
263 void WriteToLogFile(); 265 void WriteToLogFile();
264 266
265 // Write a null-terminated string to to the log file currently opened. 267 // Write a null-terminated string to to the log file currently opened.
266 void WriteCStringToLogFile(const char* str); 268 void WriteCStringToLogFile(const char* str);
267 269
268 // A handler that is called when Log::Write fails. 270 // A handler that is called when Log::Write fails.
269 typedef void (*WriteFailureHandler)(); 271 typedef void (*WriteFailureHandler)();
270 272
271 static void set_write_failure_handler(WriteFailureHandler handler) { 273 static void set_write_failure_handler(WriteFailureHandler handler) {
272 write_failure_handler = handler; 274 write_failure_handler = handler;
273 } 275 }
274 276
275 private: 277 private:
276 static WriteFailureHandler write_failure_handler; 278 static WriteFailureHandler write_failure_handler;
277 279
278 ScopedLock sl; 280 ScopedLock sl;
279 int pos_; 281 int pos_;
280 }; 282 };
281 283
282 #endif // ENABLE_LOGGING_AND_PROFILING 284 #endif // ENABLE_LOGGING_AND_PROFILING
283 285
284 } } // namespace v8::internal 286 } } // namespace v8::internal
285 287
286 #endif // V8_LOG_UTILS_H_ 288 #endif // V8_LOG_UTILS_H_
OLDNEW
« no previous file with comments | « src/log.cc ('k') | src/log-utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698