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

Side by Side 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 unified diff | Download patch
« ChangeLog ('K') | « 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;
179 }; 180 };
180 181
181 182
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
182 // Utility class for formatting log messages. It fills the message into the 226 // Utility class for formatting log messages. It fills the message into the
183 // static buffer in Log. 227 // static buffer in Log.
184 class LogMessageBuilder BASE_EMBEDDED { 228 class LogMessageBuilder BASE_EMBEDDED {
185 public: 229 public:
186 // Create a message builder starting from position 0. This acquires the mutex 230 // Create a message builder starting from position 0. This acquires the mutex
187 // in the log as well. 231 // in the log as well.
188 explicit LogMessageBuilder(); 232 explicit LogMessageBuilder();
189 ~LogMessageBuilder() { } 233 ~LogMessageBuilder() { }
190 234
191 // Append string data to the log message. 235 // Append string data to the log message.
192 void Append(const char* format, ...); 236 void Append(const char* format, ...);
193 237
194 // Append string data to the log message. 238 // Append string data to the log message.
195 void AppendVA(const char* format, va_list args); 239 void AppendVA(const char* format, va_list args);
196 240
197 // Append a character to the log message. 241 // Append a character to the log message.
198 void Append(const char c); 242 void Append(const char c);
199 243
200 // Append a heap string. 244 // Append a heap string.
201 void Append(String* str); 245 void Append(String* str);
202 246
203 // Appends an address. 247 // Appends an address, compressing it if needed by offsetting
248 // from Logger::last_address_.
204 void AppendAddress(Address addr); 249 void AppendAddress(Address addr);
205 250
251 // Appends an address, compressing it if needed.
252 void AppendAddress(Address addr, Address bias);
253
206 void AppendDetailed(String* str, bool show_impl_info); 254 void AppendDetailed(String* str, bool show_impl_info);
207 255
208 // Append a portion of a string. 256 // Append a portion of a string.
209 void AppendStringPart(const char* str, int len); 257 void AppendStringPart(const char* str, int len);
210 258
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
211 // Write the log message to the log file currently opened. 273 // Write the log message to the log file currently opened.
212 void WriteToLogFile(); 274 void WriteToLogFile();
213 275
214 // A handler that is called when Log::Write fails. 276 // A handler that is called when Log::Write fails.
215 typedef void (*WriteFailureHandler)(); 277 typedef void (*WriteFailureHandler)();
216 278
217 static void set_write_failure_handler(WriteFailureHandler handler) { 279 static void set_write_failure_handler(WriteFailureHandler handler) {
218 write_failure_handler = handler; 280 write_failure_handler = handler;
219 } 281 }
220 282
221 private: 283 private:
222 static WriteFailureHandler write_failure_handler; 284 static WriteFailureHandler write_failure_handler;
223 285
224 ScopedLock sl; 286 ScopedLock sl;
225 int pos_; 287 int pos_;
226 }; 288 };
227 289
228 #endif // ENABLE_LOGGING_AND_PROFILING 290 #endif // ENABLE_LOGGING_AND_PROFILING
229 291
230 } } // namespace v8::internal 292 } } // namespace v8::internal
231 293
232 #endif // V8_LOG_UTILS_H_ 294 #endif // V8_LOG_UTILS_H_
OLDNEW
« 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