Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: src/profile-generator.h

Issue 616963005: Extend CPU profiler with mapping ticks to source lines (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed x64.debug linker error Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/full-codegen.cc ('k') | src/profile-generator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 { return builtin_id_; } 103 Builtins::Name builtin_id() const { return builtin_id_; }
82 104
83 uint32_t GetCallUid() const; 105 uint32_t GetCallUid() const;
84 bool IsSameAs(CodeEntry* entry) const; 106 bool IsSameAs(CodeEntry* entry) const;
85 107
108 int GetSourceLine(int pc_offset) const;
109
110 Address instruction_start() const { return instruction_start_; }
111
86 static const char* const kEmptyNamePrefix; 112 static const char* const kEmptyNamePrefix;
87 static const char* const kEmptyResourceName; 113 static const char* const kEmptyResourceName;
88 static const char* const kEmptyBailoutReason; 114 static const char* const kEmptyBailoutReason;
89 115
90 private: 116 private:
91 Logger::LogEventsAndTags tag_ : 8; 117 Logger::LogEventsAndTags tag_ : 8;
92 Builtins::Name builtin_id_ : 8; 118 Builtins::Name builtin_id_ : 8;
93 const char* name_prefix_; 119 const char* name_prefix_;
94 const char* name_; 120 const char* name_;
95 const char* resource_name_; 121 const char* resource_name_;
96 int line_number_; 122 int line_number_;
97 int column_number_; 123 int column_number_;
98 int shared_id_; 124 int shared_id_;
99 int script_id_; 125 int script_id_;
100 List<OffsetRange>* no_frame_ranges_; 126 List<OffsetRange>* no_frame_ranges_;
101 const char* bailout_reason_; 127 const char* bailout_reason_;
128 JITLineInfoTable* line_info_;
129 Address instruction_start_;
102 130
103 DISALLOW_COPY_AND_ASSIGN(CodeEntry); 131 DISALLOW_COPY_AND_ASSIGN(CodeEntry);
104 }; 132 };
105 133
106 134
107 class ProfileTree; 135 class ProfileTree;
108 136
109 class ProfileNode { 137 class ProfileNode {
110 public: 138 public:
111 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); 139 inline ProfileNode(ProfileTree* tree, CodeEntry* entry);
112 140
113 ProfileNode* FindChild(CodeEntry* entry); 141 ProfileNode* FindChild(CodeEntry* entry);
114 ProfileNode* FindOrAddChild(CodeEntry* entry); 142 ProfileNode* FindOrAddChild(CodeEntry* entry);
115 void IncrementSelfTicks() { ++self_ticks_; } 143 void IncrementSelfTicks() { ++self_ticks_; }
116 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } 144 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; }
145 void IncrementLineTicks(int src_line);
117 146
118 CodeEntry* entry() const { return entry_; } 147 CodeEntry* entry() const { return entry_; }
119 unsigned self_ticks() const { return self_ticks_; } 148 unsigned self_ticks() const { return self_ticks_; }
120 const List<ProfileNode*>* children() const { return &children_list_; } 149 const List<ProfileNode*>* children() const { return &children_list_; }
121 unsigned id() const { return id_; } 150 unsigned id() const { return id_; }
151 unsigned int GetHitLineCount() const { return line_ticks_.occupancy(); }
152 bool GetLineTicks(v8::CpuProfileNode::LineTick* entries,
153 unsigned int length) const;
122 154
123 void Print(int indent); 155 void Print(int indent);
124 156
125 private: 157 private:
126 static bool CodeEntriesMatch(void* entry1, void* entry2) { 158 static bool CodeEntriesMatch(void* entry1, void* entry2) {
127 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs( 159 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs(
128 reinterpret_cast<CodeEntry*>(entry2)); 160 reinterpret_cast<CodeEntry*>(entry2));
129 } 161 }
130 162
131 static uint32_t CodeEntryHash(CodeEntry* entry) { 163 static uint32_t CodeEntryHash(CodeEntry* entry) {
132 return entry->GetCallUid(); 164 return entry->GetCallUid();
133 } 165 }
134 166
135 ProfileTree* tree_; 167 ProfileTree* tree_;
136 CodeEntry* entry_; 168 CodeEntry* entry_;
137 unsigned self_ticks_; 169 unsigned self_ticks_;
138 // Mapping from CodeEntry* to ProfileNode* 170 // Mapping from CodeEntry* to ProfileNode*
139 HashMap children_; 171 HashMap children_;
140 List<ProfileNode*> children_list_; 172 List<ProfileNode*> children_list_;
141 unsigned id_; 173 unsigned id_;
174 HashMap line_ticks_;
142 175
143 DISALLOW_COPY_AND_ASSIGN(ProfileNode); 176 DISALLOW_COPY_AND_ASSIGN(ProfileNode);
144 }; 177 };
145 178
146 179
147 class ProfileTree { 180 class ProfileTree {
148 public: 181 public:
149 ProfileTree(); 182 ProfileTree();
150 ~ProfileTree(); 183 ~ProfileTree();
151 184
152 ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path); 185 ProfileNode* AddPathFromEnd(
153 void AddPathFromStart(const Vector<CodeEntry*>& path); 186 const Vector<CodeEntry*>& path,
187 int src_line = v8::CpuProfileNode::kNoLineNumberInfo);
188 void AddPathFromStart(const Vector<CodeEntry*>& path,
189 int src_line = v8::CpuProfileNode::kNoLineNumberInfo);
154 ProfileNode* root() const { return root_; } 190 ProfileNode* root() const { return root_; }
155 unsigned next_node_id() { return next_node_id_++; } 191 unsigned next_node_id() { return next_node_id_++; }
156 192
157 void Print() { 193 void Print() {
158 root_->Print(0); 194 root_->Print(0);
159 } 195 }
160 196
161 private: 197 private:
162 template <typename Callback> 198 template <typename Callback>
163 void TraverseDepthFirst(Callback* callback); 199 void TraverseDepthFirst(Callback* callback);
164 200
165 CodeEntry root_entry_; 201 CodeEntry root_entry_;
166 unsigned next_node_id_; 202 unsigned next_node_id_;
167 ProfileNode* root_; 203 ProfileNode* root_;
168 204
169 DISALLOW_COPY_AND_ASSIGN(ProfileTree); 205 DISALLOW_COPY_AND_ASSIGN(ProfileTree);
170 }; 206 };
171 207
172 208
173 class CpuProfile { 209 class CpuProfile {
174 public: 210 public:
175 CpuProfile(const char* title, bool record_samples); 211 CpuProfile(const char* title, bool record_samples);
176 212
177 // Add pc -> ... -> main() call path to the profile. 213 // Add pc -> ... -> main() call path to the profile.
178 void AddPath(base::TimeTicks timestamp, const Vector<CodeEntry*>& path); 214 void AddPath(base::TimeTicks timestamp, const Vector<CodeEntry*>& path,
215 int src_line);
179 void CalculateTotalTicksAndSamplingRate(); 216 void CalculateTotalTicksAndSamplingRate();
180 217
181 const char* title() const { return title_; } 218 const char* title() const { return title_; }
182 const ProfileTree* top_down() const { return &top_down_; } 219 const ProfileTree* top_down() const { return &top_down_; }
183 220
184 int samples_count() const { return samples_.length(); } 221 int samples_count() const { return samples_.length(); }
185 ProfileNode* sample(int index) const { return samples_.at(index); } 222 ProfileNode* sample(int index) const { return samples_.at(index); }
186 base::TimeTicks sample_timestamp(int index) const { 223 base::TimeTicks sample_timestamp(int index) const {
187 return timestamps_.at(index); 224 return timestamps_.at(index);
188 } 225 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 const char* GetFunctionName(Name* name) { 307 const char* GetFunctionName(Name* name) {
271 return function_and_resource_names_.GetFunctionName(name); 308 return function_and_resource_names_.GetFunctionName(name);
272 } 309 }
273 const char* GetFunctionName(const char* name) { 310 const char* GetFunctionName(const char* name) {
274 return function_and_resource_names_.GetFunctionName(name); 311 return function_and_resource_names_.GetFunctionName(name);
275 } 312 }
276 bool IsLastProfile(const char* title); 313 bool IsLastProfile(const char* title);
277 void RemoveProfile(CpuProfile* profile); 314 void RemoveProfile(CpuProfile* profile);
278 315
279 CodeEntry* NewCodeEntry( 316 CodeEntry* NewCodeEntry(
280 Logger::LogEventsAndTags tag, 317 Logger::LogEventsAndTags tag, const char* name,
281 const char* name,
282 const char* name_prefix = CodeEntry::kEmptyNamePrefix, 318 const char* name_prefix = CodeEntry::kEmptyNamePrefix,
283 const char* resource_name = CodeEntry::kEmptyResourceName, 319 const char* resource_name = CodeEntry::kEmptyResourceName,
284 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, 320 int line_number = v8::CpuProfileNode::kNoLineNumberInfo,
285 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo); 321 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo,
322 JITLineInfoTable* line_info = NULL, Address instruction_start = NULL);
286 323
287 // Called from profile generator thread. 324 // Called from profile generator thread.
288 void AddPathToCurrentProfiles( 325 void AddPathToCurrentProfiles(base::TimeTicks timestamp,
289 base::TimeTicks timestamp, const Vector<CodeEntry*>& path); 326 const Vector<CodeEntry*>& path, int src_line);
290 327
291 // Limits the number of profiles that can be simultaneously collected. 328 // Limits the number of profiles that can be simultaneously collected.
292 static const int kMaxSimultaneousProfiles = 100; 329 static const int kMaxSimultaneousProfiles = 100;
293 330
294 private: 331 private:
295 StringsStorage function_and_resource_names_; 332 StringsStorage function_and_resource_names_;
296 List<CodeEntry*> code_entries_; 333 List<CodeEntry*> code_entries_;
297 List<CpuProfile*> finished_profiles_; 334 List<CpuProfile*> finished_profiles_;
298 335
299 // Accessed by VM thread and profile generator thread. 336 // Accessed by VM thread and profile generator thread.
(...skipping 29 matching lines...) Expand all
329 CodeEntry* gc_entry_; 366 CodeEntry* gc_entry_;
330 CodeEntry* unresolved_entry_; 367 CodeEntry* unresolved_entry_;
331 368
332 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); 369 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator);
333 }; 370 };
334 371
335 372
336 } } // namespace v8::internal 373 } } // namespace v8::internal
337 374
338 #endif // V8_PROFILE_GENERATOR_H_ 375 #endif // V8_PROFILE_GENERATOR_H_
OLDNEW
« no previous file with comments | « src/full-codegen.cc ('k') | src/profile-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698