[clang-tools-extra] r342026 - [clangd] Add index benchmarks

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 12 00:49:45 PDT 2018


Author: omtcyfz
Date: Wed Sep 12 00:49:44 2018
New Revision: 342026

URL: http://llvm.org/viewvc/llvm-project?rev=342026&view=rev
Log:
[clangd] Add index benchmarks

This patch introduces index benchmarks on top of the proposed LLVM
benchmark pull.

Reviewed By: sammccall, lebedev.ri

Differential Revision: https://reviews.llvm.org/D51090

Added:
    clang-tools-extra/trunk/clangd/benchmarks/
    clang-tools-extra/trunk/clangd/benchmarks/CMakeLists.txt
    clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp
    clang-tools-extra/trunk/test/clangd/Inputs/BenchmarkHeader.h
    clang-tools-extra/trunk/test/clangd/Inputs/BenchmarkSource.cpp
    clang-tools-extra/trunk/test/clangd/Inputs/requests.log
    clang-tools-extra/trunk/test/clangd/index-tools.test
Modified:
    clang-tools-extra/trunk/clangd/CMakeLists.txt
    clang-tools-extra/trunk/test/lit.cfg

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=342026&r1=342025&r2=342026&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Wed Sep 12 00:49:44 2018
@@ -75,3 +75,7 @@ endif()
 add_subdirectory(tool)
 add_subdirectory(global-symbol-builder)
 add_subdirectory(index/dex/dexp)
+
+if (LLVM_INCLUDE_BENCHMARKS)
+  add_subdirectory(benchmarks)
+endif()

Added: clang-tools-extra/trunk/clangd/benchmarks/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/benchmarks/CMakeLists.txt?rev=342026&view=auto
==============================================================================
--- clang-tools-extra/trunk/clangd/benchmarks/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clangd/benchmarks/CMakeLists.txt Wed Sep 12 00:49:44 2018
@@ -0,0 +1,9 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
+
+add_benchmark(IndexBenchmark IndexBenchmark.cpp)
+
+target_link_libraries(IndexBenchmark
+  PRIVATE
+  clangDaemon
+  LLVMSupport
+  )

Added: clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp?rev=342026&view=auto
==============================================================================
--- clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp (added)
+++ clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp Wed Sep 12 00:49:44 2018
@@ -0,0 +1,114 @@
+//===--- IndexBenchmark.cpp - Clangd index benchmarks -----------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../index/SymbolYAML.h"
+#include "../index/dex/Dex.h"
+#include "benchmark/benchmark.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Regex.h"
+#include <fstream>
+#include <streambuf>
+#include <string>
+
+const char *IndexFilename;
+const char *LogFilename;
+
+namespace clang {
+namespace clangd {
+namespace {
+
+std::unique_ptr<clang::clangd::SymbolIndex> buildMem() {
+  return clang::clangd::loadIndex(IndexFilename, {}, false);
+}
+
+std::unique_ptr<clang::clangd::SymbolIndex> buildDex() {
+  return clang::clangd::loadIndex(IndexFilename, {}, true);
+}
+
+// This function processes user-provided Log file with fuzzy find requests in
+// the following format:
+//
+// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"])
+//
+// It constructs vector of FuzzyFindRequests which is later used for the
+// benchmarks.
+std::vector<clang::clangd::FuzzyFindRequest> extractQueriesFromLogs() {
+  llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]");
+  llvm::SmallVector<llvm::StringRef, 200> Matches;
+  std::ifstream InputStream(LogFilename);
+  std::string Log((std::istreambuf_iterator<char>(InputStream)),
+                  std::istreambuf_iterator<char>());
+  llvm::StringRef Temporary(Log);
+  llvm::SmallVector<llvm::StringRef, 200> Strings;
+  Temporary.split(Strings, '\n');
+
+  clang::clangd::FuzzyFindRequest R;
+  R.MaxCandidateCount = 100;
+
+  llvm::SmallVector<llvm::StringRef, 200> CommaSeparatedValues;
+
+  std::vector<clang::clangd::FuzzyFindRequest> RealRequests;
+  for (auto Line : Strings) {
+    if (RequestMatcher.match(Line, &Matches)) {
+      R.Query = Matches[1];
+      CommaSeparatedValues.clear();
+      Line.split(CommaSeparatedValues, ',');
+      R.Scopes.clear();
+      for (auto C : CommaSeparatedValues) {
+        R.Scopes.push_back(C);
+      }
+      RealRequests.push_back(R);
+    }
+  }
+  return RealRequests;
+}
+
+static void MemQueries(benchmark::State &State) {
+  const auto Mem = buildMem();
+  const auto Requests = extractQueriesFromLogs();
+  for (auto _ : State)
+    for (const auto &Request : Requests)
+      Mem->fuzzyFind(Request, [](const Symbol &S) {});
+}
+BENCHMARK(MemQueries);
+
+static void DexQueries(benchmark::State &State) {
+  const auto Dex = buildDex();
+  const auto Requests = extractQueriesFromLogs();
+  for (auto _ : State)
+    for (const auto &Request : Requests)
+      Dex->fuzzyFind(Request, [](const Symbol &S) {});
+}
+BENCHMARK(DexQueries);
+
+} // namespace
+} // namespace clangd
+} // namespace clang
+
+// FIXME(kbobyrev): Add index building time benchmarks.
+// FIXME(kbobyrev): Add memory consumption "benchmarks" by manually measuring
+// in-memory index size and reporting it as time.
+// FIXME(kbobyrev): Create a logger wrapper to suppress debugging info printer.
+int main(int argc, char *argv[]) {
+  if (argc < 3) {
+    llvm::errs() << "Usage: " << argv[0]
+                 << " global-symbol-index.yaml fuzzy-find-requests.log "
+                    "BENCHMARK_OPTIONS...\n";
+    return -1;
+  }
+  IndexFilename = argv[1];
+  LogFilename = argv[2];
+  // Trim first two arguments of the benchmark invocation.
+  argv += 3;
+  argc -= 3;
+  ::benchmark::Initialize(&argc, argv);
+  ::benchmark::RunSpecifiedBenchmarks();
+}

Added: clang-tools-extra/trunk/test/clangd/Inputs/BenchmarkHeader.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/Inputs/BenchmarkHeader.h?rev=342026&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clangd/Inputs/BenchmarkHeader.h (added)
+++ clang-tools-extra/trunk/test/clangd/Inputs/BenchmarkHeader.h Wed Sep 12 00:49:44 2018
@@ -0,0 +1,19 @@
+namespace clang {
+namespace clangd {
+namespace dex {
+class Dex;
+} // namespace dex
+} // namespace clangd
+} // namespace clang
+
+namespace llvm {
+namespace sys {
+
+int getHostNumPhysicalCores();
+
+} // namespace sys
+} // namespace llvm
+
+namespace {
+int Variable;
+} // namespace

Added: clang-tools-extra/trunk/test/clangd/Inputs/BenchmarkSource.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/Inputs/BenchmarkSource.cpp?rev=342026&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clangd/Inputs/BenchmarkSource.cpp (added)
+++ clang-tools-extra/trunk/test/clangd/Inputs/BenchmarkSource.cpp Wed Sep 12 00:49:44 2018
@@ -0,0 +1 @@
+#include "BenchmarkHeader.h"

Added: clang-tools-extra/trunk/test/clangd/Inputs/requests.log
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/Inputs/requests.log?rev=342026&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clangd/Inputs/requests.log (added)
+++ clang-tools-extra/trunk/test/clangd/Inputs/requests.log Wed Sep 12 00:49:44 2018
@@ -0,0 +1,5 @@
+V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::])
+V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::])
+V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::])
+V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::])
+V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[])

Added: clang-tools-extra/trunk/test/clangd/index-tools.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/index-tools.test?rev=342026&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clangd/index-tools.test (added)
+++ clang-tools-extra/trunk/test/clangd/index-tools.test Wed Sep 12 00:49:44 2018
@@ -0,0 +1,2 @@
+# RUN: global-symbol-builder %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index
+# RUN: %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01

Modified: clang-tools-extra/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/lit.cfg?rev=342026&r1=342025&r2=342026&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/lit.cfg (original)
+++ clang-tools-extra/trunk/test/lit.cfg Wed Sep 12 00:49:44 2018
@@ -137,3 +137,9 @@ if config.clang_staticanalyzer:
 else:
     # exclude the clang-tidy test directory
     config.excludes.append('clang-tidy')
+
+clangd_benchmarks_dir = os.path.join(os.path.dirname(config.clang_tools_dir),
+                                     "tools", "clang", "tools", "extra",
+                                     "clangd", "benchmarks")
+config.substitutions.append(('%clangd-benchmark-dir',
+                             '%s' % (clangd_benchmarks_dir)))




More information about the cfe-commits mailing list