1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2025-01-31 12:31:45 +01:00

Optimize logs

Pass va_args instead of constructing a temporary array
This commit is contained in:
Nekotekina 2018-09-19 14:14:04 +03:00
parent 11e297c975
commit 26da91c972
2 changed files with 23 additions and 8 deletions

View File

@ -1,4 +1,4 @@
#include "Log.h" #include "Log.h"
#include "File.h" #include "File.h"
#include "StrFmt.h" #include "StrFmt.h"
#include "sema.h" #include "sema.h"
@ -7,6 +7,7 @@
#include "Utilities/Thread.h" #include "Utilities/Thread.h"
#include "rpcs3_version.h" #include "rpcs3_version.h"
#include <cstring> #include <cstring>
#include <cstdarg>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <thread> #include <thread>
@ -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 // Get timestamp
const u64 stamp = get_stamp(); 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 // Get text, extract va_args
thread_local std::string text; text.clear(); thread_local std::string text;
fmt::raw_append(text, fmt, sup, args); thread_local std::vector<u64> 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(); std::string prefix = g_tls_log_prefix();
// Get first (main) listener // Get first (main) listener

View File

@ -31,7 +31,7 @@ namespace logs
private: private:
// Send log message to global logger instance // 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; friend struct channel;
}; };
@ -73,12 +73,12 @@ namespace logs
#define GEN_LOG_METHOD(_sev)\ #define GEN_LOG_METHOD(_sev)\
const message msg_##_sev{this, level::_sev};\ const message msg_##_sev{this, level::_sev};\
template <typename... Args>\ template <typename... Args>\
SAFE_BUFFERS void _sev(const char* fmt, const Args&... args)\ void _sev(const char* fmt, const Args&... args)\
{\ {\
if (UNLIKELY(level::_sev <= enabled))\ if (UNLIKELY(level::_sev <= enabled))\
{\ {\
static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make<fmt_unveil_t<Args>>()...};\ static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make<fmt_unveil_t<Args>>()...};\
msg_##_sev.broadcast(fmt, type_list, fmt_args_t<Args...>{fmt_unveil<Args>::get(args)...});\ msg_##_sev.broadcast(fmt, type_list, u64{fmt_unveil<Args>::get(args)}...);\
}\ }\
} }