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
CXX_DEBUG_FLAGS= -g
all: example bench
all: bench
debug: example-debug bench-debug
example: example.cpp
......
......@@ -64,12 +64,13 @@ int main(int argc, char* argv[])
if (argc > 2)
threads = atoi(argv[2]);
cout << "*******************************************************************************\n";
cout << "Single thread, " << format(howmany) << " iterations, auto flush=" << auto_flush << endl;
cout << "*******************************************************************************\n";
auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st", file_size, rotating_files, auto_flush);
bench(howmany, rotating_st);
auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st", file_size, rotating_files, auto_flush);
bench(howmany, rotating_st);
auto daily_st = spdlog::daily_logger_st("daily_st", "logs/daily_st", auto_flush);
bench(howmany, daily_st);
bench(howmany, spdlog::create<null_sink_st>("null_st"));
......@@ -92,8 +93,15 @@ int main(int argc, char* argv[])
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();
......
......@@ -55,8 +55,7 @@ class async_log_helper
{
std::string logger_name;
level::level_enum level;
log_clock::time_point time;
std::tm tm_time;
log_clock::time_point time;
std::string raw_msg_str;
async_msg() = default;
......@@ -64,21 +63,16 @@ class async_log_helper
async_msg(const details::log_msg& m) :
logger_name(m.logger_name),
level(m.level),
time(m.time),
tm_time(m.tm_time),
time(m.time),
raw_msg_str(m.raw.data(), m.raw.size())
{
}
{}
log_msg to_log_msg()
{
log_msg msg;
msg.logger_name = logger_name;
msg.level = level;
msg.time = time;
msg.tm_time = tm_time;
msg.time = time;
msg.raw << raw_msg_str;
return msg;
}
......
......@@ -65,7 +65,7 @@ public:
{
_log_msg.logger_name = _callback_logger->name();
_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);
}
}
......
......@@ -37,8 +37,7 @@ struct log_msg
log_msg(level::level_enum l):
logger_name(),
level(l),
time(),
tm_time(),
time(),
raw(),
formatted() {}
......@@ -46,9 +45,7 @@ struct log_msg
log_msg(const log_msg& other) :
logger_name(other.logger_name),
level(other.level),
time(other.time),
tm_time(other.tm_time)
time(other.time)
{
if (other.raw.size())
raw << fmt::BasicStringRef<char>(other.raw.data(), other.raw.size());
......@@ -60,8 +57,7 @@ struct log_msg
log_msg(log_msg&& other) :
logger_name(std::move(other.logger_name)),
level(other.level),
time(std::move(other.time)),
tm_time(other.tm_time),
time(std::move(other.time)),
raw(std::move(other.raw)),
formatted(std::move(other.formatted))
{
......@@ -75,8 +71,7 @@ struct log_msg
logger_name = std::move(other.logger_name);
level = other.level;
time = std::move(other.time);
tm_time = other.tm_time;
time = std::move(other.time);
raw = std::move(other.raw);
formatted = std::move(other.formatted);
other.clear();
......@@ -95,7 +90,7 @@ struct log_msg
std::string logger_name;
level::level_enum level;
log_clock::time_point time;
std::tm tm_time;
//std::tm tm_time;
fmt::MemoryWriter raw;
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