blob: 1fa86d24e44d60070a80acdcba711f6b6ab306f7 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
2// 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
31#include "platform.h"
32#include "log-utils.h"
33
34namespace v8 {
35namespace internal {
36
37// Logger is used for collecting logging information from V8 during
38// execution. The result is dumped to a file.
39//
40// Available command line flags:
41//
42// --log
43// Minimal logging (no API, code, or GC sample events), default is off.
44//
45// --log-all
46// Log all events to the file, default is off. This is the same as combining
47// --log-api, --log-code, --log-gc, and --log-regexp.
48//
49// --log-api
50// Log API events to the logfile, default is off. --log-api implies --log.
51//
52// --log-code
53// Log code (create, move, and delete) events to the logfile, default is off.
54// --log-code implies --log.
55//
56// --log-gc
57// Log GC heap samples after each GC that can be processed by hp2ps, default
58// is off. --log-gc implies --log.
59//
60// --log-regexp
61// Log creation and use of regular expressions, Default is off.
62// --log-regexp implies --log.
63//
64// --logfile <filename>
65// Specify the name of the logfile, default is "v8.log".
66//
67// --prof
68// Collect statistical profiling information (ticks), default is off. The
69// tick profiler requires code events, so --prof implies --log-code.
70
71// Forward declarations.
72class Ticker;
73class Profiler;
74class Semaphore;
75class SlidingStateWindow;
76class LogMessageBuilder;
Steve Blocka7e24c12009-10-30 11:49:00 +000077
78#undef LOG
79#ifdef ENABLE_LOGGING_AND_PROFILING
Steve Block44f0eee2011-05-26 01:26:41 +010080#define LOG(isolate, Call) \
81 do { \
82 v8::internal::Logger* logger = \
83 (isolate)->logger(); \
84 if (logger->is_logging()) \
85 logger->Call; \
Steve Blocka7e24c12009-10-30 11:49:00 +000086 } while (false)
87#else
Steve Block44f0eee2011-05-26 01:26:41 +010088#define LOG(isolate, Call) ((void) 0)
Steve Blocka7e24c12009-10-30 11:49:00 +000089#endif
90
Steve Blocka7e24c12009-10-30 11:49:00 +000091#define LOG_EVENTS_AND_TAGS_LIST(V) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010092 V(CODE_CREATION_EVENT, "code-creation") \
93 V(CODE_MOVE_EVENT, "code-move") \
94 V(CODE_DELETE_EVENT, "code-delete") \
95 V(CODE_MOVING_GC, "code-moving-gc") \
Steve Block44f0eee2011-05-26 01:26:41 +010096 V(SHARED_FUNC_MOVE_EVENT, "sfi-move") \
Ben Murdochb0fe1622011-05-05 13:52:32 +010097 V(SNAPSHOT_POSITION_EVENT, "snapshot-pos") \
98 V(TICK_EVENT, "tick") \
99 V(REPEAT_META_EVENT, "repeat") \
100 V(BUILTIN_TAG, "Builtin") \
101 V(CALL_DEBUG_BREAK_TAG, "CallDebugBreak") \
102 V(CALL_DEBUG_PREPARE_STEP_IN_TAG, "CallDebugPrepareStepIn") \
103 V(CALL_IC_TAG, "CallIC") \
104 V(CALL_INITIALIZE_TAG, "CallInitialize") \
105 V(CALL_MEGAMORPHIC_TAG, "CallMegamorphic") \
106 V(CALL_MISS_TAG, "CallMiss") \
107 V(CALL_NORMAL_TAG, "CallNormal") \
108 V(CALL_PRE_MONOMORPHIC_TAG, "CallPreMonomorphic") \
109 V(KEYED_CALL_DEBUG_BREAK_TAG, "KeyedCallDebugBreak") \
110 V(KEYED_CALL_DEBUG_PREPARE_STEP_IN_TAG, \
111 "KeyedCallDebugPrepareStepIn") \
112 V(KEYED_CALL_IC_TAG, "KeyedCallIC") \
113 V(KEYED_CALL_INITIALIZE_TAG, "KeyedCallInitialize") \
114 V(KEYED_CALL_MEGAMORPHIC_TAG, "KeyedCallMegamorphic") \
115 V(KEYED_CALL_MISS_TAG, "KeyedCallMiss") \
116 V(KEYED_CALL_NORMAL_TAG, "KeyedCallNormal") \
117 V(KEYED_CALL_PRE_MONOMORPHIC_TAG, "KeyedCallPreMonomorphic") \
118 V(CALLBACK_TAG, "Callback") \
119 V(EVAL_TAG, "Eval") \
120 V(FUNCTION_TAG, "Function") \
121 V(KEYED_LOAD_IC_TAG, "KeyedLoadIC") \
Steve Block44f0eee2011-05-26 01:26:41 +0100122 V(KEYED_EXTERNAL_ARRAY_LOAD_IC_TAG, "KeyedExternalArrayLoadIC") \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100123 V(KEYED_STORE_IC_TAG, "KeyedStoreIC") \
Steve Block44f0eee2011-05-26 01:26:41 +0100124 V(KEYED_EXTERNAL_ARRAY_STORE_IC_TAG, "KeyedExternalArrayStoreIC")\
Ben Murdochb0fe1622011-05-05 13:52:32 +0100125 V(LAZY_COMPILE_TAG, "LazyCompile") \
126 V(LOAD_IC_TAG, "LoadIC") \
127 V(REG_EXP_TAG, "RegExp") \
128 V(SCRIPT_TAG, "Script") \
129 V(STORE_IC_TAG, "StoreIC") \
130 V(STUB_TAG, "Stub") \
131 V(NATIVE_FUNCTION_TAG, "Function") \
132 V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile") \
133 V(NATIVE_SCRIPT_TAG, "Script")
Steve Block6ded16b2010-05-10 14:33:55 +0100134// Note that 'NATIVE_' cases for functions and scripts are mapped onto
135// original tags when writing to the log.
136
Steve Blocka7e24c12009-10-30 11:49:00 +0000137
Steve Block44f0eee2011-05-26 01:26:41 +0100138class Sampler;
139
140
Steve Blocka7e24c12009-10-30 11:49:00 +0000141class Logger {
142 public:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100143#define DECLARE_ENUM(enum_item, ignore) enum_item,
Steve Blocka7e24c12009-10-30 11:49:00 +0000144 enum LogEventsAndTags {
145 LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM)
146 NUMBER_OF_LOG_EVENTS
147 };
148#undef DECLARE_ENUM
149
150 // Acquires resources for logging if the right flags are set.
Steve Block44f0eee2011-05-26 01:26:41 +0100151 bool Setup();
Steve Blocka7e24c12009-10-30 11:49:00 +0000152
Steve Block44f0eee2011-05-26 01:26:41 +0100153 void EnsureTickerStarted();
154 void EnsureTickerStopped();
155
156 Sampler* sampler();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100157
Steve Blocka7e24c12009-10-30 11:49:00 +0000158 // Frees resources acquired in Setup.
Steve Block44f0eee2011-05-26 01:26:41 +0100159 void TearDown();
Steve Blocka7e24c12009-10-30 11:49:00 +0000160
161 // Enable the computation of a sliding window of states.
Steve Block44f0eee2011-05-26 01:26:41 +0100162 void EnableSlidingStateWindow();
Steve Blocka7e24c12009-10-30 11:49:00 +0000163
Steve Blocka7e24c12009-10-30 11:49:00 +0000164 // Emits an event with a string value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100165 void StringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000166
167 // Emits an event with an int value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100168 void IntEvent(const char* name, int value);
169 void IntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000170
171 // Emits an event with an handle value -> (name, location).
Steve Block44f0eee2011-05-26 01:26:41 +0100172 void HandleEvent(const char* name, Object** location);
Steve Blocka7e24c12009-10-30 11:49:00 +0000173
174 // Emits memory management events for C allocated structures.
Steve Block44f0eee2011-05-26 01:26:41 +0100175 void NewEvent(const char* name, void* object, size_t size);
176 void DeleteEvent(const char* name, void* object);
177
178 // Static versions of the above, operate on current isolate's logger.
179 // Used in TRACK_MEMORY(TypeName) defined in globals.h
180 static void NewEventStatic(const char* name, void* object, size_t size);
181 static void DeleteEventStatic(const char* name, void* object);
Steve Blocka7e24c12009-10-30 11:49:00 +0000182
183 // Emits an event with a tag, and some resource usage information.
184 // -> (name, tag, <rusage information>).
185 // Currently, the resource usage information is a process time stamp
186 // and a real time timestamp.
Steve Block44f0eee2011-05-26 01:26:41 +0100187 void ResourceEvent(const char* name, const char* tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000188
189 // Emits an event that an undefined property was read from an
190 // object.
Steve Block44f0eee2011-05-26 01:26:41 +0100191 void SuspectReadEvent(String* name, Object* obj);
Steve Blocka7e24c12009-10-30 11:49:00 +0000192
193 // Emits an event when a message is put on or read from a debugging queue.
194 // DebugTag lets us put a call-site specific label on the event.
Steve Block44f0eee2011-05-26 01:26:41 +0100195 void DebugTag(const char* call_site_tag);
196 void DebugEvent(const char* event_type, Vector<uint16_t> parameter);
Steve Blocka7e24c12009-10-30 11:49:00 +0000197
198
199 // ==== Events logged by --log-api. ====
Steve Block44f0eee2011-05-26 01:26:41 +0100200 void ApiNamedSecurityCheck(Object* key);
201 void ApiIndexedSecurityCheck(uint32_t index);
202 void ApiNamedPropertyAccess(const char* tag, JSObject* holder, Object* name);
203 void ApiIndexedPropertyAccess(const char* tag,
204 JSObject* holder,
205 uint32_t index);
206 void ApiObjectAccess(const char* tag, JSObject* obj);
207 void ApiEntryCall(const char* name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000208
209
210 // ==== Events logged by --log-code. ====
Steve Blockd0582a62009-12-15 09:54:21 +0000211 // Emits a code event for a callback function.
Steve Block44f0eee2011-05-26 01:26:41 +0100212 void CallbackEvent(String* name, Address entry_point);
213 void GetterCallbackEvent(String* name, Address entry_point);
214 void SetterCallbackEvent(String* name, Address entry_point);
Steve Blocka7e24c12009-10-30 11:49:00 +0000215 // Emits a code create event.
Steve Block44f0eee2011-05-26 01:26:41 +0100216 void CodeCreateEvent(LogEventsAndTags tag,
217 Code* code, const char* source);
218 void CodeCreateEvent(LogEventsAndTags tag,
219 Code* code, String* name);
220 void CodeCreateEvent(LogEventsAndTags tag,
221 Code* code,
222 SharedFunctionInfo* shared,
223 String* name);
224 void CodeCreateEvent(LogEventsAndTags tag,
225 Code* code,
226 SharedFunctionInfo* shared,
227 String* source, int line);
228 void CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count);
229 void CodeMovingGCEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000230 // Emits a code create event for a RegExp.
Steve Block44f0eee2011-05-26 01:26:41 +0100231 void RegExpCodeCreateEvent(Code* code, String* source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000232 // Emits a code move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100233 void CodeMoveEvent(Address from, Address to);
Steve Blocka7e24c12009-10-30 11:49:00 +0000234 // Emits a code delete event.
Steve Block44f0eee2011-05-26 01:26:41 +0100235 void CodeDeleteEvent(Address from);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100236
Steve Block44f0eee2011-05-26 01:26:41 +0100237 void SharedFunctionInfoMoveEvent(Address from, Address to);
Steve Blocka7e24c12009-10-30 11:49:00 +0000238
Steve Block44f0eee2011-05-26 01:26:41 +0100239 void SnapshotPositionEvent(Address addr, int pos);
Leon Clarkee46be812010-01-19 14:06:41 +0000240
Steve Blocka7e24c12009-10-30 11:49:00 +0000241 // ==== Events logged by --log-gc. ====
242 // Heap sampling events: start, end, and individual types.
Steve Block44f0eee2011-05-26 01:26:41 +0100243 void HeapSampleBeginEvent(const char* space, const char* kind);
244 void HeapSampleEndEvent(const char* space, const char* kind);
245 void HeapSampleItemEvent(const char* type, int number, int bytes);
246 void HeapSampleJSConstructorEvent(const char* constructor,
247 int number, int bytes);
248 void HeapSampleJSRetainersEvent(const char* constructor,
Steve Blocka7e24c12009-10-30 11:49:00 +0000249 const char* event);
Steve Block44f0eee2011-05-26 01:26:41 +0100250 void HeapSampleJSProducerEvent(const char* constructor,
251 Address* stack);
252 void HeapSampleStats(const char* space, const char* kind,
253 intptr_t capacity, intptr_t used);
Steve Blocka7e24c12009-10-30 11:49:00 +0000254
Steve Block44f0eee2011-05-26 01:26:41 +0100255 void SharedLibraryEvent(const char* library_path,
256 uintptr_t start,
257 uintptr_t end);
258 void SharedLibraryEvent(const wchar_t* library_path,
259 uintptr_t start,
260 uintptr_t end);
Steve Blocka7e24c12009-10-30 11:49:00 +0000261
262 // ==== Events logged by --log-regexp ====
263 // Regexp compilation and execution events.
264
Steve Block44f0eee2011-05-26 01:26:41 +0100265 void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache);
Steve Blocka7e24c12009-10-30 11:49:00 +0000266
267 // Log an event reported from generated code
Steve Block44f0eee2011-05-26 01:26:41 +0100268 void LogRuntime(Vector<const char> format, JSArray* args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000269
270#ifdef ENABLE_LOGGING_AND_PROFILING
Steve Block44f0eee2011-05-26 01:26:41 +0100271 bool is_logging() {
Steve Block6ded16b2010-05-10 14:33:55 +0100272 return logging_nesting_ > 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000273 }
274
275 // Pause/Resume collection of profiling data.
276 // When data collection is paused, CPU Tick events are discarded until
277 // data collection is Resumed.
Steve Block44f0eee2011-05-26 01:26:41 +0100278 void PauseProfiler(int flags, int tag);
279 void ResumeProfiler(int flags, int tag);
280 int GetActiveProfilerModules();
Steve Blocka7e24c12009-10-30 11:49:00 +0000281
282 // If logging is performed into a memory buffer, allows to
283 // retrieve previously written messages. See v8.h.
Steve Block44f0eee2011-05-26 01:26:41 +0100284 int GetLogLines(int from_pos, char* dest_buf, int max_size);
Steve Blocka7e24c12009-10-30 11:49:00 +0000285
286 // Logs all compiled functions found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100287 void LogCompiledFunctions();
Steve Blockd0582a62009-12-15 09:54:21 +0000288 // Logs all accessor callbacks found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100289 void LogAccessorCallbacks();
Steve Blockd0582a62009-12-15 09:54:21 +0000290 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100291 void LogCodeObjects();
Steve Blocka7e24c12009-10-30 11:49:00 +0000292
Steve Block6ded16b2010-05-10 14:33:55 +0100293 // Converts tag to a corresponding NATIVE_... if the script is native.
294 INLINE(static LogEventsAndTags ToNativeByScript(LogEventsAndTags, Script*));
Steve Blocka7e24c12009-10-30 11:49:00 +0000295
296 // Profiler's sampling interval (in milliseconds).
Ben Murdoch75492482011-12-01 11:18:12 +0000297#if defined(ANDROID)
298 // Phones and tablets have processors that are much slower than desktop
299 // and laptop computers for which current heuristics are tuned.
300 static const int kSamplingIntervalMs = 5;
301#else
Steve Blocka7e24c12009-10-30 11:49:00 +0000302 static const int kSamplingIntervalMs = 1;
Ben Murdoch75492482011-12-01 11:18:12 +0000303#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000304
Steve Block44f0eee2011-05-26 01:26:41 +0100305 // Callback from Log, stops profiling in case of insufficient resources.
306 void LogFailure();
307
Steve Block6ded16b2010-05-10 14:33:55 +0100308 private:
Steve Block44f0eee2011-05-26 01:26:41 +0100309 Logger();
310 ~Logger();
Steve Block6ded16b2010-05-10 14:33:55 +0100311
Steve Blocka7e24c12009-10-30 11:49:00 +0000312 // Emits the profiler's first message.
Steve Block44f0eee2011-05-26 01:26:41 +0100313 void ProfilerBeginEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000314
Steve Blockd0582a62009-12-15 09:54:21 +0000315 // Emits callback event messages.
Steve Block44f0eee2011-05-26 01:26:41 +0100316 void CallbackEventInternal(const char* prefix,
317 const char* name,
318 Address entry_point);
Steve Blockd0582a62009-12-15 09:54:21 +0000319
Leon Clarked91b9f72010-01-27 17:25:45 +0000320 // Internal configurable move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100321 void MoveEventInternal(LogEventsAndTags event, Address from, Address to);
Leon Clarked91b9f72010-01-27 17:25:45 +0000322
323 // Internal configurable move event.
Steve Block44f0eee2011-05-26 01:26:41 +0100324 void DeleteEventInternal(LogEventsAndTags event, Address from);
Leon Clarked91b9f72010-01-27 17:25:45 +0000325
Steve Blocka7e24c12009-10-30 11:49:00 +0000326 // Emits the source code of a regexp. Used by regexp events.
Steve Block44f0eee2011-05-26 01:26:41 +0100327 void LogRegExpSource(Handle<JSRegExp> regexp);
Steve Blocka7e24c12009-10-30 11:49:00 +0000328
Andrei Popescu31002712010-02-23 13:46:05 +0000329 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100330 void LogCodeObject(Object* code_object);
Andrei Popescu31002712010-02-23 13:46:05 +0000331
Ben Murdochf87a2032010-10-22 12:50:53 +0100332 // Emits general information about generated code.
Steve Block44f0eee2011-05-26 01:26:41 +0100333 void LogCodeInfo();
Ben Murdochf87a2032010-10-22 12:50:53 +0100334
335 // Handles code creation when low-level profiling is active.
Steve Block44f0eee2011-05-26 01:26:41 +0100336 void LowLevelCodeCreateEvent(Code* code, LogMessageBuilder* msg);
Ben Murdochf87a2032010-10-22 12:50:53 +0100337
Steve Blocka7e24c12009-10-30 11:49:00 +0000338 // Emits a profiler tick event. Used by the profiler thread.
Steve Block44f0eee2011-05-26 01:26:41 +0100339 void TickEvent(TickSample* sample, bool overflow);
Steve Blocka7e24c12009-10-30 11:49:00 +0000340
Steve Block44f0eee2011-05-26 01:26:41 +0100341 void ApiEvent(const char* name, ...);
Steve Blocka7e24c12009-10-30 11:49:00 +0000342
343 // Logs a StringEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100344 void UncheckedStringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000345
Steve Block6ded16b2010-05-10 14:33:55 +0100346 // Logs an IntEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100347 void UncheckedIntEvent(const char* name, int value);
348 void UncheckedIntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000349
350 // Returns whether profiler's sampler is active.
Steve Block44f0eee2011-05-26 01:26:41 +0100351 bool IsProfilerSamplerActive();
Steve Blocka7e24c12009-10-30 11:49:00 +0000352
353 // The sampler used by the profiler and the sliding state window.
Steve Block44f0eee2011-05-26 01:26:41 +0100354 Ticker* ticker_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000355
356 // When the statistical profile is active, profiler_
357 // points to a Profiler, that handles collection
358 // of samples.
Steve Block44f0eee2011-05-26 01:26:41 +0100359 Profiler* profiler_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000360
Steve Blocka7e24c12009-10-30 11:49:00 +0000361 // SlidingStateWindow instance keeping a sliding window of the most
362 // recent VM states.
Steve Block44f0eee2011-05-26 01:26:41 +0100363 SlidingStateWindow* sliding_state_window_;
364
365 // An array of log events names.
366 const char* const* log_events_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000367
Steve Blocka7e24c12009-10-30 11:49:00 +0000368 // Internal implementation classes with access to
369 // private members.
Steve Blocka7e24c12009-10-30 11:49:00 +0000370 friend class EventLog;
Steve Block44f0eee2011-05-26 01:26:41 +0100371 friend class Isolate;
372 friend class LogMessageBuilder;
Steve Blocka7e24c12009-10-30 11:49:00 +0000373 friend class TimeLog;
374 friend class Profiler;
375 friend class SlidingStateWindow;
Steve Blockd0582a62009-12-15 09:54:21 +0000376 friend class StackTracer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000377 friend class VMState;
378
379 friend class LoggerTestHelper;
380
Steve Block44f0eee2011-05-26 01:26:41 +0100381
382 int logging_nesting_;
383 int cpu_profiler_nesting_;
384 int heap_profiler_nesting_;
385
386 Log* log_;
387
388 // Guards against multiple calls to TearDown() that can happen in some tests.
389 // 'true' between Setup() and TearDown().
390 bool is_initialized_;
391
392 // Support for 'incremental addresses' in compressed logs:
393 // LogMessageBuilder::AppendAddress(Address addr)
394 Address last_address_;
395 // Logger::TickEvent(...)
396 Address prev_sp_;
397 Address prev_function_;
398 // Logger::MoveEventInternal(...)
399 Address prev_to_;
400 // Logger::FunctionCreateEvent(...)
401 Address prev_code_;
Steve Block6ded16b2010-05-10 14:33:55 +0100402
403 friend class CpuProfiler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000404#else
Steve Block44f0eee2011-05-26 01:26:41 +0100405 bool is_logging() { return false; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000406#endif
407};
408
409
Steve Block44f0eee2011-05-26 01:26:41 +0100410// Process wide registry of samplers.
411class SamplerRegistry : public AllStatic {
412 public:
413 enum State {
414 HAS_NO_SAMPLERS,
415 HAS_SAMPLERS,
416 HAS_CPU_PROFILING_SAMPLERS
417 };
418
419 typedef void (*VisitSampler)(Sampler*, void*);
420
421 static State GetState();
422
423 // Iterates over all active samplers keeping the internal lock held.
424 // Returns whether there are any active samplers.
425 static bool IterateActiveSamplers(VisitSampler func, void* param);
426
427 // Adds/Removes an active sampler.
428 static void AddActiveSampler(Sampler* sampler);
429 static void RemoveActiveSampler(Sampler* sampler);
430
431 private:
432 static bool ActiveSamplersExist() {
433 return active_samplers_ != NULL && !active_samplers_->is_empty();
434 }
435
436 static Mutex* mutex_; // Protects the state below.
437 static List<Sampler*>* active_samplers_;
438
439 DISALLOW_IMPLICIT_CONSTRUCTORS(SamplerRegistry);
440};
441
442
Steve Blocka7e24c12009-10-30 11:49:00 +0000443// Class that extracts stack trace, used for profiling.
444class StackTracer : public AllStatic {
445 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100446 static void Trace(Isolate* isolate, TickSample* sample);
Steve Blocka7e24c12009-10-30 11:49:00 +0000447};
448
Steve Blocka7e24c12009-10-30 11:49:00 +0000449} } // namespace v8::internal
450
Steve Block6ded16b2010-05-10 14:33:55 +0100451
Steve Blocka7e24c12009-10-30 11:49:00 +0000452#endif // V8_LOG_H_