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

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

Issue 5575006: Remove log compression support. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
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 unified diff | Download patch | Annotate | Revision Log
« 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // mutex_ is a Mutex used for enforcing exclusive 169 // mutex_ is a Mutex used for enforcing exclusive
170 // access to the formatting buffer and the log file or log memory buffer. 170 // access to the formatting buffer and the log file or log memory buffer.
171 static Mutex* mutex_; 171 static Mutex* mutex_;
172 172
173 // Buffer used for formatting log messages. This is a singleton buffer and 173 // Buffer used for formatting log messages. This is a singleton buffer and
174 // mutex_ should be acquired before using it. 174 // mutex_ should be acquired before using it.
175 static char* message_buffer_; 175 static char* message_buffer_;
176 176
177 friend class Logger; 177 friend class Logger;
178 friend class LogMessageBuilder; 178 friend class LogMessageBuilder;
179 friend class LogRecordCompressor;
180 }; 179 };
181 180
182 181
183 // An utility class for performing backward reference compression
184 // of string ends. It operates using a window of previous strings.
185 class LogRecordCompressor {
186 public:
187 // 'window_size' is the size of backward lookup window.
188 explicit LogRecordCompressor(int window_size)
189 : buffer_(window_size + kNoCompressionWindowSize),
190 kMaxBackwardReferenceSize(
191 GetBackwardReferenceSize(window_size, Log::kMessageBufferSize)),
192 curr_(-1), prev_(-1) {
193 }
194
195 ~LogRecordCompressor();
196
197 // Fills vector with a compressed version of the previous record.
198 // Returns false if there is no previous record.
199 bool RetrievePreviousCompressed(Vector<char>* prev_record);
200
201 // Stores a record if it differs from a previous one (or there's no previous).
202 // Returns true, if the record has been stored.
203 bool Store(const Vector<const char>& record);
204
205 private:
206 // The minimum size of a buffer: a place needed for the current and
207 // the previous record. Since there is no place for precedessors of a previous
208 // record, it can't be compressed at all.
209 static const int kNoCompressionWindowSize = 2;
210
211 // Formatting strings for back references.
212 static const char* kLineBackwardReferenceFormat;
213 static const char* kBackwardReferenceFormat;
214
215 static int GetBackwardReferenceSize(int distance, int pos);
216
217 static void PrintBackwardReference(Vector<char> dest, int distance, int pos);
218
219 ScopedVector< Vector<const char> > buffer_;
220 const int kMaxBackwardReferenceSize;
221 int curr_;
222 int prev_;
223 };
224
225
226 // Utility class for formatting log messages. It fills the message into the 182 // Utility class for formatting log messages. It fills the message into the
227 // static buffer in Log. 183 // static buffer in Log.
228 class LogMessageBuilder BASE_EMBEDDED { 184 class LogMessageBuilder BASE_EMBEDDED {
229 public: 185 public:
230 // Create a message builder starting from position 0. This acquires the mutex 186 // Create a message builder starting from position 0. This acquires the mutex
231 // in the log as well. 187 // in the log as well.
232 explicit LogMessageBuilder(); 188 explicit LogMessageBuilder();
233 ~LogMessageBuilder() { } 189 ~LogMessageBuilder() { }
234 190
235 // Append string data to the log message. 191 // Append string data to the log message.
236 void Append(const char* format, ...); 192 void Append(const char* format, ...);
237 193
238 // Append string data to the log message. 194 // Append string data to the log message.
239 void AppendVA(const char* format, va_list args); 195 void AppendVA(const char* format, va_list args);
240 196
241 // Append a character to the log message. 197 // Append a character to the log message.
242 void Append(const char c); 198 void Append(const char c);
243 199
244 // Append a heap string. 200 // Append a heap string.
245 void Append(String* str); 201 void Append(String* str);
246 202
247 // Appends an address, compressing it if needed by offsetting 203 // Appends an address.
248 // from Logger::last_address_.
249 void AppendAddress(Address addr); 204 void AppendAddress(Address addr);
250 205
251 // Appends an address, compressing it if needed.
252 void AppendAddress(Address addr, Address bias);
253
254 void AppendDetailed(String* str, bool show_impl_info); 206 void AppendDetailed(String* str, bool show_impl_info);
255 207
256 // Append a portion of a string. 208 // Append a portion of a string.
257 void AppendStringPart(const char* str, int len); 209 void AppendStringPart(const char* str, int len);
258 210
259 // Stores log message into compressor, returns true if the message
260 // was stored (i.e. doesn't repeat the previous one).
261 bool StoreInCompressor(LogRecordCompressor* compressor);
262
263 // Sets log message to a previous version of compressed message.
264 // Returns false, if there is no previous message.
265 bool RetrieveCompressedPrevious(LogRecordCompressor* compressor) {
266 return RetrieveCompressedPrevious(compressor, "");
267 }
268
269 // Does the same at the version without arguments, and sets a prefix.
270 bool RetrieveCompressedPrevious(LogRecordCompressor* compressor,
271 const char* prefix);
272
273 // Write the log message to the log file currently opened. 211 // Write the log message to the log file currently opened.
274 void WriteToLogFile(); 212 void WriteToLogFile();
275 213
276 // A handler that is called when Log::Write fails. 214 // A handler that is called when Log::Write fails.
277 typedef void (*WriteFailureHandler)(); 215 typedef void (*WriteFailureHandler)();
278 216
279 static void set_write_failure_handler(WriteFailureHandler handler) { 217 static void set_write_failure_handler(WriteFailureHandler handler) {
280 write_failure_handler = handler; 218 write_failure_handler = handler;
281 } 219 }
282 220
283 private: 221 private:
284 static WriteFailureHandler write_failure_handler; 222 static WriteFailureHandler write_failure_handler;
285 223
286 ScopedLock sl; 224 ScopedLock sl;
287 int pos_; 225 int pos_;
288 }; 226 };
289 227
290 #endif // ENABLE_LOGGING_AND_PROFILING 228 #endif // ENABLE_LOGGING_AND_PROFILING
291 229
292 } } // namespace v8::internal 230 } } // namespace v8::internal
293 231
294 #endif // V8_LOG_UTILS_H_ 232 #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