| OLD | NEW |
| 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 "string-stream.h" | 9 #include "string-stream.h" |
| 10 #include "cctest.h" | 10 #include "cctest.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 env->Enter(); | 57 env->Enter(); |
| 58 | 58 |
| 59 CompileAndRunScript( | 59 CompileAndRunScript( |
| 60 "function F() {} // A constructor\n" | 60 "function F() {} // A constructor\n" |
| 61 "var f1 = new F();\n" | 61 "var f1 = new F();\n" |
| 62 "var f2 = new F();\n"); | 62 "var f2 = new F();\n"); |
| 63 | 63 |
| 64 ConstructorHeapProfileTestHelper cons_profile; | 64 ConstructorHeapProfileTestHelper cons_profile; |
| 65 i::AssertNoAllocation no_alloc; | 65 i::AssertNoAllocation no_alloc; |
| 66 i::HeapIterator iterator; | 66 i::HeapIterator iterator; |
| 67 while (iterator.has_next()) { | 67 for (i::HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) |
| 68 i::HeapObject* obj = iterator.next(); | |
| 69 cons_profile.CollectStats(obj); | 68 cons_profile.CollectStats(obj); |
| 70 } | |
| 71 CHECK_EQ(0, cons_profile.f_count()); | 69 CHECK_EQ(0, cons_profile.f_count()); |
| 72 cons_profile.PrintStats(); | 70 cons_profile.PrintStats(); |
| 73 CHECK_EQ(2, cons_profile.f_count()); | 71 CHECK_EQ(2, cons_profile.f_count()); |
| 74 } | 72 } |
| 75 | 73 |
| 76 | 74 |
| 77 static JSObjectsCluster AddHeapObjectToTree(JSObjectsRetainerTree* tree, | 75 static JSObjectsCluster AddHeapObjectToTree(JSObjectsRetainerTree* tree, |
| 78 i::String* constructor, | 76 i::String* constructor, |
| 79 int instance, | 77 int instance, |
| 80 JSObjectsCluster* ref1 = NULL, | 78 JSObjectsCluster* ref1 = NULL, |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 "function A() {}\n" | 366 "function A() {}\n" |
| 369 "function B(x) { this.x = x; }\n" | 367 "function B(x) { this.x = x; }\n" |
| 370 "function C(x) { this.x1 = x; this.x2 = x; }\n" | 368 "function C(x) { this.x1 = x; this.x2 = x; }\n" |
| 371 "var a = new A();\n" | 369 "var a = new A();\n" |
| 372 "var b1 = new B(a), b2 = new B(a);\n" | 370 "var b1 = new B(a), b2 = new B(a);\n" |
| 373 "var c = new C(a);"); | 371 "var c = new C(a);"); |
| 374 | 372 |
| 375 RetainerHeapProfile ret_profile; | 373 RetainerHeapProfile ret_profile; |
| 376 i::AssertNoAllocation no_alloc; | 374 i::AssertNoAllocation no_alloc; |
| 377 i::HeapIterator iterator; | 375 i::HeapIterator iterator; |
| 378 while (iterator.has_next()) { | 376 for (i::HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) |
| 379 i::HeapObject* obj = iterator.next(); | |
| 380 ret_profile.CollectStats(obj); | 377 ret_profile.CollectStats(obj); |
| 381 } | |
| 382 RetainerProfilePrinter printer; | 378 RetainerProfilePrinter printer; |
| 383 ret_profile.DebugPrintStats(&printer); | 379 ret_profile.DebugPrintStats(&printer); |
| 384 const char* retainers_of_a = printer.GetRetainers("A"); | 380 const char* retainers_of_a = printer.GetRetainers("A"); |
| 385 // The order of retainers is unspecified, so we check string length, and | 381 // The order of retainers is unspecified, so we check string length, and |
| 386 // verify each retainer separately. | 382 // verify each retainer separately. |
| 387 CHECK_EQ(i::StrLength("(global property);1,B;2,C;2"), | 383 CHECK_EQ(i::StrLength("(global property);1,B;2,C;2"), |
| 388 i::StrLength(retainers_of_a)); | 384 i::StrLength(retainers_of_a)); |
| 389 CHECK(strstr(retainers_of_a, "(global property);1") != NULL); | 385 CHECK(strstr(retainers_of_a, "(global property);1") != NULL); |
| 390 CHECK(strstr(retainers_of_a, "B;2") != NULL); | 386 CHECK(strstr(retainers_of_a, "B;2") != NULL); |
| 391 CHECK(strstr(retainers_of_a, "C;2") != NULL); | 387 CHECK(strstr(retainers_of_a, "C;2") != NULL); |
| 392 CHECK_EQ("(global property);2", printer.GetRetainers("B")); | 388 CHECK_EQ("(global property);2", printer.GetRetainers("B")); |
| 393 CHECK_EQ("(global property);1", printer.GetRetainers("C")); | 389 CHECK_EQ("(global property);1", printer.GetRetainers("C")); |
| 394 } | 390 } |
| 395 | 391 |
| 396 #endif // ENABLE_LOGGING_AND_PROFILING | 392 #endif // ENABLE_LOGGING_AND_PROFILING |
| OLD | NEW |