blob: abf35f0ebc5ddcf0373f598d0cf48eee1d479e5c [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_LOG_H_
6#define V8_LOG_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#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 Blocka7e24c12009-10-30 11:49:00 +000014
15namespace v8 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000016
17namespace base {
18class Semaphore;
19}
20
Steve Blocka7e24c12009-10-30 11:49:00 +000021namespace 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 Murdochb8a8cc12014-11-26 15:28:44 +000058class CodeEventListener;
59class CompilationInfo;
60class CpuProfiler;
61class Isolate;
62class Log;
63class PositionsRecorder;
Steve Blocka7e24c12009-10-30 11:49:00 +000064class Profiler;
Ben Murdoch257744e2011-11-30 15:57:28 +000065class Ticker;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066struct TickSample;
Steve Blocka7e24c12009-10-30 11:49:00 +000067
68#undef LOG
Steve Block44f0eee2011-05-26 01:26:41 +010069#define LOG(isolate, Call) \
70 do { \
71 v8::internal::Logger* logger = \
72 (isolate)->logger(); \
73 if (logger->is_logging()) \
74 logger->Call; \
Steve Blocka7e24c12009-10-30 11:49:00 +000075 } while (false)
Steve Blocka7e24c12009-10-30 11:49:00 +000076
Ben Murdochb8a8cc12014-11-26 15:28:44 +000077#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
85
Ben Murdoch257744e2011-11-30 15:57:28 +000086#define LOG_EVENTS_AND_TAGS_LIST(V) \
87 V(CODE_CREATION_EVENT, "code-creation") \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000088 V(CODE_DISABLE_OPT_EVENT, "code-disable-optimization") \
Ben Murdoch257744e2011-11-30 15:57:28 +000089 V(CODE_MOVE_EVENT, "code-move") \
90 V(CODE_DELETE_EVENT, "code-delete") \
91 V(CODE_MOVING_GC, "code-moving-gc") \
92 V(SHARED_FUNC_MOVE_EVENT, "sfi-move") \
93 V(SNAPSHOT_POSITION_EVENT, "snapshot-pos") \
94 V(SNAPSHOT_CODE_NAME_EVENT, "snapshot-code-name") \
95 V(TICK_EVENT, "tick") \
96 V(REPEAT_META_EVENT, "repeat") \
97 V(BUILTIN_TAG, "Builtin") \
98 V(CALL_DEBUG_BREAK_TAG, "CallDebugBreak") \
99 V(CALL_DEBUG_PREPARE_STEP_IN_TAG, "CallDebugPrepareStepIn") \
Ben Murdoch257744e2011-11-30 15:57:28 +0000100 V(CALL_INITIALIZE_TAG, "CallInitialize") \
101 V(CALL_MEGAMORPHIC_TAG, "CallMegamorphic") \
102 V(CALL_MISS_TAG, "CallMiss") \
103 V(CALL_NORMAL_TAG, "CallNormal") \
104 V(CALL_PRE_MONOMORPHIC_TAG, "CallPreMonomorphic") \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105 V(LOAD_INITIALIZE_TAG, "LoadInitialize") \
106 V(LOAD_PREMONOMORPHIC_TAG, "LoadPreMonomorphic") \
107 V(LOAD_MEGAMORPHIC_TAG, "LoadMegamorphic") \
108 V(STORE_INITIALIZE_TAG, "StoreInitialize") \
109 V(STORE_PREMONOMORPHIC_TAG, "StorePreMonomorphic") \
110 V(STORE_GENERIC_TAG, "StoreGeneric") \
111 V(STORE_MEGAMORPHIC_TAG, "StoreMegamorphic") \
Ben Murdoch257744e2011-11-30 15:57:28 +0000112 V(KEYED_CALL_DEBUG_BREAK_TAG, "KeyedCallDebugBreak") \
113 V(KEYED_CALL_DEBUG_PREPARE_STEP_IN_TAG, \
114 "KeyedCallDebugPrepareStepIn") \
Ben Murdoch257744e2011-11-30 15:57:28 +0000115 V(KEYED_CALL_INITIALIZE_TAG, "KeyedCallInitialize") \
116 V(KEYED_CALL_MEGAMORPHIC_TAG, "KeyedCallMegamorphic") \
117 V(KEYED_CALL_MISS_TAG, "KeyedCallMiss") \
118 V(KEYED_CALL_NORMAL_TAG, "KeyedCallNormal") \
119 V(KEYED_CALL_PRE_MONOMORPHIC_TAG, "KeyedCallPreMonomorphic") \
120 V(CALLBACK_TAG, "Callback") \
121 V(EVAL_TAG, "Eval") \
122 V(FUNCTION_TAG, "Function") \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000123 V(HANDLER_TAG, "Handler") \
Ben Murdoch257744e2011-11-30 15:57:28 +0000124 V(KEYED_LOAD_IC_TAG, "KeyedLoadIC") \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000125 V(KEYED_LOAD_POLYMORPHIC_IC_TAG, "KeyedLoadPolymorphicIC") \
Ben Murdoch257744e2011-11-30 15:57:28 +0000126 V(KEYED_EXTERNAL_ARRAY_LOAD_IC_TAG, "KeyedExternalArrayLoadIC") \
127 V(KEYED_STORE_IC_TAG, "KeyedStoreIC") \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128 V(KEYED_STORE_POLYMORPHIC_IC_TAG, "KeyedStorePolymorphicIC") \
Ben Murdoch257744e2011-11-30 15:57:28 +0000129 V(KEYED_EXTERNAL_ARRAY_STORE_IC_TAG, "KeyedExternalArrayStoreIC") \
130 V(LAZY_COMPILE_TAG, "LazyCompile") \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000131 V(CALL_IC_TAG, "CallIC") \
Ben Murdoch257744e2011-11-30 15:57:28 +0000132 V(LOAD_IC_TAG, "LoadIC") \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000133 V(LOAD_POLYMORPHIC_IC_TAG, "LoadPolymorphicIC") \
Ben Murdoch257744e2011-11-30 15:57:28 +0000134 V(REG_EXP_TAG, "RegExp") \
135 V(SCRIPT_TAG, "Script") \
136 V(STORE_IC_TAG, "StoreIC") \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000137 V(STORE_POLYMORPHIC_IC_TAG, "StorePolymorphicIC") \
Ben Murdoch257744e2011-11-30 15:57:28 +0000138 V(STUB_TAG, "Stub") \
139 V(NATIVE_FUNCTION_TAG, "Function") \
140 V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile") \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100141 V(NATIVE_SCRIPT_TAG, "Script")
Steve Block6ded16b2010-05-10 14:33:55 +0100142// Note that 'NATIVE_' cases for functions and scripts are mapped onto
143// original tags when writing to the log.
144
Steve Blocka7e24c12009-10-30 11:49:00 +0000145
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000146class JitLogger;
147class PerfBasicLogger;
148class LowLevelLogger;
149class PerfJitLogger;
Steve Block44f0eee2011-05-26 01:26:41 +0100150class Sampler;
151
Steve Blocka7e24c12009-10-30 11:49:00 +0000152class Logger {
153 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000154 enum StartEnd { START = 0, END = 1 };
155
Ben Murdochb0fe1622011-05-05 13:52:32 +0100156#define DECLARE_ENUM(enum_item, ignore) enum_item,
Steve Blocka7e24c12009-10-30 11:49:00 +0000157 enum LogEventsAndTags {
158 LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM)
159 NUMBER_OF_LOG_EVENTS
160 };
161#undef DECLARE_ENUM
162
163 // Acquires resources for logging if the right flags are set.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000164 bool SetUp(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000165
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000166 // Sets the current code event handler.
167 void SetCodeEventHandler(uint32_t options,
168 JitCodeEventHandler event_handler);
Steve Block44f0eee2011-05-26 01:26:41 +0100169
170 Sampler* sampler();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100171
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100172 // Frees resources acquired in SetUp.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000173 // When a temporary file is used for the log, returns its stream descriptor,
174 // leaving the file open.
175 FILE* TearDown();
Steve Blocka7e24c12009-10-30 11:49:00 +0000176
Steve Blocka7e24c12009-10-30 11:49:00 +0000177 // Emits an event with a string value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100178 void StringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000179
180 // Emits an event with an int value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100181 void IntEvent(const char* name, int value);
182 void IntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000183
184 // Emits an event with an handle value -> (name, location).
Steve Block44f0eee2011-05-26 01:26:41 +0100185 void HandleEvent(const char* name, Object** location);
Steve Blocka7e24c12009-10-30 11:49:00 +0000186
187 // Emits memory management events for C allocated structures.
Steve Block44f0eee2011-05-26 01:26:41 +0100188 void NewEvent(const char* name, void* object, size_t size);
189 void DeleteEvent(const char* name, void* object);
190
191 // Static versions of the above, operate on current isolate's logger.
192 // Used in TRACK_MEMORY(TypeName) defined in globals.h
193 static void NewEventStatic(const char* name, void* object, size_t size);
194 static void DeleteEventStatic(const char* name, void* object);
Steve Blocka7e24c12009-10-30 11:49:00 +0000195
196 // Emits an event with a tag, and some resource usage information.
197 // -> (name, tag, <rusage information>).
198 // Currently, the resource usage information is a process time stamp
199 // and a real time timestamp.
Steve Block44f0eee2011-05-26 01:26:41 +0100200 void ResourceEvent(const char* name, const char* tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000201
202 // Emits an event that an undefined property was read from an
203 // object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000204 void SuspectReadEvent(Name* name, Object* obj);
Steve Blocka7e24c12009-10-30 11:49:00 +0000205
206 // Emits an event when a message is put on or read from a debugging queue.
207 // DebugTag lets us put a call-site specific label on the event.
Steve Block44f0eee2011-05-26 01:26:41 +0100208 void DebugTag(const char* call_site_tag);
209 void DebugEvent(const char* event_type, Vector<uint16_t> parameter);
Steve Blocka7e24c12009-10-30 11:49:00 +0000210
211
212 // ==== Events logged by --log-api. ====
Steve Block44f0eee2011-05-26 01:26:41 +0100213 void ApiNamedSecurityCheck(Object* key);
214 void ApiIndexedSecurityCheck(uint32_t index);
215 void ApiNamedPropertyAccess(const char* tag, JSObject* holder, Object* name);
216 void ApiIndexedPropertyAccess(const char* tag,
217 JSObject* holder,
218 uint32_t index);
219 void ApiObjectAccess(const char* tag, JSObject* obj);
220 void ApiEntryCall(const char* name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000221
222
223 // ==== Events logged by --log-code. ====
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000224 void addCodeEventListener(CodeEventListener* listener);
225 void removeCodeEventListener(CodeEventListener* listener);
226 bool hasCodeEventListener(CodeEventListener* listener);
227
228
Steve Blockd0582a62009-12-15 09:54:21 +0000229 // Emits a code event for a callback function.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000230 void CallbackEvent(Name* name, Address entry_point);
231 void GetterCallbackEvent(Name* name, Address entry_point);
232 void SetterCallbackEvent(Name* name, Address entry_point);
Steve Blocka7e24c12009-10-30 11:49:00 +0000233 // Emits a code create event.
Steve Block44f0eee2011-05-26 01:26:41 +0100234 void CodeCreateEvent(LogEventsAndTags tag,
235 Code* code, const char* source);
236 void CodeCreateEvent(LogEventsAndTags tag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000237 Code* code, Name* name);
Steve Block44f0eee2011-05-26 01:26:41 +0100238 void CodeCreateEvent(LogEventsAndTags tag,
239 Code* code,
240 SharedFunctionInfo* shared,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000241 CompilationInfo* info,
242 Name* name);
Steve Block44f0eee2011-05-26 01:26:41 +0100243 void CodeCreateEvent(LogEventsAndTags tag,
244 Code* code,
245 SharedFunctionInfo* shared,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000246 CompilationInfo* info,
247 Name* source, int line, int column);
Steve Block44f0eee2011-05-26 01:26:41 +0100248 void CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000249 // Emits a code deoptimization event.
250 void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared);
Steve Block44f0eee2011-05-26 01:26:41 +0100251 void CodeMovingGCEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000252 // Emits a code create event for a RegExp.
Steve Block44f0eee2011-05-26 01:26:41 +0100253 void RegExpCodeCreateEvent(Code* code, String* source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000254 // Emits a code move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100255 void CodeMoveEvent(Address from, Address to);
Steve Blocka7e24c12009-10-30 11:49:00 +0000256 // Emits a code delete event.
Steve Block44f0eee2011-05-26 01:26:41 +0100257 void CodeDeleteEvent(Address from);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000258 // Emits a code line info add event with Postion type.
259 void CodeLinePosInfoAddPositionEvent(void* jit_handler_data,
260 int pc_offset,
261 int position);
262 // Emits a code line info add event with StatementPostion type.
263 void CodeLinePosInfoAddStatementPositionEvent(void* jit_handler_data,
264 int pc_offset,
265 int position);
266 // Emits a code line info start to record event
267 void CodeStartLinePosInfoRecordEvent(PositionsRecorder* pos_recorder);
268 // Emits a code line info finish record event.
269 // It's the callee's responsibility to dispose the parameter jit_handler_data.
270 void CodeEndLinePosInfoRecordEvent(Code* code, void* jit_handler_data);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100271
Steve Block44f0eee2011-05-26 01:26:41 +0100272 void SharedFunctionInfoMoveEvent(Address from, Address to);
Steve Blocka7e24c12009-10-30 11:49:00 +0000273
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000274 void CodeNameEvent(Address addr, int pos, const char* code_name);
Steve Block44f0eee2011-05-26 01:26:41 +0100275 void SnapshotPositionEvent(Address addr, int pos);
Leon Clarkee46be812010-01-19 14:06:41 +0000276
Steve Blocka7e24c12009-10-30 11:49:00 +0000277 // ==== Events logged by --log-gc. ====
278 // Heap sampling events: start, end, and individual types.
Steve Block44f0eee2011-05-26 01:26:41 +0100279 void HeapSampleBeginEvent(const char* space, const char* kind);
280 void HeapSampleEndEvent(const char* space, const char* kind);
281 void HeapSampleItemEvent(const char* type, int number, int bytes);
282 void HeapSampleJSConstructorEvent(const char* constructor,
283 int number, int bytes);
284 void HeapSampleJSRetainersEvent(const char* constructor,
Steve Blocka7e24c12009-10-30 11:49:00 +0000285 const char* event);
Steve Block44f0eee2011-05-26 01:26:41 +0100286 void HeapSampleJSProducerEvent(const char* constructor,
287 Address* stack);
288 void HeapSampleStats(const char* space, const char* kind,
289 intptr_t capacity, intptr_t used);
Steve Blocka7e24c12009-10-30 11:49:00 +0000290
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000291 void SharedLibraryEvent(const std::string& library_path,
Steve Block44f0eee2011-05-26 01:26:41 +0100292 uintptr_t start,
293 uintptr_t end);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000294
295 void CodeDeoptEvent(Code* code);
296 void CurrentTimeEvent();
297
298 void TimerEvent(StartEnd se, const char* name);
299
300 static void EnterExternal(Isolate* isolate);
301 static void LeaveExternal(Isolate* isolate);
302
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400303 static void DefaultEventLoggerSentinel(const char* name, int event) {}
304
305 INLINE(static void CallEventLogger(Isolate* isolate, const char* name,
306 StartEnd se, bool expose_to_api));
Steve Blocka7e24c12009-10-30 11:49:00 +0000307
308 // ==== Events logged by --log-regexp ====
309 // Regexp compilation and execution events.
310
Steve Block44f0eee2011-05-26 01:26:41 +0100311 void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache);
Steve Blocka7e24c12009-10-30 11:49:00 +0000312
Steve Block44f0eee2011-05-26 01:26:41 +0100313 bool is_logging() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000314 return is_logging_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000315 }
316
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000317 bool is_logging_code_events() {
318 return is_logging() || jit_logger_ != NULL;
319 }
320
321 // Stop collection of profiling data.
322 // When data collection is paused, CPU Tick events are discarded.
323 void StopProfiler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000324
Ben Murdoch589d6972011-11-30 16:04:58 +0000325 void LogExistingFunction(Handle<SharedFunctionInfo> shared,
326 Handle<Code> code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000327 // Logs all compiled functions found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100328 void LogCompiledFunctions();
Steve Blockd0582a62009-12-15 09:54:21 +0000329 // Logs all accessor callbacks found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100330 void LogAccessorCallbacks();
Steve Blockd0582a62009-12-15 09:54:21 +0000331 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100332 void LogCodeObjects();
Steve Blocka7e24c12009-10-30 11:49:00 +0000333
Steve Block6ded16b2010-05-10 14:33:55 +0100334 // Converts tag to a corresponding NATIVE_... if the script is native.
335 INLINE(static LogEventsAndTags ToNativeByScript(LogEventsAndTags, Script*));
Steve Blocka7e24c12009-10-30 11:49:00 +0000336
337 // Profiler's sampling interval (in milliseconds).
Ben Murdoch75492482011-12-01 11:18:12 +0000338#if defined(ANDROID)
339 // Phones and tablets have processors that are much slower than desktop
340 // and laptop computers for which current heuristics are tuned.
341 static const int kSamplingIntervalMs = 5;
342#else
Steve Blocka7e24c12009-10-30 11:49:00 +0000343 static const int kSamplingIntervalMs = 1;
Ben Murdoch75492482011-12-01 11:18:12 +0000344#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000345
Steve Block44f0eee2011-05-26 01:26:41 +0100346 // Callback from Log, stops profiling in case of insufficient resources.
347 void LogFailure();
348
Steve Block6ded16b2010-05-10 14:33:55 +0100349 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000350 explicit Logger(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100351 ~Logger();
Steve Block6ded16b2010-05-10 14:33:55 +0100352
Steve Blocka7e24c12009-10-30 11:49:00 +0000353 // Emits the profiler's first message.
Steve Block44f0eee2011-05-26 01:26:41 +0100354 void ProfilerBeginEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000355
Steve Blockd0582a62009-12-15 09:54:21 +0000356 // Emits callback event messages.
Steve Block44f0eee2011-05-26 01:26:41 +0100357 void CallbackEventInternal(const char* prefix,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000358 Name* name,
Steve Block44f0eee2011-05-26 01:26:41 +0100359 Address entry_point);
Steve Blockd0582a62009-12-15 09:54:21 +0000360
Leon Clarked91b9f72010-01-27 17:25:45 +0000361 // Internal configurable move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100362 void MoveEventInternal(LogEventsAndTags event, Address from, Address to);
Leon Clarked91b9f72010-01-27 17:25:45 +0000363
Steve Blocka7e24c12009-10-30 11:49:00 +0000364 // Emits the source code of a regexp. Used by regexp events.
Steve Block44f0eee2011-05-26 01:26:41 +0100365 void LogRegExpSource(Handle<JSRegExp> regexp);
Steve Blocka7e24c12009-10-30 11:49:00 +0000366
Andrei Popescu31002712010-02-23 13:46:05 +0000367 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100368 void LogCodeObject(Object* code_object);
Andrei Popescu31002712010-02-23 13:46:05 +0000369
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000370 // Helper method. It resets name_buffer_ and add tag name into it.
371 void InitNameBuffer(LogEventsAndTags tag);
Ben Murdochf87a2032010-10-22 12:50:53 +0100372
Steve Blocka7e24c12009-10-30 11:49:00 +0000373 // Emits a profiler tick event. Used by the profiler thread.
Steve Block44f0eee2011-05-26 01:26:41 +0100374 void TickEvent(TickSample* sample, bool overflow);
Steve Blocka7e24c12009-10-30 11:49:00 +0000375
Steve Block44f0eee2011-05-26 01:26:41 +0100376 void ApiEvent(const char* name, ...);
Steve Blocka7e24c12009-10-30 11:49:00 +0000377
378 // Logs a StringEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100379 void UncheckedStringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000380
Steve Block6ded16b2010-05-10 14:33:55 +0100381 // Logs an IntEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100382 void UncheckedIntEvent(const char* name, int value);
383 void UncheckedIntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000384
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000385 Isolate* isolate_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000386
387 // The sampler used by the profiler and the sliding state window.
Steve Block44f0eee2011-05-26 01:26:41 +0100388 Ticker* ticker_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000389
390 // When the statistical profile is active, profiler_
391 // points to a Profiler, that handles collection
392 // of samples.
Steve Block44f0eee2011-05-26 01:26:41 +0100393 Profiler* profiler_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000394
Steve Block44f0eee2011-05-26 01:26:41 +0100395 // An array of log events names.
396 const char* const* log_events_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000397
Steve Blocka7e24c12009-10-30 11:49:00 +0000398 // Internal implementation classes with access to
399 // private members.
Steve Blocka7e24c12009-10-30 11:49:00 +0000400 friend class EventLog;
Steve Block44f0eee2011-05-26 01:26:41 +0100401 friend class Isolate;
Steve Blocka7e24c12009-10-30 11:49:00 +0000402 friend class TimeLog;
403 friend class Profiler;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000404 template <StateTag Tag> friend class VMState;
Steve Blocka7e24c12009-10-30 11:49:00 +0000405 friend class LoggerTestHelper;
406
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000407 bool is_logging_;
Steve Block44f0eee2011-05-26 01:26:41 +0100408 Log* log_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000409 PerfBasicLogger* perf_basic_logger_;
410 PerfJitLogger* perf_jit_logger_;
411 LowLevelLogger* ll_logger_;
412 JitLogger* jit_logger_;
413 List<CodeEventListener*> listeners_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000414
Steve Block44f0eee2011-05-26 01:26:41 +0100415 // Guards against multiple calls to TearDown() that can happen in some tests.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100416 // 'true' between SetUp() and TearDown().
Steve Block44f0eee2011-05-26 01:26:41 +0100417 bool is_initialized_;
418
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000419 base::ElapsedTimer timer_;
Steve Block6ded16b2010-05-10 14:33:55 +0100420
421 friend class CpuProfiler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000422};
423
424
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000425#define TIMER_EVENTS_LIST(V) \
426 V(RecompileSynchronous, true) \
427 V(RecompileConcurrent, true) \
428 V(CompileFullCode, true) \
429 V(Execute, true) \
430 V(External, true) \
431 V(IcMiss, false)
432
433#define V(TimerName, expose) \
434 class TimerEvent##TimerName : public AllStatic { \
435 public: \
436 static const char* name(void* unused = NULL) { return "V8." #TimerName; } \
437 static bool expose_to_api() { return expose; } \
Steve Block44f0eee2011-05-26 01:26:41 +0100438 };
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000439TIMER_EVENTS_LIST(V)
440#undef V
Steve Block44f0eee2011-05-26 01:26:41 +0100441
Steve Block44f0eee2011-05-26 01:26:41 +0100442
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000443template <class TimerEvent>
444class TimerEventScope {
445 public:
446 explicit TimerEventScope(Isolate* isolate) : isolate_(isolate) {
447 LogTimerEvent(Logger::START);
Steve Block44f0eee2011-05-26 01:26:41 +0100448 }
449
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000450 ~TimerEventScope() { LogTimerEvent(Logger::END); }
Steve Block44f0eee2011-05-26 01:26:41 +0100451
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000452 void LogTimerEvent(Logger::StartEnd se);
453
454 private:
455 Isolate* isolate_;
Steve Block44f0eee2011-05-26 01:26:41 +0100456};
457
458
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000459class CodeEventListener {
Steve Blocka7e24c12009-10-30 11:49:00 +0000460 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000461 virtual ~CodeEventListener() {}
462
463 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
464 Code* code,
465 const char* comment) = 0;
466 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
467 Code* code,
468 Name* name) = 0;
469 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
470 Code* code,
471 SharedFunctionInfo* shared,
472 CompilationInfo* info,
473 Name* name) = 0;
474 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
475 Code* code,
476 SharedFunctionInfo* shared,
477 CompilationInfo* info,
478 Name* source,
479 int line, int column) = 0;
480 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
481 Code* code,
482 int args_count) = 0;
483 virtual void CallbackEvent(Name* name, Address entry_point) = 0;
484 virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0;
485 virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0;
486 virtual void RegExpCodeCreateEvent(Code* code, String* source) = 0;
487 virtual void CodeMoveEvent(Address from, Address to) = 0;
488 virtual void CodeDeleteEvent(Address from) = 0;
489 virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
490 virtual void CodeMovingGCEvent() = 0;
491 virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000492};
493
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000494
495class CodeEventLogger : public CodeEventListener {
496 public:
497 CodeEventLogger();
498 virtual ~CodeEventLogger();
499
500 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
501 Code* code,
502 const char* comment);
503 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
504 Code* code,
505 Name* name);
506 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
507 Code* code,
508 int args_count);
509 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
510 Code* code,
511 SharedFunctionInfo* shared,
512 CompilationInfo* info,
513 Name* name);
514 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
515 Code* code,
516 SharedFunctionInfo* shared,
517 CompilationInfo* info,
518 Name* source,
519 int line, int column);
520 virtual void RegExpCodeCreateEvent(Code* code, String* source);
521
522 virtual void CallbackEvent(Name* name, Address entry_point) { }
523 virtual void GetterCallbackEvent(Name* name, Address entry_point) { }
524 virtual void SetterCallbackEvent(Name* name, Address entry_point) { }
525 virtual void SharedFunctionInfoMoveEvent(Address from, Address to) { }
526 virtual void CodeMovingGCEvent() { }
527
528 private:
529 class NameBuffer;
530
531 virtual void LogRecordedBuffer(Code* code,
532 SharedFunctionInfo* shared,
533 const char* name,
534 int length) = 0;
535
536 NameBuffer* name_buffer_;
537};
538
539
Steve Blocka7e24c12009-10-30 11:49:00 +0000540} } // namespace v8::internal
541
Steve Block6ded16b2010-05-10 14:33:55 +0100542
Steve Blocka7e24c12009-10-30 11:49:00 +0000543#endif // V8_LOG_H_