| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if (script_id_ != v8::UnboundScript::kNoScriptId) { | 86 if (script_id_ != v8::UnboundScript::kNoScriptId) { |
| 87 return script_id_ == entry->script_id_ && position_ == entry->position_; | 87 return script_id_ == entry->script_id_ && position_ == entry->position_; |
| 88 } | 88 } |
| 89 return name_prefix_ == entry->name_prefix_ && name_ == entry->name_ && | 89 return name_prefix_ == entry->name_prefix_ && name_ == entry->name_ && |
| 90 resource_name_ == entry->resource_name_ && | 90 resource_name_ == entry->resource_name_ && |
| 91 line_number_ == entry->line_number_; | 91 line_number_ == entry->line_number_; |
| 92 } | 92 } |
| 93 | 93 |
| 94 | 94 |
| 95 void CodeEntry::SetBuiltinId(Builtins::Name id) { | 95 void CodeEntry::SetBuiltinId(Builtins::Name id) { |
| 96 bit_field_ = TagField::update(bit_field_, Logger::BUILTIN_TAG); | 96 bit_field_ = TagField::update(bit_field_, CodeEventListener::BUILTIN_TAG); |
| 97 bit_field_ = BuiltinIdField::update(bit_field_, id); | 97 bit_field_ = BuiltinIdField::update(bit_field_, id); |
| 98 } | 98 } |
| 99 | 99 |
| 100 | 100 |
| 101 int CodeEntry::GetSourceLine(int pc_offset) const { | 101 int CodeEntry::GetSourceLine(int pc_offset) const { |
| 102 if (line_info_ && !line_info_->empty()) { | 102 if (line_info_ && !line_info_->empty()) { |
| 103 return line_info_->GetSourceLineNumber(pc_offset); | 103 return line_info_->GetSourceLineNumber(pc_offset); |
| 104 } | 104 } |
| 105 return v8::CpuProfileNode::kNoLineNumberInfo; | 105 return v8::CpuProfileNode::kNoLineNumberInfo; |
| 106 } | 106 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 public: | 261 public: |
| 262 void BeforeTraversingChild(ProfileNode*, ProfileNode*) { } | 262 void BeforeTraversingChild(ProfileNode*, ProfileNode*) { } |
| 263 | 263 |
| 264 void AfterAllChildrenTraversed(ProfileNode* node) { | 264 void AfterAllChildrenTraversed(ProfileNode* node) { |
| 265 delete node; | 265 delete node; |
| 266 } | 266 } |
| 267 | 267 |
| 268 void AfterChildTraversed(ProfileNode*, ProfileNode*) { } | 268 void AfterChildTraversed(ProfileNode*, ProfileNode*) { } |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 | |
| 272 ProfileTree::ProfileTree(Isolate* isolate) | 271 ProfileTree::ProfileTree(Isolate* isolate) |
| 273 : root_entry_(Logger::FUNCTION_TAG, "(root)"), | 272 : root_entry_(CodeEventListener::FUNCTION_TAG, "(root)"), |
| 274 next_node_id_(1), | 273 next_node_id_(1), |
| 275 root_(new ProfileNode(this, &root_entry_)), | 274 root_(new ProfileNode(this, &root_entry_)), |
| 276 isolate_(isolate), | 275 isolate_(isolate), |
| 277 next_function_id_(1), | 276 next_function_id_(1), |
| 278 function_ids_(ProfileNode::CodeEntriesMatch) {} | 277 function_ids_(ProfileNode::CodeEntriesMatch) {} |
| 279 | 278 |
| 280 | |
| 281 ProfileTree::~ProfileTree() { | 279 ProfileTree::~ProfileTree() { |
| 282 DeleteNodesCallback cb; | 280 DeleteNodesCallback cb; |
| 283 TraverseDepthFirst(&cb); | 281 TraverseDepthFirst(&cb); |
| 284 } | 282 } |
| 285 | 283 |
| 286 | 284 |
| 287 unsigned ProfileTree::GetFunctionId(const ProfileNode* node) { | 285 unsigned ProfileTree::GetFunctionId(const ProfileNode* node) { |
| 288 CodeEntry* code_entry = node->entry(); | 286 CodeEntry* code_entry = node->entry(); |
| 289 base::HashMap::Entry* entry = | 287 base::HashMap::Entry* entry = |
| 290 function_ids_.LookupOrInsert(code_entry, code_entry->GetHash()); | 288 function_ids_.LookupOrInsert(code_entry, code_entry->GetHash()); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 // As starting / stopping profiles is rare relatively to this | 519 // As starting / stopping profiles is rare relatively to this |
| 522 // method, we don't bother minimizing the duration of lock holding, | 520 // method, we don't bother minimizing the duration of lock holding, |
| 523 // e.g. copying contents of the list to a local vector. | 521 // e.g. copying contents of the list to a local vector. |
| 524 current_profiles_semaphore_.Wait(); | 522 current_profiles_semaphore_.Wait(); |
| 525 for (int i = 0; i < current_profiles_.length(); ++i) { | 523 for (int i = 0; i < current_profiles_.length(); ++i) { |
| 526 current_profiles_[i]->AddPath(timestamp, path, src_line, update_stats); | 524 current_profiles_[i]->AddPath(timestamp, path, src_line, update_stats); |
| 527 } | 525 } |
| 528 current_profiles_semaphore_.Signal(); | 526 current_profiles_semaphore_.Signal(); |
| 529 } | 527 } |
| 530 | 528 |
| 531 | |
| 532 CodeEntry* CpuProfilesCollection::NewCodeEntry( | 529 CodeEntry* CpuProfilesCollection::NewCodeEntry( |
| 533 Logger::LogEventsAndTags tag, const char* name, const char* name_prefix, | 530 CodeEventListener::LogEventsAndTags tag, const char* name, |
| 534 const char* resource_name, int line_number, int column_number, | 531 const char* name_prefix, const char* resource_name, int line_number, |
| 535 JITLineInfoTable* line_info, Address instruction_start) { | 532 int column_number, JITLineInfoTable* line_info, Address instruction_start) { |
| 536 CodeEntry* code_entry = | 533 CodeEntry* code_entry = |
| 537 new CodeEntry(tag, name, name_prefix, resource_name, line_number, | 534 new CodeEntry(tag, name, name_prefix, resource_name, line_number, |
| 538 column_number, line_info, instruction_start); | 535 column_number, line_info, instruction_start); |
| 539 code_entries_.Add(code_entry); | 536 code_entries_.Add(code_entry); |
| 540 return code_entry; | 537 return code_entry; |
| 541 } | 538 } |
| 542 | 539 |
| 543 | 540 |
| 544 const char* const ProfileGenerator::kProgramEntryName = | 541 const char* const ProfileGenerator::kProgramEntryName = |
| 545 "(program)"; | 542 "(program)"; |
| 546 const char* const ProfileGenerator::kIdleEntryName = | 543 const char* const ProfileGenerator::kIdleEntryName = |
| 547 "(idle)"; | 544 "(idle)"; |
| 548 const char* const ProfileGenerator::kGarbageCollectorEntryName = | 545 const char* const ProfileGenerator::kGarbageCollectorEntryName = |
| 549 "(garbage collector)"; | 546 "(garbage collector)"; |
| 550 const char* const ProfileGenerator::kUnresolvedFunctionName = | 547 const char* const ProfileGenerator::kUnresolvedFunctionName = |
| 551 "(unresolved function)"; | 548 "(unresolved function)"; |
| 552 | 549 |
| 553 | |
| 554 ProfileGenerator::ProfileGenerator(CpuProfilesCollection* profiles) | 550 ProfileGenerator::ProfileGenerator(CpuProfilesCollection* profiles) |
| 555 : profiles_(profiles), | 551 : profiles_(profiles), |
| 556 program_entry_( | 552 program_entry_(profiles->NewCodeEntry(CodeEventListener::FUNCTION_TAG, |
| 557 profiles->NewCodeEntry(Logger::FUNCTION_TAG, kProgramEntryName)), | 553 kProgramEntryName)), |
| 558 idle_entry_( | 554 idle_entry_(profiles->NewCodeEntry(CodeEventListener::FUNCTION_TAG, |
| 559 profiles->NewCodeEntry(Logger::FUNCTION_TAG, kIdleEntryName)), | 555 kIdleEntryName)), |
| 560 gc_entry_( | 556 gc_entry_(profiles->NewCodeEntry(CodeEventListener::BUILTIN_TAG, |
| 561 profiles->NewCodeEntry(Logger::BUILTIN_TAG, | 557 kGarbageCollectorEntryName)), |
| 562 kGarbageCollectorEntryName)), | 558 unresolved_entry_(profiles->NewCodeEntry(CodeEventListener::FUNCTION_TAG, |
| 563 unresolved_entry_( | 559 kUnresolvedFunctionName)) {} |
| 564 profiles->NewCodeEntry(Logger::FUNCTION_TAG, | |
| 565 kUnresolvedFunctionName)) { | |
| 566 } | |
| 567 | |
| 568 | 560 |
| 569 void ProfileGenerator::RecordTickSample(const TickSample& sample) { | 561 void ProfileGenerator::RecordTickSample(const TickSample& sample) { |
| 570 std::vector<CodeEntry*> entries; | 562 std::vector<CodeEntry*> entries; |
| 571 // Conservatively reserve space for stack frames + pc + function + vm-state. | 563 // Conservatively reserve space for stack frames + pc + function + vm-state. |
| 572 // There could in fact be more of them because of inlined entries. | 564 // There could in fact be more of them because of inlined entries. |
| 573 entries.reserve(sample.frames_count + 3); | 565 entries.reserve(sample.frames_count + 3); |
| 574 | 566 |
| 575 // The ProfileNode knows nothing about all versions of generated code for | 567 // The ProfileNode knows nothing about all versions of generated code for |
| 576 // the same JS function. The line number information associated with | 568 // the same JS function. The line number information associated with |
| 577 // the latest version of generated code is used to find a source line number | 569 // the latest version of generated code is used to find a source line number |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 case EXTERNAL: | 676 case EXTERNAL: |
| 685 return program_entry_; | 677 return program_entry_; |
| 686 case IDLE: | 678 case IDLE: |
| 687 return idle_entry_; | 679 return idle_entry_; |
| 688 default: return NULL; | 680 default: return NULL; |
| 689 } | 681 } |
| 690 } | 682 } |
| 691 | 683 |
| 692 } // namespace internal | 684 } // namespace internal |
| 693 } // namespace v8 | 685 } // namespace v8 |
| OLD | NEW |