Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_LOG_H_ |
| 6 | #define V8_LOG_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include <string> |
| 9 | |
| 10 | #include "src/allocation.h" |
| 11 | #include "src/base/platform/elapsed-timer.h" |
| 12 | #include "src/base/platform/platform.h" |
| 13 | #include "src/objects.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 14 | |
| 15 | namespace v8 { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 16 | |
| 17 | namespace base { |
| 18 | class Semaphore; |
| 19 | } |
| 20 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 21 | namespace internal { |
| 22 | |
| 23 | // Logger is used for collecting logging information from V8 during |
| 24 | // execution. The result is dumped to a file. |
| 25 | // |
| 26 | // Available command line flags: |
| 27 | // |
| 28 | // --log |
| 29 | // Minimal logging (no API, code, or GC sample events), default is off. |
| 30 | // |
| 31 | // --log-all |
| 32 | // Log all events to the file, default is off. This is the same as combining |
| 33 | // --log-api, --log-code, --log-gc, and --log-regexp. |
| 34 | // |
| 35 | // --log-api |
| 36 | // Log API events to the logfile, default is off. --log-api implies --log. |
| 37 | // |
| 38 | // --log-code |
| 39 | // Log code (create, move, and delete) events to the logfile, default is off. |
| 40 | // --log-code implies --log. |
| 41 | // |
| 42 | // --log-gc |
| 43 | // Log GC heap samples after each GC that can be processed by hp2ps, default |
| 44 | // is off. --log-gc implies --log. |
| 45 | // |
| 46 | // --log-regexp |
| 47 | // Log creation and use of regular expressions, Default is off. |
| 48 | // --log-regexp implies --log. |
| 49 | // |
| 50 | // --logfile <filename> |
| 51 | // Specify the name of the logfile, default is "v8.log". |
| 52 | // |
| 53 | // --prof |
| 54 | // Collect statistical profiling information (ticks), default is off. The |
| 55 | // tick profiler requires code events, so --prof implies --log-code. |
| 56 | |
| 57 | // Forward declarations. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 58 | class CodeEventListener; |
| 59 | class CompilationInfo; |
| 60 | class CpuProfiler; |
| 61 | class Isolate; |
| 62 | class Log; |
| 63 | class PositionsRecorder; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 64 | class Profiler; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 65 | class Ticker; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 66 | struct TickSample; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 67 | |
| 68 | #undef LOG |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 69 | #define LOG(isolate, Call) \ |
| 70 | do { \ |
| 71 | v8::internal::Logger* logger = \ |
| 72 | (isolate)->logger(); \ |
| 73 | if (logger->is_logging()) \ |
| 74 | logger->Call; \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 75 | } while (false) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 76 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 77 | #define LOG_CODE_EVENT(isolate, Call) \ |
| 78 | do { \ |
| 79 | v8::internal::Logger* logger = \ |
| 80 | (isolate)->logger(); \ |
| 81 | if (logger->is_logging_code_events()) \ |
| 82 | logger->Call; \ |
| 83 | } while (false) |
| 84 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 85 | #define LOG_EVENTS_AND_TAGS_LIST(V) \ |
| 86 | V(CODE_CREATION_EVENT, "code-creation") \ |
| 87 | V(CODE_DISABLE_OPT_EVENT, "code-disable-optimization") \ |
| 88 | V(CODE_MOVE_EVENT, "code-move") \ |
| 89 | V(CODE_DELETE_EVENT, "code-delete") \ |
| 90 | V(CODE_MOVING_GC, "code-moving-gc") \ |
| 91 | V(SHARED_FUNC_MOVE_EVENT, "sfi-move") \ |
| 92 | V(SNAPSHOT_CODE_NAME_EVENT, "snapshot-code-name") \ |
| 93 | V(TICK_EVENT, "tick") \ |
| 94 | V(REPEAT_META_EVENT, "repeat") \ |
| 95 | V(BUILTIN_TAG, "Builtin") \ |
| 96 | V(CALL_DEBUG_BREAK_TAG, "CallDebugBreak") \ |
| 97 | V(CALL_DEBUG_PREPARE_STEP_IN_TAG, "CallDebugPrepareStepIn") \ |
| 98 | V(CALL_INITIALIZE_TAG, "CallInitialize") \ |
| 99 | V(CALL_MEGAMORPHIC_TAG, "CallMegamorphic") \ |
| 100 | V(CALL_MISS_TAG, "CallMiss") \ |
| 101 | V(CALL_NORMAL_TAG, "CallNormal") \ |
| 102 | V(CALL_PRE_MONOMORPHIC_TAG, "CallPreMonomorphic") \ |
| 103 | V(LOAD_INITIALIZE_TAG, "LoadInitialize") \ |
| 104 | V(LOAD_PREMONOMORPHIC_TAG, "LoadPreMonomorphic") \ |
| 105 | V(LOAD_MEGAMORPHIC_TAG, "LoadMegamorphic") \ |
| 106 | V(STORE_INITIALIZE_TAG, "StoreInitialize") \ |
| 107 | V(STORE_PREMONOMORPHIC_TAG, "StorePreMonomorphic") \ |
| 108 | V(STORE_GENERIC_TAG, "StoreGeneric") \ |
| 109 | V(STORE_MEGAMORPHIC_TAG, "StoreMegamorphic") \ |
| 110 | V(KEYED_CALL_DEBUG_BREAK_TAG, "KeyedCallDebugBreak") \ |
| 111 | V(KEYED_CALL_DEBUG_PREPARE_STEP_IN_TAG, "KeyedCallDebugPrepareStepIn") \ |
| 112 | V(KEYED_CALL_INITIALIZE_TAG, "KeyedCallInitialize") \ |
| 113 | V(KEYED_CALL_MEGAMORPHIC_TAG, "KeyedCallMegamorphic") \ |
| 114 | V(KEYED_CALL_MISS_TAG, "KeyedCallMiss") \ |
| 115 | V(KEYED_CALL_NORMAL_TAG, "KeyedCallNormal") \ |
| 116 | V(KEYED_CALL_PRE_MONOMORPHIC_TAG, "KeyedCallPreMonomorphic") \ |
| 117 | V(CALLBACK_TAG, "Callback") \ |
| 118 | V(EVAL_TAG, "Eval") \ |
| 119 | V(FUNCTION_TAG, "Function") \ |
| 120 | V(HANDLER_TAG, "Handler") \ |
| 121 | V(BYTECODE_HANDLER_TAG, "BytecodeHandler") \ |
| 122 | V(KEYED_LOAD_IC_TAG, "KeyedLoadIC") \ |
| 123 | V(KEYED_LOAD_POLYMORPHIC_IC_TAG, "KeyedLoadPolymorphicIC") \ |
| 124 | V(KEYED_EXTERNAL_ARRAY_LOAD_IC_TAG, "KeyedExternalArrayLoadIC") \ |
| 125 | V(KEYED_STORE_IC_TAG, "KeyedStoreIC") \ |
| 126 | V(KEYED_STORE_POLYMORPHIC_IC_TAG, "KeyedStorePolymorphicIC") \ |
| 127 | V(KEYED_EXTERNAL_ARRAY_STORE_IC_TAG, "KeyedExternalArrayStoreIC") \ |
| 128 | V(LAZY_COMPILE_TAG, "LazyCompile") \ |
| 129 | V(CALL_IC_TAG, "CallIC") \ |
| 130 | V(LOAD_IC_TAG, "LoadIC") \ |
| 131 | V(LOAD_POLYMORPHIC_IC_TAG, "LoadPolymorphicIC") \ |
| 132 | V(REG_EXP_TAG, "RegExp") \ |
| 133 | V(SCRIPT_TAG, "Script") \ |
| 134 | V(STORE_IC_TAG, "StoreIC") \ |
| 135 | V(STORE_POLYMORPHIC_IC_TAG, "StorePolymorphicIC") \ |
| 136 | V(STUB_TAG, "Stub") \ |
| 137 | V(NATIVE_FUNCTION_TAG, "Function") \ |
| 138 | V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile") \ |
| 139 | V(NATIVE_SCRIPT_TAG, "Script") |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 140 | // Note that 'NATIVE_' cases for functions and scripts are mapped onto |
| 141 | // original tags when writing to the log. |
| 142 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 143 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 144 | class JitLogger; |
| 145 | class PerfBasicLogger; |
| 146 | class LowLevelLogger; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 147 | class PerfJitLogger; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 148 | class Sampler; |
| 149 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 150 | class Logger { |
| 151 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 152 | enum StartEnd { START = 0, END = 1 }; |
| 153 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 154 | #define DECLARE_ENUM(enum_item, ignore) enum_item, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 155 | enum LogEventsAndTags { |
| 156 | LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM) |
| 157 | NUMBER_OF_LOG_EVENTS |
| 158 | }; |
| 159 | #undef DECLARE_ENUM |
| 160 | |
| 161 | // Acquires resources for logging if the right flags are set. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 162 | bool SetUp(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 163 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 164 | // Sets the current code event handler. |
| 165 | void SetCodeEventHandler(uint32_t options, |
| 166 | JitCodeEventHandler event_handler); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 167 | |
| 168 | Sampler* sampler(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 169 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 170 | // Frees resources acquired in SetUp. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 171 | // When a temporary file is used for the log, returns its stream descriptor, |
| 172 | // leaving the file open. |
| 173 | FILE* TearDown(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 174 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 175 | // Emits an event with a string value -> (name, value). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 176 | void StringEvent(const char* name, const char* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 177 | |
| 178 | // Emits an event with an int value -> (name, value). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 179 | void IntEvent(const char* name, int value); |
| 180 | void IntPtrTEvent(const char* name, intptr_t value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 181 | |
| 182 | // Emits an event with an handle value -> (name, location). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 183 | void HandleEvent(const char* name, Object** location); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 184 | |
| 185 | // Emits memory management events for C allocated structures. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 186 | void NewEvent(const char* name, void* object, size_t size); |
| 187 | void DeleteEvent(const char* name, void* object); |
| 188 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 189 | // Emits an event with a tag, and some resource usage information. |
| 190 | // -> (name, tag, <rusage information>). |
| 191 | // Currently, the resource usage information is a process time stamp |
| 192 | // and a real time timestamp. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 193 | void ResourceEvent(const char* name, const char* tag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 194 | |
| 195 | // Emits an event that an undefined property was read from an |
| 196 | // object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 197 | void SuspectReadEvent(Name* name, Object* obj); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 198 | |
| 199 | // Emits an event when a message is put on or read from a debugging queue. |
| 200 | // DebugTag lets us put a call-site specific label on the event. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 201 | void DebugTag(const char* call_site_tag); |
| 202 | void DebugEvent(const char* event_type, Vector<uint16_t> parameter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 203 | |
| 204 | |
| 205 | // ==== Events logged by --log-api. ==== |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 206 | void ApiSecurityCheck(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 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); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 213 | |
| 214 | |
| 215 | // ==== Events logged by --log-code. ==== |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 216 | void addCodeEventListener(CodeEventListener* listener); |
| 217 | void removeCodeEventListener(CodeEventListener* listener); |
| 218 | bool hasCodeEventListener(CodeEventListener* listener); |
| 219 | |
| 220 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 221 | // Emits a code event for a callback function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 222 | void CallbackEvent(Name* name, Address entry_point); |
| 223 | void GetterCallbackEvent(Name* name, Address entry_point); |
| 224 | void SetterCallbackEvent(Name* name, Address entry_point); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 225 | // Emits a code create event. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 226 | void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
| 227 | const char* source); |
| 228 | void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, Name* name); |
| 229 | void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
| 230 | SharedFunctionInfo* shared, CompilationInfo* info, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 231 | Name* name); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 232 | void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
| 233 | SharedFunctionInfo* shared, CompilationInfo* info, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 234 | Name* source, int line, int column); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 235 | void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
| 236 | int args_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 237 | // Emits a code deoptimization event. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 238 | void CodeDisableOptEvent(AbstractCode* code, SharedFunctionInfo* shared); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 239 | void CodeMovingGCEvent(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 240 | // Emits a code create event for a RegExp. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 241 | void RegExpCodeCreateEvent(AbstractCode* code, String* source); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 242 | // Emits a code move event. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 243 | void CodeMoveEvent(AbstractCode* from, Address to); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 244 | // Emits a code line info add event with Postion type. |
| 245 | void CodeLinePosInfoAddPositionEvent(void* jit_handler_data, |
| 246 | int pc_offset, |
| 247 | int position); |
| 248 | // Emits a code line info add event with StatementPostion type. |
| 249 | void CodeLinePosInfoAddStatementPositionEvent(void* jit_handler_data, |
| 250 | int pc_offset, |
| 251 | int position); |
| 252 | // Emits a code line info start to record event |
| 253 | void CodeStartLinePosInfoRecordEvent(PositionsRecorder* pos_recorder); |
| 254 | // Emits a code line info finish record event. |
| 255 | // It's the callee's responsibility to dispose the parameter jit_handler_data. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 256 | void CodeEndLinePosInfoRecordEvent(AbstractCode* code, |
| 257 | void* jit_handler_data); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 258 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 259 | void SharedFunctionInfoMoveEvent(Address from, Address to); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 260 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 261 | void CodeNameEvent(Address addr, int pos, const char* code_name); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 262 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 263 | // ==== Events logged by --log-gc. ==== |
| 264 | // Heap sampling events: start, end, and individual types. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 265 | void HeapSampleBeginEvent(const char* space, const char* kind); |
| 266 | void HeapSampleEndEvent(const char* space, const char* kind); |
| 267 | void HeapSampleItemEvent(const char* type, int number, int bytes); |
| 268 | void HeapSampleJSConstructorEvent(const char* constructor, |
| 269 | int number, int bytes); |
| 270 | void HeapSampleJSRetainersEvent(const char* constructor, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 271 | const char* event); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 272 | void HeapSampleJSProducerEvent(const char* constructor, |
| 273 | Address* stack); |
| 274 | void HeapSampleStats(const char* space, const char* kind, |
| 275 | intptr_t capacity, intptr_t used); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 276 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 277 | void SharedLibraryEvent(const std::string& library_path, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 278 | uintptr_t start, |
| 279 | uintptr_t end); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 280 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 281 | void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 282 | void CurrentTimeEvent(); |
| 283 | |
| 284 | void TimerEvent(StartEnd se, const char* name); |
| 285 | |
| 286 | static void EnterExternal(Isolate* isolate); |
| 287 | static void LeaveExternal(Isolate* isolate); |
| 288 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 289 | static void DefaultEventLoggerSentinel(const char* name, int event) {} |
| 290 | |
| 291 | INLINE(static void CallEventLogger(Isolate* isolate, const char* name, |
| 292 | StartEnd se, bool expose_to_api)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 293 | |
| 294 | // ==== Events logged by --log-regexp ==== |
| 295 | // Regexp compilation and execution events. |
| 296 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 297 | void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 298 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 299 | bool is_logging() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 300 | return is_logging_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 303 | bool is_logging_code_events() { |
| 304 | return is_logging() || jit_logger_ != NULL; |
| 305 | } |
| 306 | |
| 307 | // Stop collection of profiling data. |
| 308 | // When data collection is paused, CPU Tick events are discarded. |
| 309 | void StopProfiler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 310 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 311 | void LogExistingFunction(Handle<SharedFunctionInfo> shared, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 312 | Handle<AbstractCode> code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | // Logs all compiled functions found in the heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 314 | void LogCompiledFunctions(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 315 | // Logs all accessor callbacks found in the heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 316 | void LogAccessorCallbacks(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 317 | // Used for logging stubs found in the snapshot. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 318 | void LogCodeObjects(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 319 | // Used for logging bytecode handlers found in the snapshot. |
| 320 | void LogBytecodeHandlers(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 321 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 322 | // Converts tag to a corresponding NATIVE_... if the script is native. |
| 323 | INLINE(static LogEventsAndTags ToNativeByScript(LogEventsAndTags, Script*)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 324 | |
| 325 | // Profiler's sampling interval (in milliseconds). |
Ben Murdoch | 7549248 | 2011-12-01 11:18:12 +0000 | [diff] [blame] | 326 | #if defined(ANDROID) |
| 327 | // Phones and tablets have processors that are much slower than desktop |
| 328 | // and laptop computers for which current heuristics are tuned. |
| 329 | static const int kSamplingIntervalMs = 5; |
| 330 | #else |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 331 | static const int kSamplingIntervalMs = 1; |
Ben Murdoch | 7549248 | 2011-12-01 11:18:12 +0000 | [diff] [blame] | 332 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 333 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 334 | // Callback from Log, stops profiling in case of insufficient resources. |
| 335 | void LogFailure(); |
| 336 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 337 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 338 | explicit Logger(Isolate* isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 339 | ~Logger(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 340 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 341 | // Emits the profiler's first message. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 342 | void ProfilerBeginEvent(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 343 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 344 | // Emits callback event messages. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 345 | void CallbackEventInternal(const char* prefix, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 346 | Name* name, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 347 | Address entry_point); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 348 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 349 | // Internal configurable move event. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 350 | void MoveEventInternal(LogEventsAndTags event, Address from, Address to); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 351 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 352 | // Used for logging stubs found in the snapshot. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 353 | void LogCodeObject(Object* code_object); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 354 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 355 | // Helper method. It resets name_buffer_ and add tag name into it. |
| 356 | void InitNameBuffer(LogEventsAndTags tag); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 357 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 358 | // Emits a profiler tick event. Used by the profiler thread. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 359 | void TickEvent(TickSample* sample, bool overflow); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 360 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 361 | void ApiEvent(const char* name, ...); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 362 | |
| 363 | // Logs a StringEvent regardless of whether FLAG_log is true. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 364 | void UncheckedStringEvent(const char* name, const char* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 365 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 366 | // Logs an IntEvent regardless of whether FLAG_log is true. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 367 | void UncheckedIntEvent(const char* name, int value); |
| 368 | void UncheckedIntPtrTEvent(const char* name, intptr_t value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 369 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 370 | Isolate* isolate_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 371 | |
| 372 | // The sampler used by the profiler and the sliding state window. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 373 | Ticker* ticker_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 374 | |
| 375 | // When the statistical profile is active, profiler_ |
| 376 | // points to a Profiler, that handles collection |
| 377 | // of samples. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 378 | Profiler* profiler_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 379 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 380 | // An array of log events names. |
| 381 | const char* const* log_events_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 382 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 383 | // Internal implementation classes with access to |
| 384 | // private members. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 385 | friend class EventLog; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 386 | friend class Isolate; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 387 | friend class TimeLog; |
| 388 | friend class Profiler; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 389 | template <StateTag Tag> friend class VMState; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 390 | friend class LoggerTestHelper; |
| 391 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 392 | bool is_logging_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 393 | Log* log_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 394 | PerfBasicLogger* perf_basic_logger_; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 395 | PerfJitLogger* perf_jit_logger_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 396 | LowLevelLogger* ll_logger_; |
| 397 | JitLogger* jit_logger_; |
| 398 | List<CodeEventListener*> listeners_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 399 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 400 | // Guards against multiple calls to TearDown() that can happen in some tests. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 401 | // 'true' between SetUp() and TearDown(). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 402 | bool is_initialized_; |
| 403 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 404 | base::ElapsedTimer timer_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 405 | |
| 406 | friend class CpuProfiler; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 407 | }; |
| 408 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 409 | #define TIMER_EVENTS_LIST(V) \ |
| 410 | V(RecompileSynchronous, true) \ |
| 411 | V(RecompileConcurrent, true) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 412 | V(CompileIgnition, true) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 413 | V(CompileFullCode, true) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 414 | V(OptimizeCode, true) \ |
| 415 | V(CompileCode, true) \ |
| 416 | V(DeoptimizeCode, true) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 417 | V(Execute, true) \ |
| 418 | V(External, true) \ |
| 419 | V(IcMiss, false) |
| 420 | |
| 421 | #define V(TimerName, expose) \ |
| 422 | class TimerEvent##TimerName : public AllStatic { \ |
| 423 | public: \ |
| 424 | static const char* name(void* unused = NULL) { return "V8." #TimerName; } \ |
| 425 | static bool expose_to_api() { return expose; } \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 426 | }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 427 | TIMER_EVENTS_LIST(V) |
| 428 | #undef V |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 429 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 430 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 431 | template <class TimerEvent> |
| 432 | class TimerEventScope { |
| 433 | public: |
| 434 | explicit TimerEventScope(Isolate* isolate) : isolate_(isolate) { |
| 435 | LogTimerEvent(Logger::START); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 436 | } |
| 437 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 438 | ~TimerEventScope() { LogTimerEvent(Logger::END); } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 439 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 440 | void LogTimerEvent(Logger::StartEnd se); |
| 441 | |
| 442 | private: |
| 443 | Isolate* isolate_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 444 | }; |
| 445 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 446 | class PositionsRecorder BASE_EMBEDDED { |
| 447 | public: |
| 448 | PositionsRecorder() { jit_handler_data_ = NULL; } |
| 449 | |
| 450 | void AttachJITHandlerData(void* user_data) { jit_handler_data_ = user_data; } |
| 451 | |
| 452 | void* DetachJITHandlerData() { |
| 453 | void* old_data = jit_handler_data_; |
| 454 | jit_handler_data_ = NULL; |
| 455 | return old_data; |
| 456 | } |
| 457 | |
| 458 | protected: |
| 459 | // Currently jit_handler_data_ is used to store JITHandler-specific data |
| 460 | // over the lifetime of a PositionsRecorder |
| 461 | void* jit_handler_data_; |
| 462 | |
| 463 | private: |
| 464 | DISALLOW_COPY_AND_ASSIGN(PositionsRecorder); |
| 465 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 466 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 467 | class CodeEventListener { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 468 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 469 | virtual ~CodeEventListener() {} |
| 470 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 471 | virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 472 | const char* comment) = 0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 473 | virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 474 | Name* name) = 0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 475 | virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 476 | SharedFunctionInfo* shared, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 477 | CompilationInfo* info, Name* name) = 0; |
| 478 | virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 479 | SharedFunctionInfo* shared, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 480 | CompilationInfo* info, Name* source, int line, |
| 481 | int column) = 0; |
| 482 | virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 483 | int args_count) = 0; |
| 484 | virtual void CallbackEvent(Name* name, Address entry_point) = 0; |
| 485 | virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0; |
| 486 | virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 487 | virtual void RegExpCodeCreateEvent(AbstractCode* code, String* source) = 0; |
| 488 | virtual void CodeMoveEvent(AbstractCode* from, Address to) = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 489 | virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0; |
| 490 | virtual void CodeMovingGCEvent() = 0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 491 | virtual void CodeDisableOptEvent(AbstractCode* code, |
| 492 | SharedFunctionInfo* shared) = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 493 | }; |
| 494 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 495 | |
| 496 | class CodeEventLogger : public CodeEventListener { |
| 497 | public: |
| 498 | CodeEventLogger(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 499 | ~CodeEventLogger() override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 500 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 501 | void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, |
| 502 | const char* comment) override; |
| 503 | void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, |
| 504 | Name* name) override; |
| 505 | void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, |
| 506 | int args_count) override; |
| 507 | void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, |
| 508 | SharedFunctionInfo* shared, CompilationInfo* info, |
| 509 | Name* name) override; |
| 510 | void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, |
| 511 | SharedFunctionInfo* shared, CompilationInfo* info, |
| 512 | Name* source, int line, int column) override; |
| 513 | void RegExpCodeCreateEvent(AbstractCode* code, String* source) override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 514 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 515 | void CallbackEvent(Name* name, Address entry_point) override {} |
| 516 | void GetterCallbackEvent(Name* name, Address entry_point) override {} |
| 517 | void SetterCallbackEvent(Name* name, Address entry_point) override {} |
| 518 | void SharedFunctionInfoMoveEvent(Address from, Address to) override {} |
| 519 | void CodeMovingGCEvent() override {} |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 520 | |
| 521 | private: |
| 522 | class NameBuffer; |
| 523 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 524 | virtual void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo* shared, |
| 525 | const char* name, int length) = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 526 | |
| 527 | NameBuffer* name_buffer_; |
| 528 | }; |
| 529 | |
| 530 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 531 | } // namespace internal |
| 532 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 533 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 534 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 535 | #endif // V8_LOG_H_ |