V8 Project
cpu-profiler.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_CPU_PROFILER_H_
6 #define V8_CPU_PROFILER_H_
7 
8 #include "src/allocation.h"
9 #include "src/base/atomicops.h"
10 #include "src/base/platform/time.h"
11 #include "src/circular-queue.h"
12 #include "src/sampler.h"
13 #include "src/unbound-queue.h"
14 
15 namespace v8 {
16 namespace internal {
17 
18 // Forward declarations.
19 class CodeEntry;
20 class CodeMap;
21 class CompilationInfo;
22 class CpuProfile;
23 class CpuProfilesCollection;
24 class ProfileGenerator;
25 
26 #define CODE_EVENTS_TYPE_LIST(V) \
27  V(CODE_CREATION, CodeCreateEventRecord) \
28  V(CODE_MOVE, CodeMoveEventRecord) \
29  V(CODE_DISABLE_OPT, CodeDisableOptEventRecord) \
30  V(SHARED_FUNC_MOVE, SharedFunctionInfoMoveEventRecord) \
31  V(REPORT_BUILTIN, ReportBuiltinEventRecord)
32 
33 
35  public:
36 #define DECLARE_TYPE(type, ignore) type,
37  enum Type {
38  NONE = 0,
41  };
42 #undef DECLARE_TYPE
43 
45  mutable unsigned order;
46 };
47 
48 
50  public:
53  unsigned size;
55 
56  INLINE(void UpdateCodeMap(CodeMap* code_map));
57 };
58 
59 
61  public:
64 
65  INLINE(void UpdateCodeMap(CodeMap* code_map));
66 };
67 
68 
70  public:
72  const char* bailout_reason;
73 
74  INLINE(void UpdateCodeMap(CodeMap* code_map));
75 };
76 
77 
79  public:
82 
83  INLINE(void UpdateCodeMap(CodeMap* code_map));
84 };
85 
86 
88  public:
91 
92  INLINE(void UpdateCodeMap(CodeMap* code_map));
93 };
94 
95 
97  public:
98  // The parameterless constructor is used when we dequeue data from
99  // the ticks buffer.
101  explicit TickSampleEventRecord(unsigned order) : order(order) { }
102 
103  unsigned order;
105 };
106 
107 
109  public:
112  generic.type = type;
113  }
114  union {
116 #define DECLARE_CLASS(ignore, type) type type##_;
118 #undef DECLARE_TYPE
119  };
120 };
121 
122 
123 // This class implements both the profile events processor thread and
124 // methods called by event producers: VM and stack sampler threads.
126  public:
128  Sampler* sampler,
129  base::TimeDelta period);
131 
132  // Thread control.
133  virtual void Run();
134  void StopSynchronously();
135  INLINE(bool running()) { return running_; }
136  void Enqueue(const CodeEventsContainer& event);
137 
138  // Puts current stack into tick sample events buffer.
139  void AddCurrentStack(Isolate* isolate);
140 
141  // Tick sample events are filled directly in the buffer of the circular
142  // queue (because the structure is of fixed width, but usually not all
143  // stack frame entries are filled.) This method returns a pointer to the
144  // next record of the buffer.
145  inline TickSample* StartTickSample();
146  inline void FinishTickSample();
147 
148  // SamplingCircularQueue has stricter alignment requirements than a normal new
149  // can fulfil, so we need to provide our own new/delete here.
150  void* operator new(size_t size);
151  void operator delete(void* ptr);
152 
153  private:
154  // Called from events processing thread (Run() method.)
155  bool ProcessCodeEvent();
156 
160  NoSamplesInQueue
161  };
162  SampleProcessingResult ProcessOneSample();
163 
166  bool running_;
167  // Sampling period in microseconds.
168  const base::TimeDelta period_;
169  UnboundQueue<CodeEventsContainer> events_buffer_;
170  static const size_t kTickSampleBufferSize = 1 * MB;
171  static const size_t kTickSampleQueueLength =
172  kTickSampleBufferSize / sizeof(TickSampleEventRecord);
174  kTickSampleQueueLength> ticks_buffer_;
175  UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_;
178 };
179 
180 
181 #define PROFILE(IsolateGetter, Call) \
182  do { \
183  Isolate* cpu_profiler_isolate = (IsolateGetter); \
184  v8::internal::Logger* logger = cpu_profiler_isolate->logger(); \
185  CpuProfiler* cpu_profiler = cpu_profiler_isolate->cpu_profiler(); \
186  if (logger->is_logging_code_events() || cpu_profiler->is_profiling()) { \
187  logger->Call; \
188  } \
189  } while (false)
190 
191 
193  public:
194  explicit CpuProfiler(Isolate* isolate);
195 
197  CpuProfilesCollection* test_collection,
198  ProfileGenerator* test_generator,
199  ProfilerEventsProcessor* test_processor);
200 
201  virtual ~CpuProfiler();
202 
203  void set_sampling_interval(base::TimeDelta value);
204  void StartProfiling(const char* title, bool record_samples = false);
205  void StartProfiling(String* title, bool record_samples);
206  CpuProfile* StopProfiling(const char* title);
208  int GetProfilesCount();
209  CpuProfile* GetProfile(int index);
210  void DeleteAllProfiles();
211  void DeleteProfile(CpuProfile* profile);
212 
213  // Invoked from stack sampler (thread or signal handler.)
214  inline TickSample* StartTickSample();
215  inline void FinishTickSample();
216 
217  // Must be called via PROFILE macro, otherwise will crash when
218  // profiling is not enabled.
219  virtual void CallbackEvent(Name* name, Address entry_point);
220  virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
221  Code* code, const char* comment);
222  virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
223  Code* code, Name* name);
224  virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, Code* code,
225  SharedFunctionInfo* shared,
226  CompilationInfo* info, Name* script_name);
227  virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, Code* code,
228  SharedFunctionInfo* shared,
229  CompilationInfo* info, Name* script_name,
230  int line, int column);
231  virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
232  Code* code, int args_count);
233  virtual void CodeMovingGCEvent() {}
234  virtual void CodeMoveEvent(Address from, Address to);
235  virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared);
236  virtual void CodeDeleteEvent(Address from);
237  virtual void GetterCallbackEvent(Name* name, Address entry_point);
238  virtual void RegExpCodeCreateEvent(Code* code, String* source);
239  virtual void SetterCallbackEvent(Name* name, Address entry_point);
240  virtual void SharedFunctionInfoMoveEvent(Address from, Address to);
241 
242  INLINE(bool is_profiling() const) { return is_profiling_; }
244  return &is_profiling_;
245  }
246 
247  ProfileGenerator* generator() const { return generator_; }
249  Isolate* isolate() const { return isolate_; }
250 
251  private:
253  void StopProcessorIfLastProfile(const char* title);
254  void StopProcessor();
255  void ResetProfiles();
256  void LogBuiltins();
257 
259  base::TimeDelta sampling_interval_;
265 
267 };
268 
269 } } // namespace v8::internal
270 
271 
272 #endif // V8_CPU_PROFILER_H_
INLINE(void UpdateCodeMap(CodeMap *code_map))
INLINE(void UpdateCodeMap(CodeMap *code_map))
CodeEventsContainer(CodeEventRecord::Type type=CodeEventRecord::NONE)
Definition: cpu-profiler.h:110
INLINE(void UpdateCodeMap(CodeMap *code_map))
void StartProfiling(const char *title, bool record_samples=false)
CpuProfile * StopProfiling(const char *title)
CpuProfile * GetProfile(int index)
void StopProcessorIfLastProfile(const char *title)
ProfileGenerator * generator() const
Definition: cpu-profiler.h:247
TickSample * StartTickSample()
CpuProfiler(Isolate *isolate)
virtual void CallbackEvent(Name *name, Address entry_point)
DISALLOW_COPY_AND_ASSIGN(CpuProfiler)
virtual void GetterCallbackEvent(Name *name, Address entry_point)
ProfilerEventsProcessor * processor_
Definition: cpu-profiler.h:262
void set_sampling_interval(base::TimeDelta value)
Isolate * isolate() const
Definition: cpu-profiler.h:249
virtual void CodeDisableOptEvent(Code *code, SharedFunctionInfo *shared)
INLINE(bool is_profiling() const)
Definition: cpu-profiler.h:242
CpuProfilesCollection * profiles_
Definition: cpu-profiler.h:260
virtual void CodeMoveEvent(Address from, Address to)
virtual void CodeMovingGCEvent()
Definition: cpu-profiler.h:233
ProfilerEventsProcessor * processor() const
Definition: cpu-profiler.h:248
virtual void CodeDeleteEvent(Address from)
base::TimeDelta sampling_interval_
Definition: cpu-profiler.h:259
virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, Code *code, const char *comment)
virtual void RegExpCodeCreateEvent(Code *code, String *source)
ProfileGenerator * generator_
Definition: cpu-profiler.h:261
virtual void SharedFunctionInfoMoveEvent(Address from, Address to)
void DeleteProfile(CpuProfile *profile)
virtual void SetterCallbackEvent(Name *name, Address entry_point)
UnboundQueue< CodeEventsContainer > events_buffer_
Definition: cpu-profiler.h:169
UnboundQueue< TickSampleEventRecord > ticks_from_vm_buffer_
Definition: cpu-profiler.h:175
SamplingCircularQueue< TickSampleEventRecord, kTickSampleQueueLength > ticks_buffer_
Definition: cpu-profiler.h:174
INLINE(void UpdateCodeMap(CodeMap *code_map))
INLINE(void UpdateCodeMap(CodeMap *code_map))
#define DECLARE_TYPE(type, ignore)
Definition: cpu-profiler.h:36
#define CODE_EVENTS_TYPE_LIST(V)
Definition: cpu-profiler.h:26
#define DECLARE_CLASS(ignore, type)
Definition: cpu-profiler.h:116
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
byte * Address
Definition: globals.h:101
const int MB
Definition: globals.h:107
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20