ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 | |
| 28 | #ifndef V8_LOG_H_ |
| 29 | #define V8_LOG_H_ |
| 30 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 31 | #include "platform.h" |
| 32 | #include "log-utils.h" |
| 33 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 34 | namespace v8 { |
| 35 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | |
| 37 | // Logger is used for collecting logging information from V8 during |
| 38 | // execution. The result is dumped to a file. |
| 39 | // |
| 40 | // Available command line flags: |
| 41 | // |
| 42 | // --log |
| 43 | // Minimal logging (no API, code, or GC sample events), default is off. |
| 44 | // |
| 45 | // --log-all |
| 46 | // Log all events to the file, default is off. This is the same as combining |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 47 | // --log-api, --log-code, --log-gc, and --log-regexp. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | // |
| 49 | // --log-api |
| 50 | // Log API events to the logfile, default is off. --log-api implies --log. |
| 51 | // |
| 52 | // --log-code |
| 53 | // Log code (create, move, and delete) events to the logfile, default is off. |
| 54 | // --log-code implies --log. |
| 55 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 56 | // --log-gc |
| 57 | // Log GC heap samples after each GC that can be processed by hp2ps, default |
| 58 | // is off. --log-gc implies --log. |
| 59 | // |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 60 | // --log-regexp |
| 61 | // Log creation and use of regular expressions, Default is off. |
| 62 | // --log-regexp implies --log. |
| 63 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 64 | // --logfile <filename> |
| 65 | // Specify the name of the logfile, default is "v8.log". |
| 66 | // |
| 67 | // --prof |
| 68 | // Collect statistical profiling information (ticks), default is off. The |
| 69 | // tick profiler requires code events, so --prof implies --log-code. |
| 70 | |
| 71 | // Forward declarations. |
| 72 | class Ticker; |
| 73 | class Profiler; |
| 74 | class Semaphore; |
| 75 | class SlidingStateWindow; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 76 | class LogMessageBuilder; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 77 | class CompressionHelper; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | |
| 79 | #undef LOG |
| 80 | #ifdef ENABLE_LOGGING_AND_PROFILING |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 81 | #define LOG(Call) \ |
| 82 | do { \ |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 83 | if (v8::internal::Logger::is_logging()) \ |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 84 | v8::internal::Logger::Call; \ |
| 85 | } while (false) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 86 | #else |
| 87 | #define LOG(Call) ((void) 0) |
| 88 | #endif |
| 89 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 90 | #define LOG_EVENTS_AND_TAGS_LIST(V) \ |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 91 | V(CODE_CREATION_EVENT, "code-creation", "cc") \ |
| 92 | V(CODE_MOVE_EVENT, "code-move", "cm") \ |
| 93 | V(CODE_DELETE_EVENT, "code-delete", "cd") \ |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 94 | V(CODE_MOVING_GC, "code-moving-gc", "cg") \ |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 95 | V(FUNCTION_CREATION_EVENT, "function-creation", "fc") \ |
| 96 | V(FUNCTION_MOVE_EVENT, "function-move", "fm") \ |
| 97 | V(FUNCTION_DELETE_EVENT, "function-delete", "fd") \ |
| 98 | V(SNAPSHOT_POSITION_EVENT, "snapshot-pos", "sp") \ |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 99 | V(TICK_EVENT, "tick", "t") \ |
| 100 | V(REPEAT_META_EVENT, "repeat", "r") \ |
| 101 | V(BUILTIN_TAG, "Builtin", "bi") \ |
| 102 | V(CALL_DEBUG_BREAK_TAG, "CallDebugBreak", "cdb") \ |
| 103 | V(CALL_DEBUG_PREPARE_STEP_IN_TAG, "CallDebugPrepareStepIn", "cdbsi") \ |
| 104 | V(CALL_IC_TAG, "CallIC", "cic") \ |
| 105 | V(CALL_INITIALIZE_TAG, "CallInitialize", "ci") \ |
| 106 | V(CALL_MEGAMORPHIC_TAG, "CallMegamorphic", "cmm") \ |
| 107 | V(CALL_MISS_TAG, "CallMiss", "cm") \ |
| 108 | V(CALL_NORMAL_TAG, "CallNormal", "cn") \ |
| 109 | V(CALL_PRE_MONOMORPHIC_TAG, "CallPreMonomorphic", "cpm") \ |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 110 | V(KEYED_CALL_DEBUG_BREAK_TAG, "KeyedCallDebugBreak", "kcdb") \ |
| 111 | V(KEYED_CALL_DEBUG_PREPARE_STEP_IN_TAG, \ |
| 112 | "KeyedCallDebugPrepareStepIn", \ |
| 113 | "kcdbsi") \ |
| 114 | V(KEYED_CALL_IC_TAG, "KeyedCallIC", "kcic") \ |
| 115 | V(KEYED_CALL_INITIALIZE_TAG, "KeyedCallInitialize", "kci") \ |
| 116 | V(KEYED_CALL_MEGAMORPHIC_TAG, "KeyedCallMegamorphic", "kcmm") \ |
| 117 | V(KEYED_CALL_MISS_TAG, "KeyedCallMiss", "kcm") \ |
| 118 | V(KEYED_CALL_NORMAL_TAG, "KeyedCallNormal", "kcn") \ |
| 119 | V(KEYED_CALL_PRE_MONOMORPHIC_TAG, \ |
| 120 | "KeyedCallPreMonomorphic", \ |
| 121 | "kcpm") \ |
ager@chromium.org | 01beca7 | 2009-11-24 14:29:16 +0000 | [diff] [blame] | 122 | V(CALLBACK_TAG, "Callback", "cb") \ |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 123 | V(EVAL_TAG, "Eval", "e") \ |
| 124 | V(FUNCTION_TAG, "Function", "f") \ |
| 125 | V(KEYED_LOAD_IC_TAG, "KeyedLoadIC", "klic") \ |
| 126 | V(KEYED_STORE_IC_TAG, "KeyedStoreIC", "ksic") \ |
| 127 | V(LAZY_COMPILE_TAG, "LazyCompile", "lc") \ |
| 128 | V(LOAD_IC_TAG, "LoadIC", "lic") \ |
| 129 | V(REG_EXP_TAG, "RegExp", "re") \ |
| 130 | V(SCRIPT_TAG, "Script", "sc") \ |
| 131 | V(STORE_IC_TAG, "StoreIC", "sic") \ |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 132 | V(STUB_TAG, "Stub", "s") \ |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 133 | V(NATIVE_FUNCTION_TAG, "Function", "f") \ |
| 134 | V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile", "lc") \ |
| 135 | V(NATIVE_SCRIPT_TAG, "Script", "sc") |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 136 | // Note that 'NATIVE_' cases for functions and scripts are mapped onto |
| 137 | // original tags when writing to the log. |
| 138 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 139 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 140 | class Logger { |
| 141 | public: |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 142 | #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item, |
| 143 | enum LogEventsAndTags { |
| 144 | LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM) |
| 145 | NUMBER_OF_LOG_EVENTS |
| 146 | }; |
| 147 | #undef DECLARE_ENUM |
| 148 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 149 | // Acquires resources for logging if the right flags are set. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 150 | static bool Setup(); |
| 151 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 152 | // Frees resources acquired in Setup. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | static void TearDown(); |
| 154 | |
| 155 | // Enable the computation of a sliding window of states. |
| 156 | static void EnableSlidingStateWindow(); |
| 157 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 158 | // Emits an event with a string value -> (name, value). |
| 159 | static void StringEvent(const char* name, const char* value); |
| 160 | |
| 161 | // Emits an event with an int value -> (name, value). |
| 162 | static void IntEvent(const char* name, int value); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 163 | static void IntPtrTEvent(const char* name, intptr_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 164 | |
| 165 | // Emits an event with an handle value -> (name, location). |
| 166 | static void HandleEvent(const char* name, Object** location); |
| 167 | |
| 168 | // Emits memory management events for C allocated structures. |
| 169 | static void NewEvent(const char* name, void* object, size_t size); |
| 170 | static void DeleteEvent(const char* name, void* object); |
| 171 | |
| 172 | // Emits an event with a tag, and some resource usage information. |
| 173 | // -> (name, tag, <rusage information>). |
| 174 | // Currently, the resource usage information is a process time stamp |
| 175 | // and a real time timestamp. |
| 176 | static void ResourceEvent(const char* name, const char* tag); |
| 177 | |
| 178 | // Emits an event that an undefined property was read from an |
| 179 | // object. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 180 | static void SuspectReadEvent(String* name, Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 181 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 182 | // Emits an event when a message is put on or read from a debugging queue. |
| 183 | // DebugTag lets us put a call-site specific label on the event. |
| 184 | static void DebugTag(const char* call_site_tag); |
| 185 | static void DebugEvent(const char* event_type, Vector<uint16_t> parameter); |
| 186 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | |
| 188 | // ==== Events logged by --log-api. ==== |
| 189 | static void ApiNamedSecurityCheck(Object* key); |
| 190 | static void ApiIndexedSecurityCheck(uint32_t index); |
| 191 | static void ApiNamedPropertyAccess(const char* tag, |
| 192 | JSObject* holder, |
| 193 | Object* name); |
| 194 | static void ApiIndexedPropertyAccess(const char* tag, |
| 195 | JSObject* holder, |
| 196 | uint32_t index); |
| 197 | static void ApiObjectAccess(const char* tag, JSObject* obj); |
| 198 | static void ApiEntryCall(const char* name); |
| 199 | |
| 200 | |
| 201 | // ==== Events logged by --log-code. ==== |
ager@chromium.org | 01beca7 | 2009-11-24 14:29:16 +0000 | [diff] [blame] | 202 | // Emits a code event for a callback function. |
| 203 | static void CallbackEvent(String* name, Address entry_point); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 204 | static void GetterCallbackEvent(String* name, Address entry_point); |
| 205 | static void SetterCallbackEvent(String* name, Address entry_point); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | // Emits a code create event. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 207 | static void CodeCreateEvent(LogEventsAndTags tag, |
| 208 | Code* code, const char* source); |
| 209 | static void CodeCreateEvent(LogEventsAndTags tag, Code* code, String* name); |
| 210 | static void CodeCreateEvent(LogEventsAndTags tag, Code* code, String* name, |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 211 | String* source, int line); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 212 | static void CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 213 | static void CodeMovingGCEvent(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 214 | // Emits a code create event for a RegExp. |
| 215 | static void RegExpCodeCreateEvent(Code* code, String* source); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | // Emits a code move event. |
| 217 | static void CodeMoveEvent(Address from, Address to); |
| 218 | // Emits a code delete event. |
| 219 | static void CodeDeleteEvent(Address from); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 220 | // Emits a function object create event. |
| 221 | static void FunctionCreateEvent(JSFunction* function); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 222 | static void FunctionCreateEventFromMove(JSFunction* function); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 223 | // Emits a function move event. |
| 224 | static void FunctionMoveEvent(Address from, Address to); |
| 225 | // Emits a function delete event. |
| 226 | static void FunctionDeleteEvent(Address from); |
| 227 | |
| 228 | static void SnapshotPositionEvent(Address addr, int pos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 229 | |
| 230 | // ==== Events logged by --log-gc. ==== |
| 231 | // Heap sampling events: start, end, and individual types. |
| 232 | static void HeapSampleBeginEvent(const char* space, const char* kind); |
| 233 | static void HeapSampleEndEvent(const char* space, const char* kind); |
| 234 | static void HeapSampleItemEvent(const char* type, int number, int bytes); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 235 | static void HeapSampleJSConstructorEvent(const char* constructor, |
| 236 | int number, int bytes); |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 237 | static void HeapSampleJSRetainersEvent(const char* constructor, |
| 238 | const char* event); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 239 | static void HeapSampleJSProducerEvent(const char* constructor, |
| 240 | Address* stack); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 241 | static void HeapSampleStats(const char* space, const char* kind, |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 242 | intptr_t capacity, intptr_t used); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | |
| 244 | static void SharedLibraryEvent(const char* library_path, |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 245 | uintptr_t start, |
| 246 | uintptr_t end); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 247 | static void SharedLibraryEvent(const wchar_t* library_path, |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 248 | uintptr_t start, |
| 249 | uintptr_t end); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 250 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 251 | // ==== Events logged by --log-regexp ==== |
| 252 | // Regexp compilation and execution events. |
| 253 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 254 | static void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 255 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 256 | // Log an event reported from generated code |
| 257 | static void LogRuntime(Vector<const char> format, JSArray* args); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 258 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 259 | #ifdef ENABLE_LOGGING_AND_PROFILING |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 260 | static bool is_logging() { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 261 | return logging_nesting_ > 0; |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 262 | } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 263 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 264 | // Pause/Resume collection of profiling data. |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 265 | // When data collection is paused, CPU Tick events are discarded until |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 266 | // data collection is Resumed. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 267 | static void PauseProfiler(int flags, int tag); |
| 268 | static void ResumeProfiler(int flags, int tag); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 269 | static int GetActiveProfilerModules(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 270 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 271 | // If logging is performed into a memory buffer, allows to |
| 272 | // retrieve previously written messages. See v8.h. |
| 273 | static int GetLogLines(int from_pos, char* dest_buf, int max_size); |
| 274 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 275 | // Logs all compiled functions found in the heap. |
| 276 | static void LogCompiledFunctions(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 277 | // Logs all compiled JSFunction objects found in the heap. |
| 278 | static void LogFunctionObjects(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 279 | // Logs all accessor callbacks found in the heap. |
| 280 | static void LogAccessorCallbacks(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 281 | // Used for logging stubs found in the snapshot. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 282 | static void LogCodeObjects(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 283 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 284 | // Converts tag to a corresponding NATIVE_... if the script is native. |
| 285 | INLINE(static LogEventsAndTags ToNativeByScript(LogEventsAndTags, Script*)); |
| 286 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 287 | // Profiler's sampling interval (in milliseconds). |
| 288 | static const int kSamplingIntervalMs = 1; |
| 289 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 290 | private: |
| 291 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 292 | // Size of window used for log records compression. |
| 293 | static const int kCompressionWindowSize = 4; |
| 294 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 295 | // Emits the profiler's first message. |
| 296 | static void ProfilerBeginEvent(); |
| 297 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 298 | // Emits callback event messages. |
| 299 | static void CallbackEventInternal(const char* prefix, |
| 300 | const char* name, |
| 301 | Address entry_point); |
| 302 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 303 | // Internal configurable move event. |
| 304 | static void MoveEventInternal(LogEventsAndTags event, |
| 305 | Address from, |
| 306 | Address to); |
| 307 | |
| 308 | // Internal configurable move event. |
| 309 | static void DeleteEventInternal(LogEventsAndTags event, |
| 310 | Address from); |
| 311 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 312 | // Emits aliases for compressed messages. |
| 313 | static void LogAliases(); |
| 314 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 315 | // Emits the source code of a regexp. Used by regexp events. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 316 | static void LogRegExpSource(Handle<JSRegExp> regexp); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 317 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 318 | // Used for logging stubs found in the snapshot. |
| 319 | static void LogCodeObject(Object* code_object); |
| 320 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 321 | // Emits general information about generated code. |
| 322 | static void LogCodeInfo(); |
| 323 | |
| 324 | // Handles code creation when low-level profiling is active. |
| 325 | static void LowLevelCodeCreateEvent(Code* code, LogMessageBuilder* msg); |
| 326 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 327 | // Emits a profiler tick event. Used by the profiler thread. |
| 328 | static void TickEvent(TickSample* sample, bool overflow); |
| 329 | |
| 330 | static void ApiEvent(const char* name, ...); |
| 331 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 332 | // Logs a StringEvent regardless of whether FLAG_log is true. |
| 333 | static void UncheckedStringEvent(const char* name, const char* value); |
| 334 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 335 | // Logs an IntEvent regardless of whether FLAG_log is true. |
| 336 | static void UncheckedIntEvent(const char* name, int value); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 337 | static void UncheckedIntPtrTEvent(const char* name, intptr_t value); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 338 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 339 | // Stops logging and profiling in case of insufficient resources. |
| 340 | static void StopLoggingAndProfiling(); |
| 341 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 342 | // Returns whether profiler's sampler is active. |
| 343 | static bool IsProfilerSamplerActive(); |
| 344 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 345 | // The sampler used by the profiler and the sliding state window. |
| 346 | static Ticker* ticker_; |
| 347 | |
| 348 | // When the statistical profile is active, profiler_ |
| 349 | // points to a Profiler, that handles collection |
| 350 | // of samples. |
| 351 | static Profiler* profiler_; |
| 352 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 353 | // SlidingStateWindow instance keeping a sliding window of the most |
| 354 | // recent VM states. |
| 355 | static SlidingStateWindow* sliding_state_window_; |
| 356 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 357 | // An array of log events names. |
| 358 | static const char** log_events_; |
| 359 | |
| 360 | // An instance of helper created if log compression is enabled. |
| 361 | static CompressionHelper* compression_helper_; |
| 362 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 363 | // Internal implementation classes with access to |
| 364 | // private members. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 365 | friend class CompressionHelper; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 366 | friend class EventLog; |
| 367 | friend class TimeLog; |
| 368 | friend class Profiler; |
| 369 | friend class SlidingStateWindow; |
ager@chromium.org | 01beca7 | 2009-11-24 14:29:16 +0000 | [diff] [blame] | 370 | friend class StackTracer; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 371 | friend class VMState; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 372 | |
| 373 | friend class LoggerTestHelper; |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 374 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 375 | static int logging_nesting_; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 376 | static int cpu_profiler_nesting_; |
| 377 | static int heap_profiler_nesting_; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 378 | |
| 379 | friend class CpuProfiler; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 380 | #else |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 381 | static bool is_logging() { return false; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 382 | #endif |
| 383 | }; |
| 384 | |
| 385 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 386 | // Class that extracts stack trace, used for profiling. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 387 | class StackTracer : public AllStatic { |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 388 | public: |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 389 | static void Trace(TickSample* sample); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 390 | }; |
| 391 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 392 | } } // namespace v8::internal |
| 393 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 394 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 395 | #endif // V8_LOG_H_ |