kbobyrev updated this revision to Diff 164848. kbobyrev marked 6 inline comments as done. kbobyrev added a comment.
Address few comments (not all of them for now, though). https://reviews.llvm.org/D51090 Files: clang-tools-extra/clangd/CMakeLists.txt clang-tools-extra/clangd/benchmarks/CMakeLists.txt clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp
Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp =================================================================== --- /dev/null +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -0,0 +1,124 @@ +//===--- 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; +const char *LLVMRootPath; + +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 BuildMem(benchmark::State &State) { + for (auto _ : State) + buildMem(); +} +BENCHMARK(BuildMem); + +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 BuildDex(benchmark::State &State) { + for (auto _ : State) + buildDex(); +} +BENCHMARK(BuildDex); + +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 + +int main(int argc, char *argv[]) { + if (argc < 4) { + llvm::errs() << "Usage: " << argv[0] + << " global-symbol-index.yaml fuzzy-find-requests.log " + "/path/to/llvm BENCHMARK_OPTIONS...\n"; + return -1; + } + IndexFilename = argv[1]; + LogFilename = argv[2]; + LLVMRootPath = argv[3]; + // Trim first two arguments of the benchmark invocation. + argv += 3; + argc -= 3; + ::benchmark::Initialize(&argc, argv); + ::benchmark::RunSpecifiedBenchmarks(); +} Index: clang-tools-extra/clangd/benchmarks/CMakeLists.txt =================================================================== --- /dev/null +++ clang-tools-extra/clangd/benchmarks/CMakeLists.txt @@ -0,0 +1,9 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../) + +add_benchmark(IndexBenchmark IndexBenchmark.cpp) + +target_link_libraries(IndexBenchmark + PRIVATE + clangDaemon + LLVMSupport + ) Index: clang-tools-extra/clangd/CMakeLists.txt =================================================================== --- clang-tools-extra/clangd/CMakeLists.txt +++ clang-tools-extra/clangd/CMakeLists.txt @@ -74,3 +74,7 @@ endif() add_subdirectory(tool) add_subdirectory(global-symbol-builder) + +if (LLVM_INCLUDE_BENCHMARKS) + add_subdirectory(benchmarks) +endif()
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits