Chromium Code Reviews| 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 DCHECK(pc_offset >= 0); | |
| 57 DCHECK(line > 0); // The 1-based number of the source line. | |
| 58 pc_offset_map_.insert(std::make_pair(pc_offset, line)); | |
|
alph
2014/08/15 12:10:47
a possible optimization: you don't need to bloat i
Denis Pravdin
2014/09/01 10:44:38
SetPosition is called during code generation. GetS
Weiliang
2014/09/03 02:29:48
Does it mean below?
if (GetSourceLineNumber(pc
alph
2014/09/09 14:47:34
I meant:
if (GetSourceLineNumber(pc_offset) != lin
| |
| 59 } | |
| 60 | |
| 61 int GetSourceLineNumber(int pc_offset) const { | |
| 62 PcOffsetMap::const_iterator it = pc_offset_map_.lower_bound(pc_offset); | |
| 63 if (it == pc_offset_map_.end()) { | |
| 64 return v8::CpuProfileNode::kNoLineNumberInfo; | |
| 65 } | |
| 66 return it->second; | |
| 67 } | |
| 68 | |
| 69 bool Empty() const { return pc_offset_map_.empty(); } | |
| 70 | |
| 71 private: | |
| 72 // pc_offset -> source line | |
| 73 typedef std::map<int, int> PcOffsetMap; | |
| 74 PcOffsetMap pc_offset_map_; | |
| 75 DISALLOW_COPY_AND_ASSIGN(JITLineInfoTable); | |
| 76 }; | |
| 77 | |
| 47 class CodeEntry { | 78 class CodeEntry { |
| 48 public: | 79 public: |
| 49 // CodeEntry doesn't own name strings, just references them. | 80 // CodeEntry doesn't own name strings, just references them. |
| 50 inline CodeEntry(Logger::LogEventsAndTags tag, | 81 inline CodeEntry(Logger::LogEventsAndTags tag, |
| 51 const char* name, | 82 const char* name, |
| 52 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 83 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
| 53 const char* resource_name = CodeEntry::kEmptyResourceName, | 84 const char* resource_name = CodeEntry::kEmptyResourceName, |
| 54 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, | 85 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, |
| 55 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo); | 86 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, |
| 87 JITLineInfoTable* line_info = NULL); | |
| 56 ~CodeEntry(); | 88 ~CodeEntry(); |
| 57 | 89 |
| 58 bool is_js_function() const { return is_js_function_tag(tag_); } | 90 bool is_js_function() const { return is_js_function_tag(tag_); } |
| 59 const char* name_prefix() const { return name_prefix_; } | 91 const char* name_prefix() const { return name_prefix_; } |
| 60 bool has_name_prefix() const { return name_prefix_[0] != '\0'; } | 92 bool has_name_prefix() const { return name_prefix_[0] != '\0'; } |
| 61 const char* name() const { return name_; } | 93 const char* name() const { return name_; } |
| 62 const char* resource_name() const { return resource_name_; } | 94 const char* resource_name() const { return resource_name_; } |
| 63 int line_number() const { return line_number_; } | 95 int line_number() const { return line_number_; } |
| 64 int column_number() const { return column_number_; } | 96 int column_number() const { return column_number_; } |
| 97 const JITLineInfoTable* line_info() const { return line_info_; } | |
| 65 void set_shared_id(int shared_id) { shared_id_ = shared_id; } | 98 void set_shared_id(int shared_id) { shared_id_ = shared_id; } |
| 66 int script_id() const { return script_id_; } | 99 int script_id() const { return script_id_; } |
| 67 void set_script_id(int script_id) { script_id_ = script_id; } | 100 void set_script_id(int script_id) { script_id_ = script_id; } |
| 68 void set_bailout_reason(const char* bailout_reason) { | 101 void set_bailout_reason(const char* bailout_reason) { |
| 69 bailout_reason_ = bailout_reason; | 102 bailout_reason_ = bailout_reason; |
| 70 } | 103 } |
| 71 const char* bailout_reason() const { return bailout_reason_; } | 104 const char* bailout_reason() const { return bailout_reason_; } |
| 72 | 105 |
| 73 static inline bool is_js_function_tag(Logger::LogEventsAndTags tag); | 106 static inline bool is_js_function_tag(Logger::LogEventsAndTags tag); |
| 74 | 107 |
| 75 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } | 108 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } |
| 76 void set_no_frame_ranges(List<OffsetRange>* ranges) { | 109 void set_no_frame_ranges(List<OffsetRange>* ranges) { |
| 77 no_frame_ranges_ = ranges; | 110 no_frame_ranges_ = ranges; |
| 78 } | 111 } |
| 79 | 112 |
| 80 void SetBuiltinId(Builtins::Name id); | 113 void SetBuiltinId(Builtins::Name id); |
| 81 Builtins::Name builtin_id() const { return builtin_id_; } | 114 Builtins::Name builtin_id() const { return builtin_id_; } |
| 82 | 115 |
| 83 uint32_t GetCallUid() const; | 116 uint32_t GetCallUid() const; |
| 84 bool IsSameAs(CodeEntry* entry) const; | 117 bool IsSameAs(CodeEntry* entry) const; |
| 85 | 118 |
| 119 int GetSourceLine(int pc_offset) const; | |
| 120 | |
| 86 static const char* const kEmptyNamePrefix; | 121 static const char* const kEmptyNamePrefix; |
| 87 static const char* const kEmptyResourceName; | 122 static const char* const kEmptyResourceName; |
| 88 static const char* const kEmptyBailoutReason; | 123 static const char* const kEmptyBailoutReason; |
| 89 | 124 |
| 90 private: | 125 private: |
| 91 Logger::LogEventsAndTags tag_ : 8; | 126 Logger::LogEventsAndTags tag_ : 8; |
| 92 Builtins::Name builtin_id_ : 8; | 127 Builtins::Name builtin_id_ : 8; |
| 93 const char* name_prefix_; | 128 const char* name_prefix_; |
| 94 const char* name_; | 129 const char* name_; |
| 95 const char* resource_name_; | 130 const char* resource_name_; |
| 96 int line_number_; | 131 int line_number_; |
| 97 int column_number_; | 132 int column_number_; |
| 98 int shared_id_; | 133 int shared_id_; |
| 99 int script_id_; | 134 int script_id_; |
| 100 List<OffsetRange>* no_frame_ranges_; | 135 List<OffsetRange>* no_frame_ranges_; |
| 101 const char* bailout_reason_; | 136 const char* bailout_reason_; |
| 137 JITLineInfoTable* line_info_; | |
| 102 | 138 |
| 103 DISALLOW_COPY_AND_ASSIGN(CodeEntry); | 139 DISALLOW_COPY_AND_ASSIGN(CodeEntry); |
| 104 }; | 140 }; |
| 105 | 141 |
| 106 | 142 |
| 107 class ProfileTree; | 143 class ProfileTree; |
| 108 | 144 |
| 109 class ProfileNode { | 145 class ProfileNode { |
| 110 public: | 146 public: |
| 111 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); | 147 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); |
| 112 | 148 |
| 113 ProfileNode* FindChild(CodeEntry* entry); | 149 ProfileNode* FindChild(CodeEntry* entry); |
| 114 ProfileNode* FindOrAddChild(CodeEntry* entry); | 150 ProfileNode* FindOrAddChild(CodeEntry* entry); |
| 115 void IncrementSelfTicks() { ++self_ticks_; } | 151 void IncrementSelfTicks() { ++self_ticks_; } |
| 116 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } | 152 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } |
| 153 void IncrementLineTicks(int src_line); | |
| 117 | 154 |
| 118 CodeEntry* entry() const { return entry_; } | 155 CodeEntry* entry() const { return entry_; } |
| 119 unsigned self_ticks() const { return self_ticks_; } | 156 unsigned self_ticks() const { return self_ticks_; } |
| 120 const List<ProfileNode*>* children() const { return &children_list_; } | 157 const List<ProfileNode*>* children() const { return &children_list_; } |
| 121 unsigned id() const { return id_; } | 158 unsigned id() const { return id_; } |
| 159 unsigned int GetHitLineCount() const { return line_ticks_.occupancy(); } | |
| 160 bool GetLineTicks(v8::CpuProfileNode::LineTick* entries, | |
| 161 unsigned int length) const; | |
| 122 | 162 |
| 123 void Print(int indent); | 163 void Print(int indent); |
| 124 | 164 |
| 125 private: | 165 private: |
| 126 static bool CodeEntriesMatch(void* entry1, void* entry2) { | 166 static bool CodeEntriesMatch(void* entry1, void* entry2) { |
| 127 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs( | 167 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs( |
| 128 reinterpret_cast<CodeEntry*>(entry2)); | 168 reinterpret_cast<CodeEntry*>(entry2)); |
| 129 } | 169 } |
| 130 | 170 |
| 131 static uint32_t CodeEntryHash(CodeEntry* entry) { | 171 static uint32_t CodeEntryHash(CodeEntry* entry) { |
| 132 return entry->GetCallUid(); | 172 return entry->GetCallUid(); |
| 133 } | 173 } |
| 134 | 174 |
| 135 ProfileTree* tree_; | 175 ProfileTree* tree_; |
| 136 CodeEntry* entry_; | 176 CodeEntry* entry_; |
| 137 unsigned self_ticks_; | 177 unsigned self_ticks_; |
| 138 // Mapping from CodeEntry* to ProfileNode* | 178 // Mapping from CodeEntry* to ProfileNode* |
| 139 HashMap children_; | 179 HashMap children_; |
| 140 List<ProfileNode*> children_list_; | 180 List<ProfileNode*> children_list_; |
| 141 unsigned id_; | 181 unsigned id_; |
| 182 HashMap line_ticks_; | |
| 142 | 183 |
| 143 DISALLOW_COPY_AND_ASSIGN(ProfileNode); | 184 DISALLOW_COPY_AND_ASSIGN(ProfileNode); |
| 144 }; | 185 }; |
| 145 | 186 |
| 146 | 187 |
| 147 class ProfileTree { | 188 class ProfileTree { |
| 148 public: | 189 public: |
| 149 ProfileTree(); | 190 ProfileTree(); |
| 150 ~ProfileTree(); | 191 ~ProfileTree(); |
| 151 | 192 |
| 152 ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path); | 193 ProfileNode* AddPathFromEnd( |
| 153 void AddPathFromStart(const Vector<CodeEntry*>& path); | 194 const Vector<CodeEntry*>& path, |
| 195 int src_line = v8::CpuProfileNode::kNoLineNumberInfo); | |
| 196 void AddPathFromStart(const Vector<CodeEntry*>& path, | |
| 197 int src_line = v8::CpuProfileNode::kNoLineNumberInfo); | |
| 154 ProfileNode* root() const { return root_; } | 198 ProfileNode* root() const { return root_; } |
| 155 unsigned next_node_id() { return next_node_id_++; } | 199 unsigned next_node_id() { return next_node_id_++; } |
| 156 | 200 |
| 157 void Print() { | 201 void Print() { |
| 158 root_->Print(0); | 202 root_->Print(0); |
| 159 } | 203 } |
| 160 | 204 |
| 161 private: | 205 private: |
| 162 template <typename Callback> | 206 template <typename Callback> |
| 163 void TraverseDepthFirst(Callback* callback); | 207 void TraverseDepthFirst(Callback* callback); |
| 164 | 208 |
| 165 CodeEntry root_entry_; | 209 CodeEntry root_entry_; |
| 166 unsigned next_node_id_; | 210 unsigned next_node_id_; |
| 167 ProfileNode* root_; | 211 ProfileNode* root_; |
| 168 | 212 |
| 169 DISALLOW_COPY_AND_ASSIGN(ProfileTree); | 213 DISALLOW_COPY_AND_ASSIGN(ProfileTree); |
| 170 }; | 214 }; |
| 171 | 215 |
| 172 | 216 |
| 173 class CpuProfile { | 217 class CpuProfile { |
| 174 public: | 218 public: |
| 175 CpuProfile(const char* title, bool record_samples); | 219 CpuProfile(const char* title, bool record_samples); |
| 176 | 220 |
| 177 // Add pc -> ... -> main() call path to the profile. | 221 // Add pc -> ... -> main() call path to the profile. |
| 178 void AddPath(base::TimeTicks timestamp, const Vector<CodeEntry*>& path); | 222 void AddPath(base::TimeTicks timestamp, |
| 223 const Vector<CodeEntry*>& path, | |
| 224 int src_line); | |
| 179 void CalculateTotalTicksAndSamplingRate(); | 225 void CalculateTotalTicksAndSamplingRate(); |
| 180 | 226 |
| 181 const char* title() const { return title_; } | 227 const char* title() const { return title_; } |
| 182 const ProfileTree* top_down() const { return &top_down_; } | 228 const ProfileTree* top_down() const { return &top_down_; } |
| 183 | 229 |
| 184 int samples_count() const { return samples_.length(); } | 230 int samples_count() const { return samples_.length(); } |
| 185 ProfileNode* sample(int index) const { return samples_.at(index); } | 231 ProfileNode* sample(int index) const { return samples_.at(index); } |
| 186 base::TimeTicks sample_timestamp(int index) const { | 232 base::TimeTicks sample_timestamp(int index) const { |
| 187 return timestamps_.at(index); | 233 return timestamps_.at(index); |
| 188 } | 234 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 } | 321 } |
| 276 bool IsLastProfile(const char* title); | 322 bool IsLastProfile(const char* title); |
| 277 void RemoveProfile(CpuProfile* profile); | 323 void RemoveProfile(CpuProfile* profile); |
| 278 | 324 |
| 279 CodeEntry* NewCodeEntry( | 325 CodeEntry* NewCodeEntry( |
| 280 Logger::LogEventsAndTags tag, | 326 Logger::LogEventsAndTags tag, |
| 281 const char* name, | 327 const char* name, |
| 282 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 328 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
| 283 const char* resource_name = CodeEntry::kEmptyResourceName, | 329 const char* resource_name = CodeEntry::kEmptyResourceName, |
| 284 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, | 330 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, |
| 285 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo); | 331 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, |
| 332 JITLineInfoTable* line_info = NULL); | |
| 286 | 333 |
| 287 // Called from profile generator thread. | 334 // Called from profile generator thread. |
| 288 void AddPathToCurrentProfiles( | 335 void AddPathToCurrentProfiles(base::TimeTicks timestamp, |
| 289 base::TimeTicks timestamp, const Vector<CodeEntry*>& path); | 336 const Vector<CodeEntry*>& path, |
| 337 int src_line); | |
| 290 | 338 |
| 291 // Limits the number of profiles that can be simultaneously collected. | 339 // Limits the number of profiles that can be simultaneously collected. |
| 292 static const int kMaxSimultaneousProfiles = 100; | 340 static const int kMaxSimultaneousProfiles = 100; |
| 293 | 341 |
| 294 private: | 342 private: |
| 295 StringsStorage function_and_resource_names_; | 343 StringsStorage function_and_resource_names_; |
| 296 List<CodeEntry*> code_entries_; | 344 List<CodeEntry*> code_entries_; |
| 297 List<CpuProfile*> finished_profiles_; | 345 List<CpuProfile*> finished_profiles_; |
| 298 | 346 |
| 299 // Accessed by VM thread and profile generator thread. | 347 // Accessed by VM thread and profile generator thread. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 329 CodeEntry* gc_entry_; | 377 CodeEntry* gc_entry_; |
| 330 CodeEntry* unresolved_entry_; | 378 CodeEntry* unresolved_entry_; |
| 331 | 379 |
| 332 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 380 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
| 333 }; | 381 }; |
| 334 | 382 |
| 335 | 383 |
| 336 } } // namespace v8::internal | 384 } } // namespace v8::internal |
| 337 | 385 |
| 338 #endif // V8_PROFILE_GENERATOR_H_ | 386 #endif // V8_PROFILE_GENERATOR_H_ |
| OLD | NEW |