diff --git a/gloop/base/tracer.h b/gloop/base/tracer.h index bf0bd20f..c74b09c7 100644 --- a/gloop/base/tracer.h +++ b/gloop/base/tracer.h @@ -917,6 +917,24 @@ class Tracer { cpu_profile_ticks_.fetch_add(ticks, std::memory_order_relaxed); } + // Returns the total lock contention delay accumulated in this Tracer, if + // supported by the concrete tracer type. + // Note that this only works when the --dapper_lock_contention_reporting flag + // is set. + uint64_t lock_contention_delay_us() const { + return lock_contention_delay_us_.load(std::memory_order_relaxed); + } + + // Increments the lock contention delay by the specified duration, if + // supported by the concrete tracer type. + // Note that this only works when the --dapper_lock_contention_reporting flag + // is set. + void add_lock_contention_delay_safe(absl::Duration duration) { + lock_contention_delay_us_.fetch_add( + static_cast(absl::ToInt64Microseconds(duration)), + std::memory_order_relaxed); + } + // Registers a notification to be called just before this Tracer's final // ref is released by the application. // @@ -1370,6 +1388,9 @@ class Tracer { // meant to be used by Dapper/Census internal libraries only. std::atomic cpu_profile_ticks_ = 0; + // Stores the lock contention delay in microseconds. + std::atomic lock_contention_delay_us_{0}; + // An optional callback to invoked the first time the Tracer's reference count // drops to zero. This allows an application to capture the Tracer without // disrupting its natural lifetime as recorded in start_time/stop_time. diff --git a/gloop/base/tracer_test.cc b/gloop/base/tracer_test.cc index 4bcf48df..524c82c5 100644 --- a/gloop/base/tracer_test.cc +++ b/gloop/base/tracer_test.cc @@ -313,7 +313,7 @@ class TestTracer : public Tracer { TEST(Tracer, Size) { #ifdef NDEBUG - EXPECT_EQ(sizeof(Tracer), 112); + EXPECT_EQ(sizeof(Tracer), 120); #endif }