mirror of https://github.com/gabime/spdlog.git
Merge remote-tracking branch 'origin/v1.x' into pwm1234/rotate_on_open
commit
22f85deb2c
@ -1,91 +1,115 @@
|
|||||||
# Adapted from various sources, including:
|
# Adapted from various sources, including:
|
||||||
# - Louis Dionne's Hana: https://github.com/ldionne/hana
|
# - Louis Dionne's Hana: https://github.com/ldionne/hana
|
||||||
# - Paul Fultz II's FIT: https://github.com/pfultz2/Fit
|
# - Paul Fultz II's FIT: https://github.com/pfultz2/Fit
|
||||||
# - Eric Niebler's range-v3: https://github.com/ericniebler/range-v3
|
# - Eric Niebler's range-v3: https://github.com/ericniebler/range-v3
|
||||||
language: cpp
|
sudo: required
|
||||||
|
language: cpp
|
||||||
# Test matrix:
|
|
||||||
# - Build matrix per compiler: C++11/C++14 + Debug/Release
|
addons: &gcc48
|
||||||
# - Optionally: AddressSanitizer (ASAN)
|
apt:
|
||||||
# - Valgrind: all release builds are also tested with valgrind
|
packages:
|
||||||
# - clang 3.4, 3.5, 3.6, trunk
|
- g++-4.8
|
||||||
# - Note: 3.4 and trunk are tested with/without ASAN,
|
sources:
|
||||||
# the rest is only tested with ASAN=On.
|
- ubuntu-toolchain-r-test
|
||||||
# - gcc 4.9, 5.0
|
|
||||||
#
|
addons: &gcc7
|
||||||
matrix:
|
apt:
|
||||||
include:
|
packages:
|
||||||
|
- g++-7
|
||||||
# Test gcc-4.8: C++11, Build=Debug/Release, ASAN=Off
|
sources:
|
||||||
- env: GCC_VERSION=4.8 BUILD_TYPE=Debug CPP=11 ASAN=Off LIBCXX=Off
|
- ubuntu-toolchain-r-test
|
||||||
os: linux
|
|
||||||
addons: &gcc48
|
addons: &clang35
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
- g++-4.8
|
- clang-3.5
|
||||||
- valgrind
|
sources:
|
||||||
sources:
|
- ubuntu-toolchain-r-test
|
||||||
- ubuntu-toolchain-r-test
|
- llvm-toolchain-precise-3.5
|
||||||
|
|
||||||
- env: GCC_VERSION=4.8 BUILD_TYPE=Release CPP=11 ASAN=Off LIBCXX=Off
|
addons: &clang6
|
||||||
os: linux
|
apt:
|
||||||
addons: *gcc48
|
packages:
|
||||||
|
- clang-6.0
|
||||||
# Test gcc-4.9: C++11, Build=Debug/Release, ASAN=Off
|
sources:
|
||||||
- env: GCC_VERSION=4.9 BUILD_TYPE=Debug CPP=11 ASAN=Off LIBCXX=Off
|
- ubuntu-toolchain-r-test
|
||||||
os: linux
|
- llvm-toolchain-trusty-6.0
|
||||||
addons: &gcc49
|
|
||||||
apt:
|
|
||||||
packages:
|
matrix:
|
||||||
- g++-4.9
|
include:
|
||||||
- valgrind
|
# Test gcc-4.8: C++11, Build=Debug/Release
|
||||||
sources:
|
- env: GCC_VERSION=4.8 BUILD_TYPE=Debug CPP=11
|
||||||
- ubuntu-toolchain-r-test
|
os: linux
|
||||||
|
addons: *gcc48
|
||||||
- env: GCC_VERSION=4.9 BUILD_TYPE=Release CPP=11 ASAN=Off LIBCXX=Off
|
|
||||||
os: linux
|
- env: GCC_VERSION=4.8 BUILD_TYPE=Release CPP=11
|
||||||
addons: *gcc49
|
os: linux
|
||||||
|
addons: *gcc48
|
||||||
# Install dependencies
|
|
||||||
before_install:
|
- env: GCC_VERSION=7 BUILD_TYPE=Release CPP=11
|
||||||
- export CHECKOUT_PATH=`pwd`;
|
os: linux
|
||||||
- if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi
|
addons: *gcc7
|
||||||
- if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi
|
|
||||||
- if [ "$CLANG_VERSION" == "3.4" ]; then export CXX="/usr/local/clang-3.4/bin/clang++" CC="/usr/local/clang-3.4/bin/clang"; fi
|
# Test clang-3.5: C++11, Build=Debug/Release
|
||||||
- which $CXX
|
- env: CLANG_VERSION=3.5 BUILD_TYPE=Debug CPP=11
|
||||||
- which $CC
|
os: linux
|
||||||
- which valgrind
|
addons: *clang35
|
||||||
- if [ -n "$CLANG_VERSION" ]; then sudo CXX=$CXX CC=$CC ./tests/install_libcxx.sh; fi
|
|
||||||
|
- env: CLANG_VERSION=3.5 BUILD_TYPE=Release CPP=11
|
||||||
install:
|
os: linux
|
||||||
- cd $CHECKOUT_PATH
|
addons: *clang35
|
||||||
|
|
||||||
# Workaround for valgrind bug: https://bugs.kde.org/show_bug.cgi?id=326469.
|
# Test clang-6.0: C++11, Build=Debug, ASAN=On
|
||||||
# It is fixed in valgrind 3.10 so this won't be necessary if someone
|
- env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=On TSAN=Off
|
||||||
# replaces the current valgrind (3.7) with valgrind-3.10
|
os: linux
|
||||||
- sed -i 's/march=native/msse4.2/' example/Makefile
|
addons: *clang6
|
||||||
|
|
||||||
- if [ ! -d build ]; then mkdir build; fi
|
- env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=On TSAN=Off
|
||||||
- export CXX_FLAGS="-I${CHECKOUT_PATH}/include"
|
os: linux
|
||||||
- export CXX_LINKER_FLAGS=""
|
addons: *clang6
|
||||||
- if [ -z "$BUILD_TYPE" ]; then export BUILD_TYPE=Release; fi
|
|
||||||
- if [ "$ASAN" == "On"]; then export CXX_FLAGS="${CXX_FLAGS} -fsanitize=address,undefined,integer -fno-omit-frame-pointer -fno-sanitize=unsigned-integer-overflow"; fi
|
# Test clang-6.0: C++11, Build=Debug, TSAN=On
|
||||||
- if [ -n "$CLANG_VERSION" ]; then CXX_FLAGS="${CXX_FLAGS} -D__extern_always_inline=inline"; fi
|
- env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=Off TSAN=On
|
||||||
- if [ "$LIBCXX" == "On" ]; then CXX_FLAGS="${CXX_FLAGS} -stdlib=libc++ -I/usr/include/c++/v1/"; fi
|
os: linux
|
||||||
- if [ "$LIBCXX" == "On" ]; then CXX_LINKER_FLAGS="${CXX_FLAGS} -L/usr/lib/ -lc++"; fi
|
addons: *clang6
|
||||||
- CXX_FLAGS="${CXX_FLAGS} -std=c++${CPP}"
|
|
||||||
|
- env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=On
|
||||||
# Build examples
|
os: linux
|
||||||
- cd example
|
addons: *clang6
|
||||||
- if [ "$BUILD_TYPE" == "Release" ]; then make rebuild CXXFLAGS="${CXX_FLAGS} ${CXX_LINKER_FLAGS}" VERBOSE=1; export BIN=example; fi
|
|
||||||
- if [ "$BUILD_TYPE" == "Debug" ]; then make rebuild debug CXXFLAGS="${CXX_FLAGS} ${CXX_LINKER_FLAGS}" VERBOSE=1; export BIN=example-debug; fi
|
# osx
|
||||||
|
- env: BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=Off
|
||||||
|
os: osx
|
||||||
script:
|
|
||||||
- ./"${BIN}"
|
|
||||||
- valgrind --trace-children=yes --leak-check=full ./"${BIN}"
|
|
||||||
- cd $CHECKOUT_PATH/tests; make rebuild; ./tests
|
|
||||||
- cd $CHECKOUT_PATH/tests; STYLE=printf make rebuild; ./tests
|
before_script:
|
||||||
|
- if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi
|
||||||
notifications:
|
- if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi
|
||||||
email: false
|
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export CXX="clang++" CC="clang"; fi
|
||||||
|
- which $CXX
|
||||||
|
- which $CC
|
||||||
|
- $CXX --version
|
||||||
|
- cmake --version
|
||||||
|
|
||||||
|
script:
|
||||||
|
- cd ${TRAVIS_BUILD_DIR}
|
||||||
|
- mkdir -p build && cd build
|
||||||
|
- |
|
||||||
|
cmake .. \
|
||||||
|
--warn-uninitialized \
|
||||||
|
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
||||||
|
-DCMAKE_CXX_STANDARD=$CPP \
|
||||||
|
-DSPDLOG_BUILD_EXAMPLES=ON \
|
||||||
|
-DSPDLOG_BUILD_BENCH=OFF \
|
||||||
|
-DSPDLOG_SANITIZE_ADDRESS=$ASAN \
|
||||||
|
-DSPDLOG_SANITIZE_THREAD=$TSAN
|
||||||
|
- make VERBOSE=1 -j2
|
||||||
|
- ctest -j2 --output-on-failure
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email: false
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
# *************************************************************************/
|
||||||
|
# * Copyright (c) 2015 Ruslan Baratov. */
|
||||||
|
# * */
|
||||||
|
# * Permission is hereby granted, free of charge, to any person obtaining */
|
||||||
|
# * a copy of this software and associated documentation files (the */
|
||||||
|
# * "Software"), to deal in the Software without restriction, including */
|
||||||
|
# * without limitation the rights to use, copy, modify, merge, publish, */
|
||||||
|
# * distribute, sublicense, and/or sell copies of the Software, and to */
|
||||||
|
# * permit persons to whom the Software is furnished to do so, subject to */
|
||||||
|
# * the following conditions: */
|
||||||
|
# * */
|
||||||
|
# * The above copyright notice and this permission notice shall be */
|
||||||
|
# * included in all copies or substantial portions of the Software. */
|
||||||
|
# * */
|
||||||
|
# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||||
|
# * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||||
|
# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||||
|
# * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||||
|
# * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||||
|
# * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||||
|
# * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
|
# *************************************************************************/
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.1)
|
||||||
|
project(SpdlogBench CXX)
|
||||||
|
|
||||||
|
if(NOT TARGET spdlog)
|
||||||
|
# Stand-alone build
|
||||||
|
find_package(spdlog CONFIG REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
|
add_executable(bench bench.cpp)
|
||||||
|
target_link_libraries(bench spdlog::spdlog Threads::Threads)
|
||||||
|
|
||||||
|
add_executable(async_bench async_bench.cpp)
|
||||||
|
target_link_libraries(async_bench spdlog::spdlog Threads::Threads)
|
||||||
|
|
||||||
|
add_executable(latency latency.cpp)
|
||||||
|
target_link_libraries(latency spdlog::spdlog Threads::Threads)
|
||||||
|
|
||||||
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")
|
@ -0,0 +1,21 @@
|
|||||||
|
if(SPDLOG_SANITIZE_THREAD AND SPDLOG_SANITIZE_ADDRESS)
|
||||||
|
message(FATAL_ERROR "AddressSanitizer is not compatible with ThreadSanitizer.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(SPDLOG_SANITIZE_ADDRESS)
|
||||||
|
message(STATUS "AddressSanitizer enabled")
|
||||||
|
set(SANITIZER_FLAGS "-fsanitize=address,undefined")
|
||||||
|
add_compile_options("-fno-sanitize=signed-integer-overflow")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(SPDLOG_SANITIZE_THREAD)
|
||||||
|
message(STATUS "ThreadSanitizer enabled")
|
||||||
|
set(SANITIZER_FLAGS "-fsanitize=thread")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(SPDLOG_SANITIZE_THREAD OR SPDLOG_SANITIZE_ADDRESS)
|
||||||
|
add_compile_options(${SANITIZER_FLAGS})
|
||||||
|
add_compile_options("-fno-sanitize-recover=all")
|
||||||
|
add_compile_options("-fno-omit-frame-pointer")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS} -fuse-ld=gold")
|
||||||
|
endif()
|
@ -0,0 +1,22 @@
|
|||||||
|
#-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded
|
||||||
|
CXX ?= g++
|
||||||
|
CXX_FLAGS = -Wall -Wextra -pedantic -std=c++11 -pthread -I../include -fmax-errors=1 -Wconversion -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-weak-vtables -Wno-global-constructors
|
||||||
|
CXX_RELEASE_FLAGS = -O3 -march=native
|
||||||
|
CXX_DEBUG_FLAGS= -g
|
||||||
|
|
||||||
|
all: example
|
||||||
|
debug: example-debug
|
||||||
|
|
||||||
|
example: example.cpp
|
||||||
|
$(CXX) example.cpp -o example $(CXX_FLAGS) $(CXX_RELEASE_FLAGS) $(CXXFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
example-debug: example.cpp
|
||||||
|
$(CXX) example.cpp -o example-debug $(CXX_FLAGS) $(CXX_DEBUG_FLAGS) $(CXXFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o logs/*.txt example example-debug
|
||||||
|
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
|
rebuild-debug: clean debug
|
@ -1,12 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Install libc++ under travis
|
|
||||||
|
|
||||||
svn --quiet co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
|
|
||||||
mkdir libcxx/build
|
|
||||||
(cd libcxx/build && cmake .. -DLIBCXX_CXX_ABI=libstdc++ -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.6;/usr/include/c++/4.6/x86_64-linux-gnu")
|
|
||||||
make -C libcxx/build cxx -j2
|
|
||||||
sudo cp libcxx/build/lib/libc++.so.1.0 /usr/lib/
|
|
||||||
sudo cp -r libcxx/build/include/c++/v1 /usr/include/c++/v1/
|
|
||||||
sudo ln -sf /usr/lib/libc++.so.1.0 /usr/lib/libc++.so
|
|
||||||
sudo ln -sf /usr/lib/libc++.so.1.0 /usr/lib/libc++.so.1
|
|
@ -0,0 +1,107 @@
|
|||||||
|
#include "includes.h"
|
||||||
|
|
||||||
|
using namespace std::chrono;
|
||||||
|
using std::chrono::milliseconds;
|
||||||
|
using test_clock = std::chrono::high_resolution_clock;
|
||||||
|
|
||||||
|
static milliseconds millis_from(const test_clock::time_point &tp0)
|
||||||
|
{
|
||||||
|
return std::chrono::duration_cast<milliseconds>(test_clock::now() - tp0);
|
||||||
|
}
|
||||||
|
TEST_CASE("dequeue-empty-nowait", "[mpmc_blocking_q]")
|
||||||
|
{
|
||||||
|
size_t q_size = 100;
|
||||||
|
milliseconds tolerance_wait(10);
|
||||||
|
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||||
|
int popped_item;
|
||||||
|
|
||||||
|
auto start = test_clock::now();
|
||||||
|
auto rv = q.dequeue_for(popped_item, milliseconds::zero());
|
||||||
|
auto delta_ms = millis_from(start);
|
||||||
|
|
||||||
|
REQUIRE(rv == false);
|
||||||
|
INFO("Delta " << delta_ms.count() << " millis");
|
||||||
|
REQUIRE(delta_ms <= tolerance_wait);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]")
|
||||||
|
{
|
||||||
|
|
||||||
|
size_t q_size = 100;
|
||||||
|
milliseconds wait_ms(250);
|
||||||
|
milliseconds tolerance_wait(100);
|
||||||
|
|
||||||
|
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||||
|
int popped_item;
|
||||||
|
auto start = test_clock::now();
|
||||||
|
auto rv = q.dequeue_for(popped_item, wait_ms);
|
||||||
|
auto delta_ms = millis_from(start);
|
||||||
|
|
||||||
|
REQUIRE(rv == false);
|
||||||
|
|
||||||
|
INFO("Delta " << delta_ms.count() << " millis");
|
||||||
|
REQUIRE(delta_ms >= wait_ms);
|
||||||
|
REQUIRE(delta_ms <= wait_ms + tolerance_wait);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("enqueue_nowait", "[mpmc_blocking_q]")
|
||||||
|
{
|
||||||
|
|
||||||
|
size_t q_size = 1;
|
||||||
|
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||||
|
milliseconds tolerance_wait(10);
|
||||||
|
|
||||||
|
q.enqueue(1);
|
||||||
|
REQUIRE(q.overrun_counter() == 0);
|
||||||
|
|
||||||
|
auto start = test_clock::now();
|
||||||
|
q.enqueue_nowait(2);
|
||||||
|
auto delta_ms = millis_from(start);
|
||||||
|
|
||||||
|
INFO("Delta " << delta_ms.count() << " millis");
|
||||||
|
REQUIRE(delta_ms <= tolerance_wait);
|
||||||
|
REQUIRE(q.overrun_counter() == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("bad_queue", "[mpmc_blocking_q]")
|
||||||
|
{
|
||||||
|
size_t q_size = 0;
|
||||||
|
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||||
|
q.enqueue_nowait(1);
|
||||||
|
REQUIRE(q.overrun_counter() == 1);
|
||||||
|
int i;
|
||||||
|
REQUIRE(q.dequeue_for(i, milliseconds(0)) == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("empty_queue", "[mpmc_blocking_q]")
|
||||||
|
{
|
||||||
|
size_t q_size = 10;
|
||||||
|
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||||
|
int i;
|
||||||
|
REQUIRE(q.dequeue_for(i, milliseconds(10)) == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("full_queue", "[mpmc_blocking_q]")
|
||||||
|
{
|
||||||
|
size_t q_size = 100;
|
||||||
|
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||||
|
for (int i = 0; i < static_cast<int>(q_size); i++)
|
||||||
|
{
|
||||||
|
q.enqueue(std::move(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
q.enqueue_nowait(123456);
|
||||||
|
REQUIRE(q.overrun_counter() == 1);
|
||||||
|
|
||||||
|
for (int i = 1; i < static_cast<int>(q_size); i++)
|
||||||
|
{
|
||||||
|
int item = -1;
|
||||||
|
q.dequeue_for(item, milliseconds(0));
|
||||||
|
REQUIRE(item == i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// last item pushed has overridden the oldest.
|
||||||
|
int item = -1;
|
||||||
|
q.dequeue_for(item, milliseconds(0));
|
||||||
|
REQUIRE(item == 123456);
|
||||||
|
}
|
Loading…
Reference in New Issue