OSDN Git Service

Reset GC performance stats at zygote fork.
authorHiroshi Yamauchi <yamauchi@google.com>
Thu, 11 Jun 2015 00:20:54 +0000 (17:20 -0700)
committerHiroshi Yamauchi <yamauchi@google.com>
Thu, 11 Jun 2015 00:20:54 +0000 (17:20 -0700)
So GCs before a zygote fork won't be attributed to an app.

Bug: 21491908
Change-Id: Ib37bc587e0f039ef8faeabe63dec19de49501863

runtime/gc/heap.cc
runtime/gc/heap.h
runtime/runtime.cc

index aeab7d8..eabbbec 100644 (file)
@@ -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_) {
index 81a9741..dac747b 100644 (file)
@@ -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 {
index 9d651bf..4a2a0c9 100644 (file)
@@ -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();