Get logging to play nice with MPMCQueue
Moved the backend thread function out of Impl constructor. Pass message as rvalue. memcpy message.data into temp message, then use that message as entry message.
This commit is contained in:
@@ -186,6 +186,10 @@ public:
|
|||||||
initialization_in_progress_suppress_logging = false;
|
initialization_in_progress_suppress_logging = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Start() {
|
||||||
|
instance->StartBackendThread();
|
||||||
|
}
|
||||||
|
|
||||||
Impl(const Impl&) = delete;
|
Impl(const Impl&) = delete;
|
||||||
Impl& operator=(const Impl&) = delete;
|
Impl& operator=(const Impl&) = delete;
|
||||||
|
|
||||||
@@ -201,7 +205,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num,
|
void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num,
|
||||||
const char* function, std::string message) {
|
const char* function, fmt::string_view&& message) {
|
||||||
if (!filter.CheckMessage(log_class, log_level))
|
if (!filter.CheckMessage(log_class, log_level))
|
||||||
return;
|
return;
|
||||||
const Entry& entry =
|
const Entry& entry =
|
||||||
@@ -211,7 +215,14 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Impl(const std::filesystem::path& file_backend_filename, const Filter& filter_)
|
Impl(const std::filesystem::path& file_backend_filename, const Filter& filter_)
|
||||||
: filter{filter_}, file_backend{file_backend_filename}, backend_thread{std::thread([this] {
|
: filter{filter_}, file_backend{file_backend_filename} {}
|
||||||
|
|
||||||
|
~Impl() {
|
||||||
|
StopBackendThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartBackendThread() {
|
||||||
|
backend_thread = std::thread([this] {
|
||||||
Common::SetCurrentThreadName("yuzu:Log");
|
Common::SetCurrentThreadName("yuzu:Log");
|
||||||
Entry entry;
|
Entry entry;
|
||||||
const auto write_logs = [this, &entry]() {
|
const auto write_logs = [this, &entry]() {
|
||||||
@@ -232,10 +243,7 @@ private:
|
|||||||
while (max_logs_to_write-- && message_queue.try_pop(entry)) {
|
while (max_logs_to_write-- && message_queue.try_pop(entry)) {
|
||||||
write_logs();
|
write_logs();
|
||||||
}
|
}
|
||||||
})} {}
|
});
|
||||||
|
|
||||||
~Impl() {
|
|
||||||
StopBackendThread();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StopBackendThread() {
|
void StopBackendThread() {
|
||||||
@@ -246,11 +254,15 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr,
|
Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr,
|
||||||
const char* function, std::string message) const {
|
const char* function, fmt::string_view&& message) const {
|
||||||
using std::chrono::duration_cast;
|
using std::chrono::duration_cast;
|
||||||
using std::chrono::microseconds;
|
using std::chrono::microseconds;
|
||||||
using std::chrono::steady_clock;
|
using std::chrono::steady_clock;
|
||||||
|
|
||||||
|
auto len = message.size() + 1;
|
||||||
|
char* msg = new char[len];
|
||||||
|
memcpy(msg, message.data(), len);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
.timestamp = duration_cast<microseconds>(steady_clock::now() - time_origin),
|
.timestamp = duration_cast<microseconds>(steady_clock::now() - time_origin),
|
||||||
.log_class = log_class,
|
.log_class = log_class,
|
||||||
@@ -258,7 +270,7 @@ private:
|
|||||||
.filename = filename,
|
.filename = filename,
|
||||||
.line_num = line_nr,
|
.line_num = line_nr,
|
||||||
.function = function,
|
.function = function,
|
||||||
.message = message.c_str(),
|
.message = msg,
|
||||||
.final_entry = false,
|
.final_entry = false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -290,6 +302,10 @@ void Initialize() {
|
|||||||
Impl::Initialize();
|
Impl::Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Start() {
|
||||||
|
Impl::Start();
|
||||||
|
}
|
||||||
|
|
||||||
void DisableLoggingInTests() {
|
void DisableLoggingInTests() {
|
||||||
initialization_in_progress_suppress_logging = true;
|
initialization_in_progress_suppress_logging = true;
|
||||||
}
|
}
|
||||||
@@ -303,7 +319,7 @@ void SetColorConsoleBackendEnabled(bool enabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
|
void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
|
||||||
unsigned int line_num, const char* function, const char* format,
|
unsigned int line_num, const char* function, fmt::string_view format,
|
||||||
const fmt::format_args& args) {
|
const fmt::format_args& args) {
|
||||||
if (!initialization_in_progress_suppress_logging) {
|
if (!initialization_in_progress_suppress_logging) {
|
||||||
Impl::Instance().PushEntry(log_class, log_level, filename, line_num, function,
|
Impl::Instance().PushEntry(log_class, log_level, filename, line_num, function,
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class Filter;
|
|||||||
/// Initializes the logging system. This should be the first thing called in main.
|
/// Initializes the logging system. This should be the first thing called in main.
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
|
void Start();
|
||||||
|
|
||||||
void DisableLoggingInTests();
|
void DisableLoggingInTests();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,12 +24,12 @@ constexpr const char* TrimSourcePath(std::string_view source) {
|
|||||||
|
|
||||||
/// Logs a message to the global logger, using fmt
|
/// Logs a message to the global logger, using fmt
|
||||||
void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
|
void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
|
||||||
unsigned int line_num, const char* function, const char* format,
|
unsigned int line_num, const char* function, fmt::string_view format,
|
||||||
const fmt::format_args& args);
|
const fmt::format_args& args);
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num,
|
void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num,
|
||||||
const char* function, const char* format, const Args&... args) {
|
const char* function, fmt::string_view format, const Args&... args) {
|
||||||
FmtLogMessageImpl(log_class, log_level, filename, line_num, function, format,
|
FmtLogMessageImpl(log_class, log_level, filename, line_num, function, format,
|
||||||
fmt::make_format_args(args...));
|
fmt::make_format_args(args...));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Common::Log {
|
|||||||
* A log entry. Log entries are store in a structured format to permit more varied output
|
* A log entry. Log entries are store in a structured format to permit more varied output
|
||||||
* formatting on different frontends, as well as facilitating filtering and aggregation.
|
* formatting on different frontends, as well as facilitating filtering and aggregation.
|
||||||
*/
|
*/
|
||||||
struct Entry {
|
struct Entry final {
|
||||||
std::chrono::microseconds timestamp;
|
std::chrono::microseconds timestamp;
|
||||||
Class log_class{};
|
Class log_class{};
|
||||||
Level log_level{};
|
Level log_level{};
|
||||||
|
|||||||
@@ -287,6 +287,8 @@ GMainWindow::GMainWindow()
|
|||||||
|
|
||||||
ui->action_Fullscreen->setChecked(false);
|
ui->action_Fullscreen->setChecked(false);
|
||||||
|
|
||||||
|
Common::Log::Start();
|
||||||
|
|
||||||
QStringList args = QApplication::arguments();
|
QStringList args = QApplication::arguments();
|
||||||
|
|
||||||
if (args.size() < 2) {
|
if (args.size() < 2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user