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,12 +64,13 @@ int main(int argc, char* argv[]) ...@@ -64,12 +64,13 @@ 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";
auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st", file_size, rotating_files, auto_flush); auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st", file_size, rotating_files, auto_flush);
bench(howmany, rotating_st); bench(howmany, rotating_st);
auto daily_st = spdlog::daily_logger_st("daily_st", "logs/daily_st", auto_flush); auto daily_st = spdlog::daily_logger_st("daily_st", "logs/daily_st", auto_flush);
bench(howmany, daily_st); bench(howmany, daily_st);
bench(howmany, spdlog::create<null_sink_st>("null_st")); bench(howmany, spdlog::create<null_sink_st>("null_st"));
...@@ -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();
......
...@@ -55,8 +55,7 @@ class async_log_helper ...@@ -55,8 +55,7 @@ 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;
...@@ -64,21 +63,16 @@ class async_log_helper ...@@ -64,21 +63,16 @@ class async_log_helper
async_msg(const details::log_msg& m) : async_msg(const details::log_msg& m) :
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()
{ {
log_msg msg; log_msg msg;
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);
} }
} }
......
...@@ -37,8 +37,7 @@ struct log_msg ...@@ -37,8 +37,7 @@ struct log_msg
log_msg(level::level_enum l): log_msg(level::level_enum l):
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());
...@@ -60,8 +57,7 @@ struct log_msg ...@@ -60,8 +57,7 @@ struct log_msg
log_msg(log_msg&& other) : log_msg(log_msg&& other) :
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))
{ {
...@@ -75,8 +71,7 @@ struct log_msg ...@@ -75,8 +71,7 @@ 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