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

Side by Side Diff: src/log.h

Issue 115024: Changelist for a readability review. Not for direct commit. (Closed)
Patch Set: Second round of changes Created 11 years, 7 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/func-name-inferrer.cc ('k') | src/log.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-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_LOG_H_ 28 #ifndef V8_LOG_H_
29 #define V8_LOG_H_ 29 #define V8_LOG_H_
30 30
31 namespace v8 { namespace internal { 31 namespace v8 {
32 namespace internal {
32 33
33 // Logger is used for collecting logging information from V8 during 34 // Logger is used for collecting logging information from V8 during
34 // execution. The result is dumped to a file. 35 // execution. The result is dumped to a file.
35 // 36 //
36 // Available command line flags: 37 // Available command line flags:
37 // 38 //
38 // --log 39 // --log
39 // Minimal logging (no API, code, or GC sample events), default is off. 40 // Minimal logging (no API, code, or GC sample events), default is off.
40 // 41 //
41 // --log-all 42 // --log-all
(...skipping 26 matching lines...) Expand all
68 class Ticker; 69 class Ticker;
69 class Profiler; 70 class Profiler;
70 class Semaphore; 71 class Semaphore;
71 class SlidingStateWindow; 72 class SlidingStateWindow;
72 class LogMessageBuilder; 73 class LogMessageBuilder;
73 74
74 #undef LOG 75 #undef LOG
75 #ifdef ENABLE_LOGGING_AND_PROFILING 76 #ifdef ENABLE_LOGGING_AND_PROFILING
76 #define LOG(Call) \ 77 #define LOG(Call) \
77 do { \ 78 do { \
78 if (v8::internal::Logger::is_enabled()) \ 79 if (v8::internal::Logger::IsEnabled()) \
79 v8::internal::Logger::Call; \ 80 v8::internal::Logger::Call; \
80 } while (false) 81 } while (false)
81 #else 82 #else
82 #define LOG(Call) ((void) 0) 83 #define LOG(Call) ((void) 0)
83 #endif 84 #endif
84 85
85 86
86 class VMState BASE_EMBEDDED { 87 class VMState BASE_EMBEDDED {
87 #ifdef ENABLE_LOGGING_AND_PROFILING 88 #ifdef ENABLE_LOGGING_AND_PROFILING
88 public: 89 public:
89 explicit VMState(StateTag state); 90 explicit VMState(StateTag state);
90 ~VMState(); 91 ~VMState();
91 92
92 StateTag state() { return state_; } 93 StateTag state() { return state_; }
93 94
94 private: 95 private:
95 StateTag state_; 96 StateTag state_;
96 VMState* previous_; 97 VMState* previous_;
97 #else 98 #else
98 public: 99 public:
99 explicit VMState(StateTag state) {} 100 explicit VMState(StateTag state) {}
100 #endif 101 #endif
101 }; 102 };
102 103
103 104
104 class Logger { 105 class Logger {
105 public: 106 public:
106 // Opens the file for logging if the right flags are set. 107 // Acquires resources for logging if the right flags are set.
107 static bool Setup(); 108 static bool Setup();
108 109
109 // Closes file opened in Setup. 110 // Frees resources acquired in Setup.
110 static void TearDown(); 111 static void TearDown();
111 112
112 // Enable the computation of a sliding window of states. 113 // Enable the computation of a sliding window of states.
113 static void EnableSlidingStateWindow(); 114 static void EnableSlidingStateWindow();
114 115
115 // Write a raw string to the log to be used as a preamble. 116 // Write a raw string to the log to be used as a preamble.
116 // No check is made that the 'preamble' is actually at the beginning 117 // No check is made that the 'preamble' is actually at the beginning
117 // of the log. The preample is used to write code events saved in the 118 // of the log. The preample is used to write code events saved in the
118 // snapshot. 119 // snapshot.
119 static void Preamble(const char* content); 120 static void Preamble(const char* content);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 static void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache); 200 static void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache);
200 201
201 // Log an event reported from generated code 202 // Log an event reported from generated code
202 static void LogRuntime(Vector<const char> format, JSArray* args); 203 static void LogRuntime(Vector<const char> format, JSArray* args);
203 204
204 #ifdef ENABLE_LOGGING_AND_PROFILING 205 #ifdef ENABLE_LOGGING_AND_PROFILING
205 static StateTag state() { 206 static StateTag state() {
206 return current_state_ ? current_state_->state() : OTHER; 207 return current_state_ ? current_state_->state() : OTHER;
207 } 208 }
208 209
209 static bool is_enabled() { return logfile_ != NULL; } 210 static bool IsEnabled();
210 211
211 // Pause/Resume collection of profiling data. 212 // Pause/Resume collection of profiling data.
212 // When data collection is paused, Tick events are discarded until 213 // When data collection is paused, Tick events are discarded until
213 // data collection is Resumed. 214 // data collection is Resumed.
214 static bool IsProfilerPaused(); 215 static bool IsProfilerPaused();
215 static void PauseProfiler(); 216 static void PauseProfiler();
216 static void ResumeProfiler(); 217 static void ResumeProfiler();
217 218
219 // If logging is performed into a memory buffer, allows to
220 // retrieve previously written messages. See v8.h.
221 static int GetLogLines(int from_pos, char* dest_buf, int max_size);
222
218 private: 223 private:
219 224
220 // Emits the source code of a regexp. Used by regexp events. 225 // Emits the source code of a regexp. Used by regexp events.
221 static void LogRegExpSource(Handle<JSRegExp> regexp); 226 static void LogRegExpSource(Handle<JSRegExp> regexp);
222 227
223 // Emits a profiler tick event. Used by the profiler thread. 228 // Emits a profiler tick event. Used by the profiler thread.
224 static void TickEvent(TickSample* sample, bool overflow); 229 static void TickEvent(TickSample* sample, bool overflow);
225 230
226 static void ApiEvent(const char* name, ...); 231 static void ApiEvent(const char* name, ...);
227 232
228 // Logs a StringEvent regardless of whether FLAG_log is true. 233 // Logs a StringEvent regardless of whether FLAG_log is true.
229 static void UncheckedStringEvent(const char* name, const char* value); 234 static void UncheckedStringEvent(const char* name, const char* value);
230 235
231 // Size of buffer used for formatting log messages.
232 static const int kMessageBufferSize = 2048;
233
234 // Buffer used for formatting log messages. This is a singleton buffer and
235 // mutex_ should be acquired before using it.
236 static char* message_buffer_;
237
238 // When logging is active, logfile_ refers the file events are written to.
239 // mutex_ should be acquired before using logfile_.
240 static FILE* logfile_;
241
242 // The sampler used by the profiler and the sliding state window. 236 // The sampler used by the profiler and the sliding state window.
243 static Ticker* ticker_; 237 static Ticker* ticker_;
244 238
245 // When the statistical profile is active, profiler_ 239 // When the statistical profile is active, profiler_
246 // points to a Profiler, that handles collection 240 // points to a Profiler, that handles collection
247 // of samples. 241 // of samples.
248 static Profiler* profiler_; 242 static Profiler* profiler_;
249 243
250 // mutex_ is a Mutex used for enforcing exclusive
251 // access to the formatting buffer and the log file.
252 static Mutex* mutex_;
253
254 // A stack of VM states. 244 // A stack of VM states.
255 static VMState* current_state_; 245 static VMState* current_state_;
256 246
257 // Singleton bottom or default vm state. 247 // Singleton bottom or default vm state.
258 static VMState bottom_state_; 248 static VMState bottom_state_;
259 249
260 // SlidingStateWindow instance keeping a sliding window of the most 250 // SlidingStateWindow instance keeping a sliding window of the most
261 // recent VM states. 251 // recent VM states.
262 static SlidingStateWindow* sliding_state_window_; 252 static SlidingStateWindow* sliding_state_window_;
263 253
264 // Internal implementation classes with access to 254 // Internal implementation classes with access to
265 // private members. 255 // private members.
266 friend class LogMessageBuilder;
267 friend class EventLog; 256 friend class EventLog;
268 friend class TimeLog; 257 friend class TimeLog;
269 friend class Profiler; 258 friend class Profiler;
270 friend class SlidingStateWindow; 259 friend class SlidingStateWindow;
271 friend class VMState; 260 friend class VMState;
272 #else 261 #else
273 static bool is_enabled() { return false; } 262 static bool is_enabled() { return false; }
274 #endif 263 #endif
275 }; 264 };
276 265
277 266
278 // Class that extracts stack trace, used for profiling. 267 // Class that extracts stack trace, used for profiling.
279 class StackTracer BASE_EMBEDDED { 268 class StackTracer BASE_EMBEDDED {
280 public: 269 public:
281 explicit StackTracer(unsigned int low_stack_bound) 270 explicit StackTracer(unsigned int low_stack_bound)
282 : low_stack_bound_(low_stack_bound) { } 271 : low_stack_bound_(low_stack_bound) { }
283 void Trace(TickSample* sample); 272 void Trace(TickSample* sample);
284 private: 273 private:
285 274
286 unsigned int low_stack_bound_; 275 unsigned int low_stack_bound_;
287 }; 276 };
288 277
289 278 } // namespace internal
290 } } // namespace v8::internal 279 } // namespace v8
291 280
292 #endif // V8_LOG_H_ 281 #endif // V8_LOG_H_
OLDNEW
« no previous file with comments | « src/func-name-inferrer.cc ('k') | src/log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698