diff options
| author | Sam McCall <sam.mccall@gmail.com> | 2018-01-30 17:20:54 +0000 |
|---|---|---|
| committer | Sam McCall <sam.mccall@gmail.com> | 2018-01-30 17:20:54 +0000 |
| commit | 2b780160cd3365742d6026de87c6366d1561a3b5 (patch) | |
| tree | 72d3153fd58d1fd65dbad4d0724c98cd3f24d82d /clang-tools-extra | |
| parent | 94ae3b2f9bf58ffe18130bccee0d74cae1421d7e (diff) | |
| download | bcm5719-llvm-2b780160cd3365742d6026de87c6366d1561a3b5.tar.gz bcm5719-llvm-2b780160cd3365742d6026de87c6366d1561a3b5.zip | |
[clangd] Trace code completion.
Context passing is a little messy, but will go away with TLS soon.
llvm-svn: 323792
Diffstat (limited to 'clang-tools-extra')
| -rw-r--r-- | clang-tools-extra/clangd/CodeComplete.cpp | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index f95d77b4966..66e8a475918 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -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 CodeCompleteOptions::getClangCompleteOpts() const { // 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; |

