blob: 31d840413ce61225e4a64b8df6d6b45c9c75f6f4 [file] [log] [blame]
Ben Murdoch257744e2011-11-30 15:57:28 +00001// Copyright 2011 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +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
Ben Murdoch257744e2011-11-30 15:57:28 +000031#include "allocation.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000032#include "platform.h"
33#include "log-utils.h"
34
35namespace v8 {
36namespace internal {
37
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
48// --log-api, --log-code, --log-gc, and --log-regexp.
49//
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//
57// --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//
61// --log-regexp
62// Log creation and use of regular expressions, Default is off.
63// --log-regexp implies --log.
64//
65// --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.
Ben Murdoch257744e2011-11-30 15:57:28 +000073class HashMap;
74class LogMessageBuilder;
Steve Blocka7e24c12009-10-30 11:49:00 +000075class Profiler;
76class Semaphore;
77class SlidingStateWindow;
Ben Murdoch257744e2011-11-30 15:57:28 +000078class Ticker;
Steve Blocka7e24c12009-10-30 11:49:00 +000079
80#undef LOG
Steve Block44f0eee2011-05-26 01:26:41 +010081#define LOG(isolate, Call) \
82 do { \
83 v8::internal::Logger* logger = \
84 (isolate)->logger(); \
85 if (logger->is_logging()) \
86 logger->Call; \
Steve Blocka7e24c12009-10-30 11:49:00 +000087 } while (false)
Steve Blocka7e24c12009-10-30 11:49:00 +000088
Ben Murdoch257744e2011-11-30 15:57:28 +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") \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100134 V(NATIVE_SCRIPT_TAG, "Script")
Steve Block6ded16b2010-05-10 14:33:55 +0100135// Note that 'NATIVE_' cases for functions and scripts are mapped onto
136// original tags when writing to the log.
137
Steve Blocka7e24c12009-10-30 11:49:00 +0000138
Steve Block44f0eee2011-05-26 01:26:41 +0100139class Sampler;
140
141
Steve Blocka7e24c12009-10-30 11:49:00 +0000142class Logger {
143 public:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100144#define DECLARE_ENUM(enum_item, ignore) enum_item,
Steve Blocka7e24c12009-10-30 11:49:00 +0000145 enum LogEventsAndTags {
146 LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM)
147 NUMBER_OF_LOG_EVENTS
148 };
149#undef DECLARE_ENUM
150
151 // Acquires resources for logging if the right flags are set.
Steve Block44f0eee2011-05-26 01:26:41 +0100152 bool Setup();
Steve Blocka7e24c12009-10-30 11:49:00 +0000153
Steve Block44f0eee2011-05-26 01:26:41 +0100154 void EnsureTickerStarted();
155 void EnsureTickerStopped();
156
157 Sampler* sampler();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100158
Steve Blocka7e24c12009-10-30 11:49:00 +0000159 // Frees resources acquired in Setup.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000160 // When a temporary file is used for the log, returns its stream descriptor,
161 // leaving the file open.
162 FILE* TearDown();
Steve Blocka7e24c12009-10-30 11:49:00 +0000163
164 // Enable the computation of a sliding window of states.
Steve Block44f0eee2011-05-26 01:26:41 +0100165 void EnableSlidingStateWindow();
Steve Blocka7e24c12009-10-30 11:49:00 +0000166
Steve Blocka7e24c12009-10-30 11:49:00 +0000167 // Emits an event with a string value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100168 void StringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000169
170 // Emits an event with an int value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100171 void IntEvent(const char* name, int value);
172 void IntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000173
174 // Emits an event with an handle value -> (name, location).
Steve Block44f0eee2011-05-26 01:26:41 +0100175 void HandleEvent(const char* name, Object** location);
Steve Blocka7e24c12009-10-30 11:49:00 +0000176
177 // Emits memory management events for C allocated structures.
Steve Block44f0eee2011-05-26 01:26:41 +0100178 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);
Steve Blocka7e24c12009-10-30 11:49:00 +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.
Steve Block44f0eee2011-05-26 01:26:41 +0100190 void ResourceEvent(const char* name, const char* tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000191
192 // Emits an event that an undefined property was read from an
193 // object.
Steve Block44f0eee2011-05-26 01:26:41 +0100194 void SuspectReadEvent(String* name, Object* obj);
Steve Blocka7e24c12009-10-30 11:49:00 +0000195
196 // 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.
Steve Block44f0eee2011-05-26 01:26:41 +0100198 void DebugTag(const char* call_site_tag);
199 void DebugEvent(const char* event_type, Vector<uint16_t> parameter);
Steve Blocka7e24c12009-10-30 11:49:00 +0000200
201
202 // ==== Events logged by --log-api. ====
Steve Block44f0eee2011-05-26 01:26:41 +0100203 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);
Steve Blocka7e24c12009-10-30 11:49:00 +0000211
212
213 // ==== Events logged by --log-code. ====
Steve Blockd0582a62009-12-15 09:54:21 +0000214 // Emits a code event for a callback function.
Steve Block44f0eee2011-05-26 01:26:41 +0100215 void CallbackEvent(String* name, Address entry_point);
216 void GetterCallbackEvent(String* name, Address entry_point);
217 void SetterCallbackEvent(String* name, Address entry_point);
Steve Blocka7e24c12009-10-30 11:49:00 +0000218 // Emits a code create event.
Steve Block44f0eee2011-05-26 01:26:41 +0100219 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();
Steve Blocka7e24c12009-10-30 11:49:00 +0000233 // Emits a code create event for a RegExp.
Steve Block44f0eee2011-05-26 01:26:41 +0100234 void RegExpCodeCreateEvent(Code* code, String* source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000235 // Emits a code move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100236 void CodeMoveEvent(Address from, Address to);
Steve Blocka7e24c12009-10-30 11:49:00 +0000237 // Emits a code delete event.
Steve Block44f0eee2011-05-26 01:26:41 +0100238 void CodeDeleteEvent(Address from);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100239
Steve Block44f0eee2011-05-26 01:26:41 +0100240 void SharedFunctionInfoMoveEvent(Address from, Address to);
Steve Blocka7e24c12009-10-30 11:49:00 +0000241
Steve Block44f0eee2011-05-26 01:26:41 +0100242 void SnapshotPositionEvent(Address addr, int pos);
Leon Clarkee46be812010-01-19 14:06:41 +0000243
Steve Blocka7e24c12009-10-30 11:49:00 +0000244 // ==== Events logged by --log-gc. ====
245 // Heap sampling events: start, end, and individual types.
Steve Block44f0eee2011-05-26 01:26:41 +0100246 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,
Steve Blocka7e24c12009-10-30 11:49:00 +0000252 const char* event);
Steve Block44f0eee2011-05-26 01:26:41 +0100253 void HeapSampleJSProducerEvent(const char* constructor,
254 Address* stack);
255 void HeapSampleStats(const char* space, const char* kind,
256 intptr_t capacity, intptr_t used);
Steve Blocka7e24c12009-10-30 11:49:00 +0000257
Steve Block44f0eee2011-05-26 01:26:41 +0100258 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);
Steve Blocka7e24c12009-10-30 11:49:00 +0000264
265 // ==== Events logged by --log-regexp ====
266 // Regexp compilation and execution events.
267
Steve Block44f0eee2011-05-26 01:26:41 +0100268 void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache);
Steve Blocka7e24c12009-10-30 11:49:00 +0000269
270 // Log an event reported from generated code
Steve Block44f0eee2011-05-26 01:26:41 +0100271 void LogRuntime(Vector<const char> format, JSArray* args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000272
Steve Block44f0eee2011-05-26 01:26:41 +0100273 bool is_logging() {
Steve Block6ded16b2010-05-10 14:33:55 +0100274 return logging_nesting_ > 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000275 }
276
277 // Pause/Resume collection of profiling data.
278 // When data collection is paused, CPU Tick events are discarded until
279 // data collection is Resumed.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000280 void PauseProfiler();
281 void ResumeProfiler();
282 bool IsProfilerPaused();
Steve Blocka7e24c12009-10-30 11:49:00 +0000283
284 // Logs all compiled functions found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100285 void LogCompiledFunctions();
Steve Blockd0582a62009-12-15 09:54:21 +0000286 // Logs all accessor callbacks found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100287 void LogAccessorCallbacks();
Steve Blockd0582a62009-12-15 09:54:21 +0000288 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100289 void LogCodeObjects();
Steve Blocka7e24c12009-10-30 11:49:00 +0000290
Steve Block6ded16b2010-05-10 14:33:55 +0100291 // Converts tag to a corresponding NATIVE_... if the script is native.
292 INLINE(static LogEventsAndTags ToNativeByScript(LogEventsAndTags, Script*));
Steve Blocka7e24c12009-10-30 11:49:00 +0000293
294 // Profiler's sampling interval (in milliseconds).
Ben Murdoch75492482011-12-01 11:18:12 +0000295#if defined(ANDROID)
296 // Phones and tablets have processors that are much slower than desktop
297 // and laptop computers for which current heuristics are tuned.
298 static const int kSamplingIntervalMs = 5;
299#else
Steve Blocka7e24c12009-10-30 11:49:00 +0000300 static const int kSamplingIntervalMs = 1;
Ben Murdoch75492482011-12-01 11:18:12 +0000301#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000302
Steve Block44f0eee2011-05-26 01:26:41 +0100303 // Callback from Log, stops profiling in case of insufficient resources.
304 void LogFailure();
305
Steve Block6ded16b2010-05-10 14:33:55 +0100306 private:
Ben Murdoch257744e2011-11-30 15:57:28 +0000307 class NameBuffer;
308 class NameMap;
309
Steve Block44f0eee2011-05-26 01:26:41 +0100310 Logger();
311 ~Logger();
Steve Block6ded16b2010-05-10 14:33:55 +0100312
Steve Blocka7e24c12009-10-30 11:49:00 +0000313 // Emits the profiler's first message.
Steve Block44f0eee2011-05-26 01:26:41 +0100314 void ProfilerBeginEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000315
Steve Blockd0582a62009-12-15 09:54:21 +0000316 // Emits callback event messages.
Steve Block44f0eee2011-05-26 01:26:41 +0100317 void CallbackEventInternal(const char* prefix,
318 const char* name,
319 Address entry_point);
Steve Blockd0582a62009-12-15 09:54:21 +0000320
Leon Clarked91b9f72010-01-27 17:25:45 +0000321 // Internal configurable move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100322 void MoveEventInternal(LogEventsAndTags event, Address from, Address to);
Leon Clarked91b9f72010-01-27 17:25:45 +0000323
324 // Internal configurable move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100325 void DeleteEventInternal(LogEventsAndTags event, Address from);
Leon Clarked91b9f72010-01-27 17:25:45 +0000326
Steve Blocka7e24c12009-10-30 11:49:00 +0000327 // Emits the source code of a regexp. Used by regexp events.
Steve Block44f0eee2011-05-26 01:26:41 +0100328 void LogRegExpSource(Handle<JSRegExp> regexp);
Steve Blocka7e24c12009-10-30 11:49:00 +0000329
Andrei Popescu31002712010-02-23 13:46:05 +0000330 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100331 void LogCodeObject(Object* code_object);
Andrei Popescu31002712010-02-23 13:46:05 +0000332
Ben Murdochf87a2032010-10-22 12:50:53 +0100333 // Emits general information about generated code.
Steve Block44f0eee2011-05-26 01:26:41 +0100334 void LogCodeInfo();
Ben Murdochf87a2032010-10-22 12:50:53 +0100335
Ben Murdoch257744e2011-11-30 15:57:28 +0000336 void RegisterSnapshotCodeName(Code* code, const char* name, int name_size);
337
338 // Low-level logging support.
339
340 void LowLevelCodeCreateEvent(Code* code, const char* name, int name_size);
341
342 void LowLevelCodeMoveEvent(Address from, Address to);
343
344 void LowLevelCodeDeleteEvent(Address from);
345
346 void LowLevelSnapshotPositionEvent(Address addr, int pos);
347
348 void LowLevelLogWriteBytes(const char* bytes, int size);
349
350 template <typename T>
351 void LowLevelLogWriteStruct(const T& s) {
352 char tag = T::kTag;
353 LowLevelLogWriteBytes(reinterpret_cast<const char*>(&tag), sizeof(tag));
354 LowLevelLogWriteBytes(reinterpret_cast<const char*>(&s), sizeof(s));
355 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100356
Steve Blocka7e24c12009-10-30 11:49:00 +0000357 // Emits a profiler tick event. Used by the profiler thread.
Steve Block44f0eee2011-05-26 01:26:41 +0100358 void TickEvent(TickSample* sample, bool overflow);
Steve Blocka7e24c12009-10-30 11:49:00 +0000359
Steve Block44f0eee2011-05-26 01:26:41 +0100360 void ApiEvent(const char* name, ...);
Steve Blocka7e24c12009-10-30 11:49:00 +0000361
362 // Logs a StringEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100363 void UncheckedStringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000364
Steve Block6ded16b2010-05-10 14:33:55 +0100365 // Logs an IntEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100366 void UncheckedIntEvent(const char* name, int value);
367 void UncheckedIntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000368
369 // Returns whether profiler's sampler is active.
Steve Block44f0eee2011-05-26 01:26:41 +0100370 bool IsProfilerSamplerActive();
Steve Blocka7e24c12009-10-30 11:49:00 +0000371
372 // The sampler used by the profiler and the sliding state window.
Steve Block44f0eee2011-05-26 01:26:41 +0100373 Ticker* ticker_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000374
375 // When the statistical profile is active, profiler_
376 // points to a Profiler, that handles collection
377 // of samples.
Steve Block44f0eee2011-05-26 01:26:41 +0100378 Profiler* profiler_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000379
Steve Blocka7e24c12009-10-30 11:49:00 +0000380 // SlidingStateWindow instance keeping a sliding window of the most
381 // recent VM states.
Steve Block44f0eee2011-05-26 01:26:41 +0100382 SlidingStateWindow* sliding_state_window_;
383
384 // An array of log events names.
385 const char* const* log_events_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000386
Steve Blocka7e24c12009-10-30 11:49:00 +0000387 // Internal implementation classes with access to
388 // private members.
Steve Blocka7e24c12009-10-30 11:49:00 +0000389 friend class EventLog;
Steve Block44f0eee2011-05-26 01:26:41 +0100390 friend class Isolate;
391 friend class LogMessageBuilder;
Steve Blocka7e24c12009-10-30 11:49:00 +0000392 friend class TimeLog;
393 friend class Profiler;
394 friend class SlidingStateWindow;
Steve Blockd0582a62009-12-15 09:54:21 +0000395 friend class StackTracer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000396 friend class VMState;
397
398 friend class LoggerTestHelper;
399
Steve Block44f0eee2011-05-26 01:26:41 +0100400
401 int logging_nesting_;
402 int cpu_profiler_nesting_;
Steve Block44f0eee2011-05-26 01:26:41 +0100403
404 Log* log_;
405
Ben Murdoch257744e2011-11-30 15:57:28 +0000406 NameBuffer* name_buffer_;
407
408 NameMap* address_to_name_map_;
409
Steve Block44f0eee2011-05-26 01:26:41 +0100410 // Guards against multiple calls to TearDown() that can happen in some tests.
411 // 'true' between Setup() and TearDown().
412 bool is_initialized_;
413
414 // Support for 'incremental addresses' in compressed logs:
415 // LogMessageBuilder::AppendAddress(Address addr)
416 Address last_address_;
417 // Logger::TickEvent(...)
418 Address prev_sp_;
419 Address prev_function_;
420 // Logger::MoveEventInternal(...)
421 Address prev_to_;
422 // Logger::FunctionCreateEvent(...)
423 Address prev_code_;
Steve Block6ded16b2010-05-10 14:33:55 +0100424
425 friend class CpuProfiler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000426};
427
428
Steve Block44f0eee2011-05-26 01:26:41 +0100429// Process wide registry of samplers.
430class SamplerRegistry : public AllStatic {
431 public:
432 enum State {
433 HAS_NO_SAMPLERS,
434 HAS_SAMPLERS,
435 HAS_CPU_PROFILING_SAMPLERS
436 };
437
438 typedef void (*VisitSampler)(Sampler*, void*);
439
440 static State GetState();
441
442 // Iterates over all active samplers keeping the internal lock held.
443 // Returns whether there are any active samplers.
444 static bool IterateActiveSamplers(VisitSampler func, void* param);
445
446 // Adds/Removes an active sampler.
447 static void AddActiveSampler(Sampler* sampler);
448 static void RemoveActiveSampler(Sampler* sampler);
449
450 private:
451 static bool ActiveSamplersExist() {
452 return active_samplers_ != NULL && !active_samplers_->is_empty();
453 }
454
455 static Mutex* mutex_; // Protects the state below.
456 static List<Sampler*>* active_samplers_;
457
458 DISALLOW_IMPLICIT_CONSTRUCTORS(SamplerRegistry);
459};
460
461
Steve Blocka7e24c12009-10-30 11:49:00 +0000462// Class that extracts stack trace, used for profiling.
463class StackTracer : public AllStatic {
464 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100465 static void Trace(Isolate* isolate, TickSample* sample);
Steve Blocka7e24c12009-10-30 11:49:00 +0000466};
467
Steve Blocka7e24c12009-10-30 11:49:00 +0000468} } // namespace v8::internal
469
Steve Block6ded16b2010-05-10 14:33:55 +0100470
Steve Blocka7e24c12009-10-30 11:49:00 +0000471#endif // V8_LOG_H_