blob: c0efd6504deff5a187f2f4d541cfee6f79cd4d37 [file] [log] [blame]
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00001// Copyright 2012 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_LOG_H_
29#define V8_LOG_H_
30
lrn@chromium.org1c092762011-05-09 09:42:16 +000031#include "allocation.h"
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000032#include "objects.h"
ager@chromium.org3e875802009-06-29 08:26:34 +000033#include "platform.h"
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +000034#include "platform/elapsed-timer.h"
ager@chromium.org3e875802009-06-29 08:26:34 +000035
kasperl@chromium.org71affb52009-05-26 05:44:31 +000036namespace v8 {
37namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000038
39// Logger is used for collecting logging information from V8 during
40// execution. The result is dumped to a file.
41//
42// Available command line flags:
43//
44// --log
45// Minimal logging (no API, code, or GC sample events), default is off.
46//
47// --log-all
48// Log all events to the file, default is off. This is the same as combining
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000049// --log-api, --log-code, --log-gc, and --log-regexp.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000050//
51// --log-api
52// Log API events to the logfile, default is off. --log-api implies --log.
53//
54// --log-code
55// Log code (create, move, and delete) events to the logfile, default is off.
56// --log-code implies --log.
57//
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000058// --log-gc
59// Log GC heap samples after each GC that can be processed by hp2ps, default
60// is off. --log-gc implies --log.
61//
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000062// --log-regexp
63// Log creation and use of regular expressions, Default is off.
64// --log-regexp implies --log.
65//
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000066// --logfile <filename>
67// Specify the name of the logfile, default is "v8.log".
68//
69// --prof
70// Collect statistical profiling information (ticks), default is off. The
71// tick profiler requires code events, so --prof implies --log-code.
72
73// Forward declarations.
danno@chromium.orgd3c42102013-08-01 16:58:23 +000074class CodeEventListener;
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +000075class CompilationInfo;
76class CpuProfiler;
77class Isolate;
78class Log;
79class PositionsRecorder;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000080class Profiler;
81class Semaphore;
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +000082class Ticker;
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +000083struct TickSample;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000084
85#undef LOG
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000086#define LOG(isolate, Call) \
87 do { \
88 v8::internal::Logger* logger = \
89 (isolate)->logger(); \
90 if (logger->is_logging()) \
91 logger->Call; \
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +000092 } while (false)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000093
yangguo@chromium.org355cfd12012-08-29 15:32:24 +000094#define LOG_CODE_EVENT(isolate, Call) \
95 do { \
96 v8::internal::Logger* logger = \
97 (isolate)->logger(); \
98 if (logger->is_logging_code_events()) \
99 logger->Call; \
100 } while (false)
101
102
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000103#define LOG_EVENTS_AND_TAGS_LIST(V) \
104 V(CODE_CREATION_EVENT, "code-creation") \
105 V(CODE_MOVE_EVENT, "code-move") \
106 V(CODE_DELETE_EVENT, "code-delete") \
107 V(CODE_MOVING_GC, "code-moving-gc") \
108 V(SHARED_FUNC_MOVE_EVENT, "sfi-move") \
109 V(SNAPSHOT_POSITION_EVENT, "snapshot-pos") \
110 V(SNAPSHOT_CODE_NAME_EVENT, "snapshot-code-name") \
111 V(TICK_EVENT, "tick") \
112 V(REPEAT_META_EVENT, "repeat") \
113 V(BUILTIN_TAG, "Builtin") \
114 V(CALL_DEBUG_BREAK_TAG, "CallDebugBreak") \
115 V(CALL_DEBUG_PREPARE_STEP_IN_TAG, "CallDebugPrepareStepIn") \
116 V(CALL_IC_TAG, "CallIC") \
117 V(CALL_INITIALIZE_TAG, "CallInitialize") \
118 V(CALL_MEGAMORPHIC_TAG, "CallMegamorphic") \
119 V(CALL_MISS_TAG, "CallMiss") \
120 V(CALL_NORMAL_TAG, "CallNormal") \
121 V(CALL_PRE_MONOMORPHIC_TAG, "CallPreMonomorphic") \
122 V(KEYED_CALL_DEBUG_BREAK_TAG, "KeyedCallDebugBreak") \
123 V(KEYED_CALL_DEBUG_PREPARE_STEP_IN_TAG, \
124 "KeyedCallDebugPrepareStepIn") \
125 V(KEYED_CALL_IC_TAG, "KeyedCallIC") \
126 V(KEYED_CALL_INITIALIZE_TAG, "KeyedCallInitialize") \
127 V(KEYED_CALL_MEGAMORPHIC_TAG, "KeyedCallMegamorphic") \
128 V(KEYED_CALL_MISS_TAG, "KeyedCallMiss") \
129 V(KEYED_CALL_NORMAL_TAG, "KeyedCallNormal") \
130 V(KEYED_CALL_PRE_MONOMORPHIC_TAG, "KeyedCallPreMonomorphic") \
131 V(CALLBACK_TAG, "Callback") \
132 V(EVAL_TAG, "Eval") \
133 V(FUNCTION_TAG, "Function") \
jkummerow@chromium.org32aa03c2013-10-01 08:21:50 +0000134 V(HANDLER_TAG, "Handler") \
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000135 V(KEYED_LOAD_IC_TAG, "KeyedLoadIC") \
jkummerow@chromium.org59297c72013-01-09 16:32:23 +0000136 V(KEYED_LOAD_POLYMORPHIC_IC_TAG, "KeyedLoadPolymorphicIC") \
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000137 V(KEYED_EXTERNAL_ARRAY_LOAD_IC_TAG, "KeyedExternalArrayLoadIC") \
138 V(KEYED_STORE_IC_TAG, "KeyedStoreIC") \
jkummerow@chromium.org59297c72013-01-09 16:32:23 +0000139 V(KEYED_STORE_POLYMORPHIC_IC_TAG, "KeyedStorePolymorphicIC") \
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000140 V(KEYED_EXTERNAL_ARRAY_STORE_IC_TAG, "KeyedExternalArrayStoreIC") \
141 V(LAZY_COMPILE_TAG, "LazyCompile") \
142 V(LOAD_IC_TAG, "LoadIC") \
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000143 V(LOAD_POLYMORPHIC_IC_TAG, "LoadPolymorphicIC") \
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000144 V(REG_EXP_TAG, "RegExp") \
145 V(SCRIPT_TAG, "Script") \
146 V(STORE_IC_TAG, "StoreIC") \
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000147 V(STORE_POLYMORPHIC_IC_TAG, "StorePolymorphicIC") \
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000148 V(STUB_TAG, "Stub") \
149 V(NATIVE_FUNCTION_TAG, "Function") \
150 V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile") \
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000151 V(NATIVE_SCRIPT_TAG, "Script")
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000152// Note that 'NATIVE_' cases for functions and scripts are mapped onto
153// original tags when writing to the log.
154
ager@chromium.org357bf652010-04-12 11:30:10 +0000155
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000156class JitLogger;
jkummerow@chromium.org10480472013-07-17 08:22:15 +0000157class LowLevelLogger;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000158class Sampler;
159
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000160class Logger {
161 public:
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000162#define DECLARE_ENUM(enum_item, ignore) enum_item,
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000163 enum LogEventsAndTags {
164 LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM)
165 NUMBER_OF_LOG_EVENTS
166 };
167#undef DECLARE_ENUM
168
ager@chromium.org9085a012009-05-11 19:22:57 +0000169 // Acquires resources for logging if the right flags are set.
danno@chromium.orgca29dd82013-04-26 11:59:48 +0000170 bool SetUp(Isolate* isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000171
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000172 // Sets the current code event handler.
173 void SetCodeEventHandler(uint32_t options,
174 JitCodeEventHandler event_handler);
175
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000176 Sampler* sampler();
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000177
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000178 // Frees resources acquired in SetUp.
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000179 // When a temporary file is used for the log, returns its stream descriptor,
180 // leaving the file open.
181 FILE* TearDown();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000182
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000183 // Emits an event with a string value -> (name, value).
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000184 void StringEvent(const char* name, const char* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000185
186 // Emits an event with an int value -> (name, value).
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000187 void IntEvent(const char* name, int value);
188 void IntPtrTEvent(const char* name, intptr_t value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000189
190 // Emits an event with an handle value -> (name, location).
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000191 void HandleEvent(const char* name, Object** location);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000192
193 // Emits memory management events for C allocated structures.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000194 void NewEvent(const char* name, void* object, size_t size);
195 void DeleteEvent(const char* name, void* object);
196
197 // Static versions of the above, operate on current isolate's logger.
198 // Used in TRACK_MEMORY(TypeName) defined in globals.h
199 static void NewEventStatic(const char* name, void* object, size_t size);
200 static void DeleteEventStatic(const char* name, void* object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000201
202 // Emits an event with a tag, and some resource usage information.
203 // -> (name, tag, <rusage information>).
204 // Currently, the resource usage information is a process time stamp
205 // and a real time timestamp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000206 void ResourceEvent(const char* name, const char* tag);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000207
208 // Emits an event that an undefined property was read from an
209 // object.
ulan@chromium.org750145a2013-03-07 15:14:13 +0000210 void SuspectReadEvent(Name* name, Object* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000211
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000212 // Emits an event when a message is put on or read from a debugging queue.
213 // DebugTag lets us put a call-site specific label on the event.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000214 void DebugTag(const char* call_site_tag);
215 void DebugEvent(const char* event_type, Vector<uint16_t> parameter);
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000216
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000217
218 // ==== Events logged by --log-api. ====
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000219 void ApiNamedSecurityCheck(Object* key);
220 void ApiIndexedSecurityCheck(uint32_t index);
221 void ApiNamedPropertyAccess(const char* tag, JSObject* holder, Object* name);
222 void ApiIndexedPropertyAccess(const char* tag,
223 JSObject* holder,
224 uint32_t index);
225 void ApiObjectAccess(const char* tag, JSObject* obj);
226 void ApiEntryCall(const char* name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000227
228
229 // ==== Events logged by --log-code. ====
danno@chromium.orgd3c42102013-08-01 16:58:23 +0000230 void addCodeEventListener(CodeEventListener* listener);
231 void removeCodeEventListener(CodeEventListener* listener);
232 bool hasCodeEventListener(CodeEventListener* listener);
233
234
ager@chromium.org01beca72009-11-24 14:29:16 +0000235 // Emits a code event for a callback function.
ulan@chromium.org750145a2013-03-07 15:14:13 +0000236 void CallbackEvent(Name* name, Address entry_point);
237 void GetterCallbackEvent(Name* name, Address entry_point);
238 void SetterCallbackEvent(Name* name, Address entry_point);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000239 // Emits a code create event.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000240 void CodeCreateEvent(LogEventsAndTags tag,
241 Code* code, const char* source);
242 void CodeCreateEvent(LogEventsAndTags tag,
ulan@chromium.org750145a2013-03-07 15:14:13 +0000243 Code* code, Name* name);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000244 void CodeCreateEvent(LogEventsAndTags tag,
245 Code* code,
246 SharedFunctionInfo* shared,
jkummerow@chromium.org4e308cf2013-05-17 13:39:16 +0000247 CompilationInfo* info,
ulan@chromium.org750145a2013-03-07 15:14:13 +0000248 Name* name);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000249 void CodeCreateEvent(LogEventsAndTags tag,
250 Code* code,
251 SharedFunctionInfo* shared,
jkummerow@chromium.org4e308cf2013-05-17 13:39:16 +0000252 CompilationInfo* info,
jkummerow@chromium.org1e8da742013-08-26 17:13:35 +0000253 Name* source, int line, int column);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000254 void CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count);
255 void CodeMovingGCEvent();
ager@chromium.org71daaf62009-04-01 07:22:49 +0000256 // Emits a code create event for a RegExp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000257 void RegExpCodeCreateEvent(Code* code, String* source);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000258 // Emits a code move event.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000259 void CodeMoveEvent(Address from, Address to);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000260 // Emits a code delete event.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000261 void CodeDeleteEvent(Address from);
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +0000262 // Emits a code line info add event with Postion type.
263 void CodeLinePosInfoAddPositionEvent(void* jit_handler_data,
264 int pc_offset,
265 int position);
266 // Emits a code line info add event with StatementPostion type.
267 void CodeLinePosInfoAddStatementPositionEvent(void* jit_handler_data,
268 int pc_offset,
269 int position);
270 // Emits a code line info start to record event
271 void CodeStartLinePosInfoRecordEvent(PositionsRecorder* pos_recorder);
272 // Emits a code line info finish record event.
273 // It's the callee's responsibility to dispose the parameter jit_handler_data.
274 void CodeEndLinePosInfoRecordEvent(Code* code, void* jit_handler_data);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000275
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000276 void SharedFunctionInfoMoveEvent(Address from, Address to);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000277
danno@chromium.orgd3c42102013-08-01 16:58:23 +0000278 void CodeNameEvent(Address addr, int pos, const char* code_name);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000279 void SnapshotPositionEvent(Address addr, int pos);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000280
281 // ==== Events logged by --log-gc. ====
282 // Heap sampling events: start, end, and individual types.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000283 void HeapSampleBeginEvent(const char* space, const char* kind);
284 void HeapSampleEndEvent(const char* space, const char* kind);
285 void HeapSampleItemEvent(const char* type, int number, int bytes);
286 void HeapSampleJSConstructorEvent(const char* constructor,
287 int number, int bytes);
288 void HeapSampleJSRetainersEvent(const char* constructor,
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +0000289 const char* event);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000290 void HeapSampleJSProducerEvent(const char* constructor,
291 Address* stack);
292 void HeapSampleStats(const char* space, const char* kind,
293 intptr_t capacity, intptr_t used);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000294
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000295 void SharedLibraryEvent(const char* library_path,
296 uintptr_t start,
297 uintptr_t end);
298 void SharedLibraryEvent(const wchar_t* library_path,
299 uintptr_t start,
300 uintptr_t end);
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +0000301
302 // ==== Events logged by --log-timer-events. ====
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +0000303 enum StartEnd { START, END };
304
machenbach@chromium.orgc1789ee2013-07-05 07:09:57 +0000305 void CodeDeoptEvent(Code* code);
306
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +0000307 void TimerEvent(StartEnd se, const char* name);
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +0000308
danno@chromium.orgca29dd82013-04-26 11:59:48 +0000309 static void EnterExternal(Isolate* isolate);
310 static void LeaveExternal(Isolate* isolate);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000311
312 class TimerEventScope {
313 public:
danno@chromium.org1f34ad32012-11-26 14:53:56 +0000314 TimerEventScope(Isolate* isolate, const char* name)
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +0000315 : isolate_(isolate), name_(name) {
316 if (FLAG_log_internal_timer_events) LogTimerEvent(START);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000317 }
318
319 ~TimerEventScope() {
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +0000320 if (FLAG_log_internal_timer_events) LogTimerEvent(END);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000321 }
322
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +0000323 void LogTimerEvent(StartEnd se);
danno@chromium.org1f34ad32012-11-26 14:53:56 +0000324
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000325 static const char* v8_recompile_synchronous;
rossberg@chromium.org92597162013-08-23 13:28:00 +0000326 static const char* v8_recompile_concurrent;
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000327 static const char* v8_compile_full_code;
328 static const char* v8_execute;
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +0000329 static const char* v8_external;
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000330
331 private:
danno@chromium.org1f34ad32012-11-26 14:53:56 +0000332 Isolate* isolate_;
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000333 const char* name_;
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000334 };
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000335
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000336 // ==== Events logged by --log-regexp ====
337 // Regexp compilation and execution events.
338
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000339 void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000340
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000341 // Log an event reported from generated code
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000342 void LogRuntime(Vector<const char> format, JSArray* args);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000343
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000344 bool is_logging() {
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +0000345 return is_logging_;
ager@chromium.org3e875802009-06-29 08:26:34 +0000346 }
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000347
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000348 bool is_logging_code_events() {
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000349 return is_logging() || jit_logger_ != NULL;
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000350 }
351
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +0000352 // Stop collection of profiling data.
353 // When data collection is paused, CPU Tick events are discarded.
354 void StopProfiler();
iposva@chromium.org245aa852009-02-10 00:49:54 +0000355
lrn@chromium.org34e60782011-09-15 07:25:40 +0000356 void LogExistingFunction(Handle<SharedFunctionInfo> shared,
357 Handle<Code> code);
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000358 // Logs all compiled functions found in the heap.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000359 void LogCompiledFunctions();
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000360 // Logs all accessor callbacks found in the heap.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000361 void LogAccessorCallbacks();
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000362 // Used for logging stubs found in the snapshot.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000363 void LogCodeObjects();
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000364
ager@chromium.org357bf652010-04-12 11:30:10 +0000365 // Converts tag to a corresponding NATIVE_... if the script is native.
366 INLINE(static LogEventsAndTags ToNativeByScript(LogEventsAndTags, Script*));
367
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000368 // Profiler's sampling interval (in milliseconds).
svenpanne@chromium.orgecb9dd62011-12-01 08:22:35 +0000369#if defined(ANDROID)
370 // Phones and tablets have processors that are much slower than desktop
371 // and laptop computers for which current heuristics are tuned.
372 static const int kSamplingIntervalMs = 5;
373#else
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000374 static const int kSamplingIntervalMs = 1;
svenpanne@chromium.orgecb9dd62011-12-01 08:22:35 +0000375#endif
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000376
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000377 // Callback from Log, stops profiling in case of insufficient resources.
378 void LogFailure();
379
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000380 private:
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +0000381 explicit Logger(Isolate* isolate);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000382 ~Logger();
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000383
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000384 // Emits the profiler's first message.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000385 void ProfilerBeginEvent();
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000386
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000387 // Emits callback event messages.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000388 void CallbackEventInternal(const char* prefix,
ulan@chromium.org750145a2013-03-07 15:14:13 +0000389 Name* name,
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000390 Address entry_point);
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000391
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000392 // Internal configurable move event.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000393 void MoveEventInternal(LogEventsAndTags event, Address from, Address to);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000394
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000395 // Emits the source code of a regexp. Used by regexp events.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000396 void LogRegExpSource(Handle<JSRegExp> regexp);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000397
ager@chromium.org5c838252010-02-19 08:53:10 +0000398 // Used for logging stubs found in the snapshot.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000399 void LogCodeObject(Object* code_object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000400
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +0000401 // Helper method. It resets name_buffer_ and add tag name into it.
402 void InitNameBuffer(LogEventsAndTags tag);
403
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000404 // Emits a profiler tick event. Used by the profiler thread.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000405 void TickEvent(TickSample* sample, bool overflow);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000406
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000407 void ApiEvent(const char* name, ...);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000408
ager@chromium.org6f10e412009-02-13 10:11:16 +0000409 // Logs a StringEvent regardless of whether FLAG_log is true.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000410 void UncheckedStringEvent(const char* name, const char* value);
ager@chromium.org6f10e412009-02-13 10:11:16 +0000411
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000412 // Logs an IntEvent regardless of whether FLAG_log is true.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000413 void UncheckedIntEvent(const char* name, int value);
414 void UncheckedIntPtrTEvent(const char* name, intptr_t value);
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000415
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +0000416 Isolate* isolate_;
417
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000418 // The sampler used by the profiler and the sliding state window.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000419 Ticker* ticker_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000420
421 // When the statistical profile is active, profiler_
422 // points to a Profiler, that handles collection
423 // of samples.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000424 Profiler* profiler_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000425
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000426 // An array of log events names.
427 const char* const* log_events_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000428
429 // Internal implementation classes with access to
430 // private members.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000431 friend class EventLog;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000432 friend class Isolate;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000433 friend class TimeLog;
434 friend class Profiler;
danno@chromium.orgca29dd82013-04-26 11:59:48 +0000435 template <StateTag Tag> friend class VMState;
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000436 friend class LoggerTestHelper;
ager@chromium.org3e875802009-06-29 08:26:34 +0000437
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +0000438 bool is_logging_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000439 Log* log_;
jkummerow@chromium.org10480472013-07-17 08:22:15 +0000440 LowLevelLogger* ll_logger_;
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000441 JitLogger* jit_logger_;
danno@chromium.orgd3c42102013-08-01 16:58:23 +0000442 List<CodeEventListener*> listeners_;
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000443
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000444 // Guards against multiple calls to TearDown() that can happen in some tests.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000445 // 'true' between SetUp() and TearDown().
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000446 bool is_initialized_;
447
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +0000448 ElapsedTimer timer_;
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000449
lrn@chromium.org25156de2010-04-06 13:10:27 +0000450 friend class CpuProfiler;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000451};
452
453
danno@chromium.orgd3c42102013-08-01 16:58:23 +0000454class CodeEventListener {
455 public:
456 virtual ~CodeEventListener() {}
457
458 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
459 Code* code,
460 const char* comment) = 0;
461 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
462 Code* code,
463 Name* name) = 0;
464 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
465 Code* code,
466 SharedFunctionInfo* shared,
467 CompilationInfo* info,
468 Name* name) = 0;
469 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
470 Code* code,
471 SharedFunctionInfo* shared,
472 CompilationInfo* info,
473 Name* source,
mvstanton@chromium.orgdd6d9ee2013-10-11 10:35:37 +0000474 int line, int column) = 0;
danno@chromium.orgd3c42102013-08-01 16:58:23 +0000475 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
476 Code* code,
477 int args_count) = 0;
478 virtual void CallbackEvent(Name* name, Address entry_point) = 0;
479 virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0;
480 virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0;
481 virtual void RegExpCodeCreateEvent(Code* code, String* source) = 0;
482 virtual void CodeMoveEvent(Address from, Address to) = 0;
483 virtual void CodeDeleteEvent(Address from) = 0;
484 virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
485 virtual void CodeMovingGCEvent() = 0;
486};
487
488
489class CodeEventLogger : public CodeEventListener {
490 public:
491 CodeEventLogger();
492 virtual ~CodeEventLogger();
493
494 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
495 Code* code,
496 const char* comment);
497 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
498 Code* code,
499 Name* name);
500 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
501 Code* code,
502 int args_count);
503 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
504 Code* code,
505 SharedFunctionInfo* shared,
506 CompilationInfo* info,
507 Name* name);
508 virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
509 Code* code,
510 SharedFunctionInfo* shared,
511 CompilationInfo* info,
512 Name* source,
mvstanton@chromium.orgdd6d9ee2013-10-11 10:35:37 +0000513 int line, int column);
danno@chromium.orgd3c42102013-08-01 16:58:23 +0000514 virtual void RegExpCodeCreateEvent(Code* code, String* source);
515
516 virtual void CallbackEvent(Name* name, Address entry_point) { }
517 virtual void GetterCallbackEvent(Name* name, Address entry_point) { }
518 virtual void SetterCallbackEvent(Name* name, Address entry_point) { }
519 virtual void SharedFunctionInfoMoveEvent(Address from, Address to) { }
520 virtual void CodeMovingGCEvent() { }
521
522 private:
523 class NameBuffer;
524
525 virtual void LogRecordedBuffer(Code* code,
526 SharedFunctionInfo* shared,
527 const char* name,
528 int length) = 0;
529
530 NameBuffer* name_buffer_;
531};
532
533
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000534} } // namespace v8::internal
535
lrn@chromium.org25156de2010-04-06 13:10:27 +0000536
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000537#endif // V8_LOG_H_