mirror of
https://github.com/KjellKod/g3log.git
synced 2025-01-31 14:39:54 +01:00
Updated for g++-4.7, which no longer requires justthreads c++11 thread implementation
This commit is contained in:
parent
1e7ef6de0a
commit
f82c0ec98d
20
README
20
README
@ -3,6 +3,13 @@ HOW TO BUILD
|
||||
This g2log is a snapshot from KjellKod repository.
|
||||
It contains what is needed to build example, unit test and performance test of g2log.
|
||||
|
||||
justthread C++11 thread library is no longer needed.
|
||||
On Windows it is enough to use Visual Studio 11 (2012)
|
||||
On Linux it is enough to use gcc4.7.
|
||||
The CMakeFile.txt is updated to reflect that, the justthread parts is
|
||||
commented away in case someone still needs that.
|
||||
|
||||
|
||||
If you want to integrate g2log in your own software you need
|
||||
the following files
|
||||
g2log/src/
|
||||
@ -15,12 +22,11 @@ g2log/src/
|
||||
|
||||
BUILDING g2log:
|
||||
-----------
|
||||
The default is to build an example binary 'g2log-example'
|
||||
The default is to build an example binary 'g2log-FATAL'
|
||||
I suggest you start with that, run it and view the created log also.
|
||||
|
||||
If you are interested in the performance or unit tests then you can
|
||||
enable the creation of them in the g2log/CMakeLists.txt file. See that file
|
||||
for more details
|
||||
enable the creation of them in the g2log/CMakeLists.txt file. See that file for more details
|
||||
|
||||
--- Building on Linux ---
|
||||
cd g2log
|
||||
@ -30,13 +36,13 @@ cmake ..
|
||||
make
|
||||
|
||||
--- Building on Windows ---
|
||||
Please use the "visual studio command prompt 2010"
|
||||
Please use the Visual Studio 11 (2012) command prompt "Developer command prompt"
|
||||
cd g2log
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -G "Visual Studio 10" ..
|
||||
msbuild g2log_by_kjellkod.sln
|
||||
Debug\g2log-example.exe
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 11" ..
|
||||
msbuild g2log_by_kjellkod.sln /p:Configuration=Release
|
||||
Release\g2log-FATAL.exe
|
||||
|
||||
|
||||
|
||||
|
@ -14,42 +14,33 @@
|
||||
# the performance and unit tests creation can be enabled by switching their
|
||||
# OPTIONs from OFF to ON --- See below at around line 110
|
||||
|
||||
# 2012-05-29: justthread is no longer necessary on Windows (vs2011) and
|
||||
# linux (gcc4.7.1)
|
||||
|
||||
|
||||
# WINDOWS == README: Example how to setup environment + running an example
|
||||
# 1. please use the "Visual Studio Command Prompt 2010)"
|
||||
# 2. from the g2log folder
|
||||
# mkdir build
|
||||
# cd build;
|
||||
# 3. cmake -G "Visual Studio 10" ..
|
||||
# ALTERNATIVE: cmake -G "Visual Studio 11" ..
|
||||
# 3. cmake -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 11" ..
|
||||
# the "Visual Studio 11" .. does not require just::thread!
|
||||
# 4. msbuild g2log_by_kjellkod.sln
|
||||
# 5. Debug\g2log-example.exe
|
||||
# 4. msbuild g2log_by_kjellkod.sln /p:Configuration=Release
|
||||
# 5. Release\g2log-FATAL-example.exe
|
||||
#
|
||||
|
||||
# LINUX == README: Example how to setup environment + running tests for ===============
|
||||
# 1. Install gtest
|
||||
# cmake
|
||||
# make
|
||||
# make install (possibly as root)
|
||||
#
|
||||
# 2. update path to libraries
|
||||
# sudo /sbin/ldconfig -v | grep gtest
|
||||
#
|
||||
# the grep is only to verify that it works. It should give something like
|
||||
# ... other stuff ...
|
||||
# libgtest.so.0 -> libgtest.so.0.0.0
|
||||
# libgtest_main.so.0 -> libgtest_main.so.0.0.0
|
||||
#
|
||||
# 3. LINUX:To try this out from folder g2log:
|
||||
# . LINUX:To try this out from folder g2log:
|
||||
# mkdir build
|
||||
# cd build
|
||||
# cmake .. # create makefiles in g2log/build directory
|
||||
# make # link active_object, g2log and example code to get an "example" executable
|
||||
# ./g2log-example
|
||||
#
|
||||
# ./g2log-FATAL-example
|
||||
# ============================================================================
|
||||
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
ENABLE_LANGUAGE(CXX)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
|
||||
project (g2log_by_kjellkod)
|
||||
set(LOG_SRC ${g2log_by_kjellkod_SOURCE_DIR}/src)
|
||||
set(DIR_UNIT_TEST ${g2log_by_kjellkod_SOURCE_DIR}/test_unit)
|
||||
@ -66,35 +57,42 @@ IF(UNIX)
|
||||
MESSAGE("")
|
||||
MESSAGE("cmake for *NIX ")
|
||||
MESSAGE("if cmake finishes OK, do make")
|
||||
MESSAGE("then run './g2log-example' or whatever performance test you feel like trying")
|
||||
MESSAGE("then run './g2log-FATAL-example' or whatever performance test you feel like trying")
|
||||
MESSAGE("")
|
||||
set(PLATFORM_LINK_LIBRIES justthread rt)
|
||||
set(PLATFORM_LINK_LIBRIES rt)
|
||||
# justthread not needed from gcc4.7.1
|
||||
# set(PLATFORM_LINK_LIBRIES justthread rt)
|
||||
|
||||
# -rdynamic is needed for correct stack dumps with demangling
|
||||
set(CMAKE_CXX_FLAGS "-Wall -rdynamic -Wunused -std=c++0x ${CMAKE_CXX_FLAGS_DEBUG} -pthread -I/usr/include/justthread")
|
||||
# -D_GLIBCXX_USE_NANOSLEEP is needed for this_thread sleep (unit testing)
|
||||
set(CMAKE_CXX_FLAGS "-Wall -rdynamic -Wunused -std=c++11 ${CMAKE_CXX_FLAGS_DEBUG} -pthread -D_GLIBCXX_USE_NANOSLEEP")
|
||||
set(SRC_PLATFORM_SPECIFIC ${LOG_SRC}/crashhandler_unix.cpp)
|
||||
include_directories("/usr/include/justthread")
|
||||
|
||||
# -- justthread not needed for gcc4.7.1
|
||||
# set(CMAKE_CXX_FLAGS "-Wall -rdynamic -Wunused -std=c++0x ${CMAKE_CXX_FLAGS_DEBUG} -pthread -I/usr/include/justthread")
|
||||
# -- justhtread not needed for gcc4.7.1
|
||||
# include_directories("/usr/include/justthread")
|
||||
ENDIF(UNIX)
|
||||
|
||||
|
||||
#Visual Studio 2010
|
||||
#Visual Studio 2010 -- must use justthread
|
||||
IF(MSVC10)
|
||||
MESSAGE("")
|
||||
MESSAGE("Windows: Please run the command [cmake -G \"Visual Studio 10\" ..]")
|
||||
MESSAGE("if cmake finishes OK, do 'msbuild g2log_by_kjellkod.sln'")
|
||||
MESSAGE("then run 'Debug\\g2log-example.exe' or whatever performance test you feel like trying")
|
||||
MESSAGE("Windows: Please run the command [cmake -DCMAKE_BUILD_TYPE=Release -G \"Visual Studio 10\" ..]")
|
||||
MESSAGE("if cmake finishes OK, do 'msbuild g2log_by_kjellkod.sln /p:Configuration=Release'")
|
||||
MESSAGE("then run 'Release\\g2log-FATAL-example.exe' or whatever performance test you feel like trying")
|
||||
MESSAGE("")
|
||||
set(PLATFORM_LINK_LIBRIES $ENV{PROGRAMFILES}/JustSoftwareSolutions/JustThread/lib/justthread_vc10_mdd.lib)
|
||||
set(SRC_PLATFORM_SPECIFIC ${LOG_SRC}/crashhandler_win.cpp)
|
||||
include_directories("$ENV{PROGRAMFILES}/JustSoftwareSolutions/JustThread/include")
|
||||
ENDIF(MSVC10)
|
||||
|
||||
# Visual Studio 2011 -- BETA: std::thread etc are included with the Visual Studio package =)
|
||||
# Visual Studio 2011 -- std::thread etc are included with the Visual Studio package, so justthread dependencies are removed
|
||||
IF(MSVC11)
|
||||
MESSAGE("")
|
||||
MESSAGE("Windows: Please run the command [cmake -G \"Visual Studio 11\" ..]")
|
||||
MESSAGE("if cmake finishes OK, do 'msbuild g2log_by_kjellkod.sln'")
|
||||
MESSAGE("then run 'Debug\\g2log-example.exe' or whatever performance test you feel like trying")
|
||||
MESSAGE("Windows: Please run the command [cmake -DCMAKE_BUILD_TYPE=Release -G \"Visual Studio 11\" ..]")
|
||||
MESSAGE("if cmake finishes OK, do 'msbuild g2log_by_kjellkod.sln /p:Configuration=Release'")
|
||||
MESSAGE("then run 'Release\\g2log-FATAL-example.exe' or whatever performance test you feel like trying")
|
||||
MESSAGE("")
|
||||
set(SRC_PLATFORM_SPECIFIC ${LOG_SRC}/crashhandler_win.cpp)
|
||||
ENDIF(MSVC11)
|
||||
@ -125,7 +123,7 @@ ENDIF(MSVC11)
|
||||
|
||||
# ============================================================================
|
||||
# OPTIONS: Turn OFF the ones that is of no interest to you
|
||||
# ---- by default all is OFF: except 'g2log-example -----
|
||||
# ---- by default all is OFF: except 'g2log-FATAL-example -----
|
||||
# ---- the reason for this is that
|
||||
# ----- 1) the performance tests were only thoroughly tested on Ubuntu, not windows-
|
||||
# (g2log windows/linux, but Google's glog only on linux)
|
||||
@ -133,9 +131,10 @@ ENDIF(MSVC11)
|
||||
# 2) The unit test were tested windows/linux,. but must be unzipped
|
||||
# before it can be "cmake'd" and compiled --- leaving it as OFF for now
|
||||
# ============================================================================
|
||||
# 1. a simple test example 'g2log-example'
|
||||
# 1. a simple test example 'g2log-FATAL-example'
|
||||
option (USE_SIMPLE_EXAMPLE
|
||||
"Create a simple binary that runs a few LOG calls" ON)
|
||||
"Create simple binaries that runs a few LOG calls" ON)
|
||||
|
||||
|
||||
# 2. performance test (average + worst case) for KjellKod's g2log
|
||||
option (USE_G2LOG_PERFORMANCE
|
||||
@ -152,19 +151,17 @@ ENDIF(MSVC11)
|
||||
|
||||
|
||||
|
||||
# ========================================================
|
||||
# ===============================================================================================
|
||||
#
|
||||
# BELOW : Creating executables depending on OPTIONS above
|
||||
#
|
||||
# =======================================================
|
||||
|
||||
|
||||
# ==============================================================================================
|
||||
# 1. create the the example EXECUTABLE - hook in the test_example's CMakeLists.txt file
|
||||
if (USE_SIMPLE_EXAMPLE)
|
||||
MESSAGE(" g2log-example option ON")
|
||||
MESSAGE(" g2log-FATAL-example option ON")
|
||||
include_directories (${DIR_EXAMPLE})
|
||||
add_executable(g2log-example ${DIR_EXAMPLE}/main.cpp)
|
||||
target_link_libraries(g2log-example lib_activeobject lib_g2logger ${PLATFORM_LINK_LIBRIES})
|
||||
add_executable(g2log-FATAL-example ${DIR_EXAMPLE}/main.cpp)
|
||||
target_link_libraries(g2log-FATAL-example lib_activeobject lib_g2logger ${PLATFORM_LINK_LIBRIES})
|
||||
endif (USE_SIMPLE_EXAMPLE)
|
||||
# =========================
|
||||
|
||||
@ -221,7 +218,7 @@ ENDIF(MSVC11)
|
||||
|
||||
|
||||
endif (USE_GOOGLE_GLOG_PERFORMANCE)
|
||||
# ===========================
|
||||
# ===============================================================================================
|
||||
|
||||
|
||||
# 4. create the unit tests for g2log --- ONLY TESTED THE UNIT TEST ON LINUX
|
||||
|
@ -160,12 +160,7 @@ g2LogWorker* shutDownLogging();
|
||||
// defined here but should't not have to be used outside the g2log
|
||||
namespace internal
|
||||
{
|
||||
typedef std::chrono::steady_clock::time_point time_point;
|
||||
typedef std::chrono::duration<long,std::ratio<1, 1000> > millisecond;
|
||||
typedef std::chrono::duration<long long,std::ratio<1, 1000000> > microsecond;
|
||||
typedef std::chrono::duration<long long, std::ratio<1, 1000000> > microsecond;
|
||||
|
||||
typedef const std::string& LogEntry;
|
||||
typedef const std::string& LogEntry;
|
||||
|
||||
|
||||
/** By default the g2log will call g2LogWorker::fatal(...) which will abort() the system after flushing
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
@ -29,6 +30,11 @@ using namespace g2::internal;
|
||||
|
||||
namespace
|
||||
{
|
||||
typedef std::chrono::steady_clock::time_point time_point;
|
||||
typedef std::chrono::duration<long,std::ratio<1, 1000> > millisecond;
|
||||
typedef std::chrono::duration<long long,std::ratio<1, 1000000> > microsecond;
|
||||
|
||||
|
||||
struct LogTime
|
||||
{
|
||||
LogTime()
|
||||
@ -87,7 +93,7 @@ struct g2LogWorkerImpl
|
||||
std::string log_file_with_path_;
|
||||
std::unique_ptr<kjellkod::Active> bg_;
|
||||
std::ofstream out;
|
||||
g2::internal::time_point start_time_;
|
||||
time_point start_time_;
|
||||
|
||||
private:
|
||||
g2LogWorkerImpl& operator=(const g2LogWorkerImpl&); // c++11 feature not yet in vs2010 = delete;
|
||||
@ -196,12 +202,12 @@ void g2LogWorkerImpl::backgroundExitFatal(FatalMessage fatal_message)
|
||||
|
||||
void g2LogWorker::save(g2::internal::LogEntry msg)
|
||||
{
|
||||
pimpl_->bg_->send(std::tr1::bind(&g2LogWorkerImpl::backgroundFileWrite, pimpl_.get(), msg));
|
||||
pimpl_->bg_->send(std::bind(&g2LogWorkerImpl::backgroundFileWrite, pimpl_.get(), msg));
|
||||
}
|
||||
|
||||
void g2LogWorker::fatal(g2::internal::FatalMessage fatal_message)
|
||||
{
|
||||
pimpl_->bg_->send(std::tr1::bind(&g2LogWorkerImpl::backgroundExitFatal, pimpl_.get(), fatal_message));
|
||||
pimpl_->bg_->send(std::bind(&g2LogWorkerImpl::backgroundExitFatal, pimpl_.get(), fatal_message));
|
||||
}
|
||||
|
||||
std::string g2LogWorker::logFileName() const
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "g2logworker.h"
|
||||
#include "g2log.h"
|
||||
#include <iomanip>
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -57,14 +58,15 @@ int main(int argc, char** argv)
|
||||
{
|
||||
// OK --- on Ubunti this WILL get a compiler warning
|
||||
// On windows it'll probably crash std::cout << "\n\n***** Be ready on Windows this example will 'abort' " << std::endl;
|
||||
std::cout << "\n\n***** Be ready this last example will 'abort' if on Windows" << std::endl;
|
||||
std::cout << "************************************************************\n\n" << std::endl;
|
||||
std::cout << "\n\n***** Be ready this last example may 'abort' if on Windows/Linux_gcc4.7 " << std::endl << std::flush;
|
||||
std::cout << "************************************************************\n\n" << std::endl << std::flush;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
const std::string logging = "logging";
|
||||
LOGF(DEBUG, "ILLEGAL PRINTF_SYNTAX EXAMPLE. WILL GENERATE compiler warning.\n\nbadly formatted message:[Printf-type %s is the number 1 for many %s]", logging.c_str());
|
||||
}
|
||||
|
||||
|
||||
std::cout << "\n\n***** Be ready this last example will 'abort' " << std::endl;
|
||||
std::cout << "\n\n***** Be ready this last example will trigger 'abort' " << std::endl;
|
||||
std::cout << "************************************************************\n\n" << std::endl;
|
||||
CHECK(1<2) << "SHOULD NOT SEE THIS MESSAGE";
|
||||
CHECK(1>2) << "Test to see if contract works: onetwothree: " << 123 << ". This should be at the end of the log, and will exit this example";
|
||||
|
@ -21,17 +21,18 @@
|
||||
#if defined(G2LOG_PERFORMANCE)
|
||||
#include "g2log.h"
|
||||
#include "g2logworker.h"
|
||||
using namespace g2::internal;
|
||||
|
||||
#elif defined(GOOGLE_GLOG_PERFORMANCE)
|
||||
#include <glog/logging.h>
|
||||
#else
|
||||
#error G2LOG_PERFORMANCE or GOOGLE_GLOG_PERFORMANCE was not defined
|
||||
#endif
|
||||
|
||||
typedef std::chrono::steady_clock::time_point time_point;
|
||||
typedef std::chrono::duration<long,std::ratio<1, 1000> > millisecond;
|
||||
typedef std::chrono::duration<long long,std::ratio<1, 1000000> > microsecond;
|
||||
|
||||
// typedef std::chrono::steady_clock::time_point time_point;
|
||||
// typedef std::chrono::duration<long,std::ratio<1, 1000> > millisecond;
|
||||
// typedef std::chrono::duration<long long,std::ratio<1, 1000000> > microsecond;
|
||||
// typedef std::chrono::duration<long long, std::ratio<1, 1000000> > microsecond;
|
||||
namespace g2_test
|
||||
{
|
||||
enum WriteMode
|
||||
@ -83,6 +84,8 @@ long long mean(const std::vector<long long> &v)
|
||||
void measurePeakDuringLogWrites(const std::string& title, std::vector<long long>& result);
|
||||
inline void measurePeakDuringLogWrites(const std::string& title, std::vector<long long>& result)
|
||||
{
|
||||
|
||||
|
||||
#if defined(G2LOG_PERFORMANCE)
|
||||
std::cout << "G2LOG (" << title << ") WORST_PEAK PERFORMANCE TEST" << std::endl;
|
||||
#elif defined(GOOGLE_GLOG_PERFORMANCE)
|
||||
|
Loading…
x
Reference in New Issue
Block a user