| OLD | NEW |
| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 VMState* previous_; | 96 VMState* previous_; |
| 97 #else | 97 #else |
| 98 public: | 98 public: |
| 99 explicit VMState(StateTag state) {} | 99 explicit VMState(StateTag state) {} |
| 100 #endif | 100 #endif |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 | 103 |
| 104 class Logger { | 104 class Logger { |
| 105 public: | 105 public: |
| 106 // Opens the file for logging if the right flags are set. | 106 // Acquires resources for logging if the right flags are set. |
| 107 static bool Setup(); | 107 static bool Setup(); |
| 108 | 108 |
| 109 // Closes file opened in Setup. | 109 // Frees resources acquired in Setup. |
| 110 static void TearDown(); | 110 static void TearDown(); |
| 111 | 111 |
| 112 // Enable the computation of a sliding window of states. | 112 // Enable the computation of a sliding window of states. |
| 113 static void EnableSlidingStateWindow(); | 113 static void EnableSlidingStateWindow(); |
| 114 | 114 |
| 115 // Write a raw string to the log to be used as a preamble. | 115 // 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 | 116 // 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 | 117 // of the log. The preample is used to write code events saved in the |
| 118 // snapshot. | 118 // snapshot. |
| 119 static void Preamble(const char* content); | 119 static void Preamble(const char* content); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 static void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache); | 194 static void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache); |
| 195 | 195 |
| 196 // Log an event reported from generated code | 196 // Log an event reported from generated code |
| 197 static void LogRuntime(Vector<const char> format, JSArray* args); | 197 static void LogRuntime(Vector<const char> format, JSArray* args); |
| 198 | 198 |
| 199 #ifdef ENABLE_LOGGING_AND_PROFILING | 199 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 200 static StateTag state() { | 200 static StateTag state() { |
| 201 return current_state_ ? current_state_->state() : OTHER; | 201 return current_state_ ? current_state_->state() : OTHER; |
| 202 } | 202 } |
| 203 | 203 |
| 204 static bool is_enabled() { return logfile_ != NULL; } | 204 static bool is_enabled(); |
| 205 | 205 |
| 206 // Pause/Resume collection of profiling data. | 206 // Pause/Resume collection of profiling data. |
| 207 // When data collection is paused, Tick events are discarded until | 207 // When data collection is paused, Tick events are discarded until |
| 208 // data collection is Resumed. | 208 // data collection is Resumed. |
| 209 static bool IsProfilerPaused(); | 209 static bool IsProfilerPaused(); |
| 210 static void PauseProfiler(); | 210 static void PauseProfiler(); |
| 211 static void ResumeProfiler(); | 211 static void ResumeProfiler(); |
| 212 | 212 |
| 213 // If logging is performed into a memory buffer, allows to |
| 214 // retrieve previously written messages. See v8.h. |
| 215 static int GetLogLines(int from_pos, char* dest_buf, int max_size); |
| 216 |
| 213 private: | 217 private: |
| 214 | 218 |
| 215 // Emits the source code of a regexp. Used by regexp events. | 219 // Emits the source code of a regexp. Used by regexp events. |
| 216 static void LogRegExpSource(Handle<JSRegExp> regexp); | 220 static void LogRegExpSource(Handle<JSRegExp> regexp); |
| 217 | 221 |
| 218 // Emits a profiler tick event. Used by the profiler thread. | 222 // Emits a profiler tick event. Used by the profiler thread. |
| 219 static void TickEvent(TickSample* sample, bool overflow); | 223 static void TickEvent(TickSample* sample, bool overflow); |
| 220 | 224 |
| 221 static void ApiEvent(const char* name, ...); | 225 static void ApiEvent(const char* name, ...); |
| 222 | 226 |
| 223 // Logs a StringEvent regardless of whether FLAG_log is true. | 227 // Logs a StringEvent regardless of whether FLAG_log is true. |
| 224 static void UncheckedStringEvent(const char* name, const char* value); | 228 static void UncheckedStringEvent(const char* name, const char* value); |
| 225 | 229 |
| 226 // Size of buffer used for formatting log messages. | |
| 227 static const int kMessageBufferSize = 2048; | |
| 228 | |
| 229 // Buffer used for formatting log messages. This is a singleton buffer and | |
| 230 // mutex_ should be acquired before using it. | |
| 231 static char* message_buffer_; | |
| 232 | |
| 233 // When logging is active, logfile_ refers the file events are written to. | |
| 234 // mutex_ should be acquired before using logfile_. | |
| 235 static FILE* logfile_; | |
| 236 | |
| 237 // The sampler used by the profiler and the sliding state window. | 230 // The sampler used by the profiler and the sliding state window. |
| 238 static Ticker* ticker_; | 231 static Ticker* ticker_; |
| 239 | 232 |
| 240 // When the statistical profile is active, profiler_ | 233 // When the statistical profile is active, profiler_ |
| 241 // points to a Profiler, that handles collection | 234 // points to a Profiler, that handles collection |
| 242 // of samples. | 235 // of samples. |
| 243 static Profiler* profiler_; | 236 static Profiler* profiler_; |
| 244 | 237 |
| 245 // mutex_ is a Mutex used for enforcing exclusive | |
| 246 // access to the formatting buffer and the log file. | |
| 247 static Mutex* mutex_; | |
| 248 | |
| 249 // A stack of VM states. | 238 // A stack of VM states. |
| 250 static VMState* current_state_; | 239 static VMState* current_state_; |
| 251 | 240 |
| 252 // Singleton bottom or default vm state. | 241 // Singleton bottom or default vm state. |
| 253 static VMState bottom_state_; | 242 static VMState bottom_state_; |
| 254 | 243 |
| 255 // SlidingStateWindow instance keeping a sliding window of the most | 244 // SlidingStateWindow instance keeping a sliding window of the most |
| 256 // recent VM states. | 245 // recent VM states. |
| 257 static SlidingStateWindow* sliding_state_window_; | 246 static SlidingStateWindow* sliding_state_window_; |
| 258 | 247 |
| 259 // Internal implementation classes with access to | 248 // Internal implementation classes with access to |
| 260 // private members. | 249 // private members. |
| 261 friend class LogMessageBuilder; | |
| 262 friend class EventLog; | 250 friend class EventLog; |
| 263 friend class TimeLog; | 251 friend class TimeLog; |
| 264 friend class Profiler; | 252 friend class Profiler; |
| 265 friend class SlidingStateWindow; | 253 friend class SlidingStateWindow; |
| 266 friend class VMState; | 254 friend class VMState; |
| 267 #else | 255 #else |
| 268 static bool is_enabled() { return false; } | 256 static bool is_enabled() { return false; } |
| 269 #endif | 257 #endif |
| 270 }; | 258 }; |
| 271 | 259 |
| 272 | 260 |
| 273 // Class that extracts stack trace, used for profiling. | 261 // Class that extracts stack trace, used for profiling. |
| 274 class StackTracer BASE_EMBEDDED { | 262 class StackTracer BASE_EMBEDDED { |
| 275 public: | 263 public: |
| 276 explicit StackTracer(unsigned int low_stack_bound) | 264 explicit StackTracer(unsigned int low_stack_bound) |
| 277 : low_stack_bound_(low_stack_bound) { } | 265 : low_stack_bound_(low_stack_bound) { } |
| 278 void Trace(TickSample* sample); | 266 void Trace(TickSample* sample); |
| 279 private: | 267 private: |
| 280 | 268 |
| 281 unsigned int low_stack_bound_; | 269 unsigned int low_stack_bound_; |
| 282 }; | 270 }; |
| 283 | 271 |
| 284 | 272 |
| 285 } } // namespace v8::internal | 273 } } // namespace v8::internal |
| 286 | 274 |
| 287 #endif // V8_LOG_H_ | 275 #endif // V8_LOG_H_ |
| OLD | NEW |