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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 explicit LogRecordCompressor(int window_size_) |
| 96 : buffer_(window_size_), curr_(-1), prev_(-1) { |
| 97 // Must have place for the current record and the previous. |
| 98 ASSERT(window_size_ >= 2); |
| 99 } |
| 100 ~LogRecordCompressor(); |
| 101 |
| 102 // Fills vector with a compressed version of the previous record. |
| 103 // Returns false if there is no previous record. |
| 104 bool RetrievePreviousCompressed(Vector<char>* prev_record); |
| 105 |
| 106 // Stores a record if it differs from a previous one (or there's no previous). |
| 107 // Returns true, if the record has been stored. |
| 108 bool Store(const Vector<const char>& record); |
| 109 |
| 110 private: |
| 111 // Record field separator. It is assumed that it can't appear |
| 112 // inside a field (a simplified version of CSV format). |
| 113 static const char kFieldSeparator = ','; |
| 114 |
| 115 // Formatting string for back references. |
| 116 static const char* kBackwardReferenceFormat; |
| 117 |
| 118 // A boundary value. If current record only differs in |
| 119 // kUncompressibleBound chars, don't compress it. |
| 120 // The value must be greater than the length of maximum |
| 121 // projected backward reference length. |
| 122 static const intptr_t kUncompressibleBound = 10; |
| 123 |
| 124 ScopedVector< Vector<const char> > buffer_; |
| 125 int curr_; |
| 126 int prev_; |
| 127 }; |
| 128 |
| 129 |
91 // Functions and data for performing output of log messages. | 130 // Functions and data for performing output of log messages. |
92 class Log : public AllStatic { | 131 class Log : public AllStatic { |
93 public: | 132 public: |
94 // Opens stdout for logging. | 133 // Opens stdout for logging. |
95 static void OpenStdout(); | 134 static void OpenStdout(); |
96 | 135 |
97 // Opens file for logging. | 136 // Opens file for logging. |
98 static void OpenFile(const char* name); | 137 static void OpenFile(const char* name); |
99 | 138 |
100 // Opens memory buffer for logging. | 139 // Opens memory buffer for logging. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // access to the formatting buffer and the log file or log memory buffer. | 201 // access to the formatting buffer and the log file or log memory buffer. |
163 static Mutex* mutex_; | 202 static Mutex* mutex_; |
164 | 203 |
165 // Size of buffer used for formatting log messages. | 204 // Size of buffer used for formatting log messages. |
166 static const int kMessageBufferSize = 2048; | 205 static const int kMessageBufferSize = 2048; |
167 | 206 |
168 // Buffer used for formatting log messages. This is a singleton buffer and | 207 // Buffer used for formatting log messages. This is a singleton buffer and |
169 // mutex_ should be acquired before using it. | 208 // mutex_ should be acquired before using it. |
170 static char* message_buffer_; | 209 static char* message_buffer_; |
171 | 210 |
| 211 // Size of buffer used for record compression. |
| 212 static const int kRecordCompressorWindow = 6; |
| 213 |
| 214 // An utility object for compressing repeated parts of records. |
| 215 static LogRecordCompressor* record_compressor_; |
| 216 |
172 friend class LogMessageBuilder; | 217 friend class LogMessageBuilder; |
173 }; | 218 }; |
174 | 219 |
175 | 220 |
176 // Utility class for formatting log messages. It fills the message into the | 221 // Utility class for formatting log messages. It fills the message into the |
177 // static buffer in Log. | 222 // static buffer in Log. |
178 class LogMessageBuilder BASE_EMBEDDED { | 223 class LogMessageBuilder BASE_EMBEDDED { |
179 public: | 224 public: |
180 // Create a message builder starting from position 0. This acquires the mutex | 225 // Create a message builder starting from position 0. This acquires the mutex |
181 // in the log as well. | 226 // in the log as well. |
182 explicit LogMessageBuilder(); | 227 explicit LogMessageBuilder(); |
183 ~LogMessageBuilder() { } | 228 ~LogMessageBuilder() { } |
184 | 229 |
185 // Append string data to the log message. | 230 // Append string data to the log message. |
186 void Append(const char* format, ...); | 231 void Append(const char* format, ...); |
187 | 232 |
188 // Append string data to the log message. | 233 // Append string data to the log message. |
189 void Append(const char* format, va_list args); | 234 void Append(const char* format, va_list args); |
190 | 235 |
191 // Append a character to the log message. | 236 // Append a character to the log message. |
192 void Append(const char c); | 237 void Append(const char c); |
193 | 238 |
194 // Append a heap string. | 239 // Append a heap string. |
195 void Append(String* str); | 240 void Append(String* str); |
196 | 241 |
197 void AppendDetailed(String* str, bool show_impl_info); | 242 void AppendDetailed(String* str, bool show_impl_info); |
198 | 243 |
| 244 // Stores log message into compressor, returns true if the message |
| 245 // was stored (i.e. doesn't repeat the previous one). If log compression is |
| 246 // disabled, does nothing and returns true. |
| 247 bool StoreInCompressor(); |
| 248 |
| 249 // Sets log message to a previous version of compressed message. |
| 250 // Returns false, if there is no previous message. If log compression |
| 251 // is disabled, does nothing and retuns true. |
| 252 bool RetrieveCompressedPrevious() { return RetrieveCompressedPrevious(""); } |
| 253 |
| 254 // Does the same at the version without arguments, and sets a prefix. |
| 255 bool RetrieveCompressedPrevious(const char* prefix); |
| 256 |
199 // Write the log message to the log file currently opened. | 257 // Write the log message to the log file currently opened. |
200 void WriteToLogFile(); | 258 void WriteToLogFile(); |
201 | 259 |
202 // Write a null-terminated string to to the log file currently opened. | 260 // Write a null-terminated string to to the log file currently opened. |
203 void WriteCStringToLogFile(const char* str); | 261 void WriteCStringToLogFile(const char* str); |
204 | 262 |
205 // A handler that is called when Log::Write fails. | 263 // A handler that is called when Log::Write fails. |
206 typedef void (*WriteFailureHandler)(); | 264 typedef void (*WriteFailureHandler)(); |
207 | 265 |
208 static void set_write_failure_handler(WriteFailureHandler handler) { | 266 static void set_write_failure_handler(WriteFailureHandler handler) { |
209 write_failure_handler = handler; | 267 write_failure_handler = handler; |
210 } | 268 } |
211 | 269 |
212 private: | 270 private: |
213 static WriteFailureHandler write_failure_handler; | 271 static WriteFailureHandler write_failure_handler; |
214 | 272 |
215 ScopedLock sl; | 273 ScopedLock sl; |
216 int pos_; | 274 int pos_; |
217 }; | 275 }; |
218 | 276 |
219 #endif // ENABLE_LOGGING_AND_PROFILING | 277 #endif // ENABLE_LOGGING_AND_PROFILING |
220 | 278 |
221 } } // namespace v8::internal | 279 } } // namespace v8::internal |
222 | 280 |
223 #endif // V8_LOG_UTILS_H_ | 281 #endif // V8_LOG_UTILS_H_ |
OLD | NEW |