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

Side by Side Diff: test/cctest/test-heap-profiler.cc

Issue 3531005: Fix HeapSnapshotsDiff test, diff implementation, and a bug introduced (Closed)
Patch Set: Created 10 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
« no previous file with comments | « test/cctest/cctest.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // 2 //
3 // Tests for heap profiler 3 // Tests for heap profiler
4 4
5 #ifdef ENABLE_LOGGING_AND_PROFILING 5 #ifdef ENABLE_LOGGING_AND_PROFILING
6 6
7 #include "v8.h" 7 #include "v8.h"
8 #include "heap-profiler.h" 8 #include "heap-profiler.h"
9 #include "snapshot.h" 9 #include "snapshot.h"
10 #include "string-stream.h" 10 #include "string-stream.h"
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 } 780 }
781 781
782 782
783 TEST(HeapSnapshotsDiff) { 783 TEST(HeapSnapshotsDiff) {
784 v8::HandleScope scope; 784 v8::HandleScope scope;
785 LocalContext env; 785 LocalContext env;
786 786
787 CompileAndRunScript( 787 CompileAndRunScript(
788 "function A() {}\n" 788 "function A() {}\n"
789 "function B(x) { this.x = x; }\n" 789 "function B(x) { this.x = x; }\n"
790 "function A2(a) { for (var i = 0; i < a; ++i) this[i] = i; }\n"
790 "var a = new A();\n" 791 "var a = new A();\n"
791 "var b = new B(a);"); 792 "var b = new B(a);");
792 const v8::HeapSnapshot* snapshot1 = 793 const v8::HeapSnapshot* snapshot1 =
793 v8::HeapProfiler::TakeSnapshot(v8::String::New("s1")); 794 v8::HeapProfiler::TakeSnapshot(v8::String::New("s1"));
794 795
795 CompileAndRunScript( 796 CompileAndRunScript(
796 "delete a;\n" 797 "delete a;\n"
797 "b.x = null;\n" 798 "b.x = null;\n"
798 "var a = new A();\n" 799 "var a = new A2(20);\n"
799 "var b2 = new B(a);"); 800 "var b2 = new B(a);");
800 const v8::HeapSnapshot* snapshot2 = 801 const v8::HeapSnapshot* snapshot2 =
801 v8::HeapProfiler::TakeSnapshot(v8::String::New("s2")); 802 v8::HeapProfiler::TakeSnapshot(v8::String::New("s2"));
802 803
803 const v8::HeapSnapshotsDiff* diff = snapshot1->CompareWith(snapshot2); 804 const v8::HeapSnapshotsDiff* diff = snapshot1->CompareWith(snapshot2);
804 805
805 // Verify additions: ensure that addition of A and B was detected. 806 // Verify additions: ensure that addition of A and B was detected.
806 const v8::HeapGraphNode* additions_root = diff->GetAdditionsRoot(); 807 const v8::HeapGraphNode* additions_root = diff->GetAdditionsRoot();
807 bool found_A = false, found_B = false; 808 bool found_A = false, found_B = false;
808 uint64_t s1_A_id = 0; 809 uint64_t s1_A_id = 0;
809 for (int i = 0, count = additions_root->GetChildrenCount(); i < count; ++i) { 810 for (int i = 0, count = additions_root->GetChildrenCount(); i < count; ++i) {
810 const v8::HeapGraphEdge* prop = additions_root->GetChild(i); 811 const v8::HeapGraphEdge* prop = additions_root->GetChild(i);
811 const v8::HeapGraphNode* node = prop->GetToNode(); 812 const v8::HeapGraphNode* node = prop->GetToNode();
812 if (node->GetType() == v8::HeapGraphNode::kObject) { 813 if (node->GetType() == v8::HeapGraphNode::kObject) {
813 v8::String::AsciiValue node_name(node->GetName()); 814 v8::String::AsciiValue node_name(node->GetName());
814 if (strcmp(*node_name, "A") == 0) { 815 if (strcmp(*node_name, "A2") == 0) {
815 CHECK(IsNodeRetainedAs(node, v8::HeapGraphEdge::kProperty, "a")); 816 CHECK(IsNodeRetainedAs(node, v8::HeapGraphEdge::kProperty, "a"));
816 CHECK(!found_A); 817 CHECK(!found_A);
817 found_A = true; 818 found_A = true;
818 s1_A_id = node->GetId(); 819 s1_A_id = node->GetId();
819 } else if (strcmp(*node_name, "B") == 0) { 820 } else if (strcmp(*node_name, "B") == 0) {
820 CHECK(IsNodeRetainedAs(node, v8::HeapGraphEdge::kProperty, "b2")); 821 CHECK(IsNodeRetainedAs(node, v8::HeapGraphEdge::kProperty, "b2"));
821 CHECK(!found_B); 822 CHECK(!found_B);
822 found_B = true; 823 found_B = true;
823 } 824 }
824 } 825 }
(...skipping 17 matching lines...) Expand all
842 s2_A_id = node->GetId(); 843 s2_A_id = node->GetId();
843 } 844 }
844 } 845 }
845 } 846 }
846 CHECK(found_A_del); 847 CHECK(found_A_del);
847 CHECK_NE_UINT64_T(0, s1_A_id); 848 CHECK_NE_UINT64_T(0, s1_A_id);
848 CHECK(s1_A_id != s2_A_id); 849 CHECK(s1_A_id != s2_A_id);
849 } 850 }
850 851
851 852
853 TEST(HeapSnapshotRootPreservedAfterSorting) {
854 v8::HandleScope scope;
855 LocalContext env;
856 const v8::HeapSnapshot* snapshot =
857 v8::HeapProfiler::TakeSnapshot(v8::String::New("s"));
858 const v8::HeapGraphNode* root1 = snapshot->GetRoot();
859 const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>(
860 snapshot))->GetSortedEntriesList();
861 const v8::HeapGraphNode* root2 = snapshot->GetRoot();
862 CHECK_EQ(root1, root2);
863 }
864
865
852 namespace v8 { 866 namespace v8 {
853 namespace internal { 867 namespace internal {
854 868
855 class HeapSnapshotTester { 869 class HeapSnapshotTester {
856 public: 870 public:
857 static int CalculateNetworkSize(JSObject* obj) { 871 static int CalculateNetworkSize(JSObject* obj) {
858 return HeapSnapshot::CalculateNetworkSize(obj); 872 return HeapSnapshot::CalculateNetworkSize(obj);
859 } 873 }
860 }; 874 };
861 875
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 LocalContext env; 1149 LocalContext env;
1136 const v8::HeapSnapshot* snapshot = 1150 const v8::HeapSnapshot* snapshot =
1137 v8::HeapProfiler::TakeSnapshot(v8::String::New("abort")); 1151 v8::HeapProfiler::TakeSnapshot(v8::String::New("abort"));
1138 TestJSONStream stream(5); 1152 TestJSONStream stream(5);
1139 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); 1153 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON);
1140 CHECK_GT(stream.size(), 0); 1154 CHECK_GT(stream.size(), 0);
1141 CHECK_EQ(0, stream.eos_signaled()); 1155 CHECK_EQ(0, stream.eos_signaled());
1142 } 1156 }
1143 1157
1144 #endif // ENABLE_LOGGING_AND_PROFILING 1158 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698