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

Side by Side Diff: runtime/vm/class_table.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.h ('k') | runtime/vm/heap_test.cc » ('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 "vm/class_table.h" 5 #include "vm/class_table.h"
6 #include "vm/flags.h" 6 #include "vm/flags.h"
7 #include "vm/freelist.h" 7 #include "vm/freelist.h"
8 #include "vm/heap.h" 8 #include "vm/heap.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/raw_object.h" 10 #include "vm/raw_object.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (HasValidClassAt(i)) { 126 if (HasValidClassAt(i)) {
127 cls = At(i); 127 cls = At(i);
128 members.AddValue(cls); 128 members.AddValue(cls);
129 } 129 }
130 } 130 }
131 } 131 }
132 } 132 }
133 133
134 134
135 void ClassHeapStats::Initialize() { 135 void ClassHeapStats::Initialize() {
136 allocated_before_gc_old_space = 0; 136 pre_gc.Reset();
137 allocated_before_gc_new_space = 0; 137 post_gc.Reset();
138 allocated_size_before_gc_old_space = 0; 138 recent.Reset();
139 allocated_size_before_gc_new_space = 0; 139 accumulated.Reset();
140 live_after_gc_old_space = 0; 140 last_reset.Reset();
141 live_after_gc_new_space = 0;
142 live_size_after_gc_old_space = 0;
143 live_size_after_gc_new_space = 0;
144 allocated_since_gc_new_space = 0;
145 allocated_since_gc_old_space = 0;
146 allocated_size_since_gc_new_space = 0;
147 allocated_size_since_gc_old_space = 0;
148 } 141 }
149 142
150 143
151 void ClassHeapStats::ResetAtNewGC() { 144 void ClassHeapStats::ResetAtNewGC() {
152 allocated_before_gc_new_space = live_after_gc_new_space + 145 pre_gc.new_count = post_gc.new_count + recent.new_count;
153 allocated_since_gc_new_space; 146 pre_gc.new_size = post_gc.new_size + recent.new_size;
154 allocated_size_before_gc_new_space = live_size_after_gc_new_space + 147 // Accumulate allocations.
155 allocated_size_since_gc_new_space; 148 accumulated.new_count += recent.new_count - last_reset.new_count;
156 live_after_gc_new_space = 0; 149 accumulated.new_size += recent.new_size - last_reset.new_size;
157 live_size_after_gc_new_space = 0; 150 last_reset.ResetNew();
158 allocated_since_gc_new_space = 0; 151 post_gc.ResetNew();
159 allocated_size_since_gc_new_space = 0; 152 recent.ResetNew();
160 } 153 }
161 154
162 155
163 void ClassHeapStats::ResetAtOldGC() { 156 void ClassHeapStats::ResetAtOldGC() {
164 allocated_before_gc_old_space = live_after_gc_old_space + 157 pre_gc.old_count = post_gc.old_count + recent.old_count;
165 allocated_since_gc_old_space; 158 pre_gc.old_size = post_gc.old_size + recent.old_size;
166 allocated_size_before_gc_old_space = live_size_after_gc_old_space + 159 // Accumulate allocations.
167 allocated_size_since_gc_old_space; 160 accumulated.old_count += recent.old_count - last_reset.old_count;
168 live_after_gc_old_space = 0; 161 accumulated.old_size += recent.old_size - last_reset.old_size;
169 live_size_after_gc_old_space = 0; 162 last_reset.ResetOld();
170 allocated_since_gc_old_space = 0; 163 post_gc.ResetOld();
171 allocated_size_since_gc_old_space = 0; 164 recent.ResetOld();
172 } 165 }
173 166
174 167
175 void ClassHeapStats::UpdateSize(intptr_t instance_size) { 168 void ClassHeapStats::UpdateSize(intptr_t instance_size) {
176 ASSERT(instance_size > 0); 169 ASSERT(instance_size > 0);
177 // For classes with fixed instance size we do not emit code to update 170 // For classes with fixed instance size we do not emit code to update
178 // the size statistics. Update them here. 171 // the size statistics. Update them here.
179 allocated_size_before_gc_old_space = 172 pre_gc.old_size = pre_gc.old_count * instance_size;
180 allocated_before_gc_old_space * instance_size; 173 pre_gc.new_size = pre_gc.new_count * instance_size;
181 allocated_size_before_gc_new_space = 174 post_gc.old_size = post_gc.old_count * instance_size;
182 allocated_before_gc_new_space * instance_size; 175 post_gc.new_size = post_gc.new_count * instance_size;
183 live_size_after_gc_old_space = 176 recent.new_size = recent.new_count * instance_size;
184 live_after_gc_old_space * instance_size; 177 recent.old_size = recent.old_count * instance_size;
185 live_size_after_gc_new_space =
186 live_after_gc_new_space * instance_size;
187 allocated_size_since_gc_new_space =
188 allocated_since_gc_new_space * instance_size;
189 allocated_size_since_gc_old_space =
190 allocated_since_gc_old_space * instance_size;
191 } 178 }
192 179
193 180
181 void ClassHeapStats::ResetAccumulator() {
182 // Remember how much was allocated so we can subtract this from the result
183 // when printing.
184 last_reset.new_count = recent.new_count;
185 last_reset.new_size = recent.new_size;
186 last_reset.old_count = recent.old_count;
187 last_reset.old_size = recent.old_size;
188 accumulated.Reset();
189 }
190
191
194 void ClassHeapStats::PrintTOJSONArray(const Class& cls, JSONArray* array) { 192 void ClassHeapStats::PrintTOJSONArray(const Class& cls, JSONArray* array) {
195 JSONObject obj(array); 193 JSONObject obj(array);
196 obj.AddProperty("type", "ClassHeapStats"); 194 obj.AddProperty("type", "ClassHeapStats");
197 obj.AddProperty("class", cls); 195 obj.AddProperty("class", cls);
198 { 196 {
199 JSONArray new_stats(&obj, "new"); 197 JSONArray new_stats(&obj, "new");
200 new_stats.AddValue(allocated_before_gc_new_space); 198 new_stats.AddValue(pre_gc.new_count);
201 new_stats.AddValue(allocated_size_before_gc_new_space); 199 new_stats.AddValue(pre_gc.new_size);
202 new_stats.AddValue(live_after_gc_new_space); 200 new_stats.AddValue(post_gc.new_count);
203 new_stats.AddValue(live_size_after_gc_new_space); 201 new_stats.AddValue(post_gc.new_size);
204 new_stats.AddValue(allocated_since_gc_new_space); 202 new_stats.AddValue(recent.new_count);
205 new_stats.AddValue(allocated_size_since_gc_new_space); 203 new_stats.AddValue(recent.new_size);
204 new_stats.AddValue64(accumulated.new_count + recent.new_count -
205 last_reset.new_count);
206 new_stats.AddValue64(accumulated.new_size + recent.new_size -
207 last_reset.new_size);
206 } 208 }
207 { 209 {
208 JSONArray old_stats(&obj, "old"); 210 JSONArray old_stats(&obj, "old");
209 old_stats.AddValue(allocated_before_gc_old_space); 211 old_stats.AddValue(pre_gc.old_count);
210 old_stats.AddValue(allocated_size_before_gc_old_space); 212 old_stats.AddValue(pre_gc.old_size);
211 old_stats.AddValue(live_after_gc_old_space); 213 old_stats.AddValue(post_gc.old_count);
212 old_stats.AddValue(live_size_after_gc_old_space); 214 old_stats.AddValue(post_gc.old_size);
213 old_stats.AddValue(allocated_since_gc_old_space); 215 old_stats.AddValue(recent.old_count);
214 old_stats.AddValue(allocated_size_since_gc_old_space); 216 old_stats.AddValue(recent.old_size);
217 old_stats.AddValue64(accumulated.old_count + recent.old_count -
218 last_reset.old_count);
219 old_stats.AddValue64(accumulated.old_size + recent.old_size -
220 last_reset.old_size);
215 } 221 }
216 } 222 }
217 223
218 224
219 void ClassTable::UpdateAllocatedNew(intptr_t cid, intptr_t size) { 225 void ClassTable::UpdateAllocatedNew(intptr_t cid, intptr_t size) {
220 ClassHeapStats* stats = StatsAt(cid); 226 ClassHeapStats* stats = StatsAt(cid);
221 ASSERT(stats != NULL); 227 ASSERT(stats != NULL);
222 ASSERT(size != 0); 228 ASSERT(size != 0);
223 stats->allocated_since_gc_new_space++; 229 stats->recent.AddNew(size);
224 stats->allocated_size_since_gc_new_space += size;
225 } 230 }
226 231
227 232
228 void ClassTable::UpdateAllocatedOld(intptr_t cid, intptr_t size) { 233 void ClassTable::UpdateAllocatedOld(intptr_t cid, intptr_t size) {
229 ClassHeapStats* stats = StatsAt(cid); 234 ClassHeapStats* stats = StatsAt(cid);
230 ASSERT(stats != NULL); 235 ASSERT(stats != NULL);
231 ASSERT(size != 0); 236 ASSERT(size != 0);
232 stats->allocated_since_gc_old_space++; 237 stats->recent.AddOld(size);
233 stats->allocated_size_since_gc_old_space += size;
234 } 238 }
235 239
236 240
237 bool ClassTable::ShouldUpdateSizeForClassId(intptr_t cid) { 241 bool ClassTable::ShouldUpdateSizeForClassId(intptr_t cid) {
238 return !RawObject::IsVariableSizeClassId(cid); 242 return !RawObject::IsVariableSizeClassId(cid);
239 } 243 }
240 244
241 245
242 ClassHeapStats* ClassTable::StatsAt(intptr_t cid) { 246 ClassHeapStats* ClassTable::StatsAt(intptr_t cid) {
243 ASSERT(cid > 0); 247 ASSERT(cid > 0);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 if (ShouldUpdateSizeForClassId(i)) { 319 if (ShouldUpdateSizeForClassId(i)) {
316 intptr_t instance_size = cls.instance_size(); 320 intptr_t instance_size = cls.instance_size();
317 class_heap_stats_table_[i].UpdateSize(instance_size); 321 class_heap_stats_table_[i].UpdateSize(instance_size);
318 } 322 }
319 class_heap_stats_table_[i].PrintTOJSONArray(cls, &arr); 323 class_heap_stats_table_[i].PrintTOJSONArray(cls, &arr);
320 } 324 }
321 } 325 }
322 } 326 }
323 327
324 328
329 void ClassTable::ResetAllocationAccumulators() {
330 Class& cls = Class::Handle();
331 for (intptr_t i = 1; i < kNumPredefinedCids; i++) {
332 if (!HasValidClassAt(i) || (i == kFreeListElement) || (i == kSmiCid)) {
333 continue;
334 }
335 cls = At(i);
336 if (!(cls.is_finalized() || cls.is_prefinalized())) {
337 // Not finalized.
338 continue;
339 }
340 // Update size before resetting accumulator.
341 if (ShouldUpdateSizeForClassId(i)) {
342 intptr_t instance_size = cls.instance_size();
343 predefined_class_heap_stats_table_[i].UpdateSize(instance_size);
344 }
345 predefined_class_heap_stats_table_[i].ResetAccumulator();
346 }
347 for (intptr_t i = kNumPredefinedCids; i < top_; i++) {
348 if (!HasValidClassAt(i)) {
349 continue;
350 }
351 cls = At(i);
352 if (!(cls.is_finalized() || cls.is_prefinalized())) {
353 // Not finalized.
354 continue;
355 }
356 // Update size before resetting accumulator.
357 if (ShouldUpdateSizeForClassId(i)) {
358 intptr_t instance_size = cls.instance_size();
359 class_heap_stats_table_[i].UpdateSize(instance_size);
360 }
361 class_heap_stats_table_[i].ResetAccumulator();
362 }
363 }
364
365
325 void ClassTable::UpdateLiveOld(intptr_t cid, intptr_t size) { 366 void ClassTable::UpdateLiveOld(intptr_t cid, intptr_t size) {
326 ClassHeapStats* stats = StatsAt(cid); 367 ClassHeapStats* stats = StatsAt(cid);
327 ASSERT(stats != NULL); 368 ASSERT(stats != NULL);
328 ASSERT(size >= 0); 369 ASSERT(size >= 0);
329 stats->live_after_gc_old_space++; 370 stats->post_gc.AddOld(size);
330 stats->live_size_after_gc_old_space += size;
331 } 371 }
332 372
333 373
334 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) { 374 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) {
335 ClassHeapStats* stats = StatsAt(cid); 375 ClassHeapStats* stats = StatsAt(cid);
336 ASSERT(stats != NULL); 376 ASSERT(stats != NULL);
337 ASSERT(size >= 0); 377 ASSERT(size >= 0);
338 stats->live_after_gc_new_space++; 378 stats->post_gc.AddNew(size);
339 stats->live_size_after_gc_new_space += size;
340 } 379 }
341 380
342 381
343 } // namespace dart 382 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_table.h ('k') | runtime/vm/heap_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698