diff --git a/.travis.yml b/.travis.yml index a049d7a..0e1f031 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,16 +17,20 @@ branches: # Install dependencies before_install: - sudo apt-get update - - sudo apt-get install -y --install-recommends docutils-common libelfin-dev nodejs npm + - sudo apt-get install -y --install-recommends build-essential cmake ninja-build docutils-common nodejs npm + - sudo pip install conan # Make and install install: - - make - - sudo make install + - mkdir build && cd build + - conan install .. -s compiler.libcxx=libstdc++11 -s compiler.cppstd=11 --build=outdated + - cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_BENCHMARKS=ON -G Ninja + - ninja + - sudo ninja install -# Run the make check target (add tests later) +# Run tests script: - - make check USE_SYSTEM_COZ=1 + - CTEST_OUTPUT_ON_FAILURE=1 ninja test # Test the Rust support as well matrix: diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..37d1cf6 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 3.4) +project(coz VERSION 0.2.2 LANGUAGES C CXX) + +enable_testing() + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CONAN_CMAKE_SILENT_OUTPUT ON) + +list(APPEND CMAKE_MODULE_PATH ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake) + +find_package(Threads REQUIRED) +find_package(libelfin REQUIRED) + +add_compile_options(-gdwarf-3) + +option(INSTALL_COZ "Enable installation of coz. (Projects embedding coz may want to turn this OFF.)" ON) + +if(INSTALL_COZ) + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + install(PROGRAMS coz DESTINATION bin) + install(FILES LICENSE.md DESTINATION licenses) + configure_package_config_file( + cmake/coz-profilerConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/coz-profilerConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/coz-profilerConfigVersion.cmake + COMPATIBILITY ExactVersion) # SameMajor only applies to versions >= 1.0. Versions 0.x have to match exactly according to semver.org + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/coz-profilerConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/coz-profilerConfigVersion.cmake + DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake) + install( + EXPORT coz-profilerTargets + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake + NAMESPACE coz::) +endif() + +add_subdirectory(libcoz) + +option(BUILD_BENCHMARKS "Build benchmarks" OFF) +if(BUILD_BENCHMARKS) + if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")) + message(FATAL_ERROR "Build benchmarks with debug information - use Debug or RelWithDebInfo") + endif() + find_package(SQLite3 REQUIRED) + find_package(BZip2 REQUIRED) + add_subdirectory(benchmarks) +endif() + diff --git a/Makefile b/Makefile deleted file mode 100644 index a66cbd9..0000000 --- a/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -ROOT := . -DIRS := libcoz viewer - -include $(ROOT)/common.mk - -update-gh-pages:: all - @echo $(LOG_PREFIX) Pushing profiler viewer to gh-pages branch $(LOG_SUFFIX) - @git push origin `git subtree split --prefix viewer master 2> /dev/null`:gh-pages - -install:: all - @echo $(LOG_PREFIX) Installing coz to prefix $(prefix) $(LOG_SUFFIX) - @sed 's@destdir@"${DESTDIR}${prefix}"@g' coz-profilerConfig.cmake.in > coz-profilerConfig.cmake - @$(INSTALL) -D coz $(DESTDIR)$(bindir)/coz - @$(INSTALL) -D coz-profilerConfig.cmake $(DESTDIR)$(pkglibdir)/coz-profilerConfig.cmake - @$(INSTALL) -D libcoz/libcoz.so $(DESTDIR)$(pkglibdir)/libcoz.so - @$(INSTALL) -D include/coz.h $(DESTDIR)$(incdir)/coz.h - @mkdir -p $(DESTDIR)$(man1dir) - @$(RST2MAN) docs/coz.rst $(DESTDIR)$(man1dir)/coz.1 - -bench bench_small bench_large:: - @$(MAKE) -C benchmarks $@ - -check:: - @$(MAKE) -C benchmarks check diff --git a/README.md b/README.md index f411ba4..0d41605 100644 --- a/README.md +++ b/README.md @@ -32,16 +32,20 @@ To build Coz from source, you will need: - A copy of the source code for this project - A compiler with C++0x support (clang++ or g++) - A Python interpreter (Python 3.x is required) -- The libelfin development libraries (Use release 0.2 or the latest from . _Version 0.3 does not work_.) +- The libelfin development libraries (Use latest from . _Version 0.3 does not work_.) - The `rst2man` command (for building documentation) - NodeJS and npm (for building the profiler viewer) -Once you have all dependencies in place, run `make` to build Coz. On Debian-based distributions, the following commands should take care of the entire process: +Once you have all dependencies in place, build Coz with CMake. On Debian-based distributions, the following commands should take care of the entire process: ``` -$ sudo apt-get install clang docutils-common libelfin-dev nodejs npm python3 +$ sudo apt-get install build-essential cmake docutils-common libelfin-dev nodejs npm python3 +$ pip install conan --user $ git clone https://github.com/plasma-umass/coz.git $ cd coz +$ mkdir build && cd build +$ conan install .. +$ cmake .. $ make ``` diff --git a/benchmark.mk b/benchmark.mk deleted file mode 100644 index 4e334d9..0000000 --- a/benchmark.mk +++ /dev/null @@ -1,25 +0,0 @@ -include $(ROOT)/common.mk - -LIBS += -Wl,--push-state,--no-as-needed -ldl -Wl,--pop-state - -RECURSIVE_TARGETS += bench bench_large bench_small - -ifeq ($(USE_SYSTEM_COZ),) -CFLAGS += -I$(ROOT)/include -CXXFLAGS += -I$(ROOT)/include -endif - -# Set up build targets for benchmarking -large_inputs: - -small_inputs: - -bench:: bench_large - -bench_large:: $(OTHER_TARGETS) large_inputs - @echo $(LOG_PREFIX) Running benchmark on large input $(LOG_SUFFIX) - $(COZ) run $(COZ_ARGS) --- ./$< $(BENCH_LARGE_ARGS) - -bench_small:: $(OTHER_TARGETS) small_inputs - @echo $(LOG_PREFIX) Running benchmark on small input $(LOG_SUFFIX) - $(COZ) run $(COZ_ARGS) --- ./$< $(BENCH_SMALL_ARGS) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt new file mode 100644 index 0000000..7182564 --- /dev/null +++ b/benchmarks/CMakeLists.txt @@ -0,0 +1,18 @@ +function(add_coz_run_target name) + set(one_value_args "") + set(multi_value_args COMMAND) + set(options "") + cmake_parse_arguments(COZ_RUN "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) + + add_custom_target(${name} + COMMENT "Running coz for ${name}" + COMMAND ${PROJECT_SOURCE_DIR}/coz run --- ${COZ_RUN_COMMAND} + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS coz) +endfunction() + +file(GLOB cmake_files */CMakeLists.txt) +foreach(filepath ${cmake_files}) + get_filename_component(dir ${filepath} DIRECTORY) + add_subdirectory(${dir}) +endforeach(filepath) diff --git a/benchmarks/Makefile b/benchmarks/Makefile deleted file mode 100644 index 21f6ea5..0000000 --- a/benchmarks/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -ROOT := .. -DIRS := histogram kmeans linear_regression matrix_multiply \ - pbzip2 pca producer_consumer string_match sqlite \ - sqlite-modified toy word_count - -include $(ROOT)/common.mk - -check:: - @$(MAKE) -C kmeans - @$(RM) -f profile.coz - ../coz run --- kmeans/kmeans - @grep -q "time=" profile.coz || { echo failure: valid profile.coz not generated; exit 1; } - @grep -q "throughput-point" profile.coz || { echo failure: throughput-point not found in profile; exit 1; } - @grep -q -P "samples\tlocation=" profile.coz || { echo failure: samples not found in profile; exit 1; } - @echo success: benchmark generated valid profile.coz - @$(RM) -f profile.coz diff --git a/benchmarks/check-output.sh b/benchmarks/check-output.sh new file mode 100755 index 0000000..9d50b40 --- /dev/null +++ b/benchmarks/check-output.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e +rm -f profile.coz + +$@ + +grep -q "time=" profile.coz || { echo failure: valid profile.coz not generated; exit 1; } +grep -q "throughput-point" profile.coz || { echo failure: throughput-point not found in profile; exit 1; } +grep -q -P "samples\tlocation=" profile.coz || { echo failure: samples not found in profile; exit 1; } +echo success: benchmark generated valid profile.coz diff --git a/benchmarks/histogram/CMakeLists.txt b/benchmarks/histogram/CMakeLists.txt new file mode 100644 index 0000000..59c48d7 --- /dev/null +++ b/benchmarks/histogram/CMakeLists.txt @@ -0,0 +1,23 @@ +add_executable(histogram histogram-pthread.c) +target_link_libraries(histogram PRIVATE coz-instrumentation pthread) + +add_custom_command( + COMMENT "Downloading histogram inputs" + OUTPUT + histogram_datafiles/small.bmp + histogram_datafiles/large.bmp + COMMAND wget -cq http://csl.stanford.edu/~christos/data/histogram.tar.gz + COMMAND tar xzf histogram.tar.gz) + +add_custom_target(histogram_datafiles + DEPENDS + histogram_datafiles/small.bmp + histogram_datafiles/large.bmp) + +add_coz_run_target(run_histogram_large + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/histogram_datafiles/large.bmp) +add_dependencies(run_histogram_large histogram_datafiles) + +add_coz_run_target(run_histogram_small + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/histogram_datafiles/small.bmp) +add_dependencies(run_histogram_small histogram_datafiles) diff --git a/benchmarks/histogram/Makefile b/benchmarks/histogram/Makefile deleted file mode 100644 index ef0e61c..0000000 --- a/benchmarks/histogram/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -ROOT := ../.. -TARGETS := histogram -LIBS := -lpthread -CFLAGS := -g -O2 - -include $(ROOT)/benchmark.mk - -BENCH_LARGE_ARGS := histogram_datafiles/large.bmp -BENCH_SMALL_ARGS := histogram_datafiles/small.bmp - -large_inputs: histogram_datafiles/large.bmp - -small_inputs: histogram_datafiles/small.bmp - -histogram_datafiles/%: - @echo $(LOG_PREFIX) Downloading histogram inputs $(LOG_SUFFIX) - @wget -c http://csl.stanford.edu/~christos/data/histogram.tar.gz - @echo $(LOG_PREFIX) Unpacking histogram inputs $(LOG_SUFFIX) - @tar xzf histogram.tar.gz - @rm histogram.tar.gz diff --git a/benchmarks/kmeans/CMakeLists.txt b/benchmarks/kmeans/CMakeLists.txt new file mode 100644 index 0000000..5ffce05 --- /dev/null +++ b/benchmarks/kmeans/CMakeLists.txt @@ -0,0 +1,10 @@ +add_executable(kmeans kmeans-pthread.c) +target_link_libraries(kmeans PRIVATE coz-instrumentation pthread) + +add_coz_run_target(run_kmeans_small COMMAND $ -d 3 -c 100 -p 10000 -s 100) +add_coz_run_target(run_kmeans_large COMMAND $ -d 3 -c 100 -p 100000 -s 1000) + +add_test( + NAME test_run_kmeans + COMMAND ${PROJECT_SOURCE_DIR}/benchmarks/check-output.sh ${PROJECT_SOURCE_DIR}/coz run --- $ + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) diff --git a/benchmarks/kmeans/Makefile b/benchmarks/kmeans/Makefile deleted file mode 100644 index 885c517..0000000 --- a/benchmarks/kmeans/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -ROOT := ../.. -TARGETS := kmeans -LIBS := -lpthread -CFLAGS := -g -O2 - -include $(ROOT)/benchmark.mk - -BENCH_LARGE_ARGS := -d 3 -c 100 -p 100000 -s 1000 -BENCH_SMALL_ARGS := -d 3 -c 100 -p 10000 -s 100 diff --git a/benchmarks/linear_regression/CMakeLists.txt b/benchmarks/linear_regression/CMakeLists.txt new file mode 100644 index 0000000..6201b64 --- /dev/null +++ b/benchmarks/linear_regression/CMakeLists.txt @@ -0,0 +1,23 @@ +add_executable(linear_regression linear_regression-pthread.c) +target_link_libraries(linear_regression PRIVATE coz-instrumentation pthread) + +add_custom_command( + COMMENT "Downloading linear_regression inputs" + OUTPUT + linear_regression_datafiles/key_file_500MB.txt + linear_regression_datafiles/key_file_50MB.txt + COMMAND wget -cq http://csl.stanford.edu/~christos/data/linear_regression.tar.gz + COMMAND tar xzf linear_regression.tar.gz) + +add_custom_target(linear_regression_datafiles + DEPENDS + linear_regression_datafiles/key_file_500MB.txt + linear_regression_datafiles/key_file_50MB.txt) + +add_coz_run_target(run_linear_regression_large + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/linear_regression_datafiles/key_file_500MB.txt) +add_dependencies(run_linear_regression_large linear_regression_datafiles) + +add_coz_run_target(run_linear_regression_small + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/linear_regression_datafiles/key_file_50MB.txt) +add_dependencies(run_linear_regression_small linear_regression_datafiles) diff --git a/benchmarks/linear_regression/Makefile b/benchmarks/linear_regression/Makefile deleted file mode 100644 index de9e1d4..0000000 --- a/benchmarks/linear_regression/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -ROOT := ../.. -TARGETS := linear_regression -LIBS := -lpthread -CFLAGS := -g -O2 - -include $(ROOT)/benchmark.mk - -BENCH_LARGE_ARGS := linear_regression_datafiles/key_file_500MB.txt -BENCH_SMALL_ARGS := linear_regression_datafiles/key_file_50MB.txt - -large_inputs: linear_regression_datafiles/key_file_500MB.txt - -small_inputs: linear_regression_datafiles/key_file_50MB.txt - -linear_regression_datafiles/%: - @echo $(LOG_PREFIX) Downloading linear_regression inputs $(LOG_SUFFIX) - @wget -c http://csl.stanford.edu/~christos/data/linear_regression.tar.gz - @echo $(LOG_PREFIX) Unpacking linear_regression inputs $(LOG_SUFFIX) - @tar xzf linear_regression.tar.gz - @rm linear_regression.tar.gz diff --git a/benchmarks/matrix_multiply/CMakeLists.txt b/benchmarks/matrix_multiply/CMakeLists.txt new file mode 100644 index 0000000..c3f8184 --- /dev/null +++ b/benchmarks/matrix_multiply/CMakeLists.txt @@ -0,0 +1,31 @@ +add_executable(matrix_multiply matrix_multiply-pthread.c) +target_link_libraries(matrix_multiply PRIVATE coz-instrumentation pthread) +target_compile_options(matrix_multiply PRIVATE -Wno-format) + +add_custom_command( + COMMENT "Generating bench input" + OUTPUT ${PROJECT_BINARY_DIR}/matrix_file_A_1000.txt ${PROJECT_BINARY_DIR}/matrix_file_B_1000.txt + BYPRODUCTS ${PROJECT_BINARY_DIR}/matrix_file_out_pthreads_1000.txt + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/matrix_multiply 1000 -create_files > /dev/null + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS matrix_multiply) +add_custom_target(matrix_multiply_large_datafiles + DEPENDS ${PROJECT_BINARY_DIR}/matrix_file_A_1000.txt ${PROJECT_BINARY_DIR}/matrix_file_B_1000.txt) + +add_custom_command( + COMMENT "Generating test input" + OUTPUT ${PROJECT_BINARY_DIR}/matrix_file_A_400.txt ${PROJECT_BINARY_DIR}/matrix_file_B_400.txt + BYPRODUCTS ${PROJECT_BINARY_DIR}/matrix_file_out_pthreads_400.txt + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/matrix_multiply 400 -create_files > /dev/null + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS matrix_multiply) +add_custom_target(matrix_multiply_small_datafiles + DEPENDS ${PROJECT_BINARY_DIR}/matrix_file_A_400.txt ${PROJECT_BINARY_DIR}/matrix_file_B_400.txt) + +add_coz_run_target(run_matrix_multiply_large + COMMAND $ 1000 > /dev/null) +add_dependencies(run_matrix_multiply_large matrix_multiply_large_datafiles) + +add_coz_run_target(run_matrix_multiply_small + COMMAND $ 400 > /dev/null) +add_dependencies(run_matrix_multiply_small matrix_multiply_small_datafiles) diff --git a/benchmarks/matrix_multiply/Makefile b/benchmarks/matrix_multiply/Makefile deleted file mode 100644 index 8ada893..0000000 --- a/benchmarks/matrix_multiply/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -ROOT := ../.. -TARGETS := matrix_multiply -LIBS := -lpthread -CFLAGS := -g -O2 -Wno-format - -include $(ROOT)/benchmark.mk - -BENCH_LARGE_ARGS := 1000 > /dev/null -BENCH_SMALL_ARGS := 400 > /dev/null - -large_inputs: .input_large - -small_inputs: .input_small - -.input_large: matrix_multiply - @echo $(LOG_PREFIX) Generating bench input $(LOG_SUFFIX) - @./matrix_multiply 1000 1000 > /dev/null - @rm -f .input_small - @touch .input_large - -.input_small: matrix_multiply - @echo $(LOG_PREFIX) Generating test input $(LOG_SUFFIX) - @./matrix_multiply 400 400 > /dev/null - @rm -f .input_large - @touch .input_small diff --git a/benchmarks/matrix_multiply/matrix_multiply-pthread.c b/benchmarks/matrix_multiply/matrix_multiply-pthread.c index c02de87..fc37201 100644 --- a/benchmarks/matrix_multiply/matrix_multiply-pthread.c +++ b/benchmarks/matrix_multiply/matrix_multiply-pthread.c @@ -171,7 +171,7 @@ int main(int argc, char *argv[]) { char * fdata_A, *fdata_B; int matrix_len; struct stat finfo_A, finfo_B; - char * fname_A, *fname_B,*fname_out; + char fname_A[512], fname_B[512], fname_out[512]; int *matrix_A_ptr, *matrix_B_ptr; struct timeval starttime,endtime; @@ -181,14 +181,14 @@ int main(int argc, char *argv[]) { // Make sure a filename is specified if (argv[1] == NULL) { - printf("USAGE: %s [side of matrix] [size of Row block]\n", argv[0]); + printf("USAGE: %s size_of_matrix [-create_files]\n", argv[0]); exit(1); } - fname_A = "matrix_file_A.txt"; - fname_B = "matrix_file_B.txt"; - fname_out = "matrix_file_out_pthreads.txt"; CHECK_ERROR ( (matrix_len = atoi(argv[1])) < 0); + sprintf(fname_A, "matrix_file_A_%d.txt", matrix_len); + sprintf(fname_B, "matrix_file_B_%d.txt", matrix_len); + sprintf(fname_out, "matrix_file_out_pthreads_%d.txt", matrix_len); file_size = ((matrix_len*matrix_len))*sizeof(int); fprintf(stderr, "***** file size is %d\n", file_size); diff --git a/benchmarks/pbzip2/CMakeLists.txt b/benchmarks/pbzip2/CMakeLists.txt new file mode 100644 index 0000000..b191307 --- /dev/null +++ b/benchmarks/pbzip2/CMakeLists.txt @@ -0,0 +1,14 @@ +add_executable(pbzip2 BZ2StreamScanner.cpp ErrorContext.cpp pbzip2.cpp) +target_link_libraries(pbzip2 PRIVATE BZip2::BZip2 coz-instrumentation pthread) +target_compile_options(pbzip2 PRIVATE -Wno-format) + +set(datafiles ${CMAKE_CURRENT_BINARY_DIR}/../linear_regression/linear_regression_datafiles) + +add_coz_run_target(run_pbzip2_large + COMMAND $ -c < ${datafiles}/key_file_500MB.txt > ${CMAKE_CURRENT_BINARY_DIR}/key_file_500MB_compressed.bz2) +add_dependencies(run_pbzip2_large linear_regression_datafiles) + +add_coz_run_target(run_pbzip2_small + COMMAND $ -c < ${datafiles}/key_file_50MB.txt > ${CMAKE_CURRENT_BINARY_DIR}/key_file_50MB_compressed.bz2) +add_dependencies(run_pbzip2_small linear_regression_datafiles) + diff --git a/benchmarks/pbzip2/Makefile b/benchmarks/pbzip2/Makefile deleted file mode 100644 index b1e3eb7..0000000 --- a/benchmarks/pbzip2/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -ROOT := ../.. -TARGETS := pbzip2 -LIBS := -lbz2 -lpthread -CXXFLAGS := -g -O2 -Wno-format -Ibzip2-1.0.6 -LDFLAGS := -Lbzip2-1.0.6 - -include $(ROOT)/benchmark.mk - -# pbzip2 depends on the libbz2 library -pbzip2: bzip2-1.0.6/libbz2.a - -# Download and build libbz2 -bzip2-1.0.6/libbz2.a: - @echo $(LOG_PREFIX) Downloading libbz2 $(LOG_SUFFIX) - @wget -c https://sourceware.org/pub/bzip2/bzip2-1.0.6.tar.gz - @echo $(LOG_PREFIX) Unpacking libbz2 $(LOG_SUFFIX) - @tar xzf bzip2-1.0.6.tar.gz - @echo $(LOG_PREFIX) Building libbz2 $(LOG_SUFFIX) - @cd bzip2-1.0.6; $(MAKE) CFLAGS=-g > /dev/null - @rm bzip2-1.0.6.tar.gz - -BENCH_LARGE_ARGS := -c < data/key_file_500MB.txt > data/key_file_500MB_compressed.bz2 -BENCH_SMALL_ARGS := -c < data/key_file_50MB.txt > data/key_file_50MB_compressed.bz2 - -large_inputs: data/key_file_500MB.txt - -small_inputs: data/key_file_50MB.txt - -data/%: - @echo $(LOG_PREFIX) Downloading pbzip2 inputs $(LOG_SUFFIX) - @wget -c http://csl.stanford.edu/~christos/data/linear_regression.tar.gz - @echo $(LOG_PREFIX) Unpacking pbzip2 inputs $(LOG_SUFFIX) - @tar xzf linear_regression.tar.gz - @rm linear_regression.tar.gz - @mv linear_regression_datafiles data diff --git a/benchmarks/pca/CMakeLists.txt b/benchmarks/pca/CMakeLists.txt new file mode 100644 index 0000000..d898777 --- /dev/null +++ b/benchmarks/pca/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(pca pca-pthread.c) +target_link_libraries(pca PRIVATE coz-instrumentation pthread) + +add_coz_run_target(run_pca COMMAND $ > /dev/null) diff --git a/benchmarks/pca/Makefile b/benchmarks/pca/Makefile deleted file mode 100644 index 5c4e5dc..0000000 --- a/benchmarks/pca/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -ROOT := ../.. -TARGETS := pca -LIBS := -lpthread -CFLAGS := -g -O2 - -include $(ROOT)/benchmark.mk - -BENCH_LARGE_ARGS := > /dev/null -BENCH_SMALL_ARGS := > /dev/null diff --git a/benchmarks/producer_consumer/CMakeLists.txt b/benchmarks/producer_consumer/CMakeLists.txt new file mode 100644 index 0000000..4ab3a77 --- /dev/null +++ b/benchmarks/producer_consumer/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(producer_consumer producer_consumer.cpp) +target_link_libraries(producer_consumer PRIVATE coz-instrumentation pthread) + +add_coz_run_target(run_producer_consumer COMMAND $) diff --git a/benchmarks/producer_consumer/Makefile b/benchmarks/producer_consumer/Makefile deleted file mode 100644 index c3f636a..0000000 --- a/benchmarks/producer_consumer/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -ROOT := ../.. -TARGETS := producer_consumer -LIBS := -lpthread -CXXFLAGS := -g -O2 - -include $(ROOT)/benchmark.mk diff --git a/benchmarks/sqlite-modified/CMakeLists.txt b/benchmarks/sqlite-modified/CMakeLists.txt new file mode 100644 index 0000000..0d178b3 --- /dev/null +++ b/benchmarks/sqlite-modified/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable(sqlite-bench-modified main.c sqlite3.c) +target_compile_definitions(sqlite-bench-modified PRIVATE SQLITE_THREADSAFE=2) +target_link_libraries(sqlite-bench-modified PRIVATE SQLite::SQLite3 coz-instrumentation pthread) + +add_coz_run_target(run_sqlite_bench_modified COMMAND $) diff --git a/benchmarks/sqlite-modified/Makefile b/benchmarks/sqlite-modified/Makefile deleted file mode 100644 index bc5994a..0000000 --- a/benchmarks/sqlite-modified/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -ROOT := ../.. -TARGETS := sqlite-bench -LIBS := -lpthread -ldl -CFLAGS := -g -O2 -DSQLITE_THREADSAFE=2 -I. - -include $(ROOT)/benchmark.mk diff --git a/benchmarks/sqlite/CMakeLists.txt b/benchmarks/sqlite/CMakeLists.txt new file mode 100644 index 0000000..d3a1fba --- /dev/null +++ b/benchmarks/sqlite/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable(sqlite-bench main.c sqlite3.c) +target_compile_definitions(sqlite-bench PRIVATE SQLITE_THREADSAFE=2) +target_link_libraries(sqlite-bench PRIVATE SQLite::SQLite3 coz-instrumentation pthread) + +add_coz_run_target(run_sqlite_bench COMMAND $) diff --git a/benchmarks/sqlite/Makefile b/benchmarks/sqlite/Makefile deleted file mode 100644 index bc5994a..0000000 --- a/benchmarks/sqlite/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -ROOT := ../.. -TARGETS := sqlite-bench -LIBS := -lpthread -ldl -CFLAGS := -g -O2 -DSQLITE_THREADSAFE=2 -I. - -include $(ROOT)/benchmark.mk diff --git a/benchmarks/string_match/CMakeLists.txt b/benchmarks/string_match/CMakeLists.txt new file mode 100644 index 0000000..0eec4e3 --- /dev/null +++ b/benchmarks/string_match/CMakeLists.txt @@ -0,0 +1,23 @@ +add_executable(string_match string_match-pthread.c) +target_link_libraries(string_match PRIVATE coz-instrumentation pthread) + +add_custom_command( + COMMENT "Downloading string_match inputs" + OUTPUT + string_match_datafiles/key_file_500MB.txt + string_match_datafiles/key_file_50MB.txt + COMMAND wget -cq http://csl.stanford.edu/~christos/data/string_match.tar.gz + COMMAND tar xzf string_match.tar.gz) + +add_custom_target(string_match_datafiles + DEPENDS + string_match_datafiles/key_file_500MB.txt + string_match_datafiles/key_file_50MB.txt) + +add_coz_run_target(run_string_match_large + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/string_match_datafiles/key_file_500MB.txt) +add_dependencies(run_string_match_large string_match_datafiles) + +add_coz_run_target(run_string_match_small + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/string_match_datafiles/key_file_50MB.txt) +add_dependencies(run_string_match_small string_match_datafiles) diff --git a/benchmarks/string_match/Makefile b/benchmarks/string_match/Makefile deleted file mode 100644 index 9f9d038..0000000 --- a/benchmarks/string_match/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -ROOT := ../.. -TARGETS := string_match -LIBS := -lpthread -CFLAGS := -g -O2 - -include $(ROOT)/benchmark.mk - -BENCH_LARGE_ARGS := string_match_datafiles/key_file_500MB.txt > /dev/null -BENCH_SMALL_ARGS := string_match_datafiles/key_file_50MB.txt > /dev/null - -large_inputs: string_match_datafiles/key_file_500MB.txt - -small_inputs: string_match_datafiles/key_file_50MB.txt - -string_match_datafiles/%: - @echo $(LOG_PREFIX) Downloading string_match inputs $(LOG_SUFFIX) - @wget -c http://csl.stanford.edu/~christos/data/string_match.tar.gz - @echo $(LOG_PREFIX) Unpacking string_match inputs $(LOG_SUFFIX) - @tar xzf string_match.tar.gz - @rm string_match.tar.gz diff --git a/benchmarks/toy/CMakeLists.txt b/benchmarks/toy/CMakeLists.txt new file mode 100644 index 0000000..eb4112c --- /dev/null +++ b/benchmarks/toy/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(toy toy.cpp) +target_link_libraries(toy PRIVATE coz-instrumentation pthread) + +add_coz_run_target(run_toy COMMAND $) diff --git a/benchmarks/toy/Makefile b/benchmarks/toy/Makefile deleted file mode 100644 index 1611722..0000000 --- a/benchmarks/toy/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -ROOT := ../.. -TARGETS := toy -LIBS := -lpthread -CXXFLAGS := --std=c++11 -g -O2 - -include $(ROOT)/benchmark.mk diff --git a/benchmarks/word_count/CMakeLists.txt b/benchmarks/word_count/CMakeLists.txt new file mode 100644 index 0000000..3d4a38e --- /dev/null +++ b/benchmarks/word_count/CMakeLists.txt @@ -0,0 +1,23 @@ +add_executable(word_count sort-pthread.c word_count-pthread.c) +target_link_libraries(word_count PRIVATE coz-instrumentation pthread) + +add_custom_command( + COMMENT "Downloading word_count inputs" + OUTPUT + word_count_datafiles/word_100MB.txt + word_count_datafiles/word_10MB.txt + COMMAND wget -cq http://csl.stanford.edu/~christos/data/word_count.tar.gz + COMMAND tar xzf word_count.tar.gz) + +add_custom_target(word_count_datafiles + DEPENDS + word_count_datafiles/word_100MB.txt + word_count_datafiles/word_10MB.txt) + +add_coz_run_target(run_word_count_large + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/word_count_datafiles/word_100MB.txt) +add_dependencies(run_word_count_large word_count_datafiles) + +add_coz_run_target(run_word_count_small + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/word_count_datafiles/word_10MB.txt) +add_dependencies(run_word_count_small word_count_datafiles) diff --git a/benchmarks/word_count/Makefile b/benchmarks/word_count/Makefile deleted file mode 100644 index 58d92e6..0000000 --- a/benchmarks/word_count/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -ROOT := ../.. -TARGETS := word_count -LIBS := -lpthread -CFLAGS := -g -O2 - -include $(ROOT)/benchmark.mk - -BENCH_LARGE_ARGS := word_count_datafiles/word_100MB.txt -BENCH_SMALL_ARGS := word_count_datafiles/word_10MB.txt - -large_inputs: word_count_datafiles/word_100MB.txt - -small_inputs: word_count_datafiles/word_10MB.txt - -word_count_datafiles/%: - @echo $(LOG_PREFIX) Downloading word_count inputs $(LOG_SUFFIX) - @wget -c http://csl.stanford.edu/~christos/data/word_count.tar.gz - @echo $(LOG_PREFIX) Unpacking word_count inputs $(LOG_SUFFIX) - @tar xzf word_count.tar.gz - @rm word_count.tar.gz diff --git a/cmake/Findlibelfin.cmake b/cmake/Findlibelfin.cmake new file mode 100644 index 0000000..8acf35e --- /dev/null +++ b/cmake/Findlibelfin.cmake @@ -0,0 +1,29 @@ +include(FindPkgConfig) +pkg_check_modules(libelfxx REQUIRED libelf++>=0.3) +pkg_check_modules(libdwarfxx REQUIRED libdwarf++>=0.3) + +add_library(libelfin::libelf++ INTERFACE IMPORTED) +set_target_properties(libelfin::libelf++ PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${libelfxx_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${libelfxx_LDFLAGS}" + INTERFACE_COMPILE_OPTIONS "${libelfxx_CFLAGS};${libelfxx_CFLAGS_OTHER}") +add_library(libelfin::libdwarf++ INTERFACE IMPORTED) +set_target_properties(libelfin::libdwarf++ PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${libdwarfxx_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${libdwarfxx_LDFLAGS}" + INTERFACE_COMPILE_OPTIONS "${libdwarfxx_CFLAGS};${libdwarfxx_CFLAGS_OTHER}") + +if(libelfxx_FOUND AND libdwarfxx_FOUND) + set(libelfin_FOUND 1) + set(libelfin_VERSION ${libelfxx_VERSION}) + if(NOT TARGET libelfin::libelfin) + add_library(libelfin::libelfin INTERFACE IMPORTED) + endif() + set_target_properties(libelfin::libelfin PROPERTIES + INTERFACE_LINK_LIBRARIES "libelfin::libdwarf++;libelfin::libelf++") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(libelfin + REQUIRED_VARS libelfin_VERSION + VERSION_VAR libelfin_VERSION) diff --git a/cmake/coz-profilerConfig.cmake.in b/cmake/coz-profilerConfig.cmake.in new file mode 100644 index 0000000..8aa6c6c --- /dev/null +++ b/cmake/coz-profilerConfig.cmake.in @@ -0,0 +1,21 @@ +@PACKAGE_INIT@ + +message(INFO " ${COZ_INCLUDE_DIR} ${COZ_LIBRARY} ${COZ_FOUND}") + +# Use find_dependency to find dependend packages. + +include(${CMAKE_CURRENT_LIST_DIR}/coz-profilerTargets.cmake) + +add_executable(coz::profiler IMPORTED) + +# This includes the lib file +get_target_property(_COZ_LIBARRY_PATH coz::coz IMPORTED_LOCATION) +# {INSTALLATION}/lib/libcoz.so +get_filename_component(_IMPORT_PREFIX "${_COZ_LIBRARY_PATH}" PATH) +# {INSTALLATION}/lib +get_filename_component(_IMPORT_PREFIX "${_COZ_LIBARRY_PATH}" PATH) +# {INSTALLATION} +set_property(TARGET coz::profiler PROPERTY IMPORTED_LOCATION ${_COZ_LIBARRY_PATH}) +# Cleanup temporary variables +set(_COZ_LIBARRY_PATH) + diff --git a/common.mk b/common.mk deleted file mode 100644 index 6f0c411..0000000 --- a/common.mk +++ /dev/null @@ -1,99 +0,0 @@ -DESTDIR ?= -prefix ?= /usr -bindir := $(prefix)/bin -pkglibdir := $(prefix)/lib/coz-profiler -incdir := $(prefix)/include -mandir := $(prefix)/share/man -man1dir := $(mandir)/man1 - -INSTALL = install -RST2MAN = rst2man - -# Build with clang by default -CC ?= clang -CXX ?= clang++ - -# Set coz and include path for coz -ifeq ($(USE_SYSTEM_COZ),1) -COZ := $(shell which coz) -else -COZ := $(ROOT)/coz -endif - -# Default flags -CFLAGS ?= -g -O2 -CXXFLAGS ?= $(CFLAGS) - -# Default source and object files -SRCS ?= $(wildcard *.cpp) $(wildcard *.c) -OBJS ?= $(addprefix obj/,$(patsubst %.cpp,%.o,$(patsubst %.c,%.o,$(SRCS)))) - -# Prevent errors if files named all, clean, distclean, bench, or test exist -.PHONY: all clean distclean bench bench_small bench_large test - -# Targets to build recirsively into $(DIRS) -RECURSIVE_TARGETS ?= all clean bench bench_large bench_small test install check - -# Targets separated by type -SHARED_LIB_TARGETS := $(filter %.so, $(TARGETS)) -STATIC_LIB_TARGETS := $(filter %.a, $(TARGETS)) -OTHER_TARGETS := $(filter-out %.so, $(filter-out %.a, $(TARGETS))) - -# If not set, the build path is just the current directory name -MAKEPATH ?= $(shell basename $(shell pwd)) - -# Log the build path in gray, following by a log message in bold green -LOG_PREFIX := "$(shell tput setaf 7)[$(MAKEPATH)]$(shell tput sgr0)$(shell tput setaf 2)" -LOG_SUFFIX := "$(shell tput sgr0)" - -# Build in parallel -MAKEFLAGS += -j - -# Build all targets by default, unless this is a benchmark -all:: $(TARGETS) - -# Clean up after a build -clean:: - @for t in $(TARGETS); do \ - echo $(LOG_PREFIX) Cleaning $$t $(LOG_SUFFIX); \ - done - @rm -rf $(TARGETS) obj - -# Bring source back to pristine state -distclean:: clean - @$(MAKE) -C benchmarks clean - -# Compile a C++ source file (and generate its dependency rules) -obj/%.o: %.cpp $(PREREQS) - @echo $(LOG_PREFIX) Compiling $< $(LOG_SUFFIX) - @mkdir -p obj - @$(CXX) $(CXXFLAGS) -MMD -MP -o $@ -c $< - -# Compile a C source file (and generate its dependency rules) -obj/%.o: %.c $(PREREQS) - @echo $(LOG_PREFIX) Compiling $< $(LOG_SUFFIX) - @mkdir -p obj - @$(CC) $(CFLAGS) -MMD -MP -o $@ -c $< - -# Link a shared library -$(SHARED_LIB_TARGETS): $(OBJS) - @echo $(LOG_PREFIX) Linking $@ $(LOG_SUFFIX) - @$(CXX) -shared $(LDFLAGS) -o $@ $^ $(LIBS) - -$(STATIC_LIB_TARGETS): $(OBJS) - @echo $(LOG_PREFIX) Linking $@ $(LOG_SUFFIX) - @ar rs $@ $^ - -# Link binary targets -$(OTHER_TARGETS): $(OBJS) - @echo $(LOG_PREFIX) Linking $@ $(LOG_SUFFIX) - @$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS) - -# Include dependency rules for all objects --include $(OBJS:.o=.d) - -# Build any recursive targets in subdirectories -$(RECURSIVE_TARGETS):: - @for dir in $(DIRS); do \ - $(MAKE) -C $$dir --no-print-directory $@ MAKEPATH="$(MAKEPATH)/$$dir" || exit 1; \ - done diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..5cbd241 --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,9 @@ +[requires] +libelfin/[>=0.3] + +[build_requires] +bzip2/[>=1.0.8] +sqlite3/[>=3.33.0] + +[generators] +cmake_find_package diff --git a/coz b/coz index db10b5b..3f8830e 100755 --- a/coz +++ b/coz @@ -59,7 +59,7 @@ def _coz_run(args): os.path.join(coz_prefix, '..', 'lib', 'coz-profiler', 'libcoz.so'), # Local library under development directory - os.path.join(coz_prefix, 'libcoz', 'libcoz.so') # Local library during development + os.path.join('libcoz', 'libcoz.so') # Local library during development ] # Find the first library location that exists diff --git a/coz-profilerConfig.cmake.in b/coz-profilerConfig.cmake.in deleted file mode 100644 index c8cc516..0000000 --- a/coz-profilerConfig.cmake.in +++ /dev/null @@ -1,26 +0,0 @@ - - -set(COZDIR destdir) - -set(COZ_BIN ${COZDIR}/bin/coz) -set(COZ_INCLUDE_DIR ${COZDIR}/include) -get_filename_component(LIBRARY_DIR ${CMAKE_CURRENT_LIST_FILE} DIRECTORY) -set(COZ_LIBRARY ${LIBRARY_DIR}/libcoz.so) - -set(COZ_FOUND ON) - -message(INFO " ${COZ_INCLUDE_DIR} ${COZ_LIBRARY} ${COZ_FOUND}") - -mark_as_advanced(COZ_FOUND COZ_INCLUDE_DIR COZ_LIBRARY) - -add_library(coz::coz UNKNOWN IMPORTED) -set_target_properties(coz::coz PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${COZ_INCLUDE_DIR}") - -set_target_properties(coz::coz PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${COZ_INCLUDE_DIR}") - -add_executable(coz::profiler IMPORTED) - -set_property(TARGET coz::profiler PROPERTY IMPORTED_LOCATION ${COZ_BIN}) diff --git a/libcoz/CMakeLists.txt b/libcoz/CMakeLists.txt new file mode 100644 index 0000000..a3a9ea9 --- /dev/null +++ b/libcoz/CMakeLists.txt @@ -0,0 +1,41 @@ +set(sources + ${PROJECT_SOURCE_DIR}/include/coz.h + inspect.cpp + inspect.h + libcoz.cpp + perf.cpp + perf.h + profiler.cpp + profiler.h + progress_point.h + real.cpp + real.h + thread_state.h + util.h + ) + +add_library(coz MODULE ${sources} ${public_headers}) +if(CONAN_PACKAGE_VERSION) + set_target_properties(coz PROPERTIES VERSION ${CONAN_PACKAGE_VERSION}) +endif() +target_include_directories(coz + PUBLIC + $ + $) +target_link_libraries(coz PRIVATE ${CMAKE_DL_LIBS} rt Threads::Threads libelfin::libelfin) + +add_library(coz-instrumentation INTERFACE) +target_include_directories(coz-instrumentation + INTERFACE + $ + $) +target_link_libraries(coz-instrumentation INTERFACE -Wl,--push-state,--no-as-needed ${CMAKE_DL_LIBS} -Wl,--pop-state) + +if(INSTALL_COZ) + install(TARGETS coz + EXPORT coz-profilerTargets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +endif() diff --git a/libcoz/Makefile b/libcoz/Makefile deleted file mode 100644 index 0a2bbf9..0000000 --- a/libcoz/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -ROOT := .. -TARGETS := libcoz.so -LIBS := -ldl -lrt -lpthread $(shell pkg-config --libs libelf++ libdwarf++) -CXXFLAGS := --std=c++0x -g -O2 -fPIC -I$(ROOT)/include -I. \ - $(shell pkg-config --cflags libelf++ libdwarf++) - -include $(ROOT)/common.mk - -check:: libcoz.so - printf "int main(int argc, char *argv[])\n{\nreturn (0);\n}\n" > x.c - gcc -g -o x x.c || ( $(RM) x x.c ; exit 1) - ../coz run --- ./x - if grep -q time= profile.coz; then echo success: coz profiler ran as it should.; fi - $(RM) -f x.c x profile.coz diff --git a/viewer/Makefile b/viewer/Makefile deleted file mode 100644 index 57ee1a8..0000000 --- a/viewer/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -ROOT := .. - -include $(ROOT)/common.mk - -all:: js/ui.js - -js/ui.js: $(wildcard ts/*.ts) tsconfig.json - @echo $(LOG_PREFIX) Building profile viewer $(LOG_SUFFIX) - @npm install > /dev/null