ART: add weighted allocated bytes metrics
`process_cpu_start_time_` is moved from `art::Runtime` to `art::gc:Heap`
so that it could be reset when the app starts (current process is forked
from Zygote).
`process_cpu_end_time_` is removed from `art::Runtime` because it's only
used when the runtime is about to shutdown, so it suffices to capture it
in a local variable.
Test: Run art with -XX:DumpGCPerformanceOnShutdown on some benchmarks.
Bug: 112187497
Change-Id: I154fdb6acdf4e0c21dff835807bd4e2cf311e3d1
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index f767360..86135c1 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -210,6 +210,9 @@
low_memory_mode_(low_memory_mode),
long_pause_log_threshold_(long_pause_log_threshold),
long_gc_log_threshold_(long_gc_log_threshold),
+ process_cpu_start_time_ns_(ProcessCpuNanoTime()),
+ last_process_cpu_time_ns_(process_cpu_start_time_ns_),
+ weighted_allocated_bytes_(0u),
ignore_max_footprint_(ignore_max_footprint),
zygote_creation_lock_("zygote creation lock", kZygoteCreationLock),
zygote_space_(nullptr),
@@ -1062,6 +1065,14 @@
}
}
+void Heap::CalculateWeightedAllocatedBytes() {
+ uint64_t current_process_cpu_time = ProcessCpuNanoTime();
+ uint64_t bytes_allocated = GetBytesAllocated();
+ uint64_t weight = current_process_cpu_time - last_process_cpu_time_ns_;
+ weighted_allocated_bytes_ += weight * bytes_allocated;
+ last_process_cpu_time_ns_ = current_process_cpu_time;
+}
+
uint64_t Heap::GetTotalGcCpuTime() {
uint64_t sum = 0;
for (auto* collector : garbage_collectors_) {
@@ -1139,6 +1150,11 @@
for (auto* collector : garbage_collectors_) {
collector->ResetMeasurements();
}
+
+ process_cpu_start_time_ns_ = ProcessCpuNanoTime();
+ last_process_cpu_time_ns_ = process_cpu_start_time_ns_;
+ weighted_allocated_bytes_ = 0u;
+
total_bytes_freed_ever_ = 0;
total_objects_freed_ever_ = 0;
total_wait_time_ = 0;