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

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

Issue 3590029: Better align heap snapshots contents with debugger info. (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 | « src/profile-generator.cc ('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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 "function X(a, b) { this.a = a; this.b = b; }\n" 587 "function X(a, b) { this.a = a; this.b = b; }\n"
588 "x = new X(new X(), new X());\n" 588 "x = new X(new X(), new X());\n"
589 "x.a.a = x.b;"); 589 "x.a.a = x.b;");
590 const v8::HeapSnapshot* snapshot = 590 const v8::HeapSnapshot* snapshot =
591 v8::HeapProfiler::TakeSnapshot(v8::String::New("sizes")); 591 v8::HeapProfiler::TakeSnapshot(v8::String::New("sizes"));
592 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 592 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
593 const v8::HeapGraphNode* x = 593 const v8::HeapGraphNode* x =
594 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); 594 GetProperty(global, v8::HeapGraphEdge::kProperty, "x");
595 CHECK_NE(NULL, x); 595 CHECK_NE(NULL, x);
596 const v8::HeapGraphNode* x_prototype = 596 const v8::HeapGraphNode* x_prototype =
597 GetProperty(x, v8::HeapGraphEdge::kProperty, "prototype"); 597 GetProperty(x, v8::HeapGraphEdge::kProperty, "__proto__");
598 CHECK_NE(NULL, x_prototype); 598 CHECK_NE(NULL, x_prototype);
599 const v8::HeapGraphNode* x1 = 599 const v8::HeapGraphNode* x1 =
600 GetProperty(x, v8::HeapGraphEdge::kProperty, "a"); 600 GetProperty(x, v8::HeapGraphEdge::kProperty, "a");
601 CHECK_NE(NULL, x1); 601 CHECK_NE(NULL, x1);
602 const v8::HeapGraphNode* x2 = 602 const v8::HeapGraphNode* x2 =
603 GetProperty(x, v8::HeapGraphEdge::kProperty, "b"); 603 GetProperty(x, v8::HeapGraphEdge::kProperty, "b");
604 CHECK_NE(NULL, x2); 604 CHECK_NE(NULL, x2);
605 CHECK_EQ( 605 CHECK_EQ(
606 x->GetSelfSize() * 3, 606 x->GetSelfSize() * 3,
607 x->GetReachableSize() - x_prototype->GetReachableSize()); 607 x->GetReachableSize() - x_prototype->GetReachableSize());
608 CHECK_EQ( 608 CHECK_EQ(
609 x->GetSelfSize() * 3 + x_prototype->GetSelfSize(), x->GetRetainedSize()); 609 x->GetSelfSize() * 3, x->GetRetainedSize());
610 CHECK_EQ( 610 CHECK_EQ(
611 x1->GetSelfSize() * 2, 611 x1->GetSelfSize() * 2,
612 x1->GetReachableSize() - x_prototype->GetReachableSize()); 612 x1->GetReachableSize() - x_prototype->GetReachableSize());
613 CHECK_EQ( 613 CHECK_EQ(
614 x1->GetSelfSize(), x1->GetRetainedSize()); 614 x1->GetSelfSize(), x1->GetRetainedSize());
615 CHECK_EQ( 615 CHECK_EQ(
616 x2->GetSelfSize(), 616 x2->GetSelfSize(),
617 x2->GetReachableSize() - x_prototype->GetReachableSize()); 617 x2->GetReachableSize() - x_prototype->GetReachableSize());
618 CHECK_EQ( 618 CHECK_EQ(
619 x2->GetSelfSize(), x2->GetRetainedSize()); 619 x2->GetSelfSize(), x2->GetRetainedSize());
(...skipping 24 matching lines...) Expand all
644 } 644 }
645 645
646 646
647 TEST(HeapSnapshotCodeObjects) { 647 TEST(HeapSnapshotCodeObjects) {
648 v8::HandleScope scope; 648 v8::HandleScope scope;
649 LocalContext env; 649 LocalContext env;
650 650
651 CompileAndRunScript( 651 CompileAndRunScript(
652 "function lazy(x) { return x - 1; }\n" 652 "function lazy(x) { return x - 1; }\n"
653 "function compiled(x) { return x + 1; }\n" 653 "function compiled(x) { return x + 1; }\n"
654 "var inferred = function(x) { return x; }\n"
655 "var anonymous = (function() { return function() { return 0; } })();\n" 654 "var anonymous = (function() { return function() { return 0; } })();\n"
656 "compiled(1)"); 655 "compiled(1)");
657 const v8::HeapSnapshot* snapshot = 656 const v8::HeapSnapshot* snapshot =
658 v8::HeapProfiler::TakeSnapshot(v8::String::New("code")); 657 v8::HeapProfiler::TakeSnapshot(v8::String::New("code"));
659 658
660 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 659 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
661 const v8::HeapGraphNode* compiled = 660 const v8::HeapGraphNode* compiled =
662 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled"); 661 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled");
663 CHECK_NE(NULL, compiled); 662 CHECK_NE(NULL, compiled);
664 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType()); 663 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType());
665 const v8::HeapGraphNode* lazy = 664 const v8::HeapGraphNode* lazy =
666 GetProperty(global, v8::HeapGraphEdge::kProperty, "lazy"); 665 GetProperty(global, v8::HeapGraphEdge::kProperty, "lazy");
667 CHECK_NE(NULL, lazy); 666 CHECK_NE(NULL, lazy);
668 CHECK_EQ(v8::HeapGraphNode::kClosure, lazy->GetType()); 667 CHECK_EQ(v8::HeapGraphNode::kClosure, lazy->GetType());
669 const v8::HeapGraphNode* inferred =
670 GetProperty(global, v8::HeapGraphEdge::kProperty, "inferred");
671 CHECK_NE(NULL, inferred);
672 CHECK_EQ(v8::HeapGraphNode::kClosure, inferred->GetType());
673 v8::String::AsciiValue inferred_name(inferred->GetName());
674 CHECK_EQ("inferred", *inferred_name);
675 const v8::HeapGraphNode* anonymous = 668 const v8::HeapGraphNode* anonymous =
676 GetProperty(global, v8::HeapGraphEdge::kProperty, "anonymous"); 669 GetProperty(global, v8::HeapGraphEdge::kProperty, "anonymous");
677 CHECK_NE(NULL, anonymous); 670 CHECK_NE(NULL, anonymous);
678 CHECK_EQ(v8::HeapGraphNode::kClosure, anonymous->GetType()); 671 CHECK_EQ(v8::HeapGraphNode::kClosure, anonymous->GetType());
679 v8::String::AsciiValue anonymous_name(anonymous->GetName()); 672 v8::String::AsciiValue anonymous_name(anonymous->GetName());
680 CHECK_EQ("(anonymous function)", *anonymous_name); 673 CHECK_EQ("", *anonymous_name);
681 674
682 // Find references to code. 675 // Find references to code.
683 const v8::HeapGraphNode* compiled_code = 676 const v8::HeapGraphNode* compiled_code =
684 GetProperty(compiled, v8::HeapGraphEdge::kInternal, "code"); 677 GetProperty(compiled, v8::HeapGraphEdge::kInternal, "code");
685 CHECK_NE(NULL, compiled_code); 678 CHECK_NE(NULL, compiled_code);
686 const v8::HeapGraphNode* lazy_code = 679 const v8::HeapGraphNode* lazy_code =
687 GetProperty(lazy, v8::HeapGraphEdge::kInternal, "code"); 680 GetProperty(lazy, v8::HeapGraphEdge::kInternal, "code");
688 CHECK_NE(NULL, lazy_code); 681 CHECK_NE(NULL, lazy_code);
689 682
690 // Verify that non-compiled code doesn't contain references to "x" 683 // Verify that non-compiled code doesn't contain references to "x"
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 LocalContext env; 1142 LocalContext env;
1150 const v8::HeapSnapshot* snapshot = 1143 const v8::HeapSnapshot* snapshot =
1151 v8::HeapProfiler::TakeSnapshot(v8::String::New("abort")); 1144 v8::HeapProfiler::TakeSnapshot(v8::String::New("abort"));
1152 TestJSONStream stream(5); 1145 TestJSONStream stream(5);
1153 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); 1146 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON);
1154 CHECK_GT(stream.size(), 0); 1147 CHECK_GT(stream.size(), 0);
1155 CHECK_EQ(0, stream.eos_signaled()); 1148 CHECK_EQ(0, stream.eos_signaled());
1156 } 1149 }
1157 1150
1158 #endif // ENABLE_LOGGING_AND_PROFILING 1151 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « src/profile-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698