diff --git a/CMakeLists.txt b/CMakeLists.txt index fd67e402b..19dd2bff6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,10 @@ string(REPLACE " " "_" ProjectId ${ProjectId}) # set project name project(${ProjectId}) +# setup CMake module path, defines path for include() and find_package() +# https://cmake.org/cmake/help/latest/variable/CMAKE_MODULE_PATH.html +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) + find_package(Threads REQUIRED) # flags @@ -83,20 +87,12 @@ set(fmt_static_lib ${fmt_source_dir}/fmt/libfmt.a) # yaml-cpp set(yaml_source_dir ${libs_dir}/yaml-cpp) set(yaml_static_lib ${yaml_source_dir}/libyaml-cpp.a) -# r3 -set(r3_source_dir ${libs_dir}/r3) -set(r3_static_lib ${r3_source_dir}/.libs/libr3.a) -# http-parser -set(http_parser_source_dir "${libs_dir}/http-parser") -set(http_parser_static_lib ${http_parser_source_dir}/libhttp_parser.a) -# libuv -set(libuv_source_dir ${libs_dir}/libuv) -set(libuv_static_lib ${libuv_source_dir}/.libs/libuv.a) -# rapidjson (C++ JSON encoder/decoder) -set(rapidjson_source_dir "${libs_dir}/rapidjson") # Catch (C++ Automated Test Cases in Headers) set(catch_source_dir "${libs_dir}/Catch") +# load cmake modules: cmake/*.cmake +include(gbenchmark) + # build memgraph's cypher grammar # copy grammar file to the build directory FILE(COPY ${include_dir}/query/language/cypher/cypher.y DESTINATION ${CMAKE_BINARY_DIR}) @@ -557,7 +553,7 @@ endif() # benchmark binaries if (BENCHMARK) - add_subdirectory(benchmark) + add_subdirectory(${PROJECT_SOURCE_DIR}/tests/benchmark) endif() # memgraph build name diff --git a/Makefile b/Makefile deleted file mode 100644 index 2fe9aaf0f..000000000 --- a/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -CXX=clang++ -CFLAGS=-std=c++1y -DNDEBUG -O2 -Wall -Wno-unknown-pragmas -CFLAGS_DEBUG=-std=c++1y -Wall -Wno-unknown-pragmas -g -LDFLAGS=-luv -lhttp_parser src/speedy/r3/.libs/libr3.a -L/usr/local/lib -lpcre -pthread - -INC=-I./src/ -I./src/speedy/ -I./src/speedy/rapidjson/include/ -I./libs/lexertl -SOURCES=src/memgraph.cpp -EXECUTABLE=build/memgraph - -all: $(EXECUTABLE) - -$(EXECUTABLE): $(SOURCES) - $(CXX) $(CFLAGS) $(SOURCES) -o $(EXECUTABLE) $(INC) $(LDFLAGS) - -debug: $(SOURCES) - $(CXX) $(CFLAGS_DEBUG) $(SOURCES) -o $(EXECUTABLE) $(INC) $(LDFLAGS) - -.PHONY: -clean: - rm -f memgraph - rm -f *.o diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt deleted file mode 100644 index 55ec3b973..000000000 --- a/benchmark/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -cmake_minimum_required(VERSION 3.1) - -project(memgraph_benchmark) - -add_executable(skiplist_benchmark skiplist.cpp) -target_link_libraries(skiplist_benchmark Threads::Threads) -target_link_libraries(skiplist_benchmark memgraph) -target_link_libraries(skiplist_benchmark ${fmt_static_lib}) diff --git a/benchmark/skiplist.cpp b/benchmark/skiplist.cpp deleted file mode 100644 index 776ed64f8..000000000 --- a/benchmark/skiplist.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include - -#include "data_structures/concurrent/skiplist.hpp" -#include "utils/time/timer.hpp" - -int main(void) -{ - SkipList skiplist; - - // insert a bunch of elements - { - int iters_no = 1000000; - auto skiplist_accessor = skiplist.access(); - Stopwatch sw; - - sw.Start(); - for (int i = 0; i < iters_no; ++i) - { - skiplist_accessor.insert(std::move(i)); - } - - std::cout << "Skiplist contains: " - << skiplist_accessor.size() - << " elements" - << std::endl; - } - - return 0; -} diff --git a/build.sh b/build.sh deleted file mode 100755 index 3ed9b71ac..000000000 --- a/build.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -while [[ $# > 1 ]] -do -key="$1" -case $key in - -t|--target) - target="$2" - shift - ;; -esac -shift -done - -if [[ -z $target ]]; then - target="all" -fi - -cd src/api && python link_resources.py && cd ../.. -make clean && make $target diff --git a/cmake/DownloadProject b/cmake/DownloadProject new file mode 160000 index 000000000..bbc6bef03 --- /dev/null +++ b/cmake/DownloadProject @@ -0,0 +1 @@ +Subproject commit bbc6bef03d194cf75492ef4881156f472cb78858 diff --git a/cmake/gbenchmark.cmake b/cmake/gbenchmark.cmake new file mode 100644 index 000000000..4e268140e --- /dev/null +++ b/cmake/gbenchmark.cmake @@ -0,0 +1,18 @@ +if (CMAKE_VERSION VERSION_LESS 3.2) + set(UPDATE_DISCONNECTED_IF_AVAILABLE "") +else() + set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1") +endif() + +include(DownloadProject/DownloadProject) + +download_project( + PROJ googlebenchmark + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG master + ${UPDATE_DISCONNECTED_IF_AVAILABLE} +) + +add_subdirectory(${googlebenchmark_SOURCE_DIR} ${googlebenchmark_BINARY_DIR}) + +include_directories("${googlebenchmark_SOURCE_DIR}/include") diff --git a/cmake/setup.sh b/cmake/setup.sh new file mode 100755 index 000000000..fd706978e --- /dev/null +++ b/cmake/setup.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# DownloadProject +git clone https://github.com/Crascit/DownloadProject +download_project_tag="master" +cd DownloadProject +git checkout ${download_project_tag} +cd .. diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 000000000..464090415 --- /dev/null +++ b/docs/index.md @@ -0,0 +1 @@ +# TODO diff --git a/init.sh b/init.sh new file mode 100755 index 000000000..a93b7bc3f --- /dev/null +++ b/init.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +if ! type "wget" > /dev/null; then + echo >&2 "Please install wget or set it in your path. Aborting."; exit 1; +fi + +if ! type "git" > /dev/null; then + echo >&2 "Please install git or set it in your path. Aborting."; exit 1; +fi + +if ! type "cmake" > /dev/null; then + echo >&2 "Please install cmake or set it in your path. Aborting."; exit 1; +fi + +cd cmake +./setup.sh +cd .. + +cd libs +./setup.sh +cd .. + +echo "DONE" diff --git a/libs/setup.sh b/libs/setup.sh index 7aeb82fbb..755f4d442 100755 --- a/libs/setup.sh +++ b/libs/setup.sh @@ -25,14 +25,6 @@ cmake . make cd .. -# http_parser -git clone https://github.com/nodejs/http-parser -http_parser_tag="4e382f96e6d3321538a78f2c7f9506d4e79b08d6" -cd http-parser -git checkout ${http_parser_tag} -make package -cd .. - # lemon mkdir lemon cd lemon @@ -49,33 +41,3 @@ lexertl_tag=7d4d36a357027df0e817453cc9cf948f71047ca9 cd lexertl git checkout ${lexertl_tag} cd .. - -# libuv -git clone https://github.com/libuv/libuv.git -libuv_tag="c82eedd0a76233f0894098853b5a0c307af27064" -cd libuv -git checkout ${libuv_tag} -./autogen.sh && ./configure && make -cd .. - -# rapidjson -git clone https://github.com/miloyip/rapidjson.git -rapidjson_tag=${3d5848a7cd3367c5cb451c6493165b7745948308} -cd rapidjson -git checkout ${rapidjson_tag} -cd .. - -# r3 - -# UBUNTU 16.04 -# TODO: automate this -# sudo apt-get -y install check libpcre3 libpcre3-dev libjemalloc-dev -# sudo apt-get -y install libjemalloc1 build-essential libtool automake -# sudo apt-get -y install autoconf pkg-config - -git clone https://github.com/c9s/r3.git -r3_tag=28726b27af3cd0a9d3166033c6619a9c7227cb48 -cd r3 -git checkout ${r3_tag} -./autogen.sh && ./configure && make -cd .. diff --git a/poc/profile.cpp b/poc/profile.cpp index 41d3ff5c4..9245feb7f 100644 --- a/poc/profile.cpp +++ b/poc/profile.cpp @@ -4,7 +4,9 @@ #include #include +// TODO: remove barrier #include "barrier/barrier.cpp" + #include "database/db.hpp" #include "database/db_accessor.hpp" #include "communication/bolt/v1/serialization/bolt_serializer.hpp" diff --git a/poc/queries/astar.cpp b/poc/queries/astar.cpp index d97dd6840..03f1930f6 100644 --- a/poc/queries/astar.cpp +++ b/poc/queries/astar.cpp @@ -3,7 +3,7 @@ #include #include -#include "query_engine/i_code_cpu.hpp" +#include "query/i_code_cpu.hpp" #include "storage/model/properties/all.hpp" #include "utils/memory/stack_allocator.hpp" diff --git a/tests/benchmark/CMakeLists.txt b/tests/benchmark/CMakeLists.txt new file mode 100644 index 000000000..ef94ffd2c --- /dev/null +++ b/tests/benchmark/CMakeLists.txt @@ -0,0 +1,17 @@ +find_package(Threads REQUIRED) + +file(GLOB_RECURSE ALL_BENCH_CPP *.cpp) + +foreach(ONE_BENCH_CPP ${ALL_BENCH_CPP}) + + get_filename_component(ONE_BENCH_EXEC ${ONE_BENCH_CPP} NAME_WE) + + # Avoid name collision + set(TARGET_NAME Bench_${ONE_BENCH_EXEC}) + + add_executable(${TARGET_NAME} ${ONE_BENCH_CPP}) + set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME ${ONE_BENCH_EXEC}) + target_link_libraries(${TARGET_NAME} benchmark ${CMAKE_THREAD_LIBS_INIT}) + add_test(${TARGET_NAME} ${ONE_BENCH_EXEC}) + +endforeach() diff --git a/tests/benchmark/example.cpp b/tests/benchmark/example.cpp new file mode 100644 index 000000000..4d31d8a29 --- /dev/null +++ b/tests/benchmark/example.cpp @@ -0,0 +1,34 @@ +#include "benchmark/benchmark_api.h" + +#include +#include + +static void BM_VectorInsert(benchmark::State &state) +{ + while (state.KeepRunning()) { + std::vector insertion_test; + for (int i = 0, i_end = state.range_x(); i < i_end; i++) { + insertion_test.push_back(i); + } + } +} + +// Register the function as a benchmark +BENCHMARK(BM_VectorInsert)->Range(8, 8 << 10); + +//~~~~~~~~~~~~~~~~ + +// Define another benchmark +static void BM_SetInsert(benchmark::State &state) +{ + while (state.KeepRunning()) { + std::set insertion_test; + for (int i = 0, i_end = state.range_x(); i < i_end; i++) { + insertion_test.insert(i); + } + } +} + +BENCHMARK(BM_SetInsert)->Range(8, 8 << 10); + +BENCHMARK_MAIN(); diff --git a/tests/benchmark/gbenchmark_example.cpp b/tests/benchmark/gbenchmark_example.cpp new file mode 100644 index 000000000..4d31d8a29 --- /dev/null +++ b/tests/benchmark/gbenchmark_example.cpp @@ -0,0 +1,34 @@ +#include "benchmark/benchmark_api.h" + +#include +#include + +static void BM_VectorInsert(benchmark::State &state) +{ + while (state.KeepRunning()) { + std::vector insertion_test; + for (int i = 0, i_end = state.range_x(); i < i_end; i++) { + insertion_test.push_back(i); + } + } +} + +// Register the function as a benchmark +BENCHMARK(BM_VectorInsert)->Range(8, 8 << 10); + +//~~~~~~~~~~~~~~~~ + +// Define another benchmark +static void BM_SetInsert(benchmark::State &state) +{ + while (state.KeepRunning()) { + std::set insertion_test; + for (int i = 0, i_end = state.range_x(); i < i_end; i++) { + insertion_test.insert(i); + } + } +} + +BENCHMARK(BM_SetInsert)->Range(8, 8 << 10); + +BENCHMARK_MAIN(); diff --git a/tests/manual/cypher_ast.cpp b/tests/manual/cypher_ast.cpp index ab5242033..a2d4773d6 100644 --- a/tests/manual/cypher_ast.cpp +++ b/tests/manual/cypher_ast.cpp @@ -7,9 +7,10 @@ #include "query/language/cypher/debug/tree_print.hpp" #include "utils/command_line/arguments.hpp" #include "utils/terminate_handler.hpp" +#include "utils/variadic/variadic.hpp" +using utils::println; using std::cout; -using std::endl; int main(int argc, char *argv[]) { @@ -21,15 +22,14 @@ int main(int argc, char *argv[]) // // query extraction auto queries = extract_queries(arguments); - for (auto &query : queries) { - cout << "QUERY: " << query << endl; + println("QUERY: ", query); auto print_visitor = new PrintVisitor(cout); cypher::Compiler compiler; auto tree = compiler.syntax_tree(query); tree.root->accept(*print_visitor); - cout << endl; + println(""); } return 0; diff --git a/tests/manual/query_hasher.cpp b/tests/manual/query_hasher.cpp index 99e7dbf47..e87c0f0eb 100644 --- a/tests/manual/query_hasher.cpp +++ b/tests/manual/query_hasher.cpp @@ -4,10 +4,9 @@ #include "query/preprocesor.hpp" #include "utils/command_line/arguments.hpp" #include "utils/type_discovery.hpp" +#include "utils/variadic/variadic.hpp" -using std::cout; -using std::cin; -using std::endl; +using utils::println; int main(int argc, char **argv) { @@ -22,17 +21,15 @@ int main(int argc, char **argv) for (auto &query : queries) { auto preprocessed = preprocessor.preprocess(query); - cout << "QUERY: " << query << endl; - cout << "STRIPPED QUERY: " << preprocessed.query << endl; - cout << "QUERY HASH: " << preprocessed.hash << endl; - cout << "PROPERTIES:" << endl; + println("QUERY: ", query); + println("STRIPPED QUERY: ", preprocessed.query); + println("QUERY HASH: ", preprocessed.hash); + println("PROPERTIES:"); for (auto property : preprocessed.arguments) { - cout << " " << property << endl; + println(" ", property); } - cout << "-----------------------------" << endl; + println("-----------------------------"); } - - return 0; }