ART: fix post gc weighted allocated bytes metrics
Stop post GC measurement after the last GC, since VM shutdown is not a
real GC.
Test: Run art with -XX:DumpGCPerformanceOnShutdown on some benchmarks.
Bug: 112187497
Change-Id: Ia00fbbd8134aaea38d570c43ba87c768cbe4baae
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 341f16a..52c9386 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -441,6 +441,10 @@
return process_cpu_start_time_ns_;
}
+ uint64_t GetPostGCLastProcessCpuTime() const {
+ return post_gc_last_process_cpu_time_ns_;
+ }
+
// Set target ideal heap utilization ratio, implements
// dalvik.system.VMRuntime.setTargetHeapUtilization.
void SetTargetHeapUtilization(float target);
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index eea7c67..d79793b 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -324,7 +324,6 @@
if (dump_gc_performance_on_shutdown_) {
heap_->CalculatePreGcWeightedAllocatedBytes();
- heap_->CalculatePostGcWeightedAllocatedBytes();
uint64_t process_cpu_end_time = ProcessCpuNanoTime();
ScopedLogSeverity sls(LogSeverity::INFO);
// This can't be called from the Heap destructor below because it
@@ -341,8 +340,12 @@
<< "\n";
double pre_gc_weighted_allocated_bytes =
heap_->GetPreGcWeightedAllocatedBytes() / process_cpu_time;
+ // Here we don't use process_cpu_time for normalization, because VM shutdown is not a real
+ // GC. Both numerator and denominator take into account until the end of the last GC,
+ // instead of the whole process life time like pre_gc_weighted_allocated_bytes.
double post_gc_weighted_allocated_bytes =
- heap_->GetPostGcWeightedAllocatedBytes() / process_cpu_time;
+ heap_->GetPostGcWeightedAllocatedBytes() /
+ (heap_->GetPostGCLastProcessCpuTime() - heap_->GetProcessCpuStartTime());
LOG_STREAM(INFO) << "Average bytes allocated at GC start, weighted by CPU time between GCs: "
<< static_cast<uint64_t>(pre_gc_weighted_allocated_bytes)