diff options
| -rw-r--r-- | runtime/gc/heap.cc | 9 | ||||
| -rw-r--r-- | runtime/gc/heap.h | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index 5f62d758c6..8020f86419 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -2878,6 +2878,15 @@ void Heap::UpdateGcCountRateHistograms() { DCHECK_GE(now, last_update_time_gc_count_rate_histograms_); uint64_t time_since_last_update = now - last_update_time_gc_count_rate_histograms_; uint64_t num_of_windows = time_since_last_update / kGcCountRateHistogramWindowDuration; + + // The computed number of windows can be incoherently high if NanoTime() is not monotonic. + // Setting a limit on its maximum value reduces the impact on CPU time in such cases. + if (num_of_windows > kGcCountRateHistogramMaxNumMissedWindows) { + LOG(WARNING) << "Reducing the number of considered missed Gc histogram windows from " + << num_of_windows << " to " << kGcCountRateHistogramMaxNumMissedWindows; + num_of_windows = kGcCountRateHistogramMaxNumMissedWindows; + } + if (time_since_last_update >= kGcCountRateHistogramWindowDuration) { // Record the first window. gc_count_rate_histogram_.AddValue(gc_count_last_window_ - 1); // Exclude the current run. diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h index 4c5d896c9e..6bdba12e5c 100644 --- a/runtime/gc/heap.h +++ b/runtime/gc/heap.h @@ -1495,6 +1495,8 @@ class Heap { uint64_t blocking_gc_time_; // The duration of the window for the GC count rate histograms. static constexpr uint64_t kGcCountRateHistogramWindowDuration = MsToNs(10 * 1000); // 10s. + // Maximum number of missed histogram windows for which statistics will be collected. + static constexpr uint64_t kGcCountRateHistogramMaxNumMissedWindows = 100; // The last time when the GC count rate histograms were updated. // This is rounded by kGcCountRateHistogramWindowDuration (a multiple of 10s). uint64_t last_update_time_gc_count_rate_histograms_; |