OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #include "src/profiler/profile-generator.h" | 5 #include "src/profiler/profile-generator.h" |
6 | 6 |
7 #include "src/ast/scopeinfo.h" | 7 #include "src/ast/scopeinfo.h" |
8 #include "src/base/adapters.h" | 8 #include "src/base/adapters.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 163 } |
164 | 164 |
165 | 165 |
166 void ProfileNode::CollectDeoptInfo(CodeEntry* entry) { | 166 void ProfileNode::CollectDeoptInfo(CodeEntry* entry) { |
167 deopt_infos_.push_back(entry->GetDeoptInfo()); | 167 deopt_infos_.push_back(entry->GetDeoptInfo()); |
168 entry->clear_deopt_info(); | 168 entry->clear_deopt_info(); |
169 } | 169 } |
170 | 170 |
171 | 171 |
172 ProfileNode* ProfileNode::FindChild(CodeEntry* entry) { | 172 ProfileNode* ProfileNode::FindChild(CodeEntry* entry) { |
173 HashMap::Entry* map_entry = children_.Lookup(entry, CodeEntryHash(entry)); | 173 base::HashMap::Entry* map_entry = |
| 174 children_.Lookup(entry, CodeEntryHash(entry)); |
174 return map_entry != NULL ? | 175 return map_entry != NULL ? |
175 reinterpret_cast<ProfileNode*>(map_entry->value) : NULL; | 176 reinterpret_cast<ProfileNode*>(map_entry->value) : NULL; |
176 } | 177 } |
177 | 178 |
178 | 179 |
179 ProfileNode* ProfileNode::FindOrAddChild(CodeEntry* entry) { | 180 ProfileNode* ProfileNode::FindOrAddChild(CodeEntry* entry) { |
180 HashMap::Entry* map_entry = | 181 base::HashMap::Entry* map_entry = |
181 children_.LookupOrInsert(entry, CodeEntryHash(entry)); | 182 children_.LookupOrInsert(entry, CodeEntryHash(entry)); |
182 ProfileNode* node = reinterpret_cast<ProfileNode*>(map_entry->value); | 183 ProfileNode* node = reinterpret_cast<ProfileNode*>(map_entry->value); |
183 if (node == NULL) { | 184 if (node == NULL) { |
184 // New node added. | 185 // New node added. |
185 node = new ProfileNode(tree_, entry); | 186 node = new ProfileNode(tree_, entry); |
186 map_entry->value = node; | 187 map_entry->value = node; |
187 children_list_.Add(node); | 188 children_list_.Add(node); |
188 } | 189 } |
189 return node; | 190 return node; |
190 } | 191 } |
191 | 192 |
192 | 193 |
193 void ProfileNode::IncrementLineTicks(int src_line) { | 194 void ProfileNode::IncrementLineTicks(int src_line) { |
194 if (src_line == v8::CpuProfileNode::kNoLineNumberInfo) return; | 195 if (src_line == v8::CpuProfileNode::kNoLineNumberInfo) return; |
195 // Increment a hit counter of a certain source line. | 196 // Increment a hit counter of a certain source line. |
196 // Add a new source line if not found. | 197 // Add a new source line if not found. |
197 HashMap::Entry* e = | 198 base::HashMap::Entry* e = |
198 line_ticks_.LookupOrInsert(reinterpret_cast<void*>(src_line), src_line); | 199 line_ticks_.LookupOrInsert(reinterpret_cast<void*>(src_line), src_line); |
199 DCHECK(e); | 200 DCHECK(e); |
200 e->value = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(e->value) + 1); | 201 e->value = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(e->value) + 1); |
201 } | 202 } |
202 | 203 |
203 | 204 |
204 bool ProfileNode::GetLineTicks(v8::CpuProfileNode::LineTick* entries, | 205 bool ProfileNode::GetLineTicks(v8::CpuProfileNode::LineTick* entries, |
205 unsigned int length) const { | 206 unsigned int length) const { |
206 if (entries == NULL || length == 0) return false; | 207 if (entries == NULL || length == 0) return false; |
207 | 208 |
208 unsigned line_count = line_ticks_.occupancy(); | 209 unsigned line_count = line_ticks_.occupancy(); |
209 | 210 |
210 if (line_count == 0) return true; | 211 if (line_count == 0) return true; |
211 if (length < line_count) return false; | 212 if (length < line_count) return false; |
212 | 213 |
213 v8::CpuProfileNode::LineTick* entry = entries; | 214 v8::CpuProfileNode::LineTick* entry = entries; |
214 | 215 |
215 for (HashMap::Entry* p = line_ticks_.Start(); p != NULL; | 216 for (base::HashMap::Entry *p = line_ticks_.Start(); p != NULL; |
216 p = line_ticks_.Next(p), entry++) { | 217 p = line_ticks_.Next(p), entry++) { |
217 entry->line = | 218 entry->line = |
218 static_cast<unsigned int>(reinterpret_cast<uintptr_t>(p->key)); | 219 static_cast<unsigned int>(reinterpret_cast<uintptr_t>(p->key)); |
219 entry->hit_count = | 220 entry->hit_count = |
220 static_cast<unsigned int>(reinterpret_cast<uintptr_t>(p->value)); | 221 static_cast<unsigned int>(reinterpret_cast<uintptr_t>(p->value)); |
221 } | 222 } |
222 | 223 |
223 return true; | 224 return true; |
224 } | 225 } |
225 | 226 |
(...skipping 17 matching lines...) Expand all Loading... |
243 indent + 10, "", info.stack[index].script_id, | 244 indent + 10, "", info.stack[index].script_id, |
244 info.stack[index].position); | 245 info.stack[index].position); |
245 } | 246 } |
246 } | 247 } |
247 const char* bailout_reason = entry_->bailout_reason(); | 248 const char* bailout_reason = entry_->bailout_reason(); |
248 if (bailout_reason != GetBailoutReason(BailoutReason::kNoReason) && | 249 if (bailout_reason != GetBailoutReason(BailoutReason::kNoReason) && |
249 bailout_reason != CodeEntry::kEmptyBailoutReason) { | 250 bailout_reason != CodeEntry::kEmptyBailoutReason) { |
250 base::OS::Print("%*s bailed out due to '%s'\n", indent + 10, "", | 251 base::OS::Print("%*s bailed out due to '%s'\n", indent + 10, "", |
251 bailout_reason); | 252 bailout_reason); |
252 } | 253 } |
253 for (HashMap::Entry* p = children_.Start(); | 254 for (base::HashMap::Entry* p = children_.Start(); p != NULL; |
254 p != NULL; | |
255 p = children_.Next(p)) { | 255 p = children_.Next(p)) { |
256 reinterpret_cast<ProfileNode*>(p->value)->Print(indent + 2); | 256 reinterpret_cast<ProfileNode*>(p->value)->Print(indent + 2); |
257 } | 257 } |
258 } | 258 } |
259 | 259 |
260 | 260 |
261 class DeleteNodesCallback { | 261 class DeleteNodesCallback { |
262 public: | 262 public: |
263 void BeforeTraversingChild(ProfileNode*, ProfileNode*) { } | 263 void BeforeTraversingChild(ProfileNode*, ProfileNode*) { } |
264 | 264 |
(...skipping 15 matching lines...) Expand all Loading... |
280 | 280 |
281 | 281 |
282 ProfileTree::~ProfileTree() { | 282 ProfileTree::~ProfileTree() { |
283 DeleteNodesCallback cb; | 283 DeleteNodesCallback cb; |
284 TraverseDepthFirst(&cb); | 284 TraverseDepthFirst(&cb); |
285 } | 285 } |
286 | 286 |
287 | 287 |
288 unsigned ProfileTree::GetFunctionId(const ProfileNode* node) { | 288 unsigned ProfileTree::GetFunctionId(const ProfileNode* node) { |
289 CodeEntry* code_entry = node->entry(); | 289 CodeEntry* code_entry = node->entry(); |
290 HashMap::Entry* entry = | 290 base::HashMap::Entry* entry = |
291 function_ids_.LookupOrInsert(code_entry, code_entry->GetHash()); | 291 function_ids_.LookupOrInsert(code_entry, code_entry->GetHash()); |
292 if (!entry->value) { | 292 if (!entry->value) { |
293 entry->value = reinterpret_cast<void*>(next_function_id_++); | 293 entry->value = reinterpret_cast<void*>(next_function_id_++); |
294 } | 294 } |
295 return static_cast<unsigned>(reinterpret_cast<uintptr_t>(entry->value)); | 295 return static_cast<unsigned>(reinterpret_cast<uintptr_t>(entry->value)); |
296 } | 296 } |
297 | 297 |
298 ProfileNode* ProfileTree::AddPathFromEnd(const std::vector<CodeEntry*>& path, | 298 ProfileNode* ProfileTree::AddPathFromEnd(const std::vector<CodeEntry*>& path, |
299 int src_line, bool update_stats) { | 299 int src_line, bool update_stats) { |
300 ProfileNode* node = root_; | 300 ProfileNode* node = root_; |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 case EXTERNAL: | 715 case EXTERNAL: |
716 return program_entry_; | 716 return program_entry_; |
717 case IDLE: | 717 case IDLE: |
718 return idle_entry_; | 718 return idle_entry_; |
719 default: return NULL; | 719 default: return NULL; |
720 } | 720 } |
721 } | 721 } |
722 | 722 |
723 } // namespace internal | 723 } // namespace internal |
724 } // namespace v8 | 724 } // namespace v8 |
OLD | NEW |