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