From 2666b6cbf19b043a83dd1715c4a20d259a7bba1c Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Wed, 4 May 2016 19:24:17 -0500 Subject: [PATCH 01/10] Added header dependency tests. --- CMakeLists.txt | 7 +++ tests/CMakeLists.txt | 21 +++++++++ tests/header_dependencies/CMakeLists.txt | 58 ++++++++++++++++++++++++ tests/header_dependencies/main.c | 7 +++ tests/header_dependencies/main.cpp | 4 ++ 5 files changed, 97 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/header_dependencies/CMakeLists.txt create mode 100644 tests/header_dependencies/main.c create mode 100644 tests/header_dependencies/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f11d7327..5965bade 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) add_library(spdlog INTERFACE) option(SPDLOG_BUILD_EXAMPLES "Build examples" OFF) +option(SPDLOG_BUILD_TESTS "Build tests" OFF) target_include_directories( spdlog @@ -20,11 +21,17 @@ target_include_directories( "$" ) +set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include") + if(SPDLOG_BUILD_EXAMPLES) enable_testing() add_subdirectory(example) endif() +if(SPDLOG_BUILD_TESTS) + add_subdirectory(tests) +endif() + ### Install ### # * https://github.com/forexample/package-example set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..722a7195 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,21 @@ +# +# Tests +# + +enable_testing() + +# Build Catch unit tests +#function(add_catch_test _testname) +# add_executable(${_testname} ${_testname}.cpp) +# target_link_libraries(${_testname} Catch) +# add_test(NAME test_${_testname} COMMAND ${_testname}) +#endfunction() +# +#file(GLOB catch_tests LIST_DIRECTORIES false *.cpp) +#foreach(catch_test IN LIST catch_tests) +# add_catch_test(${catch_test}) +#endforeach() + +# Ensure headers include their own dependencies +add_subdirectory(header_dependencies) + diff --git a/tests/header_dependencies/CMakeLists.txt b/tests/header_dependencies/CMakeLists.txt new file mode 100644 index 00000000..81779694 --- /dev/null +++ b/tests/header_dependencies/CMakeLists.txt @@ -0,0 +1,58 @@ +# +# Ensure all headers include all dependencies +# + +set(IGNORED_HEADERS "") + +set(COMMON_TEST_LIBRARIES spdlog) + +add_custom_target(header_dependencies) + +file(GLOB_RECURSE headers RELATIVE "${HEADER_BASE}" ${HEADER_BASE}/*.h) +set(test_index 0) +foreach(HEADER ${headers}) + # Sample of relevant variables computed here + # HEADER: details/line_logger_impl.h + # symbolname: spdlog_details_line_logger_impl + + # Compute symbolname + string(REPLACE ".h" "" symbolname "${HEADER}") + string(MAKE_C_IDENTIFIER "${symbolname}" symbolname) + + list(FIND IGNORED_HEADERS "${HEADER}" _index) + # If we didn't explicitly ignore this and if we built this target + if(${_index} EQUAL -1) + #message(STATUS "${HEADER}: '${symbolname}'") + + set(extension cpp) + + # Name the test and output file with a number, to dodge Windows path length limits. + # Call it header, instead of test, to avoid polluting the 'executable namespace' + set(test_name "header_${extension}_${test_index}") + + set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/main.${extension}") + + add_executable(${test_name} "${source_file}") + target_compile_definitions(${test_name} PRIVATE HEADER_TO_TEST="${HEADER}") + target_include_directories(${test_name} + PRIVATE + ${BUILDTREE_HEADER_BASE} + ${HEADER_BASE}) + + set_target_properties(${test_name} PROPERTIES + FOLDER "Header dependency tests") + + target_link_libraries(${test_name} + PRIVATE + ${COMMON_TEST_LIBRARIES} + ${LIBRARIES_${symbolname}} + ${LIBRARIES_${libname}}) + + add_test(NAME ${test_name}_builds COMMAND ${test_name}) + add_dependencies(header_dependencies ${test_name}) + + math(EXPR test_index "${test_index} + 1") + endif() +endforeach() + + diff --git a/tests/header_dependencies/main.c b/tests/header_dependencies/main.c new file mode 100644 index 00000000..d2b5af77 --- /dev/null +++ b/tests/header_dependencies/main.c @@ -0,0 +1,7 @@ + +#include HEADER_TO_TEST + +int main(int argc, char** argv) +{ + return 0; +} diff --git a/tests/header_dependencies/main.cpp b/tests/header_dependencies/main.cpp new file mode 100644 index 00000000..7716c88b --- /dev/null +++ b/tests/header_dependencies/main.cpp @@ -0,0 +1,4 @@ + +#include HEADER_TO_TEST + +int main(int argc, char *argv[]) { return 0; } From e10a2fca6522bb2e7e3f1fe6cde30db1cc85bc13 Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Wed, 4 May 2016 19:25:48 -0500 Subject: [PATCH 02/10] Added missing base_sink.h include. --- include/spdlog/sinks/stdout_sinks.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index ca4c55ac..1921bce2 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -5,6 +5,7 @@ #pragma once +#include #include #include From 2907001e2258861d166e9fe9d9f8c660a2a0271d Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Wed, 4 May 2016 19:53:22 -0500 Subject: [PATCH 03/10] Fixed Catch tests. --- tests/CMakeLists.txt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 722a7195..307ddeb6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,16 +5,14 @@ enable_testing() # Build Catch unit tests -#function(add_catch_test _testname) -# add_executable(${_testname} ${_testname}.cpp) -# target_link_libraries(${_testname} Catch) -# add_test(NAME test_${_testname} COMMAND ${_testname}) -#endfunction() -# -#file(GLOB catch_tests LIST_DIRECTORIES false *.cpp) -#foreach(catch_test IN LIST catch_tests) -# add_catch_test(${catch_test}) -#endforeach() +add_library(catch INTERFACE) +target_include_directories(catch INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) + +file(GLOB catch_tests LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +add_executable(catch_tests ${catch_tests}) +target_link_libraries(catch_tests spdlog) +add_test(NAME catch_tests COMMAND catch_tests) +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") # Ensure headers include their own dependencies add_subdirectory(header_dependencies) From 1b444345ab69a444baf188735c67925ad67cb096 Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Wed, 4 May 2016 19:53:50 -0500 Subject: [PATCH 04/10] Cleaned up cmake file for examples. It's no longer a standalone cmake file because cmake was crashing when reading it as part of the subproject. --- example/CMakeLists.txt | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 6ef158e1..5abefefb 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -21,29 +21,16 @@ # * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ # *************************************************************************/ -cmake_minimum_required(VERSION 3.0) -project(SpdlogExamples) - -if(TARGET spdlog) - # Part of the main project - add_library(spdlog::spdlog ALIAS spdlog) -else() - # Stand-alone build - find_package(spdlog CONFIG REQUIRED) -endif() - -if (CMAKE_COMPILER_IS_GNUCXX) - set ( CMAKE_CXX_FLAGS "--std=c++11 -pthread") - set ( CMAKE_EXE_LIKKER_FLAGS "-pthread") -endif () +find_package(Threads) add_executable(example example.cpp) -target_link_libraries(example spdlog::spdlog) +target_link_libraries(example spdlog ${CMAKE_THREAD_LIBS_INIT}) add_executable(benchmark bench.cpp) -target_link_libraries(benchmark spdlog::spdlog) +target_link_libraries(benchmark spdlog ${CMAKE_THREAD_LIBS_INIT}) enable_testing() file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") add_test(NAME RunExample COMMAND example) add_test(NAME RunBenchmark COMMAND benchmark) + From 846fdf9f5cb8616137db1e86b2ffd498705dd334 Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Wed, 4 May 2016 19:55:00 -0500 Subject: [PATCH 05/10] Added ctest so we now have a 'make test' target for running tests. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5965bade..25f2ebcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,13 +23,13 @@ target_include_directories( set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include") +include(CTest) if(SPDLOG_BUILD_EXAMPLES) - enable_testing() - add_subdirectory(example) + add_subdirectory(example) endif() if(SPDLOG_BUILD_TESTS) - add_subdirectory(tests) + add_subdirectory(tests) endif() ### Install ### From 2132fe0ec5e4570100b951af51a52a361fb72afb Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Wed, 4 May 2016 22:46:30 -0500 Subject: [PATCH 06/10] Initial work on benchmarks of other logging systems. --- .gitmodules | 9 ++++ CMakeLists.txt | 6 +++ bench/CMakeLists.txt | 78 ++++++++++++++++++++++++++++++++++ bench/easylogging-bench-mt.cpp | 2 +- bench/easylogging-bench.cpp | 2 +- bench/zf_log-bench-mt.cpp | 4 +- bench/zf_log-bench.cpp | 4 +- vendor/CMakeLists.txt | 21 +++++++++ vendor/easyloggingpp | 1 + vendor/glog | 1 + vendor/zf_log | 1 + 11 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 .gitmodules create mode 100644 bench/CMakeLists.txt create mode 100644 vendor/CMakeLists.txt create mode 160000 vendor/easyloggingpp create mode 160000 vendor/glog create mode 160000 vendor/zf_log diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..383c487a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "vendor/zf_log"] + path = vendor/zf_log + url = https://github.com/wonder-mice/zf_log.git +[submodule "vendor/glog"] + path = vendor/glog + url = https://github.com/google/glog.git +[submodule "vendor/easyloggingpp"] + path = vendor/easyloggingpp + url = https://github.com/easylogging/easyloggingpp.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 25f2ebcf..4c85f7ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ add_library(spdlog INTERFACE) option(SPDLOG_BUILD_EXAMPLES "Build examples" OFF) option(SPDLOG_BUILD_TESTS "Build tests" OFF) +option(SPDLOG_BUILD_BENCHMARKS "Build comparison benchmarks for various logging libraries" OFF) target_include_directories( spdlog @@ -32,6 +33,11 @@ if(SPDLOG_BUILD_TESTS) add_subdirectory(tests) endif() +if(SPDLOG_BUILD_BENCHMARKS) + add_subdirectory(vendor) + add_subdirectory(bench) +endif() + ### Install ### # * https://github.com/forexample/package-example set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt new file mode 100644 index 00000000..d3506081 --- /dev/null +++ b/bench/CMakeLists.txt @@ -0,0 +1,78 @@ +# +# Benchmarks against various logging systems +# + +# +# Dependencies +# + +find_package(Threads) + +enable_testing() + +# Helper function for building benchmark programs +function(add_benchmark _target) + set(options "") # no options + set(singleValueArgs "") # no single-value arguments + set(multiValueArgs LIBS SOURCES INCLUDES DEFINITIONS) # lists of additional libraries, source files, and include directories + cmake_parse_arguments(_benchmark "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN}) + + add_executable(${_target} ${_target}.cpp ${_benchmark_SOURCES}) + target_include_directories( + ${_target} + PUBLIC + ${HEADER_BASE} + ${_benchmark_INCLUDES} + ) + + target_link_libraries( + ${_target} + ${CMAKE_THREAD_LIBS_INIT} + ${_benchmark_LIBS} + ) + + if(_benchmark_DEFINITIONS) + target_compile_definitions(${_target} ${_benchmark_DEFINITIONS}) + endif() + + add_test(NAME test_benchmark_${_target} COMMAND ${_target}) +endfunction() + +# Benchmark programs +add_benchmark(spdlog-bench) +add_benchmark(spdlog-bench-mt) +add_benchmark(spdlog-async) + +if(TARGET zf_log) + add_benchmark(zf_log-bench LIBS zf_log) + add_benchmark(zf_log-bench-mt LIBS zf_log) +endif() + +find_package(Boost QUIET COMPONENTS log) +if(Boost_FOUND) + add_benchmark(boost-bench LIBS ${Boost_LIBRARIES} INCLUDES ${Boost_INCLUDE_DIRS}) + add_benchmark(boost-bench-mt LIBS ${Boost_LIBRARIES} INCLUDES ${Boost_INCLUDE_DIRS}) +endif() + +find_package(glog QUIET) +if(TARGET glog) + add_benchmark(glog-bench LIBS glog) + add_benchmark(glog-bench-mt LIBS glog) +endif() + +# TODO make g2log find script +# TODO use g2log git submodule +find_package(g2log QUIET) +if(g2log-FOUND) + set(G2LOG_LIBRARIES lib_g2logger) + set(G2LOG_INCLUDE_DIRS /home/gabi/devel/g2log/g2log/src) + add_benchmark(g2log-async LIBS ${G2LOG_LIBRARIES} INCLUDES ${G2LOG_INCLUDE_DIRS}) +endif() + +if(TARGET easylogging) + add_benchmark(easylogging-bench LIBS easylogging) + add_benchmark(easylogging-bench-mt LIBS easylogging) +endif() + +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") + diff --git a/bench/easylogging-bench-mt.cpp b/bench/easylogging-bench-mt.cpp index 98d1ae35..18d81618 100644 --- a/bench/easylogging-bench-mt.cpp +++ b/bench/easylogging-bench-mt.cpp @@ -9,7 +9,7 @@ #define _ELPP_THREAD_SAFE #include "easylogging++.h" -_INITIALIZE_EASYLOGGINGPP +INITIALIZE_EASYLOGGINGPP using namespace std; diff --git a/bench/easylogging-bench.cpp b/bench/easylogging-bench.cpp index a952cbd5..fa20032e 100644 --- a/bench/easylogging-bench.cpp +++ b/bench/easylogging-bench.cpp @@ -6,7 +6,7 @@ #include "easylogging++.h" -_INITIALIZE_EASYLOGGINGPP +INITIALIZE_EASYLOGGINGPP int main(int, char* []) { diff --git a/bench/zf_log-bench-mt.cpp b/bench/zf_log-bench-mt.cpp index aace2770..12cb48ac 100644 --- a/bench/zf_log-bench-mt.cpp +++ b/bench/zf_log-bench-mt.cpp @@ -9,7 +9,7 @@ const char g_path[] = "logs/zf_log.txt"; int g_fd; -static void output_callback(zf_log_message *msg) +static void output_callback(const zf_log_message* msg, void* arg) { *msg->p = '\n'; write(g_fd, msg->buf, msg->p - msg->buf + 1); @@ -25,7 +25,7 @@ int main(int argc, char* argv[]) ZF_LOGE_AUX(ZF_LOG_STDERR, "Failed to open log file: %s", g_path); return -1; } - zf_log_set_output_callback(ZF_LOG_PUT_STD, output_callback); + ZF_LOG_DEFINE_GLOBAL_OUTPUT = {ZF_LOG_PUT_STD, nullptr, &output_callback}; int thread_count = 10; if(argc > 1) diff --git a/bench/zf_log-bench.cpp b/bench/zf_log-bench.cpp index a6e3e1ff..d6024cf5 100644 --- a/bench/zf_log-bench.cpp +++ b/bench/zf_log-bench.cpp @@ -4,7 +4,7 @@ const char g_path[] = "logs/zf_log.txt"; static FILE *g_f; -static void output_callback(zf_log_message *msg) +static void output_callback(const zf_log_message* msg, void* arg) { *msg->p = '\n'; fwrite(msg->buf, msg->p - msg->buf + 1, 1, g_f); @@ -18,7 +18,7 @@ int main(int, char* []) ZF_LOGE_AUX(ZF_LOG_STDERR, "Failed to open log file: %s", g_path); return -1; } - zf_log_set_output_callback(ZF_LOG_PUT_STD, output_callback); + ZF_LOG_DEFINE_GLOBAL_OUTPUT = {ZF_LOG_PUT_STD, nullptr, &output_callback}; const int howmany = 1000000; for(int i = 0 ; i < howmany; ++i) diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt new file mode 100644 index 00000000..b2abdde4 --- /dev/null +++ b/vendor/CMakeLists.txt @@ -0,0 +1,21 @@ +# +# External libraries +# +# +# Most of these libraries are used for running comparison benchmarks against +# other logging libraries. + +add_subdirectory(zf_log) + +#add_subdirectory(glog) + +add_library(easylogging INTERFACE) +set(SPDLOG_VENDORED_EASYLOGGING_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/easyloggingpp" CACHE INTERNAL "" FORCE) +target_include_directories(easylogging INTERFACE "${SPDLOG_VENDORED_EASYLOGGING_ROOT}/src") + +#add_library(zflog INTERFACE) +#set(SPDLOG_VENDORED_ZFLOG_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/zf_log" CACHE INTERNAL "" FORCE) +#target_include_directories(zflog INTERFACE "${SPDLOG_VENDORED_ZFLOG_ROOT}/zf_log") +##target_compile_definitions(zflog INTERFACE ZFLOG_DEFINITIONS) + + diff --git a/vendor/easyloggingpp b/vendor/easyloggingpp new file mode 160000 index 00000000..f926802d --- /dev/null +++ b/vendor/easyloggingpp @@ -0,0 +1 @@ +Subproject commit f926802dfbde716d82b64b8ef3c25b7f0fcfec65 diff --git a/vendor/glog b/vendor/glog new file mode 160000 index 00000000..de6149ef --- /dev/null +++ b/vendor/glog @@ -0,0 +1 @@ +Subproject commit de6149ef8e67b064a433a8b88924fa9f606ad5d5 diff --git a/vendor/zf_log b/vendor/zf_log new file mode 160000 index 00000000..4c15e670 --- /dev/null +++ b/vendor/zf_log @@ -0,0 +1 @@ +Subproject commit 4c15e6704edffdafe289d4b84c2db89009368626 From 254a6744e4e5decd4c59137e9753b0ad95c18b7e Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Wed, 4 May 2016 22:53:06 -0500 Subject: [PATCH 07/10] Fixed boost.log benchmark build. --- bench/CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index d3506081..628507ab 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -32,7 +32,7 @@ function(add_benchmark _target) ) if(_benchmark_DEFINITIONS) - target_compile_definitions(${_target} ${_benchmark_DEFINITIONS}) + target_compile_definitions(${_target} PUBLIC ${_benchmark_DEFINITIONS}) endif() add_test(NAME test_benchmark_${_target} COMMAND ${_target}) @@ -50,8 +50,9 @@ endif() find_package(Boost QUIET COMPONENTS log) if(Boost_FOUND) - add_benchmark(boost-bench LIBS ${Boost_LIBRARIES} INCLUDES ${Boost_INCLUDE_DIRS}) - add_benchmark(boost-bench-mt LIBS ${Boost_LIBRARIES} INCLUDES ${Boost_INCLUDE_DIRS}) + set(BOOST_DEFS "-DBOOST_LOG_DYN_LINK=1") + add_benchmark(boost-bench LIBS ${Boost_LIBRARIES} INCLUDES ${Boost_INCLUDE_DIRS} DEFINITIONS ${BOOST_DEFS}) + add_benchmark(boost-bench-mt LIBS ${Boost_LIBRARIES} INCLUDES ${Boost_INCLUDE_DIRS} DEFINITIONS ${BOOST_DEFS}) endif() find_package(glog QUIET) From 350ff13d77c439ef27a17b755b0f8d56749fa5ea Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Wed, 4 May 2016 23:33:38 -0500 Subject: [PATCH 08/10] Added g3log and glog benchmarks. --- .gitmodules | 3 +++ bench/CMakeLists.txt | 10 ++----- bench/g3log-async.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++ vendor/CMakeLists.txt | 5 +++- vendor/g3log | 1 + 5 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 bench/g3log-async.cpp create mode 160000 vendor/g3log diff --git a/.gitmodules b/.gitmodules index 383c487a..0a9050b3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "vendor/easyloggingpp"] path = vendor/easyloggingpp url = https://github.com/easylogging/easyloggingpp.git +[submodule "vendor/g3log"] + path = vendor/g3log + url = https://github.com/KjellKod/g3log.git diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index 628507ab..563f5b65 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -55,19 +55,13 @@ if(Boost_FOUND) add_benchmark(boost-bench-mt LIBS ${Boost_LIBRARIES} INCLUDES ${Boost_INCLUDE_DIRS} DEFINITIONS ${BOOST_DEFS}) endif() -find_package(glog QUIET) if(TARGET glog) add_benchmark(glog-bench LIBS glog) add_benchmark(glog-bench-mt LIBS glog) endif() -# TODO make g2log find script -# TODO use g2log git submodule -find_package(g2log QUIET) -if(g2log-FOUND) - set(G2LOG_LIBRARIES lib_g2logger) - set(G2LOG_INCLUDE_DIRS /home/gabi/devel/g2log/g2log/src) - add_benchmark(g2log-async LIBS ${G2LOG_LIBRARIES} INCLUDES ${G2LOG_INCLUDE_DIRS}) +if(TARGET g3logger) + add_benchmark(g3log-async LIBS g3logger INCLUDES "${g3log_SOURCE_DIR}/src") endif() if(TARGET easylogging) diff --git a/bench/g3log-async.cpp b/bench/g3log-async.cpp new file mode 100644 index 00000000..f1e5c17f --- /dev/null +++ b/bench/g3log-async.cpp @@ -0,0 +1,63 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include +#include +#include + +#include +#include + +using namespace std; +template std::string format(const T& value); + +int main(int argc, char* argv[]) +{ + using namespace std::chrono; + using clock=steady_clock; + int thread_count = 10; + + if(argc > 1) + thread_count = atoi(argv[1]); + int howmany = 1000000; + + auto g3log = g3::LogWorker::createLogWorker(); + auto defaultHandler = g3log->addDefaultLogger(argv[0], "logs"); + g3::initializeLogging(g3log.get()); + + + std::atomic msg_counter {0}; + vector threads; + auto start = clock::now(); + for (int t = 0; t < thread_count; ++t) + { + threads.push_back(std::thread([&]() + { + while (true) + { + int counter = ++msg_counter; + if (counter > howmany) break; + LOG(INFO) << "g3log message #" << counter << ": This is some text for your pleasure"; + } + })); + } + + + for(auto &t:threads) + { + t.join(); + }; + + duration delta = clock::now() - start; + float deltaf = delta.count(); + auto rate = howmany/deltaf; + + cout << "Total: " << howmany << std::endl; + cout << "Threads: " << thread_count << std::endl; + std::cout << "Delta = " << deltaf << " seconds" << std::endl; + std::cout << "Rate = " << rate << "/sec" << std::endl; +} diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index b2abdde4..86b7e33b 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -7,12 +7,15 @@ add_subdirectory(zf_log) -#add_subdirectory(glog) +add_subdirectory(glog) add_library(easylogging INTERFACE) set(SPDLOG_VENDORED_EASYLOGGING_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/easyloggingpp" CACHE INTERNAL "" FORCE) target_include_directories(easylogging INTERFACE "${SPDLOG_VENDORED_EASYLOGGING_ROOT}/src") +add_subdirectory(g3log) + + #add_library(zflog INTERFACE) #set(SPDLOG_VENDORED_ZFLOG_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/zf_log" CACHE INTERNAL "" FORCE) #target_include_directories(zflog INTERFACE "${SPDLOG_VENDORED_ZFLOG_ROOT}/zf_log") diff --git a/vendor/g3log b/vendor/g3log new file mode 160000 index 00000000..6c1698c4 --- /dev/null +++ b/vendor/g3log @@ -0,0 +1 @@ +Subproject commit 6c1698c4f7db6b9e4246ead38051f9866ea3ac06 From a95f413c6135b30b3658e56b708d32395a7c0dee Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Wed, 4 May 2016 23:39:10 -0500 Subject: [PATCH 09/10] Make vendor targets optional. --- vendor/CMakeLists.txt | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index 86b7e33b..a391b907 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -5,20 +5,21 @@ # Most of these libraries are used for running comparison benchmarks against # other logging libraries. -add_subdirectory(zf_log) +if(IS_DIRECTORY zf_log) + add_subdirectory(zf_log) +endif() -add_subdirectory(glog) +if(IS_DIRECTORY glog) + add_subdirectory(glog) +endif() -add_library(easylogging INTERFACE) -set(SPDLOG_VENDORED_EASYLOGGING_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/easyloggingpp" CACHE INTERNAL "" FORCE) -target_include_directories(easylogging INTERFACE "${SPDLOG_VENDORED_EASYLOGGING_ROOT}/src") - -add_subdirectory(g3log) - - -#add_library(zflog INTERFACE) -#set(SPDLOG_VENDORED_ZFLOG_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/zf_log" CACHE INTERNAL "" FORCE) -#target_include_directories(zflog INTERFACE "${SPDLOG_VENDORED_ZFLOG_ROOT}/zf_log") -##target_compile_definitions(zflog INTERFACE ZFLOG_DEFINITIONS) +if(IS_DIRECTORY easyloggingpp) + add_library(easylogging INTERFACE) + set(SPDLOG_VENDORED_EASYLOGGING_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/easyloggingpp" CACHE INTERNAL "" FORCE) + target_include_directories(easylogging INTERFACE "${SPDLOG_VENDORED_EASYLOGGING_ROOT}/src") +endif() +if(IS_DIRECTORY g3log) + add_subdirectory(g3log) +endif() From a86eff5636e86610d41f3f64c8f8492356060c8f Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Thu, 5 May 2016 00:00:54 -0500 Subject: [PATCH 10/10] Turns out IS_DIRECTORY needs an absolute path. --- vendor/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index a391b907..a9fed11e 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -5,21 +5,21 @@ # Most of these libraries are used for running comparison benchmarks against # other logging libraries. -if(IS_DIRECTORY zf_log) +if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/zf_log") add_subdirectory(zf_log) endif() -if(IS_DIRECTORY glog) +if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/glog") add_subdirectory(glog) endif() -if(IS_DIRECTORY easyloggingpp) +if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/easyloggingpp") add_library(easylogging INTERFACE) set(SPDLOG_VENDORED_EASYLOGGING_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/easyloggingpp" CACHE INTERNAL "" FORCE) target_include_directories(easylogging INTERFACE "${SPDLOG_VENDORED_EASYLOGGING_ROOT}/src") endif() -if(IS_DIRECTORY g3log) +if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/g3log") add_subdirectory(g3log) endif()