Commit 754cac85 authored by gabime's avatar gabime

defer localtime to formatter to improve async performace

parent c215ee61
...@@ -4,7 +4,7 @@ CXX_RELEASE_FLAGS = -O3 -flto ...@@ -4,7 +4,7 @@ CXX_RELEASE_FLAGS = -O3 -flto
CXX_DEBUG_FLAGS= -g CXX_DEBUG_FLAGS= -g
all: example bench all: bench
debug: example-debug bench-debug debug: example-debug bench-debug
example: example.cpp example: example.cpp
......
...@@ -64,6 +64,7 @@ int main(int argc, char* argv[]) ...@@ -64,6 +64,7 @@ int main(int argc, char* argv[])
if (argc > 2) if (argc > 2)
threads = atoi(argv[2]); threads = atoi(argv[2]);
cout << "*******************************************************************************\n"; cout << "*******************************************************************************\n";
cout << "Single thread, " << format(howmany) << " iterations, auto flush=" << auto_flush << endl; cout << "Single thread, " << format(howmany) << " iterations, auto flush=" << auto_flush << endl;
cout << "*******************************************************************************\n"; cout << "*******************************************************************************\n";
...@@ -92,8 +93,15 @@ int main(int argc, char* argv[]) ...@@ -92,8 +93,15 @@ int main(int argc, char* argv[])
spdlog::set_async_mode(howmany); spdlog::set_async_mode(howmany);
auto daily_st_async = spdlog::daily_logger_st("daily_async", "logs/daily_async", auto_flush);
bench_mt(howmany, daily_st_async, threads); for(int i = 0; i < 3; ++i)
{
auto as = spdlog::daily_logger_st("as", "logs/daily_async", auto_flush);
//bench_mt(howmany, spdlog::create<null_sink_st>("as"), threads);
bench_mt(howmany, as, threads);
as->stop();
spdlog::drop("as");
}
spdlog::stop(); spdlog::stop();
......
...@@ -56,7 +56,6 @@ class async_log_helper ...@@ -56,7 +56,6 @@ class async_log_helper
std::string logger_name; std::string logger_name;
level::level_enum level; level::level_enum level;
log_clock::time_point time; log_clock::time_point time;
std::tm tm_time;
std::string raw_msg_str; std::string raw_msg_str;
async_msg() = default; async_msg() = default;
...@@ -65,12 +64,8 @@ class async_log_helper ...@@ -65,12 +64,8 @@ class async_log_helper
logger_name(m.logger_name), logger_name(m.logger_name),
level(m.level), level(m.level),
time(m.time), time(m.time),
tm_time(m.tm_time),
raw_msg_str(m.raw.data(), m.raw.size()) raw_msg_str(m.raw.data(), m.raw.size())
{ {}
}
log_msg to_log_msg() log_msg to_log_msg()
{ {
...@@ -78,7 +73,6 @@ class async_log_helper ...@@ -78,7 +73,6 @@ class async_log_helper
msg.logger_name = logger_name; msg.logger_name = logger_name;
msg.level = level; msg.level = level;
msg.time = time; msg.time = time;
msg.tm_time = tm_time;
msg.raw << raw_msg_str; msg.raw << raw_msg_str;
return msg; return msg;
} }
......
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
{ {
_log_msg.logger_name = _callback_logger->name(); _log_msg.logger_name = _callback_logger->name();
_log_msg.time = log_clock::now(); _log_msg.time = log_clock::now();
_log_msg.tm_time = details::os::localtime(log_clock::to_time_t(_log_msg.time)); //_log_msg.tm_time = details::os::localtime(log_clock::to_time_t(_log_msg.time));
_callback_logger->_log_msg(_log_msg); _callback_logger->_log_msg(_log_msg);
} }
} }
......
...@@ -38,7 +38,6 @@ struct log_msg ...@@ -38,7 +38,6 @@ struct log_msg
logger_name(), logger_name(),
level(l), level(l),
time(), time(),
tm_time(),
raw(), raw(),
formatted() {} formatted() {}
...@@ -46,9 +45,7 @@ struct log_msg ...@@ -46,9 +45,7 @@ struct log_msg
log_msg(const log_msg& other) : log_msg(const log_msg& other) :
logger_name(other.logger_name), logger_name(other.logger_name),
level(other.level), level(other.level),
time(other.time), time(other.time)
tm_time(other.tm_time)
{ {
if (other.raw.size()) if (other.raw.size())
raw << fmt::BasicStringRef<char>(other.raw.data(), other.raw.size()); raw << fmt::BasicStringRef<char>(other.raw.data(), other.raw.size());
...@@ -61,7 +58,6 @@ struct log_msg ...@@ -61,7 +58,6 @@ struct log_msg
logger_name(std::move(other.logger_name)), logger_name(std::move(other.logger_name)),
level(other.level), level(other.level),
time(std::move(other.time)), time(std::move(other.time)),
tm_time(other.tm_time),
raw(std::move(other.raw)), raw(std::move(other.raw)),
formatted(std::move(other.formatted)) formatted(std::move(other.formatted))
{ {
...@@ -76,7 +72,6 @@ struct log_msg ...@@ -76,7 +72,6 @@ struct log_msg
logger_name = std::move(other.logger_name); logger_name = std::move(other.logger_name);
level = other.level; level = other.level;
time = std::move(other.time); time = std::move(other.time);
tm_time = other.tm_time;
raw = std::move(other.raw); raw = std::move(other.raw);
formatted = std::move(other.formatted); formatted = std::move(other.formatted);
other.clear(); other.clear();
...@@ -95,7 +90,7 @@ struct log_msg ...@@ -95,7 +90,7 @@ struct log_msg
std::string logger_name; std::string logger_name;
level::level_enum level; level::level_enum level;
log_clock::time_point time; log_clock::time_point time;
std::tm tm_time; //std::tm tm_time;
fmt::MemoryWriter raw; fmt::MemoryWriter raw;
fmt::MemoryWriter formatted; fmt::MemoryWriter formatted;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment