blob: 93f3fe7b25f89de3d6dd6e1b898d603b3e6768cd [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
81#ifdef ENABLE_LOGGING_AND_PROFILING
Steve Block44f0eee2011-05-26 01:26:41 +010082#define LOG(isolate, Call) \
83 do { \
84 v8::internal::Logger* logger = \
85 (isolate)->logger(); \
86 if (logger->is_logging()) \
87 logger->Call; \
Steve Blocka7e24c12009-10-30 11:49:00 +000088 } while (false)
89#else
Steve Block44f0eee2011-05-26 01:26:41 +010090#define LOG(isolate, Call) ((void) 0)
Steve Blocka7e24c12009-10-30 11:49:00 +000091#endif
92
Ben Murdoch257744e2011-11-30 15:57:28 +000093#define LOG_EVENTS_AND_TAGS_LIST(V) \
94 V(CODE_CREATION_EVENT, "code-creation") \
95 V(CODE_MOVE_EVENT, "code-move") \
96 V(CODE_DELETE_EVENT, "code-delete") \
97 V(CODE_MOVING_GC, "code-moving-gc") \
98 V(SHARED_FUNC_MOVE_EVENT, "sfi-move") \
99 V(SNAPSHOT_POSITION_EVENT, "snapshot-pos") \
100 V(SNAPSHOT_CODE_NAME_EVENT, "snapshot-code-name") \
101 V(TICK_EVENT, "tick") \
102 V(REPEAT_META_EVENT, "repeat") \
103 V(BUILTIN_TAG, "Builtin") \
104 V(CALL_DEBUG_BREAK_TAG, "CallDebugBreak") \
105 V(CALL_DEBUG_PREPARE_STEP_IN_TAG, "CallDebugPrepareStepIn") \
106 V(CALL_IC_TAG, "CallIC") \
107 V(CALL_INITIALIZE_TAG, "CallInitialize") \
108 V(CALL_MEGAMORPHIC_TAG, "CallMegamorphic") \
109 V(CALL_MISS_TAG, "CallMiss") \
110 V(CALL_NORMAL_TAG, "CallNormal") \
111 V(CALL_PRE_MONOMORPHIC_TAG, "CallPreMonomorphic") \
112 V(KEYED_CALL_DEBUG_BREAK_TAG, "KeyedCallDebugBreak") \
113 V(KEYED_CALL_DEBUG_PREPARE_STEP_IN_TAG, \
114 "KeyedCallDebugPrepareStepIn") \
115 V(KEYED_CALL_IC_TAG, "KeyedCallIC") \
116 V(KEYED_CALL_INITIALIZE_TAG, "KeyedCallInitialize") \
117 V(KEYED_CALL_MEGAMORPHIC_TAG, "KeyedCallMegamorphic") \
118 V(KEYED_CALL_MISS_TAG, "KeyedCallMiss") \
119 V(KEYED_CALL_NORMAL_TAG, "KeyedCallNormal") \
120 V(KEYED_CALL_PRE_MONOMORPHIC_TAG, "KeyedCallPreMonomorphic") \
121 V(CALLBACK_TAG, "Callback") \
122 V(EVAL_TAG, "Eval") \
123 V(FUNCTION_TAG, "Function") \
124 V(KEYED_LOAD_IC_TAG, "KeyedLoadIC") \
125 V(KEYED_LOAD_MEGAMORPHIC_IC_TAG, "KeyedLoadMegamorphicIC") \
126 V(KEYED_EXTERNAL_ARRAY_LOAD_IC_TAG, "KeyedExternalArrayLoadIC") \
127 V(KEYED_STORE_IC_TAG, "KeyedStoreIC") \
128 V(KEYED_STORE_MEGAMORPHIC_IC_TAG, "KeyedStoreMegamorphicIC") \
129 V(KEYED_EXTERNAL_ARRAY_STORE_IC_TAG, "KeyedExternalArrayStoreIC") \
130 V(LAZY_COMPILE_TAG, "LazyCompile") \
131 V(LOAD_IC_TAG, "LoadIC") \
132 V(REG_EXP_TAG, "RegExp") \
133 V(SCRIPT_TAG, "Script") \
134 V(STORE_IC_TAG, "StoreIC") \
135 V(STUB_TAG, "Stub") \
136 V(NATIVE_FUNCTION_TAG, "Function") \
137 V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile") \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100138 V(NATIVE_SCRIPT_TAG, "Script")
Steve Block6ded16b2010-05-10 14:33:55 +0100139// Note that 'NATIVE_' cases for functions and scripts are mapped onto
140// original tags when writing to the log.
141
Steve Blocka7e24c12009-10-30 11:49:00 +0000142
Steve Block44f0eee2011-05-26 01:26:41 +0100143class Sampler;
144
145
Steve Blocka7e24c12009-10-30 11:49:00 +0000146class Logger {
147 public:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100148#define DECLARE_ENUM(enum_item, ignore) enum_item,
Steve Blocka7e24c12009-10-30 11:49:00 +0000149 enum LogEventsAndTags {
150 LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM)
151 NUMBER_OF_LOG_EVENTS
152 };
153#undef DECLARE_ENUM
154
155 // Acquires resources for logging if the right flags are set.
Steve Block44f0eee2011-05-26 01:26:41 +0100156 bool Setup();
Steve Blocka7e24c12009-10-30 11:49:00 +0000157
Steve Block44f0eee2011-05-26 01:26:41 +0100158 void EnsureTickerStarted();
159 void EnsureTickerStopped();
160
161 Sampler* sampler();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100162
Steve Blocka7e24c12009-10-30 11:49:00 +0000163 // Frees resources acquired in Setup.
Steve Block44f0eee2011-05-26 01:26:41 +0100164 void TearDown();
Steve Blocka7e24c12009-10-30 11:49:00 +0000165
166 // Enable the computation of a sliding window of states.
Steve Block44f0eee2011-05-26 01:26:41 +0100167 void EnableSlidingStateWindow();
Steve Blocka7e24c12009-10-30 11:49:00 +0000168
Steve Blocka7e24c12009-10-30 11:49:00 +0000169 // Emits an event with a string value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100170 void StringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000171
172 // Emits an event with an int value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100173 void IntEvent(const char* name, int value);
174 void IntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000175
176 // Emits an event with an handle value -> (name, location).
Steve Block44f0eee2011-05-26 01:26:41 +0100177 void HandleEvent(const char* name, Object** location);
Steve Blocka7e24c12009-10-30 11:49:00 +0000178
179 // Emits memory management events for C allocated structures.
Steve Block44f0eee2011-05-26 01:26:41 +0100180 void NewEvent(const char* name, void* object, size_t size);
181 void DeleteEvent(const char* name, void* object);
182
183 // Static versions of the above, operate on current isolate's logger.
184 // Used in TRACK_MEMORY(TypeName) defined in globals.h
185 static void NewEventStatic(const char* name, void* object, size_t size);
186 static void DeleteEventStatic(const char* name, void* object);
Steve Blocka7e24c12009-10-30 11:49:00 +0000187
188 // Emits an event with a tag, and some resource usage information.
189 // -> (name, tag, <rusage information>).
190 // Currently, the resource usage information is a process time stamp
191 // and a real time timestamp.
Steve Block44f0eee2011-05-26 01:26:41 +0100192 void ResourceEvent(const char* name, const char* tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000193
194 // Emits an event that an undefined property was read from an
195 // object.
Steve Block44f0eee2011-05-26 01:26:41 +0100196 void SuspectReadEvent(String* name, Object* obj);
Steve Blocka7e24c12009-10-30 11:49:00 +0000197
198 // Emits an event when a message is put on or read from a debugging queue.
199 // DebugTag lets us put a call-site specific label on the event.
Steve Block44f0eee2011-05-26 01:26:41 +0100200 void DebugTag(const char* call_site_tag);
201 void DebugEvent(const char* event_type, Vector<uint16_t> parameter);
Steve Blocka7e24c12009-10-30 11:49:00 +0000202
203
204 // ==== Events logged by --log-api. ====
Steve Block44f0eee2011-05-26 01:26:41 +0100205 void ApiNamedSecurityCheck(Object* key);
206 void ApiIndexedSecurityCheck(uint32_t index);
207 void ApiNamedPropertyAccess(const char* tag, JSObject* holder, Object* name);
208 void ApiIndexedPropertyAccess(const char* tag,
209 JSObject* holder,
210 uint32_t index);
211 void ApiObjectAccess(const char* tag, JSObject* obj);
212 void ApiEntryCall(const char* name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000213
214
215 // ==== Events logged by --log-code. ====
Steve Blockd0582a62009-12-15 09:54:21 +0000216 // Emits a code event for a callback function.
Steve Block44f0eee2011-05-26 01:26:41 +0100217 void CallbackEvent(String* name, Address entry_point);
218 void GetterCallbackEvent(String* name, Address entry_point);
219 void SetterCallbackEvent(String* name, Address entry_point);
Steve Blocka7e24c12009-10-30 11:49:00 +0000220 // Emits a code create event.
Steve Block44f0eee2011-05-26 01:26:41 +0100221 void CodeCreateEvent(LogEventsAndTags tag,
222 Code* code, const char* source);
223 void CodeCreateEvent(LogEventsAndTags tag,
224 Code* code, String* name);
225 void CodeCreateEvent(LogEventsAndTags tag,
226 Code* code,
227 SharedFunctionInfo* shared,
228 String* name);
229 void CodeCreateEvent(LogEventsAndTags tag,
230 Code* code,
231 SharedFunctionInfo* shared,
232 String* source, int line);
233 void CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count);
234 void CodeMovingGCEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000235 // Emits a code create event for a RegExp.
Steve Block44f0eee2011-05-26 01:26:41 +0100236 void RegExpCodeCreateEvent(Code* code, String* source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000237 // Emits a code move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100238 void CodeMoveEvent(Address from, Address to);
Steve Blocka7e24c12009-10-30 11:49:00 +0000239 // Emits a code delete event.
Steve Block44f0eee2011-05-26 01:26:41 +0100240 void CodeDeleteEvent(Address from);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100241
Steve Block44f0eee2011-05-26 01:26:41 +0100242 void SharedFunctionInfoMoveEvent(Address from, Address to);
Steve Blocka7e24c12009-10-30 11:49:00 +0000243
Steve Block44f0eee2011-05-26 01:26:41 +0100244 void SnapshotPositionEvent(Address addr, int pos);
Leon Clarkee46be812010-01-19 14:06:41 +0000245
Steve Blocka7e24c12009-10-30 11:49:00 +0000246 // ==== Events logged by --log-gc. ====
247 // Heap sampling events: start, end, and individual types.
Steve Block44f0eee2011-05-26 01:26:41 +0100248 void HeapSampleBeginEvent(const char* space, const char* kind);
249 void HeapSampleEndEvent(const char* space, const char* kind);
250 void HeapSampleItemEvent(const char* type, int number, int bytes);
251 void HeapSampleJSConstructorEvent(const char* constructor,
252 int number, int bytes);
253 void HeapSampleJSRetainersEvent(const char* constructor,
Steve Blocka7e24c12009-10-30 11:49:00 +0000254 const char* event);
Steve Block44f0eee2011-05-26 01:26:41 +0100255 void HeapSampleJSProducerEvent(const char* constructor,
256 Address* stack);
257 void HeapSampleStats(const char* space, const char* kind,
258 intptr_t capacity, intptr_t used);
Steve Blocka7e24c12009-10-30 11:49:00 +0000259
Steve Block44f0eee2011-05-26 01:26:41 +0100260 void SharedLibraryEvent(const char* library_path,
261 uintptr_t start,
262 uintptr_t end);
263 void SharedLibraryEvent(const wchar_t* library_path,
264 uintptr_t start,
265 uintptr_t end);
Steve Blocka7e24c12009-10-30 11:49:00 +0000266
267 // ==== Events logged by --log-regexp ====
268 // Regexp compilation and execution events.
269
Steve Block44f0eee2011-05-26 01:26:41 +0100270 void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache);
Steve Blocka7e24c12009-10-30 11:49:00 +0000271
272 // Log an event reported from generated code
Steve Block44f0eee2011-05-26 01:26:41 +0100273 void LogRuntime(Vector<const char> format, JSArray* args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000274
275#ifdef ENABLE_LOGGING_AND_PROFILING
Steve Block44f0eee2011-05-26 01:26:41 +0100276 bool is_logging() {
Steve Block6ded16b2010-05-10 14:33:55 +0100277 return logging_nesting_ > 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000278 }
279
280 // Pause/Resume collection of profiling data.
281 // When data collection is paused, CPU Tick events are discarded until
282 // data collection is Resumed.
Steve Block44f0eee2011-05-26 01:26:41 +0100283 void PauseProfiler(int flags, int tag);
284 void ResumeProfiler(int flags, int tag);
285 int GetActiveProfilerModules();
Steve Blocka7e24c12009-10-30 11:49:00 +0000286
287 // If logging is performed into a memory buffer, allows to
288 // retrieve previously written messages. See v8.h.
Steve Block44f0eee2011-05-26 01:26:41 +0100289 int GetLogLines(int from_pos, char* dest_buf, int max_size);
Steve Blocka7e24c12009-10-30 11:49:00 +0000290
291 // Logs all compiled functions found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100292 void LogCompiledFunctions();
Steve Blockd0582a62009-12-15 09:54:21 +0000293 // Logs all accessor callbacks found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100294 void LogAccessorCallbacks();
Steve Blockd0582a62009-12-15 09:54:21 +0000295 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100296 void LogCodeObjects();
Steve Blocka7e24c12009-10-30 11:49:00 +0000297
Steve Block6ded16b2010-05-10 14:33:55 +0100298 // Converts tag to a corresponding NATIVE_... if the script is native.
299 INLINE(static LogEventsAndTags ToNativeByScript(LogEventsAndTags, Script*));
Steve Blocka7e24c12009-10-30 11:49:00 +0000300
301 // Profiler's sampling interval (in milliseconds).
Ben Murdoch75492482011-12-01 11:18:12 +0000302#if defined(ANDROID)
303 // Phones and tablets have processors that are much slower than desktop
304 // and laptop computers for which current heuristics are tuned.
305 static const int kSamplingIntervalMs = 5;
306#else
Steve Blocka7e24c12009-10-30 11:49:00 +0000307 static const int kSamplingIntervalMs = 1;
Ben Murdoch75492482011-12-01 11:18:12 +0000308#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000309
Steve Block44f0eee2011-05-26 01:26:41 +0100310 // Callback from Log, stops profiling in case of insufficient resources.
311 void LogFailure();
312
Steve Block6ded16b2010-05-10 14:33:55 +0100313 private:
Ben Murdoch257744e2011-11-30 15:57:28 +0000314 class NameBuffer;
315 class NameMap;
316
Steve Block44f0eee2011-05-26 01:26:41 +0100317 Logger();
318 ~Logger();
Steve Block6ded16b2010-05-10 14:33:55 +0100319
Steve Blocka7e24c12009-10-30 11:49:00 +0000320 // Emits the profiler's first message.
Steve Block44f0eee2011-05-26 01:26:41 +0100321 void ProfilerBeginEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000322
Steve Blockd0582a62009-12-15 09:54:21 +0000323 // Emits callback event messages.
Steve Block44f0eee2011-05-26 01:26:41 +0100324 void CallbackEventInternal(const char* prefix,
325 const char* name,
326 Address entry_point);
Steve Blockd0582a62009-12-15 09:54:21 +0000327
Leon Clarked91b9f72010-01-27 17:25:45 +0000328 // Internal configurable move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100329 void MoveEventInternal(LogEventsAndTags event, Address from, Address to);
Leon Clarked91b9f72010-01-27 17:25:45 +0000330
331 // Internal configurable move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100332 void DeleteEventInternal(LogEventsAndTags event, Address from);
Leon Clarked91b9f72010-01-27 17:25:45 +0000333
Steve Blocka7e24c12009-10-30 11:49:00 +0000334 // Emits the source code of a regexp. Used by regexp events.
Steve Block44f0eee2011-05-26 01:26:41 +0100335 void LogRegExpSource(Handle<JSRegExp> regexp);
Steve Blocka7e24c12009-10-30 11:49:00 +0000336
Andrei Popescu31002712010-02-23 13:46:05 +0000337 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100338 void LogCodeObject(Object* code_object);
Andrei Popescu31002712010-02-23 13:46:05 +0000339
Ben Murdochf87a2032010-10-22 12:50:53 +0100340 // Emits general information about generated code.
Steve Block44f0eee2011-05-26 01:26:41 +0100341 void LogCodeInfo();
Ben Murdochf87a2032010-10-22 12:50:53 +0100342
Ben Murdoch257744e2011-11-30 15:57:28 +0000343 void RegisterSnapshotCodeName(Code* code, const char* name, int name_size);
344
345 // Low-level logging support.
346
347 void LowLevelCodeCreateEvent(Code* code, const char* name, int name_size);
348
349 void LowLevelCodeMoveEvent(Address from, Address to);
350
351 void LowLevelCodeDeleteEvent(Address from);
352
353 void LowLevelSnapshotPositionEvent(Address addr, int pos);
354
355 void LowLevelLogWriteBytes(const char* bytes, int size);
356
357 template <typename T>
358 void LowLevelLogWriteStruct(const T& s) {
359 char tag = T::kTag;
360 LowLevelLogWriteBytes(reinterpret_cast<const char*>(&tag), sizeof(tag));
361 LowLevelLogWriteBytes(reinterpret_cast<const char*>(&s), sizeof(s));
362 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100363
Steve Blocka7e24c12009-10-30 11:49:00 +0000364 // Emits a profiler tick event. Used by the profiler thread.
Steve Block44f0eee2011-05-26 01:26:41 +0100365 void TickEvent(TickSample* sample, bool overflow);
Steve Blocka7e24c12009-10-30 11:49:00 +0000366
Steve Block44f0eee2011-05-26 01:26:41 +0100367 void ApiEvent(const char* name, ...);
Steve Blocka7e24c12009-10-30 11:49:00 +0000368
369 // Logs a StringEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100370 void UncheckedStringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000371
Steve Block6ded16b2010-05-10 14:33:55 +0100372 // Logs an IntEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100373 void UncheckedIntEvent(const char* name, int value);
374 void UncheckedIntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000375
376 // Returns whether profiler's sampler is active.
Steve Block44f0eee2011-05-26 01:26:41 +0100377 bool IsProfilerSamplerActive();
Steve Blocka7e24c12009-10-30 11:49:00 +0000378
379 // The sampler used by the profiler and the sliding state window.
Steve Block44f0eee2011-05-26 01:26:41 +0100380 Ticker* ticker_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000381
382 // When the statistical profile is active, profiler_
383 // points to a Profiler, that handles collection
384 // of samples.
Steve Block44f0eee2011-05-26 01:26:41 +0100385 Profiler* profiler_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000386
Steve Blocka7e24c12009-10-30 11:49:00 +0000387 // SlidingStateWindow instance keeping a sliding window of the most
388 // recent VM states.
Steve Block44f0eee2011-05-26 01:26:41 +0100389 SlidingStateWindow* sliding_state_window_;
390
391 // An array of log events names.
392 const char* const* log_events_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000393
Steve Blocka7e24c12009-10-30 11:49:00 +0000394 // Internal implementation classes with access to
395 // private members.
Steve Blocka7e24c12009-10-30 11:49:00 +0000396 friend class EventLog;
Steve Block44f0eee2011-05-26 01:26:41 +0100397 friend class Isolate;
398 friend class LogMessageBuilder;
Steve Blocka7e24c12009-10-30 11:49:00 +0000399 friend class TimeLog;
400 friend class Profiler;
401 friend class SlidingStateWindow;
Steve Blockd0582a62009-12-15 09:54:21 +0000402 friend class StackTracer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000403 friend class VMState;
404
405 friend class LoggerTestHelper;
406
Steve Block44f0eee2011-05-26 01:26:41 +0100407
408 int logging_nesting_;
409 int cpu_profiler_nesting_;
410 int heap_profiler_nesting_;
411
412 Log* log_;
413
Ben Murdoch257744e2011-11-30 15:57:28 +0000414 NameBuffer* name_buffer_;
415
416 NameMap* address_to_name_map_;
417
Steve Block44f0eee2011-05-26 01:26:41 +0100418 // Guards against multiple calls to TearDown() that can happen in some tests.
419 // 'true' between Setup() and TearDown().
420 bool is_initialized_;
421
422 // Support for 'incremental addresses' in compressed logs:
423 // LogMessageBuilder::AppendAddress(Address addr)
424 Address last_address_;
425 // Logger::TickEvent(...)
426 Address prev_sp_;
427 Address prev_function_;
428 // Logger::MoveEventInternal(...)
429 Address prev_to_;
430 // Logger::FunctionCreateEvent(...)
431 Address prev_code_;
Steve Block6ded16b2010-05-10 14:33:55 +0100432
433 friend class CpuProfiler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000434#else
Steve Block44f0eee2011-05-26 01:26:41 +0100435 bool is_logging() { return false; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000436#endif
437};
438
439
Steve Block44f0eee2011-05-26 01:26:41 +0100440// Process wide registry of samplers.
441class SamplerRegistry : public AllStatic {
442 public:
443 enum State {
444 HAS_NO_SAMPLERS,
445 HAS_SAMPLERS,
446 HAS_CPU_PROFILING_SAMPLERS
447 };
448
449 typedef void (*VisitSampler)(Sampler*, void*);
450
451 static State GetState();
452
453 // Iterates over all active samplers keeping the internal lock held.
454 // Returns whether there are any active samplers.
455 static bool IterateActiveSamplers(VisitSampler func, void* param);
456
457 // Adds/Removes an active sampler.
458 static void AddActiveSampler(Sampler* sampler);
459 static void RemoveActiveSampler(Sampler* sampler);
460
461 private:
462 static bool ActiveSamplersExist() {
463 return active_samplers_ != NULL && !active_samplers_->is_empty();
464 }
465
466 static Mutex* mutex_; // Protects the state below.
467 static List<Sampler*>* active_samplers_;
468
469 DISALLOW_IMPLICIT_CONSTRUCTORS(SamplerRegistry);
470};
471
472
Steve Blocka7e24c12009-10-30 11:49:00 +0000473// Class that extracts stack trace, used for profiling.
474class StackTracer : public AllStatic {
475 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100476 static void Trace(Isolate* isolate, TickSample* sample);
Steve Blocka7e24c12009-10-30 11:49:00 +0000477};
478
Steve Blocka7e24c12009-10-30 11:49:00 +0000479} } // namespace v8::internal
480
Steve Block6ded16b2010-05-10 14:33:55 +0100481
Steve Blocka7e24c12009-10-30 11:49:00 +0000482#endif // V8_LOG_H_