Only start timer in IncrementDisableThreadFlip when waiting
IncrementDisableThreadFlip is a hot function in System Server when
processing many binder transactions. There was code to track how much
time was spent waiting and log long waits. These days, long waits rarely
happen, but we were starting the timer even when we did not have to
wait. This led to NanoTime() showing up high in profiles.
This changes moves the first call to NanoTime() until after we know we
will spend at least some time waiting. After this change, NanoTime() did
not show up in the profile at all.
Bug: 150326920
Test: device boots
Change-Id: I6dc4cee7d18a3fbd6d2f73281cddba407e481d67
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index be3b7f8..bb9ad3b 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -901,8 +901,9 @@
MutexLock mu(self, *thread_flip_lock_);
thread_flip_cond_->CheckSafeToWait(self);
bool has_waited = false;
- uint64_t wait_start = NanoTime();
+ uint64_t wait_start = 0;
if (thread_flip_running_) {
+ wait_start = NanoTime();
ScopedTrace trace("IncrementDisableThreadFlip");
while (thread_flip_running_) {
has_waited = true;