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

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

Issue 345543003: Send allocation stats with each class and show in class view. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // Remember how much was allocated so we can subtract this from the result 233 // Remember how much was allocated so we can subtract this from the result
234 // when printing. 234 // when printing.
235 last_reset.new_count = recent.new_count; 235 last_reset.new_count = recent.new_count;
236 last_reset.new_size = recent.new_size; 236 last_reset.new_size = recent.new_size;
237 last_reset.old_count = recent.old_count; 237 last_reset.old_count = recent.old_count;
238 last_reset.old_size = recent.old_size; 238 last_reset.old_size = recent.old_size;
239 accumulated.Reset(); 239 accumulated.Reset();
240 } 240 }
241 241
242 242
243 void ClassHeapStats::PrintTOJSONArray(const Class& cls, JSONArray* array) { 243 void ClassHeapStats::PrintToJSONObject(const Class& cls,
244 JSONObject obj(array); 244 JSONObject* obj) const {
245 obj.AddProperty("type", "ClassHeapStats"); 245 obj->AddProperty("type", "ClassHeapStats");
246 obj.AddPropertyF("id", "allocationprofile/%" Pd "", cls.id()); 246 obj->AddPropertyF("id", "allocationprofile/%" Pd "", cls.id());
247 obj.AddProperty("class", cls); 247 obj->AddProperty("class", cls);
248 { 248 {
249 JSONArray new_stats(&obj, "new"); 249 JSONArray new_stats(obj, "new");
250 new_stats.AddValue(pre_gc.new_count); 250 new_stats.AddValue(pre_gc.new_count);
251 new_stats.AddValue(pre_gc.new_size); 251 new_stats.AddValue(pre_gc.new_size);
252 new_stats.AddValue(post_gc.new_count); 252 new_stats.AddValue(post_gc.new_count);
253 new_stats.AddValue(post_gc.new_size); 253 new_stats.AddValue(post_gc.new_size);
254 new_stats.AddValue(recent.new_count); 254 new_stats.AddValue(recent.new_count);
255 new_stats.AddValue(recent.new_size); 255 new_stats.AddValue(recent.new_size);
256 new_stats.AddValue64(accumulated.new_count + recent.new_count - 256 new_stats.AddValue64(accumulated.new_count + recent.new_count -
257 last_reset.new_count); 257 last_reset.new_count);
258 new_stats.AddValue64(accumulated.new_size + recent.new_size - 258 new_stats.AddValue64(accumulated.new_size + recent.new_size -
259 last_reset.new_size); 259 last_reset.new_size);
260 } 260 }
261 { 261 {
262 JSONArray old_stats(&obj, "old"); 262 JSONArray old_stats(obj, "old");
263 old_stats.AddValue(pre_gc.old_count); 263 old_stats.AddValue(pre_gc.old_count);
264 old_stats.AddValue(pre_gc.old_size); 264 old_stats.AddValue(pre_gc.old_size);
265 old_stats.AddValue(post_gc.old_count); 265 old_stats.AddValue(post_gc.old_count);
266 old_stats.AddValue(post_gc.old_size); 266 old_stats.AddValue(post_gc.old_size);
267 old_stats.AddValue(recent.old_count); 267 old_stats.AddValue(recent.old_count);
268 old_stats.AddValue(recent.old_size); 268 old_stats.AddValue(recent.old_size);
269 old_stats.AddValue64(accumulated.old_count + recent.old_count - 269 old_stats.AddValue64(accumulated.old_count + recent.old_count -
270 last_reset.old_count); 270 last_reset.old_count);
271 old_stats.AddValue64(accumulated.old_size + recent.old_size - 271 old_stats.AddValue64(accumulated.old_size + recent.old_size -
272 last_reset.old_size); 272 last_reset.old_size);
273 } 273 }
274 } 274 }
275 275
276 276
277 void ClassTable::UpdateAllocatedNew(intptr_t cid, intptr_t size) { 277 void ClassTable::UpdateAllocatedNew(intptr_t cid, intptr_t size) {
278 ClassHeapStats* stats = StatsAt(cid); 278 ClassHeapStats* stats = PreliminaryStatsAt(cid);
279 ASSERT(stats != NULL); 279 ASSERT(stats != NULL);
280 ASSERT(size != 0); 280 ASSERT(size != 0);
281 stats->recent.AddNew(size); 281 stats->recent.AddNew(size);
282 } 282 }
283 283
284 284
285 void ClassTable::UpdateAllocatedOld(intptr_t cid, intptr_t size) { 285 void ClassTable::UpdateAllocatedOld(intptr_t cid, intptr_t size) {
286 ClassHeapStats* stats = StatsAt(cid); 286 ClassHeapStats* stats = PreliminaryStatsAt(cid);
287 ASSERT(stats != NULL); 287 ASSERT(stats != NULL);
288 ASSERT(size != 0); 288 ASSERT(size != 0);
289 stats->recent.AddOld(size); 289 stats->recent.AddOld(size);
290 } 290 }
291 291
292 292
293 bool ClassTable::ShouldUpdateSizeForClassId(intptr_t cid) { 293 bool ClassTable::ShouldUpdateSizeForClassId(intptr_t cid) {
294 return !RawObject::IsVariableSizeClassId(cid); 294 return !RawObject::IsVariableSizeClassId(cid);
295 } 295 }
296 296
297 297
298 ClassHeapStats* ClassTable::StatsAt(intptr_t cid) { 298 ClassHeapStats* ClassTable::PreliminaryStatsAt(intptr_t cid) {
299 ASSERT(cid > 0); 299 ASSERT(cid > 0);
300 if (cid < kNumPredefinedCids) { 300 if (cid < kNumPredefinedCids) {
301 return &predefined_class_heap_stats_table_[cid]; 301 return &predefined_class_heap_stats_table_[cid];
302 } 302 }
303 ASSERT(cid < top_); 303 ASSERT(cid < top_);
304 return &class_heap_stats_table_[cid]; 304 return &class_heap_stats_table_[cid];
305 } 305 }
306 306
307 307
308 ClassHeapStats* ClassTable::StatsWithUpdatedSize(intptr_t cid) {
309 if (!HasValidClassAt(cid) || (cid == kFreeListElement) || (cid == kSmiCid)) {
310 return NULL;
311 }
312 Class& cls = Class::Handle(At(cid));
313 if (!(cls.is_finalized() || cls.is_prefinalized())) {
314 // Not finalized.
315 return NULL;
316 }
317 ClassHeapStats* stats = PreliminaryStatsAt(cid);
318 if (ShouldUpdateSizeForClassId(cid)) {
319 stats->UpdateSize(cls.instance_size());
320 }
321 return stats;
322 }
323
324
308 void ClassTable::ResetCountersOld() { 325 void ClassTable::ResetCountersOld() {
309 for (intptr_t i = 0; i < kNumPredefinedCids; i++) { 326 for (intptr_t i = 0; i < kNumPredefinedCids; i++) {
310 predefined_class_heap_stats_table_[i].ResetAtOldGC(); 327 predefined_class_heap_stats_table_[i].ResetAtOldGC();
311 } 328 }
312 for (intptr_t i = kNumPredefinedCids; i < top_; i++) { 329 for (intptr_t i = kNumPredefinedCids; i < top_; i++) {
313 class_heap_stats_table_[i].ResetAtOldGC(); 330 class_heap_stats_table_[i].ResetAtOldGC();
314 } 331 }
315 } 332 }
316 333
317 334
(...skipping 27 matching lines...) Expand all
345 { 362 {
346 JSONObject heaps(&obj, "heaps"); 363 JSONObject heaps(&obj, "heaps");
347 { 364 {
348 heap->PrintToJSONObject(Heap::kNew, &heaps); 365 heap->PrintToJSONObject(Heap::kNew, &heaps);
349 } 366 }
350 { 367 {
351 heap->PrintToJSONObject(Heap::kOld, &heaps); 368 heap->PrintToJSONObject(Heap::kOld, &heaps);
352 } 369 }
353 } 370 }
354 { 371 {
372 JSONArray arr(&obj, "members");
355 Class& cls = Class::Handle(); 373 Class& cls = Class::Handle();
356 JSONArray arr(&obj, "members"); 374 for (intptr_t i = 1; i < top_; i++) {
357 for (intptr_t i = 1; i < kNumPredefinedCids; i++) { 375 const ClassHeapStats* stats = StatsWithUpdatedSize(i);
358 if (!HasValidClassAt(i) || (i == kFreeListElement) || (i == kSmiCid)) { 376 if (stats != NULL) {
359 continue; 377 JSONObject obj(&arr);
378 cls = At(i);
379 stats->PrintToJSONObject(cls, &obj);
360 } 380 }
361 cls = At(i);
362 if (!(cls.is_finalized() || cls.is_prefinalized())) {
363 // Not finalized.
364 continue;
365 }
366 if (ShouldUpdateSizeForClassId(i)) {
367 intptr_t instance_size = cls.instance_size();
368 predefined_class_heap_stats_table_[i].UpdateSize(instance_size);
369 }
370 predefined_class_heap_stats_table_[i].PrintTOJSONArray(cls, &arr);
371 }
372 for (intptr_t i = kNumPredefinedCids; i < top_; i++) {
373 if (!HasValidClassAt(i)) {
374 continue;
375 }
376 cls = At(i);
377 if (!(cls.is_finalized() || cls.is_prefinalized())) {
378 // Not finalized.
379 continue;
380 }
381 if (ShouldUpdateSizeForClassId(i)) {
382 intptr_t instance_size = cls.instance_size();
383 class_heap_stats_table_[i].UpdateSize(instance_size);
384 }
385 class_heap_stats_table_[i].PrintTOJSONArray(cls, &arr);
386 } 381 }
387 } 382 }
388 } 383 }
389 384
390 385
391 void ClassTable::ResetAllocationAccumulators() { 386 void ClassTable::ResetAllocationAccumulators() {
392 Class& cls = Class::Handle(); 387 for (intptr_t i = 1; i < top_; i++) {
393 for (intptr_t i = 1; i < kNumPredefinedCids; i++) { 388 ClassHeapStats* stats = StatsWithUpdatedSize(i);
394 if (!HasValidClassAt(i) || (i == kFreeListElement) || (i == kSmiCid)) { 389 if (stats != NULL) {
395 continue; 390 stats->ResetAccumulator();
396 } 391 }
397 cls = At(i);
398 if (!(cls.is_finalized() || cls.is_prefinalized())) {
399 // Not finalized.
400 continue;
401 }
402 // Update size before resetting accumulator.
403 if (ShouldUpdateSizeForClassId(i)) {
404 intptr_t instance_size = cls.instance_size();
405 predefined_class_heap_stats_table_[i].UpdateSize(instance_size);
406 }
407 predefined_class_heap_stats_table_[i].ResetAccumulator();
408 }
409 for (intptr_t i = kNumPredefinedCids; i < top_; i++) {
410 if (!HasValidClassAt(i)) {
411 continue;
412 }
413 cls = At(i);
414 if (!(cls.is_finalized() || cls.is_prefinalized())) {
415 // Not finalized.
416 continue;
417 }
418 // Update size before resetting accumulator.
419 if (ShouldUpdateSizeForClassId(i)) {
420 intptr_t instance_size = cls.instance_size();
421 class_heap_stats_table_[i].UpdateSize(instance_size);
422 }
423 class_heap_stats_table_[i].ResetAccumulator();
424 } 392 }
425 } 393 }
426 394
427 395
428 void ClassTable::UpdateLiveOld(intptr_t cid, intptr_t size) { 396 void ClassTable::UpdateLiveOld(intptr_t cid, intptr_t size) {
429 ClassHeapStats* stats = StatsAt(cid); 397 ClassHeapStats* stats = PreliminaryStatsAt(cid);
430 ASSERT(stats != NULL); 398 ASSERT(stats != NULL);
431 ASSERT(size >= 0); 399 ASSERT(size >= 0);
432 stats->post_gc.AddOld(size); 400 stats->post_gc.AddOld(size);
433 } 401 }
434 402
435 403
436 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) { 404 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) {
437 ClassHeapStats* stats = StatsAt(cid); 405 ClassHeapStats* stats = PreliminaryStatsAt(cid);
438 ASSERT(stats != NULL); 406 ASSERT(stats != NULL);
439 ASSERT(size >= 0); 407 ASSERT(size >= 0);
440 stats->post_gc.AddNew(size); 408 stats->post_gc.AddNew(size);
441 } 409 }
442 410
443 411
444 } // namespace dart 412 } // 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