Report time spent doing madvise in GC performance dump am: 2750a9884d

Change-Id: Ib4c65bbb1665be04cdbbd0bc9676cf2346540deb
diff --git a/runtime/gc/collector/concurrent_copying.cc b/runtime/gc/collector/concurrent_copying.cc
index 9e582b7..ff73437 100644
--- a/runtime/gc/collector/concurrent_copying.cc
+++ b/runtime/gc/collector/concurrent_copying.cc
@@ -3813,6 +3813,9 @@
      << ") / " << region_space_->GetNumRegions() / 2 << " ("
      << PrettySize(region_space_->GetNumRegions() * space::RegionSpace::kRegionSize / 2)
      << ")\n";
+  if (!young_gen_) {
+    os << "Total madvise time " << PrettyDuration(region_space_->GetMadviseTime()) << "\n";
+  }
 }
 
 }  // namespace collector
diff --git a/runtime/gc/space/region_space.cc b/runtime/gc/space/region_space.cc
index 7b3a8f7..8dc3d8e 100644
--- a/runtime/gc/space/region_space.cc
+++ b/runtime/gc/space/region_space.cc
@@ -120,6 +120,7 @@
       use_generational_cc_(use_generational_cc),
       time_(1U),
       num_regions_(mem_map_.Size() / kRegionSize),
+      madvise_time_(0U),
       num_non_free_regions_(0U),
       num_evac_regions_(0U),
       max_peak_num_non_free_regions_(0U),
@@ -508,8 +509,13 @@
     }
   }
   // Madvise the memory ranges.
+  uint64_t start_time = NanoTime();
   for (const auto &iter : madvise_list) {
     PurgePages(iter.first, iter.second - iter.first);
+  }
+  madvise_time_ += NanoTime() - start_time;
+
+  for (const auto &iter : madvise_list) {
     if (clear_bitmap) {
       GetLiveBitmap()->ClearRange(
           reinterpret_cast<mirror::Object*>(iter.first),
diff --git a/runtime/gc/space/region_space.h b/runtime/gc/space/region_space.h
index d515412..84ccf58 100644
--- a/runtime/gc/space/region_space.h
+++ b/runtime/gc/space/region_space.h
@@ -387,6 +387,10 @@
     return num_evac_regions_ * kRegionSize;
   }
 
+  uint64_t GetMadviseTime() const {
+    return madvise_time_;
+  }
+
  private:
   RegionSpace(const std::string& name, MemMap&& mem_map, bool use_generational_cc);
 
@@ -747,6 +751,7 @@
   const bool use_generational_cc_;
   uint32_t time_;                  // The time as the number of collections since the startup.
   size_t num_regions_;             // The number of regions in this space.
+  uint64_t madvise_time_;          // The amount of time spent in madvise for purging pages.
   // The number of non-free regions in this space.
   size_t num_non_free_regions_ GUARDED_BY(region_lock_);