[PATCH] D78436: [clangd] Record metrics for code action and rename usage

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 18 15:05:40 PDT 2020


kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

Depends on D78429 <https://reviews.llvm.org/D78429>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78436

Files:
  clang-tools-extra/clangd/ClangdServer.cpp


Index: clang-tools-extra/clangd/ClangdServer.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -43,6 +43,7 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <future>
@@ -396,6 +397,10 @@
       if (Err)
         return CB(std::move(Err));
     }
+    trace::Metric M("/clangd/rename");
+    M.T = trace::Metric::Sample;
+    M.Value = Edits->size();
+    trace::record(M);
     return CB(std::move(*Edits));
   };
   WorkScheduler.runWithAST("Rename", File, std::move(Action));
@@ -438,10 +443,15 @@
     auto Filter = [&](const Tweak &T) {
       return TweakFilter(T) && !PreparedTweaks.count(T.id());
     };
+    trace::Metric M("/clangd/shown_codeaction");
+    M.T = trace::Metric::Increment;
+    M.Value = 1;
     for (const auto &Sel : *Selections) {
       for (auto &T : prepareTweaks(*Sel, Filter)) {
         Res.push_back({T->id(), T->title(), T->intent()});
         PreparedTweaks.insert(T->id());
+        M.Labels = {T->id()};
+        trace::record(M);
       }
     }
 
@@ -462,6 +472,11 @@
         auto Selections = tweakSelection(Sel, *InpAST);
         if (!Selections)
           return CB(Selections.takeError());
+        trace::Metric M("/clangd/executed_tweaks");
+        M.T = trace::Metric::Increment;
+        M.Value = 1;
+        M.Labels = {TweakID, /*Error=*/""};
+        auto _ = llvm::make_scope_exit([&M] { trace::record(M); });
         llvm::Optional<llvm::Expected<Tweak::Effect>> Effect;
         // Try each selection, take the first one that prepare()s.
         // If they all fail, Effect will hold get the last error.
@@ -483,8 +498,11 @@
             if (llvm::Error Err = reformatEdit(E, Style))
               elog("Failed to format {0}: {1}", It.first(), std::move(Err));
           }
+          return CB(std::move(*Effect));
         }
-        return CB(std::move(*Effect));
+        auto Err = Effect->takeError();
+        M.Labels.back() = llvm::to_string(Err);
+        return CB(std::move(Err));
       };
   WorkScheduler.runWithAST("ApplyTweak", File, std::move(Action));
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78436.258560.patch
Type: text/x-patch
Size: 2324 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200418/8889675e/attachment.bin>


More information about the cfe-commits mailing list