ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1 | // Copyright 2011 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 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 32 | #include "platform.h" |
| 33 | #include "log-utils.h" |
| 34 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 35 | namespace v8 { |
| 36 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | |
| 38 | // Logger is used for collecting logging information from V8 during |
| 39 | // execution. The result is dumped to a file. |
| 40 | // |
| 41 | // Available command line flags: |
| 42 | // |
| 43 | // --log |
| 44 | // Minimal logging (no API, code, or GC sample events), default is off. |
| 45 | // |
| 46 | // --log-all |
| 47 | // 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] | 48 | // --log-api, --log-code, --log-gc, and --log-regexp. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 49 | // |
| 50 | // --log-api |
| 51 | // Log API events to the logfile, default is off. --log-api implies --log. |
| 52 | // |
| 53 | // --log-code |
| 54 | // Log code (create, move, and delete) events to the logfile, default is off. |
| 55 | // --log-code implies --log. |
| 56 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | // --log-gc |
| 58 | // Log GC heap samples after each GC that can be processed by hp2ps, default |
| 59 | // is off. --log-gc implies --log. |
| 60 | // |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 61 | // --log-regexp |
| 62 | // Log creation and use of regular expressions, Default is off. |
| 63 | // --log-regexp implies --log. |
| 64 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | // --logfile <filename> |
| 66 | // Specify the name of the logfile, default is "v8.log". |
| 67 | // |
| 68 | // --prof |
| 69 | // Collect statistical profiling information (ticks), default is off. The |
| 70 | // tick profiler requires code events, so --prof implies --log-code. |
| 71 | |
| 72 | // Forward declarations. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 73 | class HashMap; |
| 74 | class LogMessageBuilder; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 75 | class Profiler; |
| 76 | class Semaphore; |
| 77 | class SlidingStateWindow; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 78 | class Ticker; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 79 | |
| 80 | #undef LOG |
| 81 | #ifdef ENABLE_LOGGING_AND_PROFILING |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 82 | #define LOG(isolate, Call) \ |
| 83 | do { \ |
| 84 | v8::internal::Logger* logger = \ |
| 85 | (isolate)->logger(); \ |
| 86 | if (logger->is_logging()) \ |
| 87 | logger->Call; \ |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 88 | } while (false) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | #else |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 90 | #define LOG(isolate, Call) ((void) 0) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 91 | #endif |
| 92 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 93 | #define LOG_EVENTS_AND_TAGS_LIST(V) \ |
| 94 | V(CODE_CREATION_EVENT, "code-creation") \ |
| 95 | V(CODE_MOVE_EVENT, "code-move") \ |
| 96 | V(CODE_DELETE_EVENT, "code-delete") \ |
| 97 | V(CODE_MOVING_GC, "code-moving-gc") \ |
| 98 | V(SHARED_FUNC_MOVE_EVENT, "sfi-move") \ |
| 99 | V(SNAPSHOT_POSITION_EVENT, "snapshot-pos") \ |
| 100 | V(SNAPSHOT_CODE_NAME_EVENT, "snapshot-code-name") \ |
| 101 | V(TICK_EVENT, "tick") \ |
| 102 | V(REPEAT_META_EVENT, "repeat") \ |
| 103 | V(BUILTIN_TAG, "Builtin") \ |
| 104 | V(CALL_DEBUG_BREAK_TAG, "CallDebugBreak") \ |
| 105 | V(CALL_DEBUG_PREPARE_STEP_IN_TAG, "CallDebugPrepareStepIn") \ |
| 106 | V(CALL_IC_TAG, "CallIC") \ |
| 107 | V(CALL_INITIALIZE_TAG, "CallInitialize") \ |
| 108 | V(CALL_MEGAMORPHIC_TAG, "CallMegamorphic") \ |
| 109 | V(CALL_MISS_TAG, "CallMiss") \ |
| 110 | V(CALL_NORMAL_TAG, "CallNormal") \ |
| 111 | V(CALL_PRE_MONOMORPHIC_TAG, "CallPreMonomorphic") \ |
| 112 | V(KEYED_CALL_DEBUG_BREAK_TAG, "KeyedCallDebugBreak") \ |
| 113 | V(KEYED_CALL_DEBUG_PREPARE_STEP_IN_TAG, \ |
| 114 | "KeyedCallDebugPrepareStepIn") \ |
| 115 | V(KEYED_CALL_IC_TAG, "KeyedCallIC") \ |
| 116 | V(KEYED_CALL_INITIALIZE_TAG, "KeyedCallInitialize") \ |
| 117 | V(KEYED_CALL_MEGAMORPHIC_TAG, "KeyedCallMegamorphic") \ |
| 118 | V(KEYED_CALL_MISS_TAG, "KeyedCallMiss") \ |
| 119 | V(KEYED_CALL_NORMAL_TAG, "KeyedCallNormal") \ |
| 120 | V(KEYED_CALL_PRE_MONOMORPHIC_TAG, "KeyedCallPreMonomorphic") \ |
| 121 | V(CALLBACK_TAG, "Callback") \ |
| 122 | V(EVAL_TAG, "Eval") \ |
| 123 | V(FUNCTION_TAG, "Function") \ |
| 124 | V(KEYED_LOAD_IC_TAG, "KeyedLoadIC") \ |
| 125 | V(KEYED_LOAD_MEGAMORPHIC_IC_TAG, "KeyedLoadMegamorphicIC") \ |
| 126 | V(KEYED_EXTERNAL_ARRAY_LOAD_IC_TAG, "KeyedExternalArrayLoadIC") \ |
| 127 | V(KEYED_STORE_IC_TAG, "KeyedStoreIC") \ |
| 128 | V(KEYED_STORE_MEGAMORPHIC_IC_TAG, "KeyedStoreMegamorphicIC") \ |
| 129 | V(KEYED_EXTERNAL_ARRAY_STORE_IC_TAG, "KeyedExternalArrayStoreIC") \ |
| 130 | V(LAZY_COMPILE_TAG, "LazyCompile") \ |
| 131 | V(LOAD_IC_TAG, "LoadIC") \ |
| 132 | V(REG_EXP_TAG, "RegExp") \ |
| 133 | V(SCRIPT_TAG, "Script") \ |
| 134 | V(STORE_IC_TAG, "StoreIC") \ |
| 135 | V(STUB_TAG, "Stub") \ |
| 136 | V(NATIVE_FUNCTION_TAG, "Function") \ |
| 137 | V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile") \ |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 138 | V(NATIVE_SCRIPT_TAG, "Script") |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 139 | // Note that 'NATIVE_' cases for functions and scripts are mapped onto |
| 140 | // original tags when writing to the log. |
| 141 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 142 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 143 | class Sampler; |
| 144 | |
| 145 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 146 | class Logger { |
| 147 | public: |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 148 | #define DECLARE_ENUM(enum_item, ignore) enum_item, |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 149 | enum LogEventsAndTags { |
| 150 | LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM) |
| 151 | NUMBER_OF_LOG_EVENTS |
| 152 | }; |
| 153 | #undef DECLARE_ENUM |
| 154 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 155 | // Acquires resources for logging if the right flags are set. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 156 | bool Setup(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 157 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 158 | void EnsureTickerStarted(); |
| 159 | void EnsureTickerStopped(); |
| 160 | |
| 161 | Sampler* sampler(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 162 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 163 | // Frees resources acquired in Setup. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 164 | void TearDown(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 165 | |
| 166 | // Enable the computation of a sliding window of states. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 167 | void EnableSlidingStateWindow(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 168 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 169 | // Emits an event with a string value -> (name, value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 170 | void StringEvent(const char* name, const char* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 171 | |
| 172 | // Emits an event with an int value -> (name, value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 173 | void IntEvent(const char* name, int value); |
| 174 | void IntPtrTEvent(const char* name, intptr_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 175 | |
| 176 | // Emits an event with an handle value -> (name, location). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 177 | void HandleEvent(const char* name, Object** location); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 178 | |
| 179 | // Emits memory management events for C allocated structures. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 180 | void NewEvent(const char* name, void* object, size_t size); |
| 181 | void DeleteEvent(const char* name, void* object); |
| 182 | |
| 183 | // Static versions of the above, operate on current isolate's logger. |
| 184 | // Used in TRACK_MEMORY(TypeName) defined in globals.h |
| 185 | static void NewEventStatic(const char* name, void* object, size_t size); |
| 186 | static void DeleteEventStatic(const char* name, void* object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | |
| 188 | // Emits an event with a tag, and some resource usage information. |
| 189 | // -> (name, tag, <rusage information>). |
| 190 | // Currently, the resource usage information is a process time stamp |
| 191 | // and a real time timestamp. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 192 | void ResourceEvent(const char* name, const char* tag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | |
| 194 | // Emits an event that an undefined property was read from an |
| 195 | // object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 196 | void SuspectReadEvent(String* name, Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 197 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 198 | // Emits an event when a message is put on or read from a debugging queue. |
| 199 | // DebugTag lets us put a call-site specific label on the event. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 200 | void DebugTag(const char* call_site_tag); |
| 201 | void DebugEvent(const char* event_type, Vector<uint16_t> parameter); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 202 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 203 | |
| 204 | // ==== Events logged by --log-api. ==== |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 205 | void ApiNamedSecurityCheck(Object* key); |
| 206 | void ApiIndexedSecurityCheck(uint32_t index); |
| 207 | void ApiNamedPropertyAccess(const char* tag, JSObject* holder, Object* name); |
| 208 | void ApiIndexedPropertyAccess(const char* tag, |
| 209 | JSObject* holder, |
| 210 | uint32_t index); |
| 211 | void ApiObjectAccess(const char* tag, JSObject* obj); |
| 212 | void ApiEntryCall(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 213 | |
| 214 | |
| 215 | // ==== Events logged by --log-code. ==== |
ager@chromium.org | 01beca7 | 2009-11-24 14:29:16 +0000 | [diff] [blame] | 216 | // Emits a code event for a callback function. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 217 | void CallbackEvent(String* name, Address entry_point); |
| 218 | void GetterCallbackEvent(String* name, Address entry_point); |
| 219 | void SetterCallbackEvent(String* name, Address entry_point); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 220 | // Emits a code create event. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 221 | void CodeCreateEvent(LogEventsAndTags tag, |
| 222 | Code* code, const char* source); |
| 223 | void CodeCreateEvent(LogEventsAndTags tag, |
| 224 | Code* code, String* name); |
| 225 | void CodeCreateEvent(LogEventsAndTags tag, |
| 226 | Code* code, |
| 227 | SharedFunctionInfo* shared, |
| 228 | String* name); |
| 229 | void CodeCreateEvent(LogEventsAndTags tag, |
| 230 | Code* code, |
| 231 | SharedFunctionInfo* shared, |
| 232 | String* source, int line); |
| 233 | void CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count); |
| 234 | void CodeMovingGCEvent(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 235 | // Emits a code create event for a RegExp. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 236 | void RegExpCodeCreateEvent(Code* code, String* source); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 237 | // Emits a code move event. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 238 | void CodeMoveEvent(Address from, Address to); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 239 | // Emits a code delete event. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 240 | void CodeDeleteEvent(Address from); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 241 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 242 | void SharedFunctionInfoMoveEvent(Address from, Address to); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 243 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 244 | void SnapshotPositionEvent(Address addr, int pos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 245 | |
| 246 | // ==== Events logged by --log-gc. ==== |
| 247 | // Heap sampling events: start, end, and individual types. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 248 | void HeapSampleBeginEvent(const char* space, const char* kind); |
| 249 | void HeapSampleEndEvent(const char* space, const char* kind); |
| 250 | void HeapSampleItemEvent(const char* type, int number, int bytes); |
| 251 | void HeapSampleJSConstructorEvent(const char* constructor, |
| 252 | int number, int bytes); |
| 253 | void HeapSampleJSRetainersEvent(const char* constructor, |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 254 | const char* event); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 255 | void HeapSampleJSProducerEvent(const char* constructor, |
| 256 | Address* stack); |
| 257 | void HeapSampleStats(const char* space, const char* kind, |
| 258 | intptr_t capacity, intptr_t used); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 259 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 260 | void SharedLibraryEvent(const char* library_path, |
| 261 | uintptr_t start, |
| 262 | uintptr_t end); |
| 263 | void SharedLibraryEvent(const wchar_t* library_path, |
| 264 | uintptr_t start, |
| 265 | uintptr_t end); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 266 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 267 | // ==== Events logged by --log-regexp ==== |
| 268 | // Regexp compilation and execution events. |
| 269 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 270 | void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 271 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 272 | // Log an event reported from generated code |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 273 | void LogRuntime(Vector<const char> format, JSArray* args); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 274 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 275 | #ifdef ENABLE_LOGGING_AND_PROFILING |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 276 | bool is_logging() { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 277 | return logging_nesting_ > 0; |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 278 | } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 279 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 280 | // Pause/Resume collection of profiling data. |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 281 | // When data collection is paused, CPU Tick events are discarded until |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 282 | // data collection is Resumed. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame^] | 283 | void PauseProfiler(); |
| 284 | void ResumeProfiler(); |
| 285 | bool IsProfilerPaused(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 286 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 287 | // If logging is performed into a memory buffer, allows to |
| 288 | // retrieve previously written messages. See v8.h. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 289 | int GetLogLines(int from_pos, char* dest_buf, int max_size); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 290 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 291 | // Logs all compiled functions found in the heap. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 292 | void LogCompiledFunctions(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 293 | // Logs all accessor callbacks found in the heap. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 294 | void LogAccessorCallbacks(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 295 | // Used for logging stubs found in the snapshot. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 296 | void LogCodeObjects(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 297 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 298 | // Converts tag to a corresponding NATIVE_... if the script is native. |
| 299 | INLINE(static LogEventsAndTags ToNativeByScript(LogEventsAndTags, Script*)); |
| 300 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 301 | // Profiler's sampling interval (in milliseconds). |
| 302 | static const int kSamplingIntervalMs = 1; |
| 303 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 304 | // Callback from Log, stops profiling in case of insufficient resources. |
| 305 | void LogFailure(); |
| 306 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 307 | private: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 308 | class NameBuffer; |
| 309 | class NameMap; |
| 310 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 311 | Logger(); |
| 312 | ~Logger(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 313 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 314 | // Emits the profiler's first message. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 315 | void ProfilerBeginEvent(); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 316 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 317 | // Emits callback event messages. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 318 | void CallbackEventInternal(const char* prefix, |
| 319 | const char* name, |
| 320 | Address entry_point); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 321 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 322 | // Internal configurable move event. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 323 | void MoveEventInternal(LogEventsAndTags event, Address from, Address to); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 324 | |
| 325 | // Internal configurable move event. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 326 | void DeleteEventInternal(LogEventsAndTags event, Address from); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 327 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 328 | // Emits the source code of a regexp. Used by regexp events. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 329 | void LogRegExpSource(Handle<JSRegExp> regexp); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 330 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 331 | // Used for logging stubs found in the snapshot. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 332 | void LogCodeObject(Object* code_object); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 333 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 334 | // Emits general information about generated code. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 335 | void LogCodeInfo(); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 336 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 337 | void RegisterSnapshotCodeName(Code* code, const char* name, int name_size); |
| 338 | |
| 339 | // Low-level logging support. |
| 340 | |
| 341 | void LowLevelCodeCreateEvent(Code* code, const char* name, int name_size); |
| 342 | |
| 343 | void LowLevelCodeMoveEvent(Address from, Address to); |
| 344 | |
| 345 | void LowLevelCodeDeleteEvent(Address from); |
| 346 | |
| 347 | void LowLevelSnapshotPositionEvent(Address addr, int pos); |
| 348 | |
| 349 | void LowLevelLogWriteBytes(const char* bytes, int size); |
| 350 | |
| 351 | template <typename T> |
| 352 | void LowLevelLogWriteStruct(const T& s) { |
| 353 | char tag = T::kTag; |
| 354 | LowLevelLogWriteBytes(reinterpret_cast<const char*>(&tag), sizeof(tag)); |
| 355 | LowLevelLogWriteBytes(reinterpret_cast<const char*>(&s), sizeof(s)); |
| 356 | } |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 357 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 358 | // Emits a profiler tick event. Used by the profiler thread. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 359 | void TickEvent(TickSample* sample, bool overflow); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 360 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 361 | void ApiEvent(const char* name, ...); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 362 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 363 | // Logs a StringEvent regardless of whether FLAG_log is true. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 364 | void UncheckedStringEvent(const char* name, const char* value); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 365 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 366 | // Logs an IntEvent regardless of whether FLAG_log is true. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 367 | void UncheckedIntEvent(const char* name, int value); |
| 368 | void UncheckedIntPtrTEvent(const char* name, intptr_t value); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 369 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 370 | // Returns whether profiler's sampler is active. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 371 | bool IsProfilerSamplerActive(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 372 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 373 | // The sampler used by the profiler and the sliding state window. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 374 | Ticker* ticker_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 375 | |
| 376 | // When the statistical profile is active, profiler_ |
| 377 | // points to a Profiler, that handles collection |
| 378 | // of samples. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 379 | Profiler* profiler_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 380 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 381 | // SlidingStateWindow instance keeping a sliding window of the most |
| 382 | // recent VM states. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 383 | SlidingStateWindow* sliding_state_window_; |
| 384 | |
| 385 | // An array of log events names. |
| 386 | const char* const* log_events_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 387 | |
| 388 | // Internal implementation classes with access to |
| 389 | // private members. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 390 | friend class EventLog; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 391 | friend class Isolate; |
| 392 | friend class LogMessageBuilder; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 393 | friend class TimeLog; |
| 394 | friend class Profiler; |
| 395 | friend class SlidingStateWindow; |
ager@chromium.org | 01beca7 | 2009-11-24 14:29:16 +0000 | [diff] [blame] | 396 | friend class StackTracer; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 397 | friend class VMState; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 398 | |
| 399 | friend class LoggerTestHelper; |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 400 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 401 | |
| 402 | int logging_nesting_; |
| 403 | int cpu_profiler_nesting_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 404 | |
| 405 | Log* log_; |
| 406 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 407 | NameBuffer* name_buffer_; |
| 408 | |
| 409 | NameMap* address_to_name_map_; |
| 410 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 411 | // Guards against multiple calls to TearDown() that can happen in some tests. |
| 412 | // 'true' between Setup() and TearDown(). |
| 413 | bool is_initialized_; |
| 414 | |
| 415 | // Support for 'incremental addresses' in compressed logs: |
| 416 | // LogMessageBuilder::AppendAddress(Address addr) |
| 417 | Address last_address_; |
| 418 | // Logger::TickEvent(...) |
| 419 | Address prev_sp_; |
| 420 | Address prev_function_; |
| 421 | // Logger::MoveEventInternal(...) |
| 422 | Address prev_to_; |
| 423 | // Logger::FunctionCreateEvent(...) |
| 424 | Address prev_code_; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 425 | |
| 426 | friend class CpuProfiler; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 427 | #else |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 428 | bool is_logging() { return false; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 429 | #endif |
| 430 | }; |
| 431 | |
| 432 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 433 | // Process wide registry of samplers. |
| 434 | class SamplerRegistry : public AllStatic { |
| 435 | public: |
| 436 | enum State { |
| 437 | HAS_NO_SAMPLERS, |
| 438 | HAS_SAMPLERS, |
| 439 | HAS_CPU_PROFILING_SAMPLERS |
| 440 | }; |
| 441 | |
| 442 | typedef void (*VisitSampler)(Sampler*, void*); |
| 443 | |
| 444 | static State GetState(); |
| 445 | |
| 446 | // Iterates over all active samplers keeping the internal lock held. |
| 447 | // Returns whether there are any active samplers. |
| 448 | static bool IterateActiveSamplers(VisitSampler func, void* param); |
| 449 | |
| 450 | // Adds/Removes an active sampler. |
| 451 | static void AddActiveSampler(Sampler* sampler); |
| 452 | static void RemoveActiveSampler(Sampler* sampler); |
| 453 | |
| 454 | private: |
| 455 | static bool ActiveSamplersExist() { |
| 456 | return active_samplers_ != NULL && !active_samplers_->is_empty(); |
| 457 | } |
| 458 | |
| 459 | static Mutex* mutex_; // Protects the state below. |
| 460 | static List<Sampler*>* active_samplers_; |
| 461 | |
| 462 | DISALLOW_IMPLICIT_CONSTRUCTORS(SamplerRegistry); |
| 463 | }; |
| 464 | |
| 465 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 466 | // Class that extracts stack trace, used for profiling. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 467 | class StackTracer : public AllStatic { |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 468 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 469 | static void Trace(Isolate* isolate, TickSample* sample); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 470 | }; |
| 471 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 472 | } } // namespace v8::internal |
| 473 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 474 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | #endif // V8_LOG_H_ |