diff options
author | Abseil Team <absl-team@google.com> | 2022-10-07 14:21:24 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-10-07 14:22:13 -0700 |
commit | 76466b85fb9c86be56bfe773667ee6ad4fc3b87f (patch) | |
tree | 9ed2d3ccfa33e9ee501801cf8a7299521d208e10 /absl/synchronization/mutex.cc | |
parent | 192e9834bc6f3aa52a0bad24ef96e658d9ce882f (diff) |
Changes mutex unlock profiling
PiperOrigin-RevId: 479667897
Change-Id: I6085df8bfcfb009806230f8d71b576a1371a4d1f
Diffstat (limited to 'absl/synchronization/mutex.cc')
-rw-r--r-- | absl/synchronization/mutex.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/absl/synchronization/mutex.cc b/absl/synchronization/mutex.cc index c0268b62..69103ed8 100644 --- a/absl/synchronization/mutex.cc +++ b/absl/synchronization/mutex.cc @@ -2342,22 +2342,26 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) { } // end of for(;;)-loop if (wake_list != kPerThreadSynchNull) { - int64_t wait_cycles = 0; + int64_t total_wait_cycles = 0; + int64_t max_wait_cycles = 0; int64_t now = base_internal::CycleClock::Now(); do { - // Sample lock contention events only if the waiter was trying to acquire + // Profile lock contention events only if the waiter was trying to acquire // the lock, not waiting on a condition variable or Condition. if (!wake_list->cond_waiter) { - wait_cycles += (now - wake_list->waitp->contention_start_cycles); + int64_t cycles_waited = + (now - wake_list->waitp->contention_start_cycles); + total_wait_cycles += cycles_waited; + if (max_wait_cycles == 0) max_wait_cycles = cycles_waited; wake_list->waitp->contention_start_cycles = now; wake_list->waitp->should_submit_contention_data = true; } wake_list = Wakeup(wake_list); // wake waiters } while (wake_list != kPerThreadSynchNull); - if (wait_cycles > 0) { - mutex_tracer("slow release", this, wait_cycles); + if (total_wait_cycles > 0) { + mutex_tracer("slow release", this, total_wait_cycles); ABSL_TSAN_MUTEX_PRE_DIVERT(this, 0); - submit_profile_data(wait_cycles); + submit_profile_data(total_wait_cycles); ABSL_TSAN_MUTEX_POST_DIVERT(this, 0); } } |