From 26da91c972cb2813d89ea7a4d4608ef2736808a4 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Wed, 19 Sep 2018 14:14:04 +0300 Subject: [PATCH] Optimize logs Pass va_args instead of constructing a temporary array --- Utilities/Log.cpp | 25 ++++++++++++++++++++----- Utilities/Log.h | 6 +++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 74d0157cfd..ee76f7d307 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -1,4 +1,4 @@ -#include "Log.h" +#include "Log.h" #include "File.h" #include "StrFmt.h" #include "sema.h" @@ -7,6 +7,7 @@ #include "Utilities/Thread.h" #include "rpcs3_version.h" #include +#include #include #include #include @@ -240,7 +241,7 @@ void logs::listener::add(logs::listener* _new) } } -void logs::message::broadcast(const char* fmt, const fmt_type_info* sup, const u64* args) const +void logs::message::broadcast(const char* fmt, const fmt_type_info* sup, ...) const { // Get timestamp const u64 stamp = get_stamp(); @@ -269,9 +270,23 @@ void logs::message::broadcast(const char* fmt, const fmt_type_info* sup, const u } } - // Get text - thread_local std::string text; text.clear(); - fmt::raw_append(text, fmt, sup, args); + // Get text, extract va_args + thread_local std::string text; + thread_local std::vector args; + + std::size_t args_count = 0; + for (auto v = sup; v->fmt_string; v++) + args_count++; + + text.clear(); + args.resize(args_count); + + va_list c_args; + va_start(c_args, sup); + for (u64& arg : args) + arg = va_arg(c_args, u64); + va_end(c_args); + fmt::raw_append(text, fmt, sup, args.data()); std::string prefix = g_tls_log_prefix(); // Get first (main) listener diff --git a/Utilities/Log.h b/Utilities/Log.h index 8c98e34a95..353ff4abe4 100644 --- a/Utilities/Log.h +++ b/Utilities/Log.h @@ -31,7 +31,7 @@ namespace logs private: // Send log message to global logger instance - void broadcast(const char*, const fmt_type_info*, const u64*) const; + void broadcast(const char*, const fmt_type_info*, ...) const; friend struct channel; }; @@ -73,12 +73,12 @@ namespace logs #define GEN_LOG_METHOD(_sev)\ const message msg_##_sev{this, level::_sev};\ template \ - SAFE_BUFFERS void _sev(const char* fmt, const Args&... args)\ + void _sev(const char* fmt, const Args&... args)\ {\ if (UNLIKELY(level::_sev <= enabled))\ {\ static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make>()...};\ - msg_##_sev.broadcast(fmt, type_list, fmt_args_t{fmt_unveil::get(args)...});\ + msg_##_sev.broadcast(fmt, type_list, u64{fmt_unveil::get(args)}...);\ }\ }