[clangd] Trace time the operations wait on Semaphore.

The Semaphore is currently used to limit the number of concurrently
running tasks. Tracing the wait times will allow to find out how much
time is wasted waiting on other operations to complete.

llvm-svn: 334495
This commit is contained in:
Ilya Biryukov 2018-06-12 11:56:21 +00:00
parent 73bf3206ae
commit 9d8f61ad60
1 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,5 @@
#include "Threading.h"
#include "Trace.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Threading.h"
@ -23,9 +24,14 @@ void Notification::wait() const {
Semaphore::Semaphore(std::size_t MaxLocks) : FreeSlots(MaxLocks) {}
void Semaphore::lock() {
std::unique_lock<std::mutex> Lock(Mutex);
SlotsChanged.wait(Lock, [&]() { return FreeSlots > 0; });
--FreeSlots;
trace::Span Span("WaitForFreeSemaphoreSlot");
// trace::Span can also acquire locks in ctor and dtor, we make sure it
// happens when Semaphore's own lock is not held.
{
std::unique_lock<std::mutex> Lock(Mutex);
SlotsChanged.wait(Lock, [&]() { return FreeSlots > 0; });
--FreeSlots;
}
}
void Semaphore::unlock() {