OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PROFILE_GENERATOR_H_ | 5 #ifndef V8_PROFILE_GENERATOR_H_ |
6 #define V8_PROFILE_GENERATOR_H_ | 6 #define V8_PROFILE_GENERATOR_H_ |
7 | 7 |
8 #include <map> | |
9 #include "include/v8-profiler.h" | 8 #include "include/v8-profiler.h" |
10 #include "src/allocation.h" | 9 #include "src/allocation.h" |
11 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
12 | 11 |
13 namespace v8 { | 12 namespace v8 { |
14 namespace internal { | 13 namespace internal { |
15 | 14 |
16 struct OffsetRange; | 15 struct OffsetRange; |
17 | 16 |
18 // Provides a storage of strings allocated in C++ heap, to hold them | 17 // Provides a storage of strings allocated in C++ heap, to hold them |
(...skipping 19 matching lines...) Expand all Loading... |
38 const char* AddOrDisposeString(char* str, int len); | 37 const char* AddOrDisposeString(char* str, int len); |
39 HashMap::Entry* GetEntry(const char* str, int len); | 38 HashMap::Entry* GetEntry(const char* str, int len); |
40 | 39 |
41 uint32_t hash_seed_; | 40 uint32_t hash_seed_; |
42 HashMap names_; | 41 HashMap names_; |
43 | 42 |
44 DISALLOW_COPY_AND_ASSIGN(StringsStorage); | 43 DISALLOW_COPY_AND_ASSIGN(StringsStorage); |
45 }; | 44 }; |
46 | 45 |
47 | 46 |
48 // Provides a mapping from the offsets within generated code to | |
49 // the source line. | |
50 class JITLineInfoTable : public Malloced { | |
51 public: | |
52 JITLineInfoTable(); | |
53 ~JITLineInfoTable(); | |
54 | |
55 void SetPosition(int pc_offset, int line); | |
56 int GetSourceLineNumber(int pc_offset) const; | |
57 | |
58 bool empty() const { return pc_offset_map_.empty(); } | |
59 | |
60 private: | |
61 // pc_offset -> source line | |
62 typedef std::map<int, int> PcOffsetMap; | |
63 PcOffsetMap pc_offset_map_; | |
64 DISALLOW_COPY_AND_ASSIGN(JITLineInfoTable); | |
65 }; | |
66 | |
67 class CodeEntry { | 47 class CodeEntry { |
68 public: | 48 public: |
69 // CodeEntry doesn't own name strings, just references them. | 49 // CodeEntry doesn't own name strings, just references them. |
70 inline CodeEntry(Logger::LogEventsAndTags tag, const char* name, | 50 inline CodeEntry(Logger::LogEventsAndTags tag, |
| 51 const char* name, |
71 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 52 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
72 const char* resource_name = CodeEntry::kEmptyResourceName, | 53 const char* resource_name = CodeEntry::kEmptyResourceName, |
73 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, | 54 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, |
74 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, | 55 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo); |
75 JITLineInfoTable* line_info = NULL, | |
76 Address instruction_start = NULL); | |
77 ~CodeEntry(); | 56 ~CodeEntry(); |
78 | 57 |
79 bool is_js_function() const { return is_js_function_tag(tag_); } | 58 bool is_js_function() const { return is_js_function_tag(tag_); } |
80 const char* name_prefix() const { return name_prefix_; } | 59 const char* name_prefix() const { return name_prefix_; } |
81 bool has_name_prefix() const { return name_prefix_[0] != '\0'; } | 60 bool has_name_prefix() const { return name_prefix_[0] != '\0'; } |
82 const char* name() const { return name_; } | 61 const char* name() const { return name_; } |
83 const char* resource_name() const { return resource_name_; } | 62 const char* resource_name() const { return resource_name_; } |
84 int line_number() const { return line_number_; } | 63 int line_number() const { return line_number_; } |
85 int column_number() const { return column_number_; } | 64 int column_number() const { return column_number_; } |
86 const JITLineInfoTable* line_info() const { return line_info_; } | |
87 void set_shared_id(int shared_id) { shared_id_ = shared_id; } | 65 void set_shared_id(int shared_id) { shared_id_ = shared_id; } |
88 int script_id() const { return script_id_; } | 66 int script_id() const { return script_id_; } |
89 void set_script_id(int script_id) { script_id_ = script_id; } | 67 void set_script_id(int script_id) { script_id_ = script_id; } |
90 void set_bailout_reason(const char* bailout_reason) { | 68 void set_bailout_reason(const char* bailout_reason) { |
91 bailout_reason_ = bailout_reason; | 69 bailout_reason_ = bailout_reason; |
92 } | 70 } |
93 const char* bailout_reason() const { return bailout_reason_; } | 71 const char* bailout_reason() const { return bailout_reason_; } |
94 | 72 |
95 static inline bool is_js_function_tag(Logger::LogEventsAndTags tag); | 73 static inline bool is_js_function_tag(Logger::LogEventsAndTags tag); |
96 | 74 |
97 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } | 75 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } |
98 void set_no_frame_ranges(List<OffsetRange>* ranges) { | 76 void set_no_frame_ranges(List<OffsetRange>* ranges) { |
99 no_frame_ranges_ = ranges; | 77 no_frame_ranges_ = ranges; |
100 } | 78 } |
101 | 79 |
102 void SetBuiltinId(Builtins::Name id); | 80 void SetBuiltinId(Builtins::Name id); |
103 Builtins::Name builtin_id() const { return builtin_id_; } | 81 Builtins::Name builtin_id() const { return builtin_id_; } |
104 | 82 |
105 uint32_t GetCallUid() const; | 83 uint32_t GetCallUid() const; |
106 bool IsSameAs(CodeEntry* entry) const; | 84 bool IsSameAs(CodeEntry* entry) const; |
107 | 85 |
108 int GetSourceLine(int pc_offset) const; | |
109 | |
110 Address instruction_start() const { return instruction_start_; } | |
111 | |
112 static const char* const kEmptyNamePrefix; | 86 static const char* const kEmptyNamePrefix; |
113 static const char* const kEmptyResourceName; | 87 static const char* const kEmptyResourceName; |
114 static const char* const kEmptyBailoutReason; | 88 static const char* const kEmptyBailoutReason; |
115 | 89 |
116 private: | 90 private: |
117 Logger::LogEventsAndTags tag_ : 8; | 91 Logger::LogEventsAndTags tag_ : 8; |
118 Builtins::Name builtin_id_ : 8; | 92 Builtins::Name builtin_id_ : 8; |
119 const char* name_prefix_; | 93 const char* name_prefix_; |
120 const char* name_; | 94 const char* name_; |
121 const char* resource_name_; | 95 const char* resource_name_; |
122 int line_number_; | 96 int line_number_; |
123 int column_number_; | 97 int column_number_; |
124 int shared_id_; | 98 int shared_id_; |
125 int script_id_; | 99 int script_id_; |
126 List<OffsetRange>* no_frame_ranges_; | 100 List<OffsetRange>* no_frame_ranges_; |
127 const char* bailout_reason_; | 101 const char* bailout_reason_; |
128 JITLineInfoTable* line_info_; | |
129 Address instruction_start_; | |
130 | 102 |
131 DISALLOW_COPY_AND_ASSIGN(CodeEntry); | 103 DISALLOW_COPY_AND_ASSIGN(CodeEntry); |
132 }; | 104 }; |
133 | 105 |
134 | 106 |
135 class ProfileTree; | 107 class ProfileTree; |
136 | 108 |
137 class ProfileNode { | 109 class ProfileNode { |
138 public: | 110 public: |
139 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); | 111 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); |
140 | 112 |
141 ProfileNode* FindChild(CodeEntry* entry); | 113 ProfileNode* FindChild(CodeEntry* entry); |
142 ProfileNode* FindOrAddChild(CodeEntry* entry); | 114 ProfileNode* FindOrAddChild(CodeEntry* entry); |
143 void IncrementSelfTicks() { ++self_ticks_; } | 115 void IncrementSelfTicks() { ++self_ticks_; } |
144 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } | 116 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } |
145 void IncrementLineTicks(int src_line); | |
146 | 117 |
147 CodeEntry* entry() const { return entry_; } | 118 CodeEntry* entry() const { return entry_; } |
148 unsigned self_ticks() const { return self_ticks_; } | 119 unsigned self_ticks() const { return self_ticks_; } |
149 const List<ProfileNode*>* children() const { return &children_list_; } | 120 const List<ProfileNode*>* children() const { return &children_list_; } |
150 unsigned id() const { return id_; } | 121 unsigned id() const { return id_; } |
151 unsigned int GetHitLineCount() const { return line_ticks_.occupancy(); } | |
152 bool GetLineTicks(v8::CpuProfileNode::LineTick* entries, | |
153 unsigned int length) const; | |
154 | 122 |
155 void Print(int indent); | 123 void Print(int indent); |
156 | 124 |
157 private: | 125 private: |
158 static bool CodeEntriesMatch(void* entry1, void* entry2) { | 126 static bool CodeEntriesMatch(void* entry1, void* entry2) { |
159 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs( | 127 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs( |
160 reinterpret_cast<CodeEntry*>(entry2)); | 128 reinterpret_cast<CodeEntry*>(entry2)); |
161 } | 129 } |
162 | 130 |
163 static uint32_t CodeEntryHash(CodeEntry* entry) { | 131 static uint32_t CodeEntryHash(CodeEntry* entry) { |
164 return entry->GetCallUid(); | 132 return entry->GetCallUid(); |
165 } | 133 } |
166 | 134 |
167 ProfileTree* tree_; | 135 ProfileTree* tree_; |
168 CodeEntry* entry_; | 136 CodeEntry* entry_; |
169 unsigned self_ticks_; | 137 unsigned self_ticks_; |
170 // Mapping from CodeEntry* to ProfileNode* | 138 // Mapping from CodeEntry* to ProfileNode* |
171 HashMap children_; | 139 HashMap children_; |
172 List<ProfileNode*> children_list_; | 140 List<ProfileNode*> children_list_; |
173 unsigned id_; | 141 unsigned id_; |
174 HashMap line_ticks_; | |
175 | 142 |
176 DISALLOW_COPY_AND_ASSIGN(ProfileNode); | 143 DISALLOW_COPY_AND_ASSIGN(ProfileNode); |
177 }; | 144 }; |
178 | 145 |
179 | 146 |
180 class ProfileTree { | 147 class ProfileTree { |
181 public: | 148 public: |
182 ProfileTree(); | 149 ProfileTree(); |
183 ~ProfileTree(); | 150 ~ProfileTree(); |
184 | 151 |
185 ProfileNode* AddPathFromEnd( | 152 ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path); |
186 const Vector<CodeEntry*>& path, | 153 void AddPathFromStart(const Vector<CodeEntry*>& path); |
187 int src_line = v8::CpuProfileNode::kNoLineNumberInfo); | |
188 void AddPathFromStart(const Vector<CodeEntry*>& path, | |
189 int src_line = v8::CpuProfileNode::kNoLineNumberInfo); | |
190 ProfileNode* root() const { return root_; } | 154 ProfileNode* root() const { return root_; } |
191 unsigned next_node_id() { return next_node_id_++; } | 155 unsigned next_node_id() { return next_node_id_++; } |
192 | 156 |
193 void Print() { | 157 void Print() { |
194 root_->Print(0); | 158 root_->Print(0); |
195 } | 159 } |
196 | 160 |
197 private: | 161 private: |
198 template <typename Callback> | 162 template <typename Callback> |
199 void TraverseDepthFirst(Callback* callback); | 163 void TraverseDepthFirst(Callback* callback); |
200 | 164 |
201 CodeEntry root_entry_; | 165 CodeEntry root_entry_; |
202 unsigned next_node_id_; | 166 unsigned next_node_id_; |
203 ProfileNode* root_; | 167 ProfileNode* root_; |
204 | 168 |
205 DISALLOW_COPY_AND_ASSIGN(ProfileTree); | 169 DISALLOW_COPY_AND_ASSIGN(ProfileTree); |
206 }; | 170 }; |
207 | 171 |
208 | 172 |
209 class CpuProfile { | 173 class CpuProfile { |
210 public: | 174 public: |
211 CpuProfile(const char* title, bool record_samples); | 175 CpuProfile(const char* title, bool record_samples); |
212 | 176 |
213 // Add pc -> ... -> main() call path to the profile. | 177 // Add pc -> ... -> main() call path to the profile. |
214 void AddPath(base::TimeTicks timestamp, const Vector<CodeEntry*>& path, | 178 void AddPath(base::TimeTicks timestamp, const Vector<CodeEntry*>& path); |
215 int src_line); | |
216 void CalculateTotalTicksAndSamplingRate(); | 179 void CalculateTotalTicksAndSamplingRate(); |
217 | 180 |
218 const char* title() const { return title_; } | 181 const char* title() const { return title_; } |
219 const ProfileTree* top_down() const { return &top_down_; } | 182 const ProfileTree* top_down() const { return &top_down_; } |
220 | 183 |
221 int samples_count() const { return samples_.length(); } | 184 int samples_count() const { return samples_.length(); } |
222 ProfileNode* sample(int index) const { return samples_.at(index); } | 185 ProfileNode* sample(int index) const { return samples_.at(index); } |
223 base::TimeTicks sample_timestamp(int index) const { | 186 base::TimeTicks sample_timestamp(int index) const { |
224 return timestamps_.at(index); | 187 return timestamps_.at(index); |
225 } | 188 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 const char* GetFunctionName(Name* name) { | 270 const char* GetFunctionName(Name* name) { |
308 return function_and_resource_names_.GetFunctionName(name); | 271 return function_and_resource_names_.GetFunctionName(name); |
309 } | 272 } |
310 const char* GetFunctionName(const char* name) { | 273 const char* GetFunctionName(const char* name) { |
311 return function_and_resource_names_.GetFunctionName(name); | 274 return function_and_resource_names_.GetFunctionName(name); |
312 } | 275 } |
313 bool IsLastProfile(const char* title); | 276 bool IsLastProfile(const char* title); |
314 void RemoveProfile(CpuProfile* profile); | 277 void RemoveProfile(CpuProfile* profile); |
315 | 278 |
316 CodeEntry* NewCodeEntry( | 279 CodeEntry* NewCodeEntry( |
317 Logger::LogEventsAndTags tag, const char* name, | 280 Logger::LogEventsAndTags tag, |
| 281 const char* name, |
318 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 282 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
319 const char* resource_name = CodeEntry::kEmptyResourceName, | 283 const char* resource_name = CodeEntry::kEmptyResourceName, |
320 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, | 284 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, |
321 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, | 285 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo); |
322 JITLineInfoTable* line_info = NULL, Address instruction_start = NULL); | |
323 | 286 |
324 // Called from profile generator thread. | 287 // Called from profile generator thread. |
325 void AddPathToCurrentProfiles(base::TimeTicks timestamp, | 288 void AddPathToCurrentProfiles( |
326 const Vector<CodeEntry*>& path, int src_line); | 289 base::TimeTicks timestamp, const Vector<CodeEntry*>& path); |
327 | 290 |
328 // Limits the number of profiles that can be simultaneously collected. | 291 // Limits the number of profiles that can be simultaneously collected. |
329 static const int kMaxSimultaneousProfiles = 100; | 292 static const int kMaxSimultaneousProfiles = 100; |
330 | 293 |
331 private: | 294 private: |
332 StringsStorage function_and_resource_names_; | 295 StringsStorage function_and_resource_names_; |
333 List<CodeEntry*> code_entries_; | 296 List<CodeEntry*> code_entries_; |
334 List<CpuProfile*> finished_profiles_; | 297 List<CpuProfile*> finished_profiles_; |
335 | 298 |
336 // Accessed by VM thread and profile generator thread. | 299 // Accessed by VM thread and profile generator thread. |
(...skipping 29 matching lines...) Expand all Loading... |
366 CodeEntry* gc_entry_; | 329 CodeEntry* gc_entry_; |
367 CodeEntry* unresolved_entry_; | 330 CodeEntry* unresolved_entry_; |
368 | 331 |
369 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 332 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
370 }; | 333 }; |
371 | 334 |
372 | 335 |
373 } } // namespace v8::internal | 336 } } // namespace v8::internal |
374 | 337 |
375 #endif // V8_PROFILE_GENERATOR_H_ | 338 #endif // V8_PROFILE_GENERATOR_H_ |
OLD | NEW |