V8 Project
profile-generator.h
Go to the documentation of this file.
1 // Copyright 2011 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_PROFILE_GENERATOR_H_
6 #define V8_PROFILE_GENERATOR_H_
7 
8 #include "include/v8-profiler.h"
9 #include "src/allocation.h"
10 #include "src/hashmap.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 struct OffsetRange;
16 
17 // Provides a storage of strings allocated in C++ heap, to hold them
18 // forever, even if they disappear from JS heap or external storage.
20  public:
21  explicit StringsStorage(Heap* heap);
23 
24  const char* GetCopy(const char* src);
25  const char* GetFormatted(const char* format, ...);
26  const char* GetVFormatted(const char* format, va_list args);
27  const char* GetName(Name* name);
28  const char* GetName(int index);
29  const char* GetFunctionName(Name* name);
30  const char* GetFunctionName(const char* name);
31  size_t GetUsedMemorySize() const;
32 
33  private:
34  static const int kMaxNameSize = 1024;
35 
36  static bool StringsMatch(void* key1, void* key2);
37  const char* AddOrDisposeString(char* str, int len);
38  HashMap::Entry* GetEntry(const char* str, int len);
39 
42 
44 };
45 
46 
47 class CodeEntry {
48  public:
49  // CodeEntry doesn't own name strings, just references them.
51  const char* name,
56  ~CodeEntry();
57 
58  bool is_js_function() const { return is_js_function_tag(tag_); }
59  const char* name_prefix() const { return name_prefix_; }
60  bool has_name_prefix() const { return name_prefix_[0] != '\0'; }
61  const char* name() const { return name_; }
62  const char* resource_name() const { return resource_name_; }
63  int line_number() const { return line_number_; }
64  int column_number() const { return column_number_; }
65  void set_shared_id(int shared_id) { shared_id_ = shared_id; }
66  int script_id() const { return script_id_; }
68  void set_bailout_reason(const char* bailout_reason) {
70  }
71  const char* bailout_reason() const { return bailout_reason_; }
72 
73  static inline bool is_js_function_tag(Logger::LogEventsAndTags tag);
74 
77  no_frame_ranges_ = ranges;
78  }
79 
82 
83  uint32_t GetCallUid() const;
84  bool IsSameAs(CodeEntry* entry) const;
85 
86  static const char* const kEmptyNamePrefix;
87  static const char* const kEmptyResourceName;
88  static const char* const kEmptyBailoutReason;
89 
90  private:
93  const char* name_prefix_;
94  const char* name_;
95  const char* resource_name_;
101  const char* bailout_reason_;
102 
104 };
105 
106 
107 class ProfileTree;
108 
109 class ProfileNode {
110  public:
111  inline ProfileNode(ProfileTree* tree, CodeEntry* entry);
112 
116  void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; }
117 
118  CodeEntry* entry() const { return entry_; }
119  unsigned self_ticks() const { return self_ticks_; }
120  const List<ProfileNode*>* children() const { return &children_list_; }
121  unsigned id() const { return id_; }
122 
123  void Print(int indent);
124 
125  private:
126  static bool CodeEntriesMatch(void* entry1, void* entry2) {
127  return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs(
128  reinterpret_cast<CodeEntry*>(entry2));
129  }
130 
132  return entry->GetCallUid();
133  }
134 
137  unsigned self_ticks_;
138  // Mapping from CodeEntry* to ProfileNode*
141  unsigned id_;
142 
144 };
145 
146 
147 class ProfileTree {
148  public:
149  ProfileTree();
150  ~ProfileTree();
151 
153  void AddPathFromStart(const Vector<CodeEntry*>& path);
154  ProfileNode* root() const { return root_; }
155  unsigned next_node_id() { return next_node_id_++; }
156 
157  void Print() {
158  root_->Print(0);
159  }
160 
161  private:
162  template <typename Callback>
163  void TraverseDepthFirst(Callback* callback);
164 
166  unsigned next_node_id_;
168 
170 };
171 
172 
173 class CpuProfile {
174  public:
175  CpuProfile(const char* title, bool record_samples);
176 
177  // Add pc -> ... -> main() call path to the profile.
178  void AddPath(base::TimeTicks timestamp, const Vector<CodeEntry*>& path);
180 
181  const char* title() const { return title_; }
182  const ProfileTree* top_down() const { return &top_down_; }
183 
184  int samples_count() const { return samples_.length(); }
185  ProfileNode* sample(int index) const { return samples_.at(index); }
186  base::TimeTicks sample_timestamp(int index) const {
187  return timestamps_.at(index);
188  }
189 
190  base::TimeTicks start_time() const { return start_time_; }
191  base::TimeTicks end_time() const { return end_time_; }
192 
194 
195  void Print();
196 
197  private:
198  const char* title_;
200  base::TimeTicks start_time_;
201  base::TimeTicks end_time_;
205 
207 };
208 
209 
210 class CodeMap {
211  public:
213  void AddCode(Address addr, CodeEntry* entry, unsigned size);
214  void MoveCode(Address from, Address to);
215  CodeEntry* FindEntry(Address addr, Address* start = NULL);
216  int GetSharedId(Address addr);
217 
218  void Print();
219 
220  private:
221  struct CodeEntryInfo {
222  CodeEntryInfo(CodeEntry* an_entry, unsigned a_size)
223  : entry(an_entry), size(a_size) { }
225  unsigned size;
226  };
227 
228  struct CodeTreeConfig {
229  typedef Address Key;
231  static const Key kNoKey;
232  static const Value NoValue() { return CodeEntryInfo(NULL, 0); }
233  static int Compare(const Key& a, const Key& b) {
234  return a < b ? -1 : (a > b ? 1 : 0);
235  }
236  };
238 
240  public:
241  void Call(const Address& key, const CodeEntryInfo& value);
242  };
243 
244  void DeleteAllCoveredCode(Address start, Address end);
245 
246  // Fake CodeEntry pointer to distinguish shared function entries.
248 
251 
253 };
254 
255 
257  public:
258  explicit CpuProfilesCollection(Heap* heap);
260 
261  bool StartProfiling(const char* title, bool record_samples);
262  CpuProfile* StopProfiling(const char* title);
264  const char* GetName(Name* name) {
266  }
267  const char* GetName(int args_count) {
268  return function_and_resource_names_.GetName(args_count);
269  }
270  const char* GetFunctionName(Name* name) {
272  }
273  const char* GetFunctionName(const char* name) {
275  }
276  bool IsLastProfile(const char* title);
277  void RemoveProfile(CpuProfile* profile);
278 
281  const char* name,
282  const char* name_prefix = CodeEntry::kEmptyNamePrefix,
283  const char* resource_name = CodeEntry::kEmptyResourceName,
284  int line_number = v8::CpuProfileNode::kNoLineNumberInfo,
285  int column_number = v8::CpuProfileNode::kNoColumnNumberInfo);
286 
287  // Called from profile generator thread.
289  base::TimeTicks timestamp, const Vector<CodeEntry*>& path);
290 
291  // Limits the number of profiles that can be simultaneously collected.
292  static const int kMaxSimultaneousProfiles = 100;
293 
294  private:
298 
299  // Accessed by VM thread and profile generator thread.
302 
304 };
305 
306 
308  public:
309  explicit ProfileGenerator(CpuProfilesCollection* profiles);
310 
311  void RecordTickSample(const TickSample& sample);
312 
313  CodeMap* code_map() { return &code_map_; }
314 
315  static const char* const kProgramEntryName;
316  static const char* const kIdleEntryName;
317  static const char* const kGarbageCollectorEntryName;
318  // Used to represent frames for which we have no reliable way to
319  // detect function.
320  static const char* const kUnresolvedFunctionName;
321 
322  private:
324 
331 
333 };
334 
335 
336 } } // namespace v8::internal
337 
338 #endif // V8_PROFILE_GENERATOR_H_
static const int kNoColumnNumberInfo
Definition: v8-profiler.h:69
static const int kNoLineNumberInfo
Definition: v8-profiler.h:68
void SetBuiltinId(Builtins::Name id)
Logger::LogEventsAndTags tag_
void set_script_id(int script_id)
List< OffsetRange > * no_frame_ranges_
void set_shared_id(int shared_id)
void set_bailout_reason(const char *bailout_reason)
static const char *const kEmptyResourceName
static bool is_js_function_tag(Logger::LogEventsAndTags tag)
const char * bailout_reason() const
const char * name_prefix() const
const char * resource_name() const
static const char *const kEmptyBailoutReason
static const char *const kEmptyNamePrefix
List< OffsetRange > * no_frame_ranges() const
Builtins::Name builtin_id() const
CodeEntry(Logger::LogEventsAndTags tag, const char *name, const char *name_prefix=CodeEntry::kEmptyNamePrefix, const char *resource_name=CodeEntry::kEmptyResourceName, int line_number=v8::CpuProfileNode::kNoLineNumberInfo, int column_number=v8::CpuProfileNode::kNoColumnNumberInfo)
DISALLOW_COPY_AND_ASSIGN(CodeEntry)
bool IsSameAs(CodeEntry *entry) const
void set_no_frame_ranges(List< OffsetRange > *ranges)
const char * name() const
void Call(const Address &key, const CodeEntryInfo &value)
void DeleteAllCoveredCode(Address start, Address end)
DISALLOW_COPY_AND_ASSIGN(CodeMap)
void AddCode(Address addr, CodeEntry *entry, unsigned size)
static CodeEntry *const kSharedFunctionCodeEntry
int GetSharedId(Address addr)
SplayTree< CodeTreeConfig > CodeTree
void MoveCode(Address from, Address to)
CodeEntry * FindEntry(Address addr, Address *start=NULL)
const ProfileTree * top_down() const
base::TimeTicks sample_timestamp(int index) const
base::TimeTicks start_time() const
const char * title() const
CpuProfile(const char *title, bool record_samples)
DISALLOW_COPY_AND_ASSIGN(CpuProfile)
base::TimeTicks end_time() const
void AddPath(base::TimeTicks timestamp, const Vector< CodeEntry * > &path)
ProfileNode * sample(int index) const
List< ProfileNode * > samples_
List< base::TimeTicks > timestamps_
const char * GetName(int args_count)
CodeEntry * NewCodeEntry(Logger::LogEventsAndTags tag, const char *name, const char *name_prefix=CodeEntry::kEmptyNamePrefix, const char *resource_name=CodeEntry::kEmptyResourceName, int line_number=v8::CpuProfileNode::kNoLineNumberInfo, int column_number=v8::CpuProfileNode::kNoColumnNumberInfo)
bool StartProfiling(const char *title, bool record_samples)
void AddPathToCurrentProfiles(base::TimeTicks timestamp, const Vector< CodeEntry * > &path)
const char * GetFunctionName(Name *name)
void RemoveProfile(CpuProfile *profile)
DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection)
CpuProfile * StopProfiling(const char *title)
const char * GetFunctionName(const char *name)
T & at(int i) const
Definition: list.h:69
CodeEntry * EntryForVMState(StateTag tag)
void RecordTickSample(const TickSample &sample)
CpuProfilesCollection * profiles_
ProfileGenerator(CpuProfilesCollection *profiles)
static const char *const kProgramEntryName
static const char *const kUnresolvedFunctionName
DISALLOW_COPY_AND_ASSIGN(ProfileGenerator)
static const char *const kIdleEntryName
static const char *const kGarbageCollectorEntryName
CodeEntry * entry() const
static bool CodeEntriesMatch(void *entry1, void *entry2)
DISALLOW_COPY_AND_ASSIGN(ProfileNode)
ProfileNode * FindChild(CodeEntry *entry)
const List< ProfileNode * > * children() const
ProfileNode * FindOrAddChild(CodeEntry *entry)
static uint32_t CodeEntryHash(CodeEntry *entry)
void IncreaseSelfTicks(unsigned amount)
List< ProfileNode * > children_list_
ProfileNode(ProfileTree *tree, CodeEntry *entry)
ProfileNode * root() const
ProfileNode * AddPathFromEnd(const Vector< CodeEntry * > &path)
void TraverseDepthFirst(Callback *callback)
DISALLOW_COPY_AND_ASSIGN(ProfileTree)
void AddPathFromStart(const Vector< CodeEntry * > &path)
const char * GetFunctionName(Name *name)
const char * GetName(Name *name)
const char * AddOrDisposeString(char *str, int len)
const char * GetFormatted(const char *format,...)
const char * GetCopy(const char *src)
const char * GetVFormatted(const char *format, va_list args)
HashMap::Entry * GetEntry(const char *str, int len)
static bool StringsMatch(void *key1, void *key2)
DISALLOW_COPY_AND_ASSIGN(StringsStorage)
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
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 NULL
byte * Address
Definition: globals.h:101
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
CodeEntryInfo(CodeEntry *an_entry, unsigned a_size)
static int Compare(const Key &a, const Key &b)