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 "include/v8-profiler.h" | 8 #include "include/v8-profiler.h" |
| 9 #include "src/allocation.h" | 9 #include "src/allocation.h" |
| 10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 | 46 |
| 47 | 47 |
| 48 class CodeEntry { | 48 class CodeEntry { |
| 49 public: | 49 public: |
| 50 // CodeEntry doesn't own name strings, just references them. | 50 // CodeEntry doesn't own name strings, just references them. |
| 51 inline CodeEntry(Logger::LogEventsAndTags tag, | 51 inline CodeEntry(Logger::LogEventsAndTags tag, |
| 52 const char* name, | 52 const char* name, |
| 53 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 53 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
| 54 const char* resource_name = CodeEntry::kEmptyResourceName, | 54 const char* resource_name = CodeEntry::kEmptyResourceName, |
| 55 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, | 55 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, |
| 56 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo); | 56 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, |
| 57 JITLineInfoTable* line_info = NULL); | |
| 57 ~CodeEntry(); | 58 ~CodeEntry(); |
| 58 | 59 |
| 59 bool is_js_function() const { return is_js_function_tag(tag_); } | 60 bool is_js_function() const { return is_js_function_tag(tag_); } |
| 60 const char* name_prefix() const { return name_prefix_; } | 61 const char* name_prefix() const { return name_prefix_; } |
| 61 bool has_name_prefix() const { return name_prefix_[0] != '\0'; } | 62 bool has_name_prefix() const { return name_prefix_[0] != '\0'; } |
| 62 const char* name() const { return name_; } | 63 const char* name() const { return name_; } |
| 63 const char* resource_name() const { return resource_name_; } | 64 const char* resource_name() const { return resource_name_; } |
| 64 int line_number() const { return line_number_; } | 65 int line_number() const { return line_number_; } |
| 65 int column_number() const { return column_number_; } | 66 int column_number() const { return column_number_; } |
| 67 const JITLineInfoTable& line_info() const { return line_info_; } | |
| 66 void set_shared_id(int shared_id) { shared_id_ = shared_id; } | 68 void set_shared_id(int shared_id) { shared_id_ = shared_id; } |
| 67 int script_id() const { return script_id_; } | 69 int script_id() const { return script_id_; } |
| 68 void set_script_id(int script_id) { script_id_ = script_id; } | 70 void set_script_id(int script_id) { script_id_ = script_id; } |
| 69 void set_bailout_reason(const char* bailout_reason) { | 71 void set_bailout_reason(const char* bailout_reason) { |
| 70 bailout_reason_ = bailout_reason; | 72 bailout_reason_ = bailout_reason; |
| 71 } | 73 } |
| 72 const char* bailout_reason() const { return bailout_reason_; } | 74 const char* bailout_reason() const { return bailout_reason_; } |
| 73 | 75 |
| 74 static inline bool is_js_function_tag(Logger::LogEventsAndTags tag); | 76 static inline bool is_js_function_tag(Logger::LogEventsAndTags tag); |
| 75 | 77 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 89 static const char* const kEmptyBailoutReason; | 91 static const char* const kEmptyBailoutReason; |
| 90 | 92 |
| 91 private: | 93 private: |
| 92 Logger::LogEventsAndTags tag_ : 8; | 94 Logger::LogEventsAndTags tag_ : 8; |
| 93 Builtins::Name builtin_id_ : 8; | 95 Builtins::Name builtin_id_ : 8; |
| 94 const char* name_prefix_; | 96 const char* name_prefix_; |
| 95 const char* name_; | 97 const char* name_; |
| 96 const char* resource_name_; | 98 const char* resource_name_; |
| 97 int line_number_; | 99 int line_number_; |
| 98 int column_number_; | 100 int column_number_; |
| 101 JITLineInfoTable line_info_; | |
| 99 int shared_id_; | 102 int shared_id_; |
| 100 int script_id_; | 103 int script_id_; |
| 101 List<OffsetRange>* no_frame_ranges_; | 104 List<OffsetRange>* no_frame_ranges_; |
| 102 const char* bailout_reason_; | 105 const char* bailout_reason_; |
| 103 | 106 |
| 104 DISALLOW_COPY_AND_ASSIGN(CodeEntry); | 107 DISALLOW_COPY_AND_ASSIGN(CodeEntry); |
| 105 }; | 108 }; |
| 106 | 109 |
| 107 | 110 |
| 108 class ProfileTree; | 111 class ProfileTree; |
| 109 | 112 |
| 110 class ProfileNode { | 113 class ProfileNode { |
| 111 public: | 114 public: |
| 112 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); | 115 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); |
| 113 | 116 |
| 114 ProfileNode* FindChild(CodeEntry* entry); | 117 ProfileNode* FindChild(CodeEntry* entry); |
| 115 ProfileNode* FindOrAddChild(CodeEntry* entry); | 118 ProfileNode* FindOrAddChild(CodeEntry* entry); |
| 116 void IncrementSelfTicks() { ++self_ticks_; } | 119 void IncrementSelfTicks() { ++self_ticks_; } |
| 117 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } | 120 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } |
| 121 void IncrementLineTicks(int src_line); | |
| 118 | 122 |
| 119 CodeEntry* entry() const { return entry_; } | 123 CodeEntry* entry() const { return entry_; } |
| 120 unsigned self_ticks() const { return self_ticks_; } | 124 unsigned self_ticks() const { return self_ticks_; } |
| 121 const List<ProfileNode*>* children() const { return &children_list_; } | 125 const List<ProfileNode*>* children() const { return &children_list_; } |
| 122 unsigned id() const { return id_; } | 126 unsigned id() const { return id_; } |
| 127 unsigned int GetHitLineCount() const { return line_ticks_.occupancy(); } | |
| 128 bool GetLineTicks(LineTick* entries, unsigned int number) const; | |
| 123 | 129 |
| 124 void Print(int indent); | 130 void Print(int indent); |
| 125 | 131 |
| 126 private: | 132 private: |
| 127 static bool CodeEntriesMatch(void* entry1, void* entry2) { | 133 static bool CodeEntriesMatch(void* entry1, void* entry2) { |
| 128 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs( | 134 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs( |
| 129 reinterpret_cast<CodeEntry*>(entry2)); | 135 reinterpret_cast<CodeEntry*>(entry2)); |
| 130 } | 136 } |
| 131 | 137 |
| 132 static uint32_t CodeEntryHash(CodeEntry* entry) { | 138 static uint32_t CodeEntryHash(CodeEntry* entry) { |
| 133 return entry->GetCallUid(); | 139 return entry->GetCallUid(); |
| 134 } | 140 } |
| 135 | 141 |
| 136 ProfileTree* tree_; | 142 ProfileTree* tree_; |
| 137 CodeEntry* entry_; | 143 CodeEntry* entry_; |
| 138 unsigned self_ticks_; | 144 unsigned self_ticks_; |
| 139 // Mapping from CodeEntry* to ProfileNode* | 145 // Mapping from CodeEntry* to ProfileNode* |
| 140 HashMap children_; | 146 HashMap children_; |
| 141 List<ProfileNode*> children_list_; | 147 List<ProfileNode*> children_list_; |
| 142 unsigned id_; | 148 unsigned id_; |
| 149 HashMap line_ticks_; | |
| 143 | 150 |
| 144 DISALLOW_COPY_AND_ASSIGN(ProfileNode); | 151 DISALLOW_COPY_AND_ASSIGN(ProfileNode); |
| 145 }; | 152 }; |
| 146 | 153 |
| 147 | 154 |
| 148 class ProfileTree { | 155 class ProfileTree { |
| 149 public: | 156 public: |
| 150 ProfileTree(); | 157 ProfileTree(); |
| 151 ~ProfileTree(); | 158 ~ProfileTree(); |
| 152 | 159 |
| 153 ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path); | 160 ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path, |
| 154 void AddPathFromStart(const Vector<CodeEntry*>& path); | 161 int src_line = v8::CpuProfileNode::kNoLineNumberInfo); |
|
yurys
2014/07/29 13:15:10
style: wrong alignment
| |
| 162 void AddPathFromStart(const Vector<CodeEntry*>& path, | |
| 163 int src_line = v8::CpuProfileNode::kNoLineNumberInfo); | |
|
yurys
2014/07/29 13:15:10
ditto
| |
| 155 ProfileNode* root() const { return root_; } | 164 ProfileNode* root() const { return root_; } |
| 156 unsigned next_node_id() { return next_node_id_++; } | 165 unsigned next_node_id() { return next_node_id_++; } |
| 157 | 166 |
| 158 void Print() { | 167 void Print() { |
| 159 root_->Print(0); | 168 root_->Print(0); |
| 160 } | 169 } |
| 161 | 170 |
| 162 private: | 171 private: |
| 163 template <typename Callback> | 172 template <typename Callback> |
| 164 void TraverseDepthFirst(Callback* callback); | 173 void TraverseDepthFirst(Callback* callback); |
| 165 | 174 |
| 166 CodeEntry root_entry_; | 175 CodeEntry root_entry_; |
| 167 unsigned next_node_id_; | 176 unsigned next_node_id_; |
| 168 ProfileNode* root_; | 177 ProfileNode* root_; |
| 169 | 178 |
| 170 DISALLOW_COPY_AND_ASSIGN(ProfileTree); | 179 DISALLOW_COPY_AND_ASSIGN(ProfileTree); |
| 171 }; | 180 }; |
| 172 | 181 |
| 173 | 182 |
| 174 class CpuProfile { | 183 class CpuProfile { |
| 175 public: | 184 public: |
| 176 CpuProfile(const char* title, bool record_samples); | 185 CpuProfile(const char* title, bool record_samples); |
| 177 | 186 |
| 178 // Add pc -> ... -> main() call path to the profile. | 187 // Add pc -> ... -> main() call path to the profile. |
| 179 void AddPath(base::TimeTicks timestamp, const Vector<CodeEntry*>& path); | 188 void AddPath(base::TimeTicks timestamp, const Vector<CodeEntry*>& path, |
| 189 int src_line); | |
| 180 void CalculateTotalTicksAndSamplingRate(); | 190 void CalculateTotalTicksAndSamplingRate(); |
| 181 | 191 |
| 182 const char* title() const { return title_; } | 192 const char* title() const { return title_; } |
| 183 const ProfileTree* top_down() const { return &top_down_; } | 193 const ProfileTree* top_down() const { return &top_down_; } |
| 184 | 194 |
| 185 int samples_count() const { return samples_.length(); } | 195 int samples_count() const { return samples_.length(); } |
| 186 ProfileNode* sample(int index) const { return samples_.at(index); } | 196 ProfileNode* sample(int index) const { return samples_.at(index); } |
| 187 base::TimeTicks sample_timestamp(int index) const { | 197 base::TimeTicks sample_timestamp(int index) const { |
| 188 return timestamps_.at(index); | 198 return timestamps_.at(index); |
| 189 } | 199 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 } | 286 } |
| 277 bool IsLastProfile(const char* title); | 287 bool IsLastProfile(const char* title); |
| 278 void RemoveProfile(CpuProfile* profile); | 288 void RemoveProfile(CpuProfile* profile); |
| 279 | 289 |
| 280 CodeEntry* NewCodeEntry( | 290 CodeEntry* NewCodeEntry( |
| 281 Logger::LogEventsAndTags tag, | 291 Logger::LogEventsAndTags tag, |
| 282 const char* name, | 292 const char* name, |
| 283 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 293 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
| 284 const char* resource_name = CodeEntry::kEmptyResourceName, | 294 const char* resource_name = CodeEntry::kEmptyResourceName, |
| 285 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, | 295 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, |
| 286 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo); | 296 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, |
| 297 JITLineInfoTable* line_info = NULL); | |
| 287 | 298 |
| 288 // Called from profile generator thread. | 299 // Called from profile generator thread. |
| 289 void AddPathToCurrentProfiles( | 300 void AddPathToCurrentProfiles( |
| 290 base::TimeTicks timestamp, const Vector<CodeEntry*>& path); | 301 base::TimeTicks timestamp, const Vector<CodeEntry*>& path, |
| 302 int src_line); | |
| 291 | 303 |
| 292 // Limits the number of profiles that can be simultaneously collected. | 304 // Limits the number of profiles that can be simultaneously collected. |
| 293 static const int kMaxSimultaneousProfiles = 100; | 305 static const int kMaxSimultaneousProfiles = 100; |
| 294 | 306 |
| 295 private: | 307 private: |
| 296 StringsStorage function_and_resource_names_; | 308 StringsStorage function_and_resource_names_; |
| 297 List<CodeEntry*> code_entries_; | 309 List<CodeEntry*> code_entries_; |
| 298 List<CpuProfile*> finished_profiles_; | 310 List<CpuProfile*> finished_profiles_; |
| 299 | 311 |
| 300 // Accessed by VM thread and profile generator thread. | 312 // Accessed by VM thread and profile generator thread. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 331 CodeEntry* gc_entry_; | 343 CodeEntry* gc_entry_; |
| 332 CodeEntry* unresolved_entry_; | 344 CodeEntry* unresolved_entry_; |
| 333 | 345 |
| 334 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 346 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
| 335 }; | 347 }; |
| 336 | 348 |
| 337 | 349 |
| 338 } } // namespace v8::internal | 350 } } // namespace v8::internal |
| 339 | 351 |
| 340 #endif // V8_PROFILE_GENERATOR_H_ | 352 #endif // V8_PROFILE_GENERATOR_H_ |
| OLD | NEW |