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