Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions gloop/base/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(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.
//
Expand Down Expand Up @@ -1370,6 +1388,9 @@ class Tracer {
// meant to be used by Dapper/Census internal libraries only.
std::atomic<int32_t> cpu_profile_ticks_ = 0;

// Stores the lock contention delay in microseconds.
std::atomic<uint64_t> 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.
Expand Down
2 changes: 1 addition & 1 deletion gloop/base/tracer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class TestTracer : public Tracer {

TEST(Tracer, Size) {
#ifdef NDEBUG
EXPECT_EQ(sizeof(Tracer), 112);
EXPECT_EQ(sizeof(Tracer), 120);
#endif
}

Expand Down
Loading