Index: runtime/vm/heap.cc |
diff --git a/runtime/vm/heap.cc b/runtime/vm/heap.cc |
index b3d604a03fade64655399b7cadab688ff8f88541..f3c79cc9fe163c108c98f9ebe77265198516b53c 100644 |
--- a/runtime/vm/heap.cc |
+++ b/runtime/vm/heap.cc |
@@ -165,6 +165,7 @@ void Heap::CollectGarbage(Space space, ApiCallbacks api_callbacks) { |
switch (space) { |
case kNew: { |
RecordBeforeGC(kNew, kNewSpace); |
+ UpdateClassHeapStatsBeforeGC(kNew); |
new_space_->Scavenge(invoke_api_callbacks); |
RecordAfterGC(); |
PrintStats(); |
@@ -178,6 +179,7 @@ void Heap::CollectGarbage(Space space, ApiCallbacks api_callbacks) { |
case kCode: { |
bool promotion_failure = new_space_->HadPromotionFailure(); |
RecordBeforeGC(kOld, promotion_failure ? kPromotionFailure : kOldSpace); |
+ UpdateClassHeapStatsBeforeGC(kOld); |
old_space_->MarkSweep(invoke_api_callbacks); |
RecordAfterGC(); |
PrintStats(); |
@@ -197,6 +199,17 @@ void Heap::UpdateObjectHistogram() { |
} |
+void Heap::UpdateClassHeapStatsBeforeGC(Heap::Space space) { |
+ Isolate* isolate = Isolate::Current(); |
+ ClassTable* class_table = isolate->class_table(); |
+ if (space == kNew) { |
+ class_table->ResetCountersNew(); |
+ } else { |
+ class_table->ResetCountersOld(); |
+ } |
+} |
+ |
+ |
void Heap::CollectGarbage(Space space) { |
ApiCallbacks api_callbacks; |
if (space == kOld) { |
@@ -210,10 +223,12 @@ void Heap::CollectGarbage(Space space) { |
void Heap::CollectAllGarbage() { |
RecordBeforeGC(kNew, kFull); |
+ UpdateClassHeapStatsBeforeGC(kNew); |
new_space_->Scavenge(kInvokeApiCallbacks); |
RecordAfterGC(); |
PrintStats(); |
RecordBeforeGC(kOld, kFull); |
+ UpdateClassHeapStatsBeforeGC(kOld); |
old_space_->MarkSweep(kInvokeApiCallbacks); |
RecordAfterGC(); |
PrintStats(); |
@@ -321,6 +336,35 @@ intptr_t Heap::CapacityInWords(Space space) const { |
} |
+int64_t Heap::GCTimeInMicros(Space space) const { |
+ if (space == kNew) { |
+ return new_space_->gc_time_micros(); |
+ } |
+ return old_space_->gc_time_micros(); |
+} |
+ |
+ |
+double Heap::GCTimeInSeconds(Space space) const { |
+ int64_t micros = 0; |
+ if (space == kNew) { |
+ micros = new_space_->gc_time_micros(); |
+ } else { |
+ micros = old_space_->gc_time_micros(); |
+ } |
+ double seconds = static_cast<double>(micros) / |
Ivan Posva
2014/01/17 06:53:16
RoundMicrosecondsToSeconds
Cutch
2014/01/17 18:37:59
Done.
|
+ static_cast<double>(kMicrosecondsPerSecond); |
+ return seconds; |
+} |
+ |
+ |
+intptr_t Heap::Collections(Space space) const { |
+ if (space == kNew) { |
+ return new_space_->collections(); |
+ } |
+ return old_space_->collections(); |
+} |
+ |
+ |
void Heap::Profile(Dart_FileWriteCallback callback, void* stream) const { |
HeapProfiler profiler(callback, stream); |
@@ -435,6 +479,14 @@ void Heap::RecordBeforeGC(Space space, GCReason reason) { |
void Heap::RecordAfterGC() { |
stats_.after_.micros_ = OS::GetCurrentTimeMicros(); |
+ int64_t delta = stats_.after_.micros_ - stats_.before_.micros_; |
+ if (stats_.space_ == kNew) { |
+ new_space_->AddGCTime(delta); |
+ new_space_->IncrementCollections(); |
+ } else { |
+ old_space_->AddGCTime(delta); |
+ old_space_->IncrementCollections(); |
+ } |
stats_.after_.new_used_in_words_ = new_space_->UsedInWords(); |
stats_.after_.new_capacity_in_words_ = new_space_->CapacityInWords(); |
stats_.after_.old_used_in_words_ = old_space_->UsedInWords(); |