diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/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 #include @@ -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> 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)); }