blob: 02250595f840015ef47afe5ae490d97a63730f85 [file] [log] [blame]
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001// Copyright 2011 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"
ager@chromium.org3e875802009-06-29 08:26:34 +000032#include "platform.h"
33#include "log-utils.h"
34
kasperl@chromium.org71affb52009-05-26 05:44:31 +000035namespace v8 {
36namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000037
38// Logger is used for collecting logging information from V8 during
39// execution. The result is dumped to a file.
40//
41// Available command line flags:
42//
43// --log
44// Minimal logging (no API, code, or GC sample events), default is off.
45//
46// --log-all
47// Log all events to the file, default is off. This is the same as combining
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000048// --log-api, --log-code, --log-gc, and --log-regexp.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000049//
50// --log-api
51// Log API events to the logfile, default is off. --log-api implies --log.
52//
53// --log-code
54// Log code (create, move, and delete) events to the logfile, default is off.
55// --log-code implies --log.
56//
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000057// --log-gc
58// Log GC heap samples after each GC that can be processed by hp2ps, default
59// is off. --log-gc implies --log.
60//
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000061// --log-regexp
62// Log creation and use of regular expressions, Default is off.
63// --log-regexp implies --log.
64//
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000065// --logfile <filename>
66// Specify the name of the logfile, default is "v8.log".
67//
68// --prof
69// Collect statistical profiling information (ticks), default is off. The
70// tick profiler requires code events, so --prof implies --log-code.
71
72// Forward declarations.
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +000073class HashMap;
74class LogMessageBuilder;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000075class Profiler;
76class Semaphore;
77class SlidingStateWindow;
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +000078class Ticker;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000079
80#undef LOG
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000081#define LOG(isolate, Call) \
82 do { \
83 v8::internal::Logger* logger = \
84 (isolate)->logger(); \
85 if (logger->is_logging()) \
86 logger->Call; \
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +000087 } while (false)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000088
ager@chromium.orgea91cc52011-05-23 06:06:11 +000089#define LOG_EVENTS_AND_TAGS_LIST(V) \
90 V(CODE_CREATION_EVENT, "code-creation") \
91 V(CODE_MOVE_EVENT, "code-move") \
92 V(CODE_DELETE_EVENT, "code-delete") \
93 V(CODE_MOVING_GC, "code-moving-gc") \
94 V(SHARED_FUNC_MOVE_EVENT, "sfi-move") \
95 V(SNAPSHOT_POSITION_EVENT, "snapshot-pos") \
96 V(SNAPSHOT_CODE_NAME_EVENT, "snapshot-code-name") \
97 V(TICK_EVENT, "tick") \
98 V(REPEAT_META_EVENT, "repeat") \
99 V(BUILTIN_TAG, "Builtin") \
100 V(CALL_DEBUG_BREAK_TAG, "CallDebugBreak") \
101 V(CALL_DEBUG_PREPARE_STEP_IN_TAG, "CallDebugPrepareStepIn") \
102 V(CALL_IC_TAG, "CallIC") \
103 V(CALL_INITIALIZE_TAG, "CallInitialize") \
104 V(CALL_MEGAMORPHIC_TAG, "CallMegamorphic") \
105 V(CALL_MISS_TAG, "CallMiss") \
106 V(CALL_NORMAL_TAG, "CallNormal") \
107 V(CALL_PRE_MONOMORPHIC_TAG, "CallPreMonomorphic") \
108 V(KEYED_CALL_DEBUG_BREAK_TAG, "KeyedCallDebugBreak") \
109 V(KEYED_CALL_DEBUG_PREPARE_STEP_IN_TAG, \
110 "KeyedCallDebugPrepareStepIn") \
111 V(KEYED_CALL_IC_TAG, "KeyedCallIC") \
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(KEYED_LOAD_IC_TAG, "KeyedLoadIC") \
121 V(KEYED_LOAD_MEGAMORPHIC_IC_TAG, "KeyedLoadMegamorphicIC") \
122 V(KEYED_EXTERNAL_ARRAY_LOAD_IC_TAG, "KeyedExternalArrayLoadIC") \
123 V(KEYED_STORE_IC_TAG, "KeyedStoreIC") \
124 V(KEYED_STORE_MEGAMORPHIC_IC_TAG, "KeyedStoreMegamorphicIC") \
125 V(KEYED_EXTERNAL_ARRAY_STORE_IC_TAG, "KeyedExternalArrayStoreIC") \
126 V(LAZY_COMPILE_TAG, "LazyCompile") \
127 V(LOAD_IC_TAG, "LoadIC") \
128 V(REG_EXP_TAG, "RegExp") \
129 V(SCRIPT_TAG, "Script") \
130 V(STORE_IC_TAG, "StoreIC") \
131 V(STUB_TAG, "Stub") \
132 V(NATIVE_FUNCTION_TAG, "Function") \
133 V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile") \
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000134 V(NATIVE_SCRIPT_TAG, "Script")
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000135// Note that 'NATIVE_' cases for functions and scripts are mapped onto
136// original tags when writing to the log.
137
ager@chromium.org357bf652010-04-12 11:30:10 +0000138
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000139class Sampler;
140
141
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000142class Logger {
143 public:
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000144#define DECLARE_ENUM(enum_item, ignore) enum_item,
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000145 enum LogEventsAndTags {
146 LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM)
147 NUMBER_OF_LOG_EVENTS
148 };
149#undef DECLARE_ENUM
150
ager@chromium.org9085a012009-05-11 19:22:57 +0000151 // Acquires resources for logging if the right flags are set.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000152 bool Setup();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000153
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000154 void EnsureTickerStarted();
155 void EnsureTickerStopped();
156
157 Sampler* sampler();
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000158
ager@chromium.org9085a012009-05-11 19:22:57 +0000159 // Frees resources acquired in Setup.
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000160 // When a temporary file is used for the log, returns its stream descriptor,
161 // leaving the file open.
162 FILE* TearDown();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000163
164 // Enable the computation of a sliding window of states.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000165 void EnableSlidingStateWindow();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000166
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000167 // Emits an event with a string value -> (name, value).
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000168 void StringEvent(const char* name, const char* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000169
170 // Emits an event with an int value -> (name, value).
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000171 void IntEvent(const char* name, int value);
172 void IntPtrTEvent(const char* name, intptr_t value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000173
174 // Emits an event with an handle value -> (name, location).
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000175 void HandleEvent(const char* name, Object** location);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000176
177 // Emits memory management events for C allocated structures.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000178 void NewEvent(const char* name, void* object, size_t size);
179 void DeleteEvent(const char* name, void* object);
180
181 // Static versions of the above, operate on current isolate's logger.
182 // Used in TRACK_MEMORY(TypeName) defined in globals.h
183 static void NewEventStatic(const char* name, void* object, size_t size);
184 static void DeleteEventStatic(const char* name, void* object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000185
186 // Emits an event with a tag, and some resource usage information.
187 // -> (name, tag, <rusage information>).
188 // Currently, the resource usage information is a process time stamp
189 // and a real time timestamp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000190 void ResourceEvent(const char* name, const char* tag);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000191
192 // Emits an event that an undefined property was read from an
193 // object.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000194 void SuspectReadEvent(String* name, Object* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000195
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000196 // Emits an event when a message is put on or read from a debugging queue.
197 // DebugTag lets us put a call-site specific label on the event.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000198 void DebugTag(const char* call_site_tag);
199 void DebugEvent(const char* event_type, Vector<uint16_t> parameter);
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000200
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000201
202 // ==== Events logged by --log-api. ====
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000203 void ApiNamedSecurityCheck(Object* key);
204 void ApiIndexedSecurityCheck(uint32_t index);
205 void ApiNamedPropertyAccess(const char* tag, JSObject* holder, Object* name);
206 void ApiIndexedPropertyAccess(const char* tag,
207 JSObject* holder,
208 uint32_t index);
209 void ApiObjectAccess(const char* tag, JSObject* obj);
210 void ApiEntryCall(const char* name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000211
212
213 // ==== Events logged by --log-code. ====
ager@chromium.org01beca72009-11-24 14:29:16 +0000214 // Emits a code event for a callback function.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000215 void CallbackEvent(String* name, Address entry_point);
216 void GetterCallbackEvent(String* name, Address entry_point);
217 void SetterCallbackEvent(String* name, Address entry_point);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000218 // Emits a code create event.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000219 void CodeCreateEvent(LogEventsAndTags tag,
220 Code* code, const char* source);
221 void CodeCreateEvent(LogEventsAndTags tag,
222 Code* code, String* name);
223 void CodeCreateEvent(LogEventsAndTags tag,
224 Code* code,
225 SharedFunctionInfo* shared,
226 String* name);
227 void CodeCreateEvent(LogEventsAndTags tag,
228 Code* code,
229 SharedFunctionInfo* shared,
230 String* source, int line);
231 void CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count);
232 void CodeMovingGCEvent();
ager@chromium.org71daaf62009-04-01 07:22:49 +0000233 // Emits a code create event for a RegExp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000234 void RegExpCodeCreateEvent(Code* code, String* source);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000235 // Emits a code move event.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000236 void CodeMoveEvent(Address from, Address to);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000237 // Emits a code delete event.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000238 void CodeDeleteEvent(Address from);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000239
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000240 void SharedFunctionInfoMoveEvent(Address from, Address to);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000241
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000242 void SnapshotPositionEvent(Address addr, int pos);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000243
244 // ==== Events logged by --log-gc. ====
245 // Heap sampling events: start, end, and individual types.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000246 void HeapSampleBeginEvent(const char* space, const char* kind);
247 void HeapSampleEndEvent(const char* space, const char* kind);
248 void HeapSampleItemEvent(const char* type, int number, int bytes);
249 void HeapSampleJSConstructorEvent(const char* constructor,
250 int number, int bytes);
251 void HeapSampleJSRetainersEvent(const char* constructor,
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +0000252 const char* event);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000253 void HeapSampleJSProducerEvent(const char* constructor,
254 Address* stack);
255 void HeapSampleStats(const char* space, const char* kind,
256 intptr_t capacity, intptr_t used);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000257
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000258 void SharedLibraryEvent(const char* library_path,
259 uintptr_t start,
260 uintptr_t end);
261 void SharedLibraryEvent(const wchar_t* library_path,
262 uintptr_t start,
263 uintptr_t end);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000264
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000265 // ==== Events logged by --log-regexp ====
266 // Regexp compilation and execution events.
267
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000268 void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000269
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000270 // Log an event reported from generated code
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000271 void LogRuntime(Vector<const char> format, JSArray* args);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000272
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000273 bool is_logging() {
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000274 return logging_nesting_ > 0;
ager@chromium.org3e875802009-06-29 08:26:34 +0000275 }
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000276
iposva@chromium.org245aa852009-02-10 00:49:54 +0000277 // Pause/Resume collection of profiling data.
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000278 // When data collection is paused, CPU Tick events are discarded until
iposva@chromium.org245aa852009-02-10 00:49:54 +0000279 // data collection is Resumed.
ricow@chromium.org4f693d62011-07-04 14:01:31 +0000280 void PauseProfiler();
281 void ResumeProfiler();
282 bool IsProfilerPaused();
iposva@chromium.org245aa852009-02-10 00:49:54 +0000283
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000284 // Logs all compiled functions found in the heap.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000285 void LogCompiledFunctions();
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000286 // Logs all accessor callbacks found in the heap.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000287 void LogAccessorCallbacks();
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000288 // Used for logging stubs found in the snapshot.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000289 void LogCodeObjects();
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000290
ager@chromium.org357bf652010-04-12 11:30:10 +0000291 // Converts tag to a corresponding NATIVE_... if the script is native.
292 INLINE(static LogEventsAndTags ToNativeByScript(LogEventsAndTags, Script*));
293
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000294 // Profiler's sampling interval (in milliseconds).
295 static const int kSamplingIntervalMs = 1;
296
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000297 // Callback from Log, stops profiling in case of insufficient resources.
298 void LogFailure();
299
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000300 private:
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000301 class NameBuffer;
302 class NameMap;
303
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000304 Logger();
305 ~Logger();
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000306
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000307 // Emits the profiler's first message.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000308 void ProfilerBeginEvent();
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000309
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000310 // Emits callback event messages.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000311 void CallbackEventInternal(const char* prefix,
312 const char* name,
313 Address entry_point);
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000314
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000315 // Internal configurable move event.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000316 void MoveEventInternal(LogEventsAndTags event, Address from, Address to);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000317
318 // Internal configurable move event.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000319 void DeleteEventInternal(LogEventsAndTags event, Address from);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000320
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000321 // Emits the source code of a regexp. Used by regexp events.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000322 void LogRegExpSource(Handle<JSRegExp> regexp);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000323
ager@chromium.org5c838252010-02-19 08:53:10 +0000324 // Used for logging stubs found in the snapshot.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000325 void LogCodeObject(Object* code_object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000326
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000327 // Emits general information about generated code.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000328 void LogCodeInfo();
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000329
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000330 void RegisterSnapshotCodeName(Code* code, const char* name, int name_size);
331
332 // Low-level logging support.
333
334 void LowLevelCodeCreateEvent(Code* code, const char* name, int name_size);
335
336 void LowLevelCodeMoveEvent(Address from, Address to);
337
338 void LowLevelCodeDeleteEvent(Address from);
339
340 void LowLevelSnapshotPositionEvent(Address addr, int pos);
341
342 void LowLevelLogWriteBytes(const char* bytes, int size);
343
344 template <typename T>
345 void LowLevelLogWriteStruct(const T& s) {
346 char tag = T::kTag;
347 LowLevelLogWriteBytes(reinterpret_cast<const char*>(&tag), sizeof(tag));
348 LowLevelLogWriteBytes(reinterpret_cast<const char*>(&s), sizeof(s));
349 }
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000350
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000351 // Emits a profiler tick event. Used by the profiler thread.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000352 void TickEvent(TickSample* sample, bool overflow);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000353
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000354 void ApiEvent(const char* name, ...);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000355
ager@chromium.org6f10e412009-02-13 10:11:16 +0000356 // Logs a StringEvent regardless of whether FLAG_log is true.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000357 void UncheckedStringEvent(const char* name, const char* value);
ager@chromium.org6f10e412009-02-13 10:11:16 +0000358
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000359 // Logs an IntEvent regardless of whether FLAG_log is true.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000360 void UncheckedIntEvent(const char* name, int value);
361 void UncheckedIntPtrTEvent(const char* name, intptr_t value);
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000362
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000363 // Returns whether profiler's sampler is active.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000364 bool IsProfilerSamplerActive();
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000365
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000366 // The sampler used by the profiler and the sliding state window.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000367 Ticker* ticker_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000368
369 // When the statistical profile is active, profiler_
370 // points to a Profiler, that handles collection
371 // of samples.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000372 Profiler* profiler_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000373
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000374 // SlidingStateWindow instance keeping a sliding window of the most
375 // recent VM states.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000376 SlidingStateWindow* sliding_state_window_;
377
378 // An array of log events names.
379 const char* const* log_events_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000380
381 // Internal implementation classes with access to
382 // private members.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000383 friend class EventLog;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000384 friend class Isolate;
385 friend class LogMessageBuilder;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000386 friend class TimeLog;
387 friend class Profiler;
388 friend class SlidingStateWindow;
ager@chromium.org01beca72009-11-24 14:29:16 +0000389 friend class StackTracer;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000390 friend class VMState;
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000391
392 friend class LoggerTestHelper;
ager@chromium.org3e875802009-06-29 08:26:34 +0000393
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000394
395 int logging_nesting_;
396 int cpu_profiler_nesting_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000397
398 Log* log_;
399
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000400 NameBuffer* name_buffer_;
401
402 NameMap* address_to_name_map_;
403
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000404 // Guards against multiple calls to TearDown() that can happen in some tests.
405 // 'true' between Setup() and TearDown().
406 bool is_initialized_;
407
408 // Support for 'incremental addresses' in compressed logs:
409 // LogMessageBuilder::AppendAddress(Address addr)
410 Address last_address_;
411 // Logger::TickEvent(...)
412 Address prev_sp_;
413 Address prev_function_;
414 // Logger::MoveEventInternal(...)
415 Address prev_to_;
416 // Logger::FunctionCreateEvent(...)
417 Address prev_code_;
lrn@chromium.org25156de2010-04-06 13:10:27 +0000418
419 friend class CpuProfiler;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000420};
421
422
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000423// Process wide registry of samplers.
424class SamplerRegistry : public AllStatic {
425 public:
426 enum State {
427 HAS_NO_SAMPLERS,
428 HAS_SAMPLERS,
429 HAS_CPU_PROFILING_SAMPLERS
430 };
431
432 typedef void (*VisitSampler)(Sampler*, void*);
433
434 static State GetState();
435
436 // Iterates over all active samplers keeping the internal lock held.
437 // Returns whether there are any active samplers.
438 static bool IterateActiveSamplers(VisitSampler func, void* param);
439
440 // Adds/Removes an active sampler.
441 static void AddActiveSampler(Sampler* sampler);
442 static void RemoveActiveSampler(Sampler* sampler);
443
444 private:
445 static bool ActiveSamplersExist() {
446 return active_samplers_ != NULL && !active_samplers_->is_empty();
447 }
448
449 static Mutex* mutex_; // Protects the state below.
450 static List<Sampler*>* active_samplers_;
451
452 DISALLOW_IMPLICIT_CONSTRUCTORS(SamplerRegistry);
453};
454
455
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000456// Class that extracts stack trace, used for profiling.
ager@chromium.orge2902be2009-06-08 12:21:35 +0000457class StackTracer : public AllStatic {
kasperl@chromium.org061ef742009-02-27 12:16:20 +0000458 public:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000459 static void Trace(Isolate* isolate, TickSample* sample);
kasperl@chromium.org061ef742009-02-27 12:16:20 +0000460};
461
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000462} } // namespace v8::internal
463
lrn@chromium.org25156de2010-04-06 13:10:27 +0000464
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000465#endif // V8_LOG_H_