summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Emmanuel Gil Peyrot2015-03-06 19:15:02 +0100
committerGravatar Emmanuel Gil Peyrot2015-03-06 19:23:52 +0100
commit0aa44e238db7a72f4fb8b347168ec76c3ce48ad5 (patch)
treedba02c60d0a663708265089394c634a655417f9d /src
parentMerge pull request #630 from archshift/swap (diff)
downloadyuzu-0aa44e238db7a72f4fb8b347168ec76c3ce48ad5.tar.gz
yuzu-0aa44e238db7a72f4fb8b347168ec76c3ce48ad5.tar.xz
yuzu-0aa44e238db7a72f4fb8b347168ec76c3ce48ad5.zip
Logging: check for filter before sending to the queue, to skip all heavy formatting on the other thread.
Diffstat (limited to 'src')
-rw-r--r--src/citra/citra.cpp3
-rw-r--r--src/citra_qt/main.cpp3
-rw-r--r--src/common/logging/backend.cpp9
-rw-r--r--src/common/logging/backend.h3
-rw-r--r--src/common/logging/filter.h2
-rw-r--r--src/common/logging/text_formatter.cpp7
-rw-r--r--src/common/logging/text_formatter.h3
7 files changed, 21 insertions, 9 deletions
diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp
index 69f0b35b3..2c6ced920 100644
--- a/src/citra/citra.cpp
+++ b/src/citra/citra.cpp
@@ -22,7 +22,8 @@
22int __cdecl main(int argc, char **argv) { 22int __cdecl main(int argc, char **argv) {
23 std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger(); 23 std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger();
24 Log::Filter log_filter(Log::Level::Debug); 24 Log::Filter log_filter(Log::Level::Debug);
25 std::thread logging_thread(Log::TextLoggingLoop, logger, &log_filter); 25 Log::SetFilter(&log_filter);
26 std::thread logging_thread(Log::TextLoggingLoop, logger);
26 SCOPE_EXIT({ 27 SCOPE_EXIT({
27 logger->Close(); 28 logger->Close();
28 logging_thread.join(); 29 logging_thread.join();
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 881c7d337..df7699921 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -310,7 +310,8 @@ int __cdecl main(int argc, char* argv[])
310{ 310{
311 std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger(); 311 std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger();
312 Log::Filter log_filter(Log::Level::Info); 312 Log::Filter log_filter(Log::Level::Info);
313 std::thread logging_thread(Log::TextLoggingLoop, logger, &log_filter); 313 Log::SetFilter(&log_filter);
314 std::thread logging_thread(Log::TextLoggingLoop, logger);
314 SCOPE_EXIT({ 315 SCOPE_EXIT({
315 logger->Close(); 316 logger->Close();
316 logging_thread.join(); 317 logging_thread.join();
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 7c1010b22..7b479b569 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -135,9 +135,18 @@ Entry CreateEntry(Class log_class, Level log_level,
135 return std::move(entry); 135 return std::move(entry);
136} 136}
137 137
138static Filter* filter;
139
140void SetFilter(Filter* new_filter) {
141 filter = new_filter;
142}
143
138void LogMessage(Class log_class, Level log_level, 144void LogMessage(Class log_class, Level log_level,
139 const char* filename, unsigned int line_nr, const char* function, 145 const char* filename, unsigned int line_nr, const char* function,
140 const char* format, ...) { 146 const char* format, ...) {
147 if (!filter->CheckMessage(log_class, log_level))
148 return;
149
141 va_list args; 150 va_list args;
142 va_start(args, format); 151 va_start(args, format);
143 Entry entry = CreateEntry(log_class, log_level, 152 Entry entry = CreateEntry(log_class, log_level,
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h
index 1c44c929e..3114f864c 100644
--- a/src/common/logging/backend.h
+++ b/src/common/logging/backend.h
@@ -10,6 +10,7 @@
10 10
11#include "common/concurrent_ring_buffer.h" 11#include "common/concurrent_ring_buffer.h"
12 12
13#include "common/logging/filter.h"
13#include "common/logging/log.h" 14#include "common/logging/log.h"
14 15
15namespace Log { 16namespace Log {
@@ -131,4 +132,6 @@ Entry CreateEntry(Class log_class, Level log_level,
131/// Initializes the default Logger. 132/// Initializes the default Logger.
132std::shared_ptr<Logger> InitGlobalLogger(); 133std::shared_ptr<Logger> InitGlobalLogger();
133 134
135void SetFilter(Filter* filter);
136
134} 137}
diff --git a/src/common/logging/filter.h b/src/common/logging/filter.h
index c3da9989f..b53e4e633 100644
--- a/src/common/logging/filter.h
+++ b/src/common/logging/filter.h
@@ -2,6 +2,8 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#pragma once
6
5#include <array> 7#include <array>
6#include <string> 8#include <string>
7 9
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp
index ef5739d84..36c91c4f6 100644
--- a/src/common/logging/text_formatter.cpp
+++ b/src/common/logging/text_formatter.cpp
@@ -11,7 +11,6 @@
11#endif 11#endif
12 12
13#include "common/logging/backend.h" 13#include "common/logging/backend.h"
14#include "common/logging/filter.h"
15#include "common/logging/log.h" 14#include "common/logging/log.h"
16#include "common/logging/text_formatter.h" 15#include "common/logging/text_formatter.h"
17 16
@@ -116,7 +115,7 @@ void PrintColoredMessage(const Entry& entry) {
116#endif 115#endif
117} 116}
118 117
119void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter) { 118void TextLoggingLoop(std::shared_ptr<Logger> logger) {
120 std::array<Entry, 256> entry_buffer; 119 std::array<Entry, 256> entry_buffer;
121 120
122 while (true) { 121 while (true) {
@@ -126,9 +125,7 @@ void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter) {
126 } 125 }
127 for (size_t i = 0; i < num_entries; ++i) { 126 for (size_t i = 0; i < num_entries; ++i) {
128 const Entry& entry = entry_buffer[i]; 127 const Entry& entry = entry_buffer[i];
129 if (filter->CheckMessage(entry.log_class, entry.log_level)) { 128 PrintColoredMessage(entry);
130 PrintColoredMessage(entry);
131 }
132 } 129 }
133 } 130 }
134} 131}
diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h
index 2f05794f0..8474a1904 100644
--- a/src/common/logging/text_formatter.h
+++ b/src/common/logging/text_formatter.h
@@ -11,7 +11,6 @@ namespace Log {
11 11
12class Logger; 12class Logger;
13struct Entry; 13struct Entry;
14class Filter;
15 14
16/** 15/**
17 * Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's 16 * Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's
@@ -36,6 +35,6 @@ void PrintColoredMessage(const Entry& entry);
36 * Logging loop that repeatedly reads messages from the provided logger and prints them to the 35 * Logging loop that repeatedly reads messages from the provided logger and prints them to the
37 * console. It is the baseline barebones log outputter. 36 * console. It is the baseline barebones log outputter.
38 */ 37 */
39void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter); 38void TextLoggingLoop(std::shared_ptr<Logger> logger);
40 39
41} 40}