[clang-tools-extra] 05737fa - [clangd] Trace preamble throttle time

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 5 09:34:56 PDT 2022


Author: Sam McCall
Date: 2022-09-05T18:34:41+02:00
New Revision: 05737fa209ba97b330739af3b00834c21b0547b7

URL: https://github.com/llvm/llvm-project/commit/05737fa209ba97b330739af3b00834c21b0547b7
DIFF: https://github.com/llvm/llvm-project/commit/05737fa209ba97b330739af3b00834c21b0547b7.diff

LOG: [clangd] Trace preamble throttle time

Added: 
    

Modified: 
    clang-tools-extra/clangd/TUScheduler.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp
index 4c6c8c679be3..1e64fac80d94 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -390,13 +390,16 @@ class PreambleThrottlerRequest {
   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 @@ class PreambleThrottlerRequest {
   }
 
 private:
+  llvm::Optional<trace::Span> Tracer;
   PreambleThrottler::RequestID ID;
   PreambleThrottler *Throttler;
   std::atomic<bool> Satisfied = {false};
@@ -473,13 +477,18 @@ class PreambleThread {
         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!


        


More information about the cfe-commits mailing list