OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // | 2 // |
3 // Tests for heap profiler | 3 // Tests for heap profiler |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "cctest.h" | 7 #include "cctest.h" |
8 #include "heap-profiler.h" | 8 #include "heap-profiler.h" |
9 #include "snapshot.h" | 9 #include "snapshot.h" |
10 #include "utils-inl.h" | 10 #include "utils-inl.h" |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 CHECK_EQ(control.total(), control.done()); | 659 CHECK_EQ(control.total(), control.done()); |
660 CHECK_GT(control.total(), 0); | 660 CHECK_GT(control.total(), 0); |
661 } | 661 } |
662 | 662 |
663 | 663 |
664 namespace { | 664 namespace { |
665 | 665 |
666 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { | 666 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
667 public: | 667 public: |
668 TestRetainedObjectInfo(int hash, | 668 TestRetainedObjectInfo(int hash, |
| 669 const char* group_label, |
669 const char* label, | 670 const char* label, |
670 intptr_t element_count = -1, | 671 intptr_t element_count = -1, |
671 intptr_t size = -1) | 672 intptr_t size = -1) |
672 : disposed_(false), | 673 : disposed_(false), |
673 hash_(hash), | 674 hash_(hash), |
| 675 group_label_(group_label), |
674 label_(label), | 676 label_(label), |
675 element_count_(element_count), | 677 element_count_(element_count), |
676 size_(size) { | 678 size_(size) { |
677 instances.Add(this); | 679 instances.Add(this); |
678 } | 680 } |
679 virtual ~TestRetainedObjectInfo() {} | 681 virtual ~TestRetainedObjectInfo() {} |
680 virtual void Dispose() { | 682 virtual void Dispose() { |
681 CHECK(!disposed_); | 683 CHECK(!disposed_); |
682 disposed_ = true; | 684 disposed_ = true; |
683 } | 685 } |
684 virtual bool IsEquivalent(RetainedObjectInfo* other) { | 686 virtual bool IsEquivalent(RetainedObjectInfo* other) { |
685 return GetHash() == other->GetHash(); | 687 return GetHash() == other->GetHash(); |
686 } | 688 } |
687 virtual intptr_t GetHash() { return hash_; } | 689 virtual intptr_t GetHash() { return hash_; } |
| 690 virtual const char* GetGroupLabel() { return group_label_; } |
688 virtual const char* GetLabel() { return label_; } | 691 virtual const char* GetLabel() { return label_; } |
689 virtual intptr_t GetElementCount() { return element_count_; } | 692 virtual intptr_t GetElementCount() { return element_count_; } |
690 virtual intptr_t GetSizeInBytes() { return size_; } | 693 virtual intptr_t GetSizeInBytes() { return size_; } |
691 bool disposed() { return disposed_; } | 694 bool disposed() { return disposed_; } |
692 | 695 |
693 static v8::RetainedObjectInfo* WrapperInfoCallback( | 696 static v8::RetainedObjectInfo* WrapperInfoCallback( |
694 uint16_t class_id, v8::Handle<v8::Value> wrapper) { | 697 uint16_t class_id, v8::Handle<v8::Value> wrapper) { |
695 if (class_id == 1) { | 698 if (class_id == 1) { |
696 if (wrapper->IsString()) { | 699 if (wrapper->IsString()) { |
697 v8::String::AsciiValue ascii(wrapper); | 700 v8::String::AsciiValue ascii(wrapper); |
698 if (strcmp(*ascii, "AAA") == 0) | 701 if (strcmp(*ascii, "AAA") == 0) |
699 return new TestRetainedObjectInfo(1, "aaa", 100); | 702 return new TestRetainedObjectInfo(1, "aaa-group", "aaa", 100); |
700 else if (strcmp(*ascii, "BBB") == 0) | 703 else if (strcmp(*ascii, "BBB") == 0) |
701 return new TestRetainedObjectInfo(1, "aaa", 100); | 704 return new TestRetainedObjectInfo(1, "aaa-group", "aaa", 100); |
702 } | 705 } |
703 } else if (class_id == 2) { | 706 } else if (class_id == 2) { |
704 if (wrapper->IsString()) { | 707 if (wrapper->IsString()) { |
705 v8::String::AsciiValue ascii(wrapper); | 708 v8::String::AsciiValue ascii(wrapper); |
706 if (strcmp(*ascii, "CCC") == 0) | 709 if (strcmp(*ascii, "CCC") == 0) |
707 return new TestRetainedObjectInfo(2, "ccc"); | 710 return new TestRetainedObjectInfo(2, "ccc-group", "ccc"); |
708 } | 711 } |
709 } | 712 } |
710 CHECK(false); | 713 CHECK(false); |
711 return NULL; | 714 return NULL; |
712 } | 715 } |
713 | 716 |
714 static i::List<TestRetainedObjectInfo*> instances; | 717 static i::List<TestRetainedObjectInfo*> instances; |
715 | 718 |
716 private: | 719 private: |
717 bool disposed_; | 720 bool disposed_; |
718 int category_; | 721 int category_; |
719 int hash_; | 722 int hash_; |
| 723 const char* group_label_; |
720 const char* label_; | 724 const char* label_; |
721 intptr_t element_count_; | 725 intptr_t element_count_; |
722 intptr_t size_; | 726 intptr_t size_; |
723 }; | 727 }; |
724 | 728 |
725 | 729 |
726 i::List<TestRetainedObjectInfo*> TestRetainedObjectInfo::instances; | 730 i::List<TestRetainedObjectInfo*> TestRetainedObjectInfo::instances; |
727 } | 731 } |
728 | 732 |
729 | 733 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 CHECK_EQ(0, TestRetainedObjectInfo::instances.length()); | 766 CHECK_EQ(0, TestRetainedObjectInfo::instances.length()); |
763 const v8::HeapSnapshot* snapshot = | 767 const v8::HeapSnapshot* snapshot = |
764 v8::HeapProfiler::TakeSnapshot(v8_str("retained")); | 768 v8::HeapProfiler::TakeSnapshot(v8_str("retained")); |
765 | 769 |
766 CHECK_EQ(3, TestRetainedObjectInfo::instances.length()); | 770 CHECK_EQ(3, TestRetainedObjectInfo::instances.length()); |
767 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) { | 771 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) { |
768 CHECK(TestRetainedObjectInfo::instances[i]->disposed()); | 772 CHECK(TestRetainedObjectInfo::instances[i]->disposed()); |
769 delete TestRetainedObjectInfo::instances[i]; | 773 delete TestRetainedObjectInfo::instances[i]; |
770 } | 774 } |
771 | 775 |
772 const v8::HeapGraphNode* natives = GetNode( | 776 const v8::HeapGraphNode* native_group_aaa = GetNode( |
773 snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(Native objects)"); | 777 snapshot->GetRoot(), v8::HeapGraphNode::kNative, "aaa-group"); |
774 CHECK_NE(NULL, natives); | 778 CHECK_NE(NULL, native_group_aaa); |
775 CHECK_EQ(2, natives->GetChildrenCount()); | 779 CHECK_EQ(1, native_group_aaa->GetChildrenCount()); |
776 const v8::HeapGraphNode* aaa = GetNode( | 780 const v8::HeapGraphNode* aaa = GetNode( |
777 natives, v8::HeapGraphNode::kNative, "aaa / 100 entries"); | 781 native_group_aaa, v8::HeapGraphNode::kNative, "aaa / 100 entries"); |
778 CHECK_NE(NULL, aaa); | 782 CHECK_NE(NULL, aaa); |
| 783 CHECK_EQ(2, aaa->GetChildrenCount()); |
| 784 |
| 785 const v8::HeapGraphNode* native_group_ccc = GetNode( |
| 786 snapshot->GetRoot(), v8::HeapGraphNode::kNative, "ccc-group"); |
779 const v8::HeapGraphNode* ccc = GetNode( | 787 const v8::HeapGraphNode* ccc = GetNode( |
780 natives, v8::HeapGraphNode::kNative, "ccc"); | 788 native_group_ccc, v8::HeapGraphNode::kNative, "ccc"); |
781 CHECK_NE(NULL, ccc); | 789 CHECK_NE(NULL, ccc); |
782 | 790 |
783 CHECK_EQ(2, aaa->GetChildrenCount()); | |
784 const v8::HeapGraphNode* n_AAA = GetNode( | 791 const v8::HeapGraphNode* n_AAA = GetNode( |
785 aaa, v8::HeapGraphNode::kString, "AAA"); | 792 aaa, v8::HeapGraphNode::kString, "AAA"); |
786 CHECK_NE(NULL, n_AAA); | 793 CHECK_NE(NULL, n_AAA); |
787 const v8::HeapGraphNode* n_BBB = GetNode( | 794 const v8::HeapGraphNode* n_BBB = GetNode( |
788 aaa, v8::HeapGraphNode::kString, "BBB"); | 795 aaa, v8::HeapGraphNode::kString, "BBB"); |
789 CHECK_NE(NULL, n_BBB); | 796 CHECK_NE(NULL, n_BBB); |
790 CHECK_EQ(1, ccc->GetChildrenCount()); | 797 CHECK_EQ(1, ccc->GetChildrenCount()); |
791 const v8::HeapGraphNode* n_CCC = GetNode( | 798 const v8::HeapGraphNode* n_CCC = GetNode( |
792 ccc, v8::HeapGraphNode::kString, "CCC"); | 799 ccc, v8::HeapGraphNode::kString, "CCC"); |
793 CHECK_NE(NULL, n_CCC); | 800 CHECK_NE(NULL, n_CCC); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); | 1155 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); |
1149 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1156 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1150 CHECK_NE(NULL, global); | 1157 CHECK_NE(NULL, global); |
1151 const v8::HeapGraphNode* fun = | 1158 const v8::HeapGraphNode* fun = |
1152 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun"); | 1159 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun"); |
1153 CHECK(HasWeakEdge(fun)); | 1160 CHECK(HasWeakEdge(fun)); |
1154 const v8::HeapGraphNode* shared = | 1161 const v8::HeapGraphNode* shared = |
1155 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); | 1162 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); |
1156 CHECK(HasWeakEdge(shared)); | 1163 CHECK(HasWeakEdge(shared)); |
1157 } | 1164 } |
OLD | NEW |