diff --git a/src/workerd/io/observer.h b/src/workerd/io/observer.h index 9b439fd6a49..e71a561f3b4 100644 --- a/src/workerd/io/observer.h +++ b/src/workerd/io/observer.h @@ -109,6 +109,10 @@ class IsolateObserver: public kj::AtomicRefcounted { class LockTiming { public: + virtual void waitingForOtherIsolate(kj::StringPtr id) {} + // Called by `Isolate::takeAsyncLock()` when it is blocked by a different isolate lock on the + // same thread. + virtual void reportAsyncInfo(uint currentLoad, bool threadWaitingSameLock, uint threadWaitingDifferentLockCount) {} // Call if this is an async lock attempt, before constructing LockRecord. diff --git a/src/workerd/io/worker.c++ b/src/workerd/io/worker.c++ index 054469fc550..fd7952ebd55 100644 --- a/src/workerd/io/worker.c++ +++ b/src/workerd/io/worker.c++ @@ -1780,6 +1780,9 @@ kj::Promise Worker::Isolate::takeAsyncLockImpl( // be released before we try to lock a different isolate. // TODO(perf): Use of ForkedPromise leads to thundering herd here. Should be minor in practice, // but we could consider creating another linked list instead... + KJ_IF_MAYBE(lt, lockTiming) { + lt->get()->waitingForOtherIsolate(waiter->isolate->getId()); + } co_await waiter->releasePromise.addBranch(); } }