[clang-tools-extra] r323792 - [clangd] Trace code completion.
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 30 09:20:55 PST 2018
Author: sammccall
Date: Tue Jan 30 09:20:54 2018
New Revision: 323792
URL: http://llvm.org/viewvc/llvm-project?rev=323792&view=rev
Log:
[clangd] Trace code completion.
Context passing is a little messy, but will go away with TLS soon.
Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=323792&r1=323791&r2=323792&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Jan 30 09:20:54 2018
@@ -19,6 +19,7 @@
#include "Compiler.h"
#include "FuzzyMatch.h"
#include "Logger.h"
+#include "Trace.h"
#include "index/Index.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
@@ -637,6 +638,7 @@ bool semaCodeComplete(const Context &Ctx
const clang::CodeCompleteOptions &Options,
const SemaCompleteInput &Input,
llvm::function_ref<void()> Callback = nullptr) {
+ auto Tracer = llvm::make_unique<trace::Span>(Ctx, "Sema completion");
std::vector<const char *> ArgStrs;
for (const auto &S : Input.Command.CommandLine)
ArgStrs.push_back(S.c_str());
@@ -697,9 +699,12 @@ bool semaCodeComplete(const Context &Ctx
"Execute() failed when running codeComplete for " + Input.FileName);
return false;
}
+ Tracer.reset();
if (Callback)
Callback();
+
+ Tracer = llvm::make_unique<trace::Span>(Ctx, "Sema completion cleanup");
Action.EndSourceFile();
return true;
@@ -796,6 +801,7 @@ clang::CodeCompleteOptions CodeCompleteO
// This score is combined with the result quality score for the final score.
// - TopN determines the results with the best score.
class CodeCompleteFlow {
+ trace::Span Tracer;
const Context &Ctx;
const CodeCompleteOptions &Opts;
// Sema takes ownership of Recorder. Recorder is valid until Sema cleanup.
@@ -808,8 +814,8 @@ class CodeCompleteFlow {
public:
// A CodeCompleteFlow object is only useful for calling run() exactly once.
CodeCompleteFlow(const Context &Ctx, const CodeCompleteOptions &Opts)
- : Ctx(Ctx), Opts(Opts), RecorderOwner(new CompletionRecorder(Opts)),
- Recorder(*RecorderOwner) {}
+ : Tracer(Ctx, "CodeCompleteFlow"), Ctx(Tracer.Ctx), Opts(Opts),
+ RecorderOwner(new CompletionRecorder(Opts)), Recorder(*RecorderOwner) {}
CompletionList run(const SemaCompleteInput &SemaCCInput) && {
// We run Sema code completion first. It builds an AST and calculates:
@@ -824,6 +830,11 @@ public:
log(Ctx, "Code complete: no Sema callback, 0 results");
});
+ SPAN_ATTACH(Tracer, "sema_results", NSema);
+ SPAN_ATTACH(Tracer, "index_results", NIndex);
+ SPAN_ATTACH(Tracer, "merged_results", NBoth);
+ SPAN_ATTACH(Tracer, "returned_results", Output.items.size());
+ SPAN_ATTACH(Tracer, "incomplete", Output.isIncomplete);
log(Ctx,
llvm::formatv("Code complete: {0} results from Sema, {1} from Index, "
"{2} matched, {3} returned{4}.",
@@ -860,6 +871,9 @@ private:
SymbolSlab queryIndex() {
if (!Opts.Index || !allowIndex(Recorder.CCContext.getKind()))
return SymbolSlab();
+ trace::Span Tracer(Ctx, "Query index");
+ SPAN_ATTACH(Tracer, "limit", Opts.Limit);
+
SymbolSlab::Builder ResultsBuilder;
// Build the query.
FuzzyFindRequest Req;
@@ -868,12 +882,15 @@ private:
Req.Query = Filter->pattern();
Req.Scopes =
getQueryScopes(Recorder.CCContext, Recorder.CCSema->getSourceManager());
- log(Ctx, llvm::formatv(
- "Code complete: fuzzyFind(\"{0}\", Scopes: [{1}]", Req.Query,
- llvm::join(Req.Scopes.begin(), Req.Scopes.end(), ",")));
+ log(Tracer.Ctx,
+ llvm::formatv("Code complete: fuzzyFind(\"{0}\", Scopes: [{1}]",
+ Req.Query,
+ llvm::join(Req.Scopes.begin(), Req.Scopes.end(), ",")));
// Run the query against the index.
- Incomplete |= !Opts.Index->fuzzyFind(
- Ctx, Req, [&](const Symbol &Sym) { ResultsBuilder.insert(Sym); });
+ Incomplete |=
+ !Opts.Index->fuzzyFind(Tracer.Ctx, Req, [&](const Symbol &Sym) {
+ ResultsBuilder.insert(Sym);
+ });
return std::move(ResultsBuilder).build();
}
@@ -882,6 +899,7 @@ private:
std::vector<std::pair<CompletionCandidate, CompletionItemScores>>
mergeResults(const std::vector<CodeCompletionResult> &SemaResults,
const SymbolSlab &IndexResults) {
+ trace::Span Tracer(Ctx, "Merge and score results");
// We only keep the best N results at any time, in "native" format.
TopN Top(Opts.Limit == 0 ? TopN::Unbounded : Opts.Limit);
llvm::DenseSet<const Symbol *> UsedIndexResults;
More information about the cfe-commits
mailing list