[clangd] Trace preamble throttle time
authorSam McCall <sam.mccall@gmail.com>
Mon, 5 Sep 2022 16:34:41 +0000 (18:34 +0200)
committerSam McCall <sam.mccall@gmail.com>
Mon, 5 Sep 2022 16:34:41 +0000 (18:34 +0200)
clang-tools-extra/clangd/TUScheduler.cpp

index 4c6c8c6..1e64fac 100644 (file)
@@ -390,13 +390,16 @@ public:
   PreambleThrottlerRequest(llvm::StringRef Filename,
                            PreambleThrottler *Throttler,
                            std::condition_variable &CV)
-      : Throttler(Throttler), Satisfied(Throttler == nullptr) {
+      : Throttler(Throttler),
+        Satisfied(Throttler == nullptr) {
     // If there is no throttler, this dummy request is always satisfied.
     if (!Throttler)
       return;
+    Tracer.emplace("PreambleThrottled");
     ID = Throttler->acquire(Filename, [&] {
       Satisfied.store(true, std::memory_order_release);
       CV.notify_all();
+      Tracer.reset();
     });
   }
 
@@ -411,6 +414,7 @@ public:
   }
 
 private:
+  llvm::Optional<trace::Span> Tracer;
   PreambleThrottler::RequestID ID;
   PreambleThrottler *Throttler;
   std::atomic<bool> Satisfied = {false};
@@ -473,13 +477,18 @@ public:
         if (Done)
           break;
 
-        Throttle.emplace(FileName, Throttler, ReqCV);
-        // If acquire succeeded synchronously, avoid status jitter.
-        if (!Throttle->satisfied())
-          Status.update([&](TUStatus &Status) {
-            Status.PreambleActivity = PreambleAction::Queued;
-          });
-        ReqCV.wait(Lock, [&] { return Throttle->satisfied() || Done; });
+        {
+          Throttle.emplace(FileName, Throttler, ReqCV);
+          llvm::Optional<trace::Span> Tracer;
+          // If acquire succeeded synchronously, avoid status jitter.
+          if (!Throttle->satisfied()) {
+            Tracer.emplace("PreambleThrottle");
+            Status.update([&](TUStatus &Status) {
+              Status.PreambleActivity = PreambleAction::Queued;
+            });
+          }
+          ReqCV.wait(Lock, [&] { return Throttle->satisfied() || Done; });
+        }
         if (Done)
           break;
         // While waiting for the throttler, the request may have been updated!