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 <map> |
| 9 #include "include/v8-profiler.h" | 9 #include "include/v8-profiler.h" |
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 bool empty() const { return pc_offset_map_.empty(); } | 30 bool empty() const { return pc_offset_map_.empty(); } |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 // pc_offset -> source line | 33 // pc_offset -> source line |
| 34 typedef std::map<int, int> PcOffsetMap; | 34 typedef std::map<int, int> PcOffsetMap; |
| 35 PcOffsetMap pc_offset_map_; | 35 PcOffsetMap pc_offset_map_; |
| 36 DISALLOW_COPY_AND_ASSIGN(JITLineInfoTable); | 36 DISALLOW_COPY_AND_ASSIGN(JITLineInfoTable); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 | |
| 40 struct DeoptInfo { | |
|
alph
2015/03/18 18:15:19
turn it into a class?
loislo
2015/03/19 08:16:12
done
| |
| 41 const char* deopt_reason; | |
| 42 struct Frame { | |
| 43 int script_id; | |
| 44 int position; | |
| 45 }; | |
| 46 std::vector<Frame> stack; | |
| 47 void AddInlineFrame(int script_id, int position) { | |
| 48 Frame frame = {script_id, position}; | |
| 49 stack.push_back(frame); | |
| 50 } | |
| 51 }; | |
| 52 | |
| 53 | |
| 39 class CodeEntry { | 54 class CodeEntry { |
| 40 public: | 55 public: |
| 41 // CodeEntry doesn't own name strings, just references them. | 56 // CodeEntry doesn't own name strings, just references them. |
| 42 inline CodeEntry(Logger::LogEventsAndTags tag, const char* name, | 57 inline CodeEntry(Logger::LogEventsAndTags tag, const char* name, |
| 43 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 58 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
| 44 const char* resource_name = CodeEntry::kEmptyResourceName, | 59 const char* resource_name = CodeEntry::kEmptyResourceName, |
| 45 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, | 60 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, |
| 46 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, | 61 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, |
| 47 JITLineInfoTable* line_info = NULL, | 62 JITLineInfoTable* line_info = NULL, |
| 48 Address instruction_start = NULL); | 63 Address instruction_start = NULL); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 65 } | 80 } |
| 66 const char* bailout_reason() const { return bailout_reason_; } | 81 const char* bailout_reason() const { return bailout_reason_; } |
| 67 | 82 |
| 68 void set_deopt_info(const char* deopt_reason, SourcePosition position, | 83 void set_deopt_info(const char* deopt_reason, SourcePosition position, |
| 69 size_t pc_offset) { | 84 size_t pc_offset) { |
| 70 DCHECK(deopt_position_.IsUnknown()); | 85 DCHECK(deopt_position_.IsUnknown()); |
| 71 deopt_reason_ = deopt_reason; | 86 deopt_reason_ = deopt_reason; |
| 72 deopt_position_ = position; | 87 deopt_position_ = position; |
| 73 pc_offset_ = pc_offset; | 88 pc_offset_ = pc_offset; |
| 74 } | 89 } |
| 90 DeoptInfo GetDeoptInfo(); | |
|
alph
2015/03/18 18:15:19
seems to be quite a big object to return by value
loislo
2015/03/19 08:16:12
done
| |
| 75 const char* deopt_reason() const { return deopt_reason_; } | 91 const char* deopt_reason() const { return deopt_reason_; } |
| 76 SourcePosition deopt_position() const { return deopt_position_; } | 92 SourcePosition deopt_position() const { return deopt_position_; } |
| 77 bool has_deopt_info() const { return !deopt_position_.IsUnknown(); } | 93 bool has_deopt_info() const { return !deopt_position_.IsUnknown(); } |
| 78 void clear_deopt_info() { | 94 void clear_deopt_info() { |
| 79 deopt_reason_ = kNoDeoptReason; | 95 deopt_reason_ = kNoDeoptReason; |
| 80 deopt_position_ = SourcePosition::Unknown(); | 96 deopt_position_ = SourcePosition::Unknown(); |
| 81 } | 97 } |
| 82 | 98 |
| 83 void FillFunctionInfo(SharedFunctionInfo* shared); | 99 void FillFunctionInfo(SharedFunctionInfo* shared); |
| 84 | 100 |
| 85 static inline bool is_js_function_tag(Logger::LogEventsAndTags tag); | 101 static inline bool is_js_function_tag(Logger::LogEventsAndTags tag); |
| 86 | 102 |
| 87 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } | 103 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } |
| 88 void set_no_frame_ranges(List<OffsetRange>* ranges) { | 104 void set_no_frame_ranges(List<OffsetRange>* ranges) { |
| 89 no_frame_ranges_ = ranges; | 105 no_frame_ranges_ = ranges; |
| 90 } | 106 } |
| 107 void set_inlined_function_infos(std::vector<InlinedFunctionInfo>* infos) { | |
| 108 DCHECK(!inlined_function_infos_); | |
| 109 inlined_function_infos_ = infos; | |
| 110 } | |
| 111 std::vector<InlinedFunctionInfo>* ReleaseInlinedFunctionInfos() { | |
| 112 std::vector<InlinedFunctionInfo>* tmp = inlined_function_infos_; | |
| 113 inlined_function_infos_ = NULL; | |
| 114 return tmp; | |
| 115 } | |
| 91 | 116 |
| 92 void SetBuiltinId(Builtins::Name id); | 117 void SetBuiltinId(Builtins::Name id); |
| 93 Builtins::Name builtin_id() const { | 118 Builtins::Name builtin_id() const { |
| 94 return BuiltinIdField::decode(bit_field_); | 119 return BuiltinIdField::decode(bit_field_); |
| 95 } | 120 } |
| 96 | 121 |
| 97 uint32_t GetHash() const; | 122 uint32_t GetHash() const; |
| 98 bool IsSameFunctionAs(CodeEntry* entry) const; | 123 bool IsSameFunctionAs(CodeEntry* entry) const; |
| 99 | 124 |
| 100 int GetSourceLine(int pc_offset) const; | 125 int GetSourceLine(int pc_offset) const; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 120 int script_id_; | 145 int script_id_; |
| 121 int position_; | 146 int position_; |
| 122 List<OffsetRange>* no_frame_ranges_; | 147 List<OffsetRange>* no_frame_ranges_; |
| 123 const char* bailout_reason_; | 148 const char* bailout_reason_; |
| 124 const char* deopt_reason_; | 149 const char* deopt_reason_; |
| 125 SourcePosition deopt_position_; | 150 SourcePosition deopt_position_; |
| 126 size_t pc_offset_; | 151 size_t pc_offset_; |
| 127 JITLineInfoTable* line_info_; | 152 JITLineInfoTable* line_info_; |
| 128 Address instruction_start_; | 153 Address instruction_start_; |
| 129 | 154 |
| 155 std::vector<InlinedFunctionInfo>* inlined_function_infos_; | |
| 156 | |
| 130 DISALLOW_COPY_AND_ASSIGN(CodeEntry); | 157 DISALLOW_COPY_AND_ASSIGN(CodeEntry); |
| 131 }; | 158 }; |
| 132 | 159 |
| 133 | 160 |
| 134 class ProfileTree; | 161 class ProfileTree; |
| 135 | 162 |
| 136 class ProfileNode { | 163 class ProfileNode { |
| 137 private: | |
| 138 struct DeoptInfo { | |
| 139 DeoptInfo(const char* deopt_reason, SourcePosition deopt_position) | |
| 140 : deopt_reason(deopt_reason), deopt_position(deopt_position) {} | |
| 141 DeoptInfo(const DeoptInfo& info) | |
| 142 : deopt_reason(info.deopt_reason), | |
| 143 deopt_position(info.deopt_position) {} | |
| 144 const char* deopt_reason; | |
| 145 SourcePosition deopt_position; | |
| 146 }; | |
| 147 | |
| 148 public: | 164 public: |
| 149 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); | 165 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); |
| 150 | 166 |
| 151 ProfileNode* FindChild(CodeEntry* entry); | 167 ProfileNode* FindChild(CodeEntry* entry); |
| 152 ProfileNode* FindOrAddChild(CodeEntry* entry); | 168 ProfileNode* FindOrAddChild(CodeEntry* entry); |
| 153 void IncrementSelfTicks() { ++self_ticks_; } | 169 void IncrementSelfTicks() { ++self_ticks_; } |
| 154 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } | 170 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } |
| 155 void IncrementLineTicks(int src_line); | 171 void IncrementLineTicks(int src_line); |
| 156 | 172 |
| 157 CodeEntry* entry() const { return entry_; } | 173 CodeEntry* entry() const { return entry_; } |
| 158 unsigned self_ticks() const { return self_ticks_; } | 174 unsigned self_ticks() const { return self_ticks_; } |
| 159 const List<ProfileNode*>* children() const { return &children_list_; } | 175 const List<ProfileNode*>* children() const { return &children_list_; } |
| 160 unsigned id() const { return id_; } | 176 unsigned id() const { return id_; } |
| 161 unsigned function_id() const; | 177 unsigned function_id() const; |
| 162 unsigned int GetHitLineCount() const { return line_ticks_.occupancy(); } | 178 unsigned int GetHitLineCount() const { return line_ticks_.occupancy(); } |
| 163 bool GetLineTicks(v8::CpuProfileNode::LineTick* entries, | 179 bool GetLineTicks(v8::CpuProfileNode::LineTick* entries, |
| 164 unsigned int length) const; | 180 unsigned int length) const; |
| 165 void CollectDeoptInfo(CodeEntry* entry); | 181 void CollectDeoptInfo(CodeEntry* entry); |
| 166 const List<DeoptInfo>& deopt_infos() const { return deopt_infos_; } | 182 const std::vector<DeoptInfo>& deopt_infos() const { return deopt_infos_; } |
| 167 | 183 |
| 168 void Print(int indent); | 184 void Print(int indent); |
| 169 | 185 |
| 170 static bool CodeEntriesMatch(void* entry1, void* entry2) { | 186 static bool CodeEntriesMatch(void* entry1, void* entry2) { |
| 171 return reinterpret_cast<CodeEntry*>(entry1) | 187 return reinterpret_cast<CodeEntry*>(entry1) |
| 172 ->IsSameFunctionAs(reinterpret_cast<CodeEntry*>(entry2)); | 188 ->IsSameFunctionAs(reinterpret_cast<CodeEntry*>(entry2)); |
| 173 } | 189 } |
| 174 | 190 |
| 175 private: | 191 private: |
| 176 static uint32_t CodeEntryHash(CodeEntry* entry) { return entry->GetHash(); } | 192 static uint32_t CodeEntryHash(CodeEntry* entry) { return entry->GetHash(); } |
| 177 | 193 |
| 178 static bool LineTickMatch(void* a, void* b) { return a == b; } | 194 static bool LineTickMatch(void* a, void* b) { return a == b; } |
| 179 | 195 |
| 180 ProfileTree* tree_; | 196 ProfileTree* tree_; |
| 181 CodeEntry* entry_; | 197 CodeEntry* entry_; |
| 182 unsigned self_ticks_; | 198 unsigned self_ticks_; |
| 183 // Mapping from CodeEntry* to ProfileNode* | 199 // Mapping from CodeEntry* to ProfileNode* |
| 184 HashMap children_; | 200 HashMap children_; |
| 185 List<ProfileNode*> children_list_; | 201 List<ProfileNode*> children_list_; |
| 186 unsigned id_; | 202 unsigned id_; |
| 187 HashMap line_ticks_; | 203 HashMap line_ticks_; |
| 188 | 204 |
| 189 List<DeoptInfo> deopt_infos_; | 205 std::vector<DeoptInfo> deopt_infos_; |
| 206 | |
| 190 DISALLOW_COPY_AND_ASSIGN(ProfileNode); | 207 DISALLOW_COPY_AND_ASSIGN(ProfileNode); |
| 191 }; | 208 }; |
| 192 | 209 |
| 193 | 210 |
| 194 class ProfileTree { | 211 class ProfileTree { |
| 195 public: | 212 public: |
| 196 ProfileTree(); | 213 ProfileTree(); |
| 197 ~ProfileTree(); | 214 ~ProfileTree(); |
| 198 | 215 |
| 199 ProfileNode* AddPathFromEnd( | 216 ProfileNode* AddPathFromEnd( |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 CodeEntry* gc_entry_; | 395 CodeEntry* gc_entry_; |
| 379 CodeEntry* unresolved_entry_; | 396 CodeEntry* unresolved_entry_; |
| 380 | 397 |
| 381 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 398 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
| 382 }; | 399 }; |
| 383 | 400 |
| 384 | 401 |
| 385 } } // namespace v8::internal | 402 } } // namespace v8::internal |
| 386 | 403 |
| 387 #endif // V8_PROFILE_GENERATOR_H_ | 404 #endif // V8_PROFILE_GENERATOR_H_ |
| OLD | NEW |