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