From 9a7fffb36bad0bf3e7bac21dd223d975bc9dde55 Mon Sep 17 00:00:00 2001 From: Hiroshi Yamauchi Date: Wed, 10 Jun 2015 17:20:54 -0700 Subject: [PATCH] Reset GC performance stats at zygote fork. So GCs before a zygote fork won't be attributed to an app. Bug: 21491908 Change-Id: Ib37bc587e0f039ef8faeabe63dec19de49501863 --- runtime/gc/heap.cc | 21 +++++++++++++++++++++ runtime/gc/heap.h | 1 + runtime/runtime.cc | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index aeab7d80b..eabbbec49 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -1000,6 +1000,27 @@ void Heap::DumpGcPerformanceInfo(std::ostream& os) { BaseMutex::DumpAll(os); } +void Heap::ResetGcPerformanceInfo() { + for (auto& collector : garbage_collectors_) { + collector->ResetMeasurements(); + } + total_allocation_time_.StoreRelaxed(0); + total_bytes_freed_ever_ = 0; + total_objects_freed_ever_ = 0; + total_wait_time_ = 0; + blocking_gc_count_ = 0; + blocking_gc_time_ = 0; + gc_count_last_window_ = 0; + blocking_gc_count_last_window_ = 0; + last_update_time_gc_count_rate_histograms_ = // Round down by the window duration. + (NanoTime() / kGcCountRateHistogramWindowDuration) * kGcCountRateHistogramWindowDuration; + { + MutexLock mu(Thread::Current(), *gc_complete_lock_); + gc_count_rate_histogram_.Reset(); + blocking_gc_count_rate_histogram_.Reset(); + } +} + uint64_t Heap::GetGcCount() const { uint64_t gc_count = 0U; for (auto& collector : garbage_collectors_) { diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h index 81a97414b..dac747b85 100644 --- a/runtime/gc/heap.h +++ b/runtime/gc/heap.h @@ -597,6 +597,7 @@ class Heap { // GC performance measuring void DumpGcPerformanceInfo(std::ostream& os); + void ResetGcPerformanceInfo(); // Returns true if we currently care about pause times. bool CareAboutPauseTimes() const { diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 9d651bf6a..4a2a0c911 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -645,6 +645,10 @@ void Runtime::DidForkFromZygote(JNIEnv* env, NativeBridgeAction action, const ch // Create the thread pools. heap_->CreateThreadPool(); + // Reset the gc performance data at zygote fork so that the GCs + // before fork aren't attributed to an app. + heap_->ResetGcPerformanceInfo(); + if (jit_.get() == nullptr && jit_options_->UseJIT()) { // Create the JIT if the flag is set and we haven't already create it (happens for run-tests). CreateJit(); -- 2.11.0