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

Side by Side Diff: runtime/vm/heap_test.cc

Issue 173013004: Add accumulator to allocation profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/class_table.cc ('k') | runtime/vm/json_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/dart_api_impl.h" 6 #include "vm/dart_api_impl.h"
7 #include "vm/globals.h" 7 #include "vm/globals.h"
8 #include "vm/heap.h" 8 #include "vm/heap.h"
9 #include "vm/unit_test.h" 9 #include "vm/unit_test.h"
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 class ClassHeapStatsTestHelper { 51 class ClassHeapStatsTestHelper {
52 public: 52 public:
53 static ClassHeapStats* GetHeapStatsForCid(ClassTable* class_table, 53 static ClassHeapStats* GetHeapStatsForCid(ClassTable* class_table,
54 intptr_t cid) { 54 intptr_t cid) {
55 return class_table->StatsAt(cid); 55 return class_table->StatsAt(cid);
56 } 56 }
57 57
58 static void DumpClassHeapStats(ClassHeapStats* stats) { 58 static void DumpClassHeapStats(ClassHeapStats* stats) {
59 printf("%" Pd " ", stats->allocated_since_gc_new_space); 59 printf("%" Pd " ", stats->recent.new_count);
60 printf("%" Pd " ", stats->live_after_gc_new_space); 60 printf("%" Pd " ", stats->post_gc.new_count);
61 printf("%" Pd " ", stats->allocated_before_gc_new_space); 61 printf("%" Pd " ", stats->pre_gc.new_count);
62 printf("\n"); 62 printf("\n");
63 } 63 }
64 }; 64 };
65 65
66 66
67 static RawClass* GetClass(const Library& lib, const char* name) { 67 static RawClass* GetClass(const Library& lib, const char* name) {
68 const Class& cls = Class::Handle( 68 const Class& cls = Class::Handle(
69 lib.LookupClass(String::Handle(Symbols::New(name)))); 69 lib.LookupClass(String::Handle(Symbols::New(name))));
70 EXPECT(!cls.IsNull()); // No ambiguity error expected. 70 EXPECT(!cls.IsNull()); // No ambiguity error expected.
71 return cls.raw(); 71 return cls.raw();
(...skipping 22 matching lines...) Expand all
94 Library& lib = Library::Handle(); 94 Library& lib = Library::Handle();
95 lib ^= Api::UnwrapHandle(h_lib); 95 lib ^= Api::UnwrapHandle(h_lib);
96 EXPECT(!lib.IsNull()); 96 EXPECT(!lib.IsNull());
97 const Class& cls = Class::Handle(GetClass(lib, "A")); 97 const Class& cls = Class::Handle(GetClass(lib, "A"));
98 ASSERT(!cls.IsNull()); 98 ASSERT(!cls.IsNull());
99 intptr_t cid = cls.id(); 99 intptr_t cid = cls.id();
100 ClassHeapStats* class_stats = 100 ClassHeapStats* class_stats =
101 ClassHeapStatsTestHelper::GetHeapStatsForCid(class_table, 101 ClassHeapStatsTestHelper::GetHeapStatsForCid(class_table,
102 cid); 102 cid);
103 // Verify preconditions: 103 // Verify preconditions:
104 EXPECT_EQ(0, class_stats->allocated_before_gc_old_space); 104 EXPECT_EQ(0, class_stats->pre_gc.old_count);
105 EXPECT_EQ(0, class_stats->live_after_gc_old_space); 105 EXPECT_EQ(0, class_stats->post_gc.old_count);
106 EXPECT_EQ(0, class_stats->allocated_since_gc_old_space); 106 EXPECT_EQ(0, class_stats->recent.old_count);
107 EXPECT_EQ(0, class_stats->allocated_before_gc_new_space); 107 EXPECT_EQ(0, class_stats->pre_gc.new_count);
108 EXPECT_EQ(0, class_stats->live_after_gc_new_space); 108 EXPECT_EQ(0, class_stats->post_gc.new_count);
109 // Class allocated twice since GC from new space. 109 // Class allocated twice since GC from new space.
110 EXPECT_EQ(2, class_stats->allocated_since_gc_new_space); 110 EXPECT_EQ(2, class_stats->recent.new_count);
111 // Perform GC. 111 // Perform GC.
112 heap->CollectGarbage(Heap::kNew); 112 heap->CollectGarbage(Heap::kNew);
113 // Verify postconditions: 113 // Verify postconditions:
114 EXPECT_EQ(0, class_stats->allocated_before_gc_old_space); 114 EXPECT_EQ(0, class_stats->pre_gc.old_count);
115 EXPECT_EQ(0, class_stats->live_after_gc_old_space); 115 EXPECT_EQ(0, class_stats->post_gc.old_count);
116 EXPECT_EQ(0, class_stats->allocated_since_gc_old_space); 116 EXPECT_EQ(0, class_stats->recent.old_count);
117 // Total allocations before GC. 117 // Total allocations before GC.
118 EXPECT_EQ(2, class_stats->allocated_before_gc_new_space); 118 EXPECT_EQ(2, class_stats->pre_gc.new_count);
119 // Only one survived. 119 // Only one survived.
120 EXPECT_EQ(1, class_stats->live_after_gc_new_space); 120 EXPECT_EQ(1, class_stats->post_gc.new_count);
121 EXPECT_EQ(0, class_stats->allocated_since_gc_new_space); 121 EXPECT_EQ(0, class_stats->recent.new_count);
122 // Perform GC. The following is heavily dependent on the behaviour 122 // Perform GC. The following is heavily dependent on the behaviour
123 // of the GC: Retained instance of A will be promoted. 123 // of the GC: Retained instance of A will be promoted.
124 heap->CollectGarbage(Heap::kNew); 124 heap->CollectGarbage(Heap::kNew);
125 // Verify postconditions: 125 // Verify postconditions:
126 EXPECT_EQ(0, class_stats->allocated_before_gc_old_space); 126 EXPECT_EQ(0, class_stats->pre_gc.old_count);
127 EXPECT_EQ(0, class_stats->live_after_gc_old_space); 127 EXPECT_EQ(0, class_stats->post_gc.old_count);
128 // Promotion counted as an allocation from old space. 128 // Promotion counted as an allocation from old space.
129 EXPECT_EQ(1, class_stats->allocated_since_gc_old_space); 129 EXPECT_EQ(1, class_stats->recent.old_count);
130 // There was one instance allocated before GC. 130 // There was one instance allocated before GC.
131 EXPECT_EQ(1, class_stats->allocated_before_gc_new_space); 131 EXPECT_EQ(1, class_stats->pre_gc.new_count);
132 // There are no instances allocated in new space after GC. 132 // There are no instances allocated in new space after GC.
133 EXPECT_EQ(0, class_stats->live_after_gc_new_space); 133 EXPECT_EQ(0, class_stats->post_gc.new_count);
134 // No new allocations. 134 // No new allocations.
135 EXPECT_EQ(0, class_stats->allocated_since_gc_new_space); 135 EXPECT_EQ(0, class_stats->recent.new_count);
136 // Perform a GC on new space. 136 // Perform a GC on new space.
137 heap->CollectGarbage(Heap::kNew); 137 heap->CollectGarbage(Heap::kNew);
138 // There were no instances allocated before GC. 138 // There were no instances allocated before GC.
139 EXPECT_EQ(0, class_stats->allocated_before_gc_new_space); 139 EXPECT_EQ(0, class_stats->pre_gc.new_count);
140 // There are no instances allocated in new space after GC. 140 // There are no instances allocated in new space after GC.
141 EXPECT_EQ(0, class_stats->live_after_gc_new_space); 141 EXPECT_EQ(0, class_stats->post_gc.new_count);
142 // No new allocations. 142 // No new allocations.
143 EXPECT_EQ(0, class_stats->allocated_since_gc_new_space); 143 EXPECT_EQ(0, class_stats->recent.new_count);
144 heap->CollectGarbage(Heap::kOld); 144 heap->CollectGarbage(Heap::kOld);
145 // Verify postconditions: 145 // Verify postconditions:
146 EXPECT_EQ(1, class_stats->allocated_before_gc_old_space); 146 EXPECT_EQ(1, class_stats->pre_gc.old_count);
147 EXPECT_EQ(1, class_stats->live_after_gc_old_space); 147 EXPECT_EQ(1, class_stats->post_gc.old_count);
148 EXPECT_EQ(0, class_stats->allocated_since_gc_old_space); 148 EXPECT_EQ(0, class_stats->recent.old_count);
149 // Exit scope, freeing instance. 149 // Exit scope, freeing instance.
150 Dart_ExitScope(); 150 Dart_ExitScope();
151 // Perform GC. 151 // Perform GC.
152 heap->CollectGarbage(Heap::kOld); 152 heap->CollectGarbage(Heap::kOld);
153 // Verify postconditions: 153 // Verify postconditions:
154 EXPECT_EQ(1, class_stats->allocated_before_gc_old_space); 154 EXPECT_EQ(1, class_stats->pre_gc.old_count);
155 EXPECT_EQ(0, class_stats->live_after_gc_old_space); 155 EXPECT_EQ(0, class_stats->post_gc.old_count);
156 EXPECT_EQ(0, class_stats->allocated_since_gc_old_space); 156 EXPECT_EQ(0, class_stats->recent.old_count);
157 // Perform GC. 157 // Perform GC.
158 heap->CollectGarbage(Heap::kOld); 158 heap->CollectGarbage(Heap::kOld);
159 EXPECT_EQ(0, class_stats->allocated_before_gc_old_space); 159 EXPECT_EQ(0, class_stats->pre_gc.old_count);
160 EXPECT_EQ(0, class_stats->live_after_gc_old_space); 160 EXPECT_EQ(0, class_stats->post_gc.old_count);
161 EXPECT_EQ(0, class_stats->allocated_since_gc_old_space); 161 EXPECT_EQ(0, class_stats->recent.old_count);
162 } 162 }
163 163
164 } // namespace dart. 164 } // namespace dart.
OLDNEW
« no previous file with comments | « runtime/vm/class_table.cc ('k') | runtime/vm/json_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698