blob: 9953b4cd8735468e157c2b18b008a541afece107 [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"
Ben Murdochc5610432016-08-08 18:44:38 +010011#include "src/base/compiler-specific.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000012#include "src/base/platform/elapsed-timer.h"
13#include "src/base/platform/platform.h"
14#include "src/objects.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000015
16namespace v8 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000017
18namespace base {
19class Semaphore;
20}
21
Steve Blocka7e24c12009-10-30 11:49:00 +000022namespace internal {
23
24// Logger is used for collecting logging information from V8 during
25// execution. The result is dumped to a file.
26//
27// Available command line flags:
28//
29// --log
30// Minimal logging (no API, code, or GC sample events), default is off.
31//
32// --log-all
33// Log all events to the file, default is off. This is the same as combining
34// --log-api, --log-code, --log-gc, and --log-regexp.
35//
36// --log-api
37// Log API events to the logfile, default is off. --log-api implies --log.
38//
39// --log-code
40// Log code (create, move, and delete) events to the logfile, default is off.
41// --log-code implies --log.
42//
43// --log-gc
44// Log GC heap samples after each GC that can be processed by hp2ps, default
45// is off. --log-gc implies --log.
46//
47// --log-regexp
48// Log creation and use of regular expressions, Default is off.
49// --log-regexp implies --log.
50//
51// --logfile <filename>
52// Specify the name of the logfile, default is "v8.log".
53//
54// --prof
55// Collect statistical profiling information (ticks), default is off. The
56// tick profiler requires code events, so --prof implies --log-code.
57
58// Forward declarations.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059class CodeEventListener;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000060class 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
Ben Murdochda12d292016-06-02 14:46:10 +010085#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") \
Ben Murdochda12d292016-06-02 14:46:10 +0100102 V(LOAD_INITIALIZE_TAG, "LoadInitialize") \
Ben Murdochda12d292016-06-02 14:46:10 +0100103 V(LOAD_MEGAMORPHIC_TAG, "LoadMegamorphic") \
104 V(STORE_INITIALIZE_TAG, "StoreInitialize") \
Ben Murdochda12d292016-06-02 14:46:10 +0100105 V(STORE_GENERIC_TAG, "StoreGeneric") \
106 V(STORE_MEGAMORPHIC_TAG, "StoreMegamorphic") \
107 V(KEYED_CALL_DEBUG_BREAK_TAG, "KeyedCallDebugBreak") \
108 V(KEYED_CALL_DEBUG_PREPARE_STEP_IN_TAG, "KeyedCallDebugPrepareStepIn") \
109 V(KEYED_CALL_INITIALIZE_TAG, "KeyedCallInitialize") \
110 V(KEYED_CALL_MEGAMORPHIC_TAG, "KeyedCallMegamorphic") \
111 V(KEYED_CALL_MISS_TAG, "KeyedCallMiss") \
112 V(KEYED_CALL_NORMAL_TAG, "KeyedCallNormal") \
Ben Murdochda12d292016-06-02 14:46:10 +0100113 V(CALLBACK_TAG, "Callback") \
114 V(EVAL_TAG, "Eval") \
115 V(FUNCTION_TAG, "Function") \
116 V(HANDLER_TAG, "Handler") \
117 V(BYTECODE_HANDLER_TAG, "BytecodeHandler") \
118 V(KEYED_LOAD_IC_TAG, "KeyedLoadIC") \
119 V(KEYED_LOAD_POLYMORPHIC_IC_TAG, "KeyedLoadPolymorphicIC") \
120 V(KEYED_EXTERNAL_ARRAY_LOAD_IC_TAG, "KeyedExternalArrayLoadIC") \
121 V(KEYED_STORE_IC_TAG, "KeyedStoreIC") \
122 V(KEYED_STORE_POLYMORPHIC_IC_TAG, "KeyedStorePolymorphicIC") \
123 V(KEYED_EXTERNAL_ARRAY_STORE_IC_TAG, "KeyedExternalArrayStoreIC") \
124 V(LAZY_COMPILE_TAG, "LazyCompile") \
125 V(CALL_IC_TAG, "CallIC") \
126 V(LOAD_IC_TAG, "LoadIC") \
127 V(LOAD_POLYMORPHIC_IC_TAG, "LoadPolymorphicIC") \
128 V(REG_EXP_TAG, "RegExp") \
129 V(SCRIPT_TAG, "Script") \
130 V(STORE_IC_TAG, "StoreIC") \
131 V(STORE_POLYMORPHIC_IC_TAG, "StorePolymorphicIC") \
132 V(STUB_TAG, "Stub") \
133 V(NATIVE_FUNCTION_TAG, "Function") \
134 V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile") \
135 V(NATIVE_SCRIPT_TAG, "Script")
Steve Block6ded16b2010-05-10 14:33:55 +0100136// Note that 'NATIVE_' cases for functions and scripts are mapped onto
137// original tags when writing to the log.
138
Steve Blocka7e24c12009-10-30 11:49:00 +0000139
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000140class JitLogger;
141class PerfBasicLogger;
142class LowLevelLogger;
Ben Murdochda12d292016-06-02 14:46:10 +0100143class PerfJitLogger;
Steve Block44f0eee2011-05-26 01:26:41 +0100144class Sampler;
145
Steve Blocka7e24c12009-10-30 11:49:00 +0000146class Logger {
147 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000148 enum StartEnd { START = 0, END = 1 };
149
Ben Murdochb0fe1622011-05-05 13:52:32 +0100150#define DECLARE_ENUM(enum_item, ignore) enum_item,
Steve Blocka7e24c12009-10-30 11:49:00 +0000151 enum LogEventsAndTags {
152 LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM)
153 NUMBER_OF_LOG_EVENTS
154 };
155#undef DECLARE_ENUM
156
157 // Acquires resources for logging if the right flags are set.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000158 bool SetUp(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000159
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000160 // Sets the current code event handler.
161 void SetCodeEventHandler(uint32_t options,
162 JitCodeEventHandler event_handler);
Steve Block44f0eee2011-05-26 01:26:41 +0100163
164 Sampler* sampler();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100165
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100166 // Frees resources acquired in SetUp.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000167 // When a temporary file is used for the log, returns its stream descriptor,
168 // leaving the file open.
169 FILE* TearDown();
Steve Blocka7e24c12009-10-30 11:49:00 +0000170
Steve Blocka7e24c12009-10-30 11:49:00 +0000171 // Emits an event with a string value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100172 void StringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000173
174 // Emits an event with an int value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100175 void IntEvent(const char* name, int value);
176 void IntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000177
178 // Emits an event with an handle value -> (name, location).
Steve Block44f0eee2011-05-26 01:26:41 +0100179 void HandleEvent(const char* name, Object** location);
Steve Blocka7e24c12009-10-30 11:49:00 +0000180
181 // Emits memory management events for C allocated structures.
Steve Block44f0eee2011-05-26 01:26:41 +0100182 void NewEvent(const char* name, void* object, size_t size);
183 void DeleteEvent(const char* name, void* object);
184
Steve Blocka7e24c12009-10-30 11:49:00 +0000185 // Emits an event with a tag, and some resource usage information.
186 // -> (name, tag, <rusage information>).
187 // Currently, the resource usage information is a process time stamp
188 // and a real time timestamp.
Steve Block44f0eee2011-05-26 01:26:41 +0100189 void ResourceEvent(const char* name, const char* tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000190
191 // Emits an event that an undefined property was read from an
192 // object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000193 void SuspectReadEvent(Name* name, Object* obj);
Steve Blocka7e24c12009-10-30 11:49:00 +0000194
195 // Emits an event when a message is put on or read from a debugging queue.
196 // DebugTag lets us put a call-site specific label on the event.
Steve Block44f0eee2011-05-26 01:26:41 +0100197 void DebugTag(const char* call_site_tag);
198 void DebugEvent(const char* event_type, Vector<uint16_t> parameter);
Steve Blocka7e24c12009-10-30 11:49:00 +0000199
200
201 // ==== Events logged by --log-api. ====
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000202 void ApiSecurityCheck();
Steve Block44f0eee2011-05-26 01:26:41 +0100203 void ApiNamedPropertyAccess(const char* tag, JSObject* holder, Object* name);
204 void ApiIndexedPropertyAccess(const char* tag,
205 JSObject* holder,
206 uint32_t index);
207 void ApiObjectAccess(const char* tag, JSObject* obj);
208 void ApiEntryCall(const char* name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000209
210
211 // ==== Events logged by --log-code. ====
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000212 void addCodeEventListener(CodeEventListener* listener);
213 void removeCodeEventListener(CodeEventListener* listener);
214 bool hasCodeEventListener(CodeEventListener* listener);
215
216
Steve Blockd0582a62009-12-15 09:54:21 +0000217 // Emits a code event for a callback function.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000218 void CallbackEvent(Name* name, Address entry_point);
219 void GetterCallbackEvent(Name* name, Address entry_point);
220 void SetterCallbackEvent(Name* name, Address entry_point);
Steve Blocka7e24c12009-10-30 11:49:00 +0000221 // Emits a code create event.
Ben Murdochda12d292016-06-02 14:46:10 +0100222 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
223 const char* source);
224 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, Name* name);
225 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
Ben Murdochc5610432016-08-08 18:44:38 +0100226 SharedFunctionInfo* shared, Name* name);
Ben Murdochda12d292016-06-02 14:46:10 +0100227 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
Ben Murdochc5610432016-08-08 18:44:38 +0100228 SharedFunctionInfo* shared, Name* source, int line,
229 int column);
Ben Murdochda12d292016-06-02 14:46:10 +0100230 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
231 int args_count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000232 // Emits a code deoptimization event.
Ben Murdochda12d292016-06-02 14:46:10 +0100233 void CodeDisableOptEvent(AbstractCode* code, SharedFunctionInfo* shared);
Steve Block44f0eee2011-05-26 01:26:41 +0100234 void CodeMovingGCEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000235 // Emits a code create event for a RegExp.
Ben Murdochda12d292016-06-02 14:46:10 +0100236 void RegExpCodeCreateEvent(AbstractCode* code, String* source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000237 // Emits a code move event.
Ben Murdochda12d292016-06-02 14:46:10 +0100238 void CodeMoveEvent(AbstractCode* from, Address to);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000239 // Emits a code line info add event with Postion type.
240 void CodeLinePosInfoAddPositionEvent(void* jit_handler_data,
241 int pc_offset,
242 int position);
243 // Emits a code line info add event with StatementPostion type.
244 void CodeLinePosInfoAddStatementPositionEvent(void* jit_handler_data,
245 int pc_offset,
246 int position);
247 // Emits a code line info start to record event
248 void CodeStartLinePosInfoRecordEvent(PositionsRecorder* pos_recorder);
249 // Emits a code line info finish record event.
250 // It's the callee's responsibility to dispose the parameter jit_handler_data.
Ben Murdochda12d292016-06-02 14:46:10 +0100251 void CodeEndLinePosInfoRecordEvent(AbstractCode* code,
252 void* jit_handler_data);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100253
Steve Block44f0eee2011-05-26 01:26:41 +0100254 void SharedFunctionInfoMoveEvent(Address from, Address to);
Steve Blocka7e24c12009-10-30 11:49:00 +0000255
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000256 void CodeNameEvent(Address addr, int pos, const char* code_name);
Leon Clarkee46be812010-01-19 14:06:41 +0000257
Steve Blocka7e24c12009-10-30 11:49:00 +0000258 // ==== Events logged by --log-gc. ====
259 // Heap sampling events: start, end, and individual types.
Steve Block44f0eee2011-05-26 01:26:41 +0100260 void HeapSampleBeginEvent(const char* space, const char* kind);
261 void HeapSampleEndEvent(const char* space, const char* kind);
262 void HeapSampleItemEvent(const char* type, int number, int bytes);
263 void HeapSampleJSConstructorEvent(const char* constructor,
264 int number, int bytes);
265 void HeapSampleJSRetainersEvent(const char* constructor,
Steve Blocka7e24c12009-10-30 11:49:00 +0000266 const char* event);
Steve Block44f0eee2011-05-26 01:26:41 +0100267 void HeapSampleJSProducerEvent(const char* constructor,
268 Address* stack);
269 void HeapSampleStats(const char* space, const char* kind,
270 intptr_t capacity, intptr_t used);
Steve Blocka7e24c12009-10-30 11:49:00 +0000271
Ben Murdochc5610432016-08-08 18:44:38 +0100272 void SharedLibraryEvent(const std::string& library_path, uintptr_t start,
273 uintptr_t end, intptr_t aslr_slide);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000274
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000275 void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000276 void CurrentTimeEvent();
277
278 void TimerEvent(StartEnd se, const char* name);
279
280 static void EnterExternal(Isolate* isolate);
281 static void LeaveExternal(Isolate* isolate);
282
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400283 static void DefaultEventLoggerSentinel(const char* name, int event) {}
284
285 INLINE(static void CallEventLogger(Isolate* isolate, const char* name,
286 StartEnd se, bool expose_to_api));
Steve Blocka7e24c12009-10-30 11:49:00 +0000287
288 // ==== Events logged by --log-regexp ====
289 // Regexp compilation and execution events.
290
Steve Block44f0eee2011-05-26 01:26:41 +0100291 void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache);
Steve Blocka7e24c12009-10-30 11:49:00 +0000292
Steve Block44f0eee2011-05-26 01:26:41 +0100293 bool is_logging() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000294 return is_logging_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000295 }
296
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000297 bool is_logging_code_events() {
298 return is_logging() || jit_logger_ != NULL;
299 }
300
301 // Stop collection of profiling data.
302 // When data collection is paused, CPU Tick events are discarded.
303 void StopProfiler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000304
Ben Murdoch589d6972011-11-30 16:04:58 +0000305 void LogExistingFunction(Handle<SharedFunctionInfo> shared,
Ben Murdochda12d292016-06-02 14:46:10 +0100306 Handle<AbstractCode> code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000307 // Logs all compiled functions found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100308 void LogCompiledFunctions();
Steve Blockd0582a62009-12-15 09:54:21 +0000309 // Logs all accessor callbacks found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100310 void LogAccessorCallbacks();
Steve Blockd0582a62009-12-15 09:54:21 +0000311 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100312 void LogCodeObjects();
Ben Murdochda12d292016-06-02 14:46:10 +0100313 // Used for logging bytecode handlers found in the snapshot.
314 void LogBytecodeHandlers();
Steve Blocka7e24c12009-10-30 11:49:00 +0000315
Steve Block6ded16b2010-05-10 14:33:55 +0100316 // Converts tag to a corresponding NATIVE_... if the script is native.
317 INLINE(static LogEventsAndTags ToNativeByScript(LogEventsAndTags, Script*));
Steve Blocka7e24c12009-10-30 11:49:00 +0000318
319 // Profiler's sampling interval (in milliseconds).
Ben Murdoch75492482011-12-01 11:18:12 +0000320#if defined(ANDROID)
321 // Phones and tablets have processors that are much slower than desktop
322 // and laptop computers for which current heuristics are tuned.
323 static const int kSamplingIntervalMs = 5;
324#else
Steve Blocka7e24c12009-10-30 11:49:00 +0000325 static const int kSamplingIntervalMs = 1;
Ben Murdoch75492482011-12-01 11:18:12 +0000326#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000327
Steve Block44f0eee2011-05-26 01:26:41 +0100328 // Callback from Log, stops profiling in case of insufficient resources.
329 void LogFailure();
330
Steve Block6ded16b2010-05-10 14:33:55 +0100331 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000332 explicit Logger(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100333 ~Logger();
Steve Block6ded16b2010-05-10 14:33:55 +0100334
Steve Blocka7e24c12009-10-30 11:49:00 +0000335 // Emits the profiler's first message.
Steve Block44f0eee2011-05-26 01:26:41 +0100336 void ProfilerBeginEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000337
Steve Blockd0582a62009-12-15 09:54:21 +0000338 // Emits callback event messages.
Steve Block44f0eee2011-05-26 01:26:41 +0100339 void CallbackEventInternal(const char* prefix,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000340 Name* name,
Steve Block44f0eee2011-05-26 01:26:41 +0100341 Address entry_point);
Steve Blockd0582a62009-12-15 09:54:21 +0000342
Leon Clarked91b9f72010-01-27 17:25:45 +0000343 // Internal configurable move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100344 void MoveEventInternal(LogEventsAndTags event, Address from, Address to);
Leon Clarked91b9f72010-01-27 17:25:45 +0000345
Andrei Popescu31002712010-02-23 13:46:05 +0000346 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100347 void LogCodeObject(Object* code_object);
Andrei Popescu31002712010-02-23 13:46:05 +0000348
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000349 // Helper method. It resets name_buffer_ and add tag name into it.
350 void InitNameBuffer(LogEventsAndTags tag);
Ben Murdochf87a2032010-10-22 12:50:53 +0100351
Steve Blocka7e24c12009-10-30 11:49:00 +0000352 // Emits a profiler tick event. Used by the profiler thread.
Steve Block44f0eee2011-05-26 01:26:41 +0100353 void TickEvent(TickSample* sample, bool overflow);
Steve Blocka7e24c12009-10-30 11:49:00 +0000354
Ben Murdochc5610432016-08-08 18:44:38 +0100355 PRINTF_FORMAT(2, 3) void ApiEvent(const char* format, ...);
Steve Blocka7e24c12009-10-30 11:49:00 +0000356
357 // Logs a StringEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100358 void UncheckedStringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000359
Steve Block6ded16b2010-05-10 14:33:55 +0100360 // Logs an IntEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100361 void UncheckedIntEvent(const char* name, int value);
362 void UncheckedIntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000363
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000364 Isolate* isolate_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000365
366 // The sampler used by the profiler and the sliding state window.
Steve Block44f0eee2011-05-26 01:26:41 +0100367 Ticker* ticker_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000368
369 // When the statistical profile is active, profiler_
370 // points to a Profiler, that handles collection
371 // of samples.
Steve Block44f0eee2011-05-26 01:26:41 +0100372 Profiler* profiler_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000373
Steve Block44f0eee2011-05-26 01:26:41 +0100374 // An array of log events names.
375 const char* const* log_events_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000376
Steve Blocka7e24c12009-10-30 11:49:00 +0000377 // Internal implementation classes with access to
378 // private members.
Steve Blocka7e24c12009-10-30 11:49:00 +0000379 friend class EventLog;
Steve Block44f0eee2011-05-26 01:26:41 +0100380 friend class Isolate;
Steve Blocka7e24c12009-10-30 11:49:00 +0000381 friend class TimeLog;
382 friend class Profiler;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000383 template <StateTag Tag> friend class VMState;
Steve Blocka7e24c12009-10-30 11:49:00 +0000384 friend class LoggerTestHelper;
385
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000386 bool is_logging_;
Steve Block44f0eee2011-05-26 01:26:41 +0100387 Log* log_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000388 PerfBasicLogger* perf_basic_logger_;
Ben Murdochda12d292016-06-02 14:46:10 +0100389 PerfJitLogger* perf_jit_logger_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000390 LowLevelLogger* ll_logger_;
391 JitLogger* jit_logger_;
392 List<CodeEventListener*> listeners_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000393
Steve Block44f0eee2011-05-26 01:26:41 +0100394 // Guards against multiple calls to TearDown() that can happen in some tests.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100395 // 'true' between SetUp() and TearDown().
Steve Block44f0eee2011-05-26 01:26:41 +0100396 bool is_initialized_;
397
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000398 base::ElapsedTimer timer_;
Steve Block6ded16b2010-05-10 14:33:55 +0100399
400 friend class CpuProfiler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000401};
402
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000403#define TIMER_EVENTS_LIST(V) \
404 V(RecompileSynchronous, true) \
405 V(RecompileConcurrent, true) \
Ben Murdochda12d292016-06-02 14:46:10 +0100406 V(CompileIgnition, true) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000407 V(CompileFullCode, true) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100408 V(OptimizeCode, true) \
409 V(CompileCode, true) \
410 V(DeoptimizeCode, true) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000411 V(Execute, true) \
412 V(External, true) \
413 V(IcMiss, false)
414
415#define V(TimerName, expose) \
416 class TimerEvent##TimerName : public AllStatic { \
417 public: \
418 static const char* name(void* unused = NULL) { return "V8." #TimerName; } \
419 static bool expose_to_api() { return expose; } \
Steve Block44f0eee2011-05-26 01:26:41 +0100420 };
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000421TIMER_EVENTS_LIST(V)
422#undef V
Steve Block44f0eee2011-05-26 01:26:41 +0100423
Steve Block44f0eee2011-05-26 01:26:41 +0100424
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000425template <class TimerEvent>
426class TimerEventScope {
427 public:
428 explicit TimerEventScope(Isolate* isolate) : isolate_(isolate) {
429 LogTimerEvent(Logger::START);
Steve Block44f0eee2011-05-26 01:26:41 +0100430 }
431
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000432 ~TimerEventScope() { LogTimerEvent(Logger::END); }
Steve Block44f0eee2011-05-26 01:26:41 +0100433
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000434 void LogTimerEvent(Logger::StartEnd se);
435
436 private:
437 Isolate* isolate_;
Steve Block44f0eee2011-05-26 01:26:41 +0100438};
439
Ben Murdochda12d292016-06-02 14:46:10 +0100440class PositionsRecorder BASE_EMBEDDED {
441 public:
442 PositionsRecorder() { jit_handler_data_ = NULL; }
443
444 void AttachJITHandlerData(void* user_data) { jit_handler_data_ = user_data; }
445
446 void* DetachJITHandlerData() {
447 void* old_data = jit_handler_data_;
448 jit_handler_data_ = NULL;
449 return old_data;
450 }
451
452 protected:
453 // Currently jit_handler_data_ is used to store JITHandler-specific data
454 // over the lifetime of a PositionsRecorder
455 void* jit_handler_data_;
456
457 private:
458 DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
459};
Steve Block44f0eee2011-05-26 01:26:41 +0100460
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000461class CodeEventListener {
Steve Blocka7e24c12009-10-30 11:49:00 +0000462 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000463 virtual ~CodeEventListener() {}
464
Ben Murdochda12d292016-06-02 14:46:10 +0100465 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000466 const char* comment) = 0;
Ben Murdochda12d292016-06-02 14:46:10 +0100467 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000468 Name* name) = 0;
Ben Murdochda12d292016-06-02 14:46:10 +0100469 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code,
Ben Murdochc5610432016-08-08 18:44:38 +0100470 SharedFunctionInfo* shared, Name* name) = 0;
Ben Murdochda12d292016-06-02 14:46:10 +0100471 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code,
Ben Murdochc5610432016-08-08 18:44:38 +0100472 SharedFunctionInfo* shared, Name* source,
473 int line, int column) = 0;
Ben Murdochda12d292016-06-02 14:46:10 +0100474 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000475 int args_count) = 0;
476 virtual void CallbackEvent(Name* name, Address entry_point) = 0;
477 virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0;
478 virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0;
Ben Murdochda12d292016-06-02 14:46:10 +0100479 virtual void RegExpCodeCreateEvent(AbstractCode* code, String* source) = 0;
480 virtual void CodeMoveEvent(AbstractCode* from, Address to) = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000481 virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
482 virtual void CodeMovingGCEvent() = 0;
Ben Murdochda12d292016-06-02 14:46:10 +0100483 virtual void CodeDisableOptEvent(AbstractCode* code,
484 SharedFunctionInfo* shared) = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000485};
486
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000487
488class CodeEventLogger : public CodeEventListener {
489 public:
490 CodeEventLogger();
Ben Murdochda12d292016-06-02 14:46:10 +0100491 ~CodeEventLogger() override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000492
Ben Murdochda12d292016-06-02 14:46:10 +0100493 void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code,
494 const char* comment) override;
495 void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code,
496 Name* name) override;
497 void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code,
498 int args_count) override;
499 void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code,
Ben Murdochc5610432016-08-08 18:44:38 +0100500 SharedFunctionInfo* shared, Name* name) override;
Ben Murdochda12d292016-06-02 14:46:10 +0100501 void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code,
Ben Murdochc5610432016-08-08 18:44:38 +0100502 SharedFunctionInfo* shared, Name* source, int line,
503 int column) override;
Ben Murdochda12d292016-06-02 14:46:10 +0100504 void RegExpCodeCreateEvent(AbstractCode* code, String* source) override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000505
Ben Murdochda12d292016-06-02 14:46:10 +0100506 void CallbackEvent(Name* name, Address entry_point) override {}
507 void GetterCallbackEvent(Name* name, Address entry_point) override {}
508 void SetterCallbackEvent(Name* name, Address entry_point) override {}
509 void SharedFunctionInfoMoveEvent(Address from, Address to) override {}
510 void CodeMovingGCEvent() override {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000511
512 private:
513 class NameBuffer;
514
Ben Murdochda12d292016-06-02 14:46:10 +0100515 virtual void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo* shared,
516 const char* name, int length) = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000517
518 NameBuffer* name_buffer_;
519};
520
521
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000522} // namespace internal
523} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +0000524
Steve Block6ded16b2010-05-10 14:33:55 +0100525
Steve Blocka7e24c12009-10-30 11:49:00 +0000526#endif // V8_LOG_H_