Trace heap size for allocations

Trace the heap size when we get bulk allocated bytes. This doesn't
happen often for RosAlloc/TLAB and should not hurt
performance.

The motivation is to enable systrace to see allocation behavior of
apps.

Test: test-art-host

Change-Id: I1e373b29507cc64bd5b6ecc9b4e9278399adf4b1
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 880b2d4..ad4c0d5 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -2678,6 +2678,10 @@
   }
 }
 
+void Heap::TraceHeapSize(size_t heap_size) {
+  ATRACE_INT("Heap size (KB)", heap_size / KB);
+}
+
 collector::GcType Heap::CollectGarbageInternal(collector::GcType gc_type,
                                                GcCause gc_cause,
                                                bool clear_soft_references) {
@@ -2726,8 +2730,6 @@
     ++self->GetStats()->gc_for_alloc_count;
   }
   const uint64_t bytes_allocated_before_gc = GetBytesAllocated();
-  // Approximate heap size.
-  ATRACE_INT("Heap size (KB)", bytes_allocated_before_gc / KB);
 
   if (gc_type == NonStickyGcType()) {
     // Move all bytes from new_native_bytes_allocated_ to
@@ -3632,6 +3634,8 @@
   // We know what our utilization is at this moment.
   // This doesn't actually resize any memory. It just lets the heap grow more when necessary.
   const uint64_t bytes_allocated = GetBytesAllocated();
+  // Trace the new heap size after the GC is finished.
+  TraceHeapSize(bytes_allocated);
   uint64_t target_size;
   collector::GcType gc_type = collector_ran->GetGcType();
   const double multiplier = HeapGrowthMultiplier();  // Use the multiplier to grow more for