mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-06 15:04:49 +08:00
Fix Visual Studio poor std::this_thread::get_id() performance by using GetCurrentThreadId() (and pthread_self() under linux)
This commit is contained in:
parent
67e0957e67
commit
a09107927b
@ -60,7 +60,7 @@ class async_log_helper
|
||||
level::level_enum level;
|
||||
log_clock::time_point time;
|
||||
std::string txt;
|
||||
std::thread::id thread_id;
|
||||
uint64_t thread_id;
|
||||
|
||||
async_msg() = default;
|
||||
~async_msg() = default;
|
||||
|
@ -64,7 +64,9 @@ public:
|
||||
{
|
||||
_log_msg.logger_name = _callback_logger->name();
|
||||
_log_msg.time = os::now();
|
||||
_log_msg.thread_id = std::this_thread::get_id();
|
||||
_log_msg.thread_id = os::thread_id();
|
||||
|
||||
|
||||
_callback_logger->_log_msg(_log_msg);
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ struct log_msg
|
||||
|
||||
log_msg(const log_msg& other) :
|
||||
logger_name(other.logger_name),
|
||||
level(other.level),
|
||||
level(other.level),
|
||||
time(other.time),
|
||||
thread_id(other.thread_id)
|
||||
{
|
||||
@ -84,7 +84,7 @@ struct log_msg
|
||||
|
||||
void clear()
|
||||
{
|
||||
level = level::off;
|
||||
level = level::off;
|
||||
raw.clear();
|
||||
formatted.clear();
|
||||
}
|
||||
@ -92,7 +92,7 @@ struct log_msg
|
||||
std::string logger_name;
|
||||
level::level_enum level;
|
||||
log_clock::time_point time;
|
||||
std::thread::id thread_id;
|
||||
uint64_t thread_id;
|
||||
fmt::MemoryWriter raw;
|
||||
fmt::MemoryWriter formatted;
|
||||
};
|
||||
|
@ -32,6 +32,8 @@
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif
|
||||
# include <Windows.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include "../common.h"
|
||||
@ -167,6 +169,17 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime())
|
||||
}
|
||||
|
||||
|
||||
inline uint64_t thread_id()
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
return ::GetCurrentThreadId();
|
||||
#else
|
||||
return (uint64_t) pthread_self();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
} //os
|
||||
} //details
|
||||
} //spdlog
|
||||
|
@ -354,7 +354,7 @@ class t_formatter :public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg, const std::tm&) override
|
||||
{
|
||||
msg.formatted << std::hash<std::thread::id>()(msg.thread_id);
|
||||
msg.formatted << msg.thread_id;
|
||||
}
|
||||
};
|
||||
|
||||
@ -478,7 +478,7 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
|
||||
{
|
||||
switch (flag)
|
||||
{
|
||||
// logger name
|
||||
// logger name
|
||||
case 'n':
|
||||
_formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::name_formatter()));
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user