Under linux, use the much faster CLOCK_REALTIME_COARSE clock by default (SPDLOG_CLOCK_COARSE is defined in common.h)
This commit is contained in:
		@@ -36,6 +36,14 @@
 | 
				
			|||||||
#define SPDLOG_NOEXCEPT
 | 
					#define SPDLOG_NOEXCEPT
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// under linux, use the much faster CLOCK_REALTIME_COARSE clock.
 | 
				
			||||||
 | 
					// this clock is less accurate - resolution is 1ms under i386 and x86_64.
 | 
				
			||||||
 | 
					// comment to use the regular (and slower) clock
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __linux__
 | 
				
			||||||
 | 
					#define SPDLOG_CLOCK_COARSE
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace spdlog
 | 
					namespace spdlog
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,9 +26,6 @@
 | 
				
			|||||||
#include <type_traits>
 | 
					#include <type_traits>
 | 
				
			||||||
#include "../common.h"
 | 
					#include "../common.h"
 | 
				
			||||||
#include "../logger.h"
 | 
					#include "../logger.h"
 | 
				
			||||||
#ifdef SPDLOG_CLOCK_COARSE
 | 
					 | 
				
			||||||
#include <time.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Line logger class - aggregates operator<< calls to fast ostream
 | 
					// Line logger class - aggregates operator<< calls to fast ostream
 | 
				
			||||||
@@ -67,15 +64,7 @@ public:
 | 
				
			|||||||
        if (_enabled)
 | 
					        if (_enabled)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _log_msg.logger_name = _callback_logger->name();
 | 
					            _log_msg.logger_name = _callback_logger->name();
 | 
				
			||||||
#ifndef SPDLOG_CLOCK_COARSE
 | 
					            _log_msg.time = os::now();
 | 
				
			||||||
            _log_msg.time = log_clock::now();
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
            timespec ts;
 | 
					 | 
				
			||||||
            ::clock_gettime(CLOCK_REALTIME_COARSE, &ts);
 | 
					 | 
				
			||||||
            _log_msg.time = std::chrono::time_point<log_clock, typename log_clock::duration>(
 | 
					 | 
				
			||||||
                                std::chrono::duration_cast<typename log_clock::duration>(
 | 
					 | 
				
			||||||
                                    std::chrono::seconds(ts.tv_sec) + std::chrono::nanoseconds(ts.tv_nsec)));
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
            _callback_logger->_log_msg(_log_msg);
 | 
					            _callback_logger->_log_msg(_log_msg);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -83,7 +72,7 @@ public:
 | 
				
			|||||||
    //
 | 
					    //
 | 
				
			||||||
    // Support for format string with variadic args
 | 
					    // Support for format string with variadic args
 | 
				
			||||||
    //
 | 
					    //
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void write(const char* what)
 | 
					    void write(const char* what)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -106,7 +95,7 @@ public:
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    //
 | 
					    //
 | 
				
			||||||
    // Support for operator<<
 | 
					    // Support for operator<<
 | 
				
			||||||
    //
 | 
					    //
 | 
				
			||||||
@@ -194,7 +183,7 @@ public:
 | 
				
			|||||||
            _log_msg.raw << what;
 | 
					            _log_msg.raw << what;
 | 
				
			||||||
        return *this;
 | 
					        return *this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
   
 | 
					
 | 
				
			||||||
    //Support user types which implements operator<<
 | 
					    //Support user types which implements operator<<
 | 
				
			||||||
    template<typename T>
 | 
					    template<typename T>
 | 
				
			||||||
    line_logger& operator<<(const T& what)
 | 
					    line_logger& operator<<(const T& what)
 | 
				
			||||||
@@ -204,7 +193,7 @@ public:
 | 
				
			|||||||
        return *this;
 | 
					        return *this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
           
 | 
					
 | 
				
			||||||
    void disable()
 | 
					    void disable()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        _enabled = false;
 | 
					        _enabled = false;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,6 @@
 | 
				
			|||||||
/*************************************************************************/
 | 
					/*************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					 | 
				
			||||||
#include<string>
 | 
					#include<string>
 | 
				
			||||||
#include<cstdio>
 | 
					#include<cstdio>
 | 
				
			||||||
#include<ctime>
 | 
					#include<ctime>
 | 
				
			||||||
@@ -35,6 +34,8 @@
 | 
				
			|||||||
# include <Windows.h>
 | 
					# include <Windows.h>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "..\common.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace spdlog
 | 
					namespace spdlog
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
namespace details
 | 
					namespace details
 | 
				
			||||||
@@ -42,6 +43,21 @@ namespace details
 | 
				
			|||||||
namespace os
 | 
					namespace os
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					inline spdlog::log_clock::time_point now()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef SPDLOG_CLOCK_COARSE
 | 
				
			||||||
 | 
					    timespec ts;
 | 
				
			||||||
 | 
					    ::clock_gettime(CLOCK_REALTIME_COARSE, &ts);
 | 
				
			||||||
 | 
					    return std::chrono::time_point<log_clock, typename log_clock::duration>(
 | 
				
			||||||
 | 
					               std::chrono::duration_cast<typename log_clock::duration>(
 | 
				
			||||||
 | 
					                   std::chrono::seconds(ts.tv_sec) + std::chrono::nanoseconds(ts.tv_nsec)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    return log_clock::now();
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
inline std::tm localtime(const std::time_t &time_tt)
 | 
					inline std::tm localtime(const std::time_t &time_tt)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user