From 0d9e87da1844238672c0152312789404e9f7d686 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Fri, 30 Dec 2011 20:51:17 -0800 Subject: [PATCH] prevent CLogWindow::UpdateLog from constantly burning through timer objects, because it was allocating memory a lot and making it hard to debug some things. I think this should be faster even in release builds, but any speedup is probably too tiny to measure. --- Source/Core/DolphinWX/Src/LogWindow.cpp | 77 +++++++++++++------------ Source/Core/DolphinWX/Src/LogWindow.h | 1 + 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/Source/Core/DolphinWX/Src/LogWindow.cpp b/Source/Core/DolphinWX/Src/LogWindow.cpp index 3942988efe..489d81c08d 100644 --- a/Source/Core/DolphinWX/Src/LogWindow.cpp +++ b/Source/Core/DolphinWX/Src/LogWindow.cpp @@ -39,7 +39,7 @@ CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxPanel(parent, id, pos, size, style, name) , x(0), y(0), winpos(0) - , Parent(parent) , m_LogAccess(true) + , Parent(parent), m_ignoreLogTimer(false), m_LogAccess(true) , m_Log(NULL), m_cmdline(NULL), m_FontChoice(NULL) , m_SJISConv(*(wxCSConv*)wxConvCurrent) { @@ -279,6 +279,7 @@ void CLogWindow::OnWrapLineCheck(wxCommandEvent& event) void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event)) { if (!m_LogAccess) return; + if (m_ignoreLogTimer) return; UpdateLog(); // Scroll to the last line @@ -294,52 +295,56 @@ void CLogWindow::UpdateLog() if (!m_LogAccess) return; if (!m_Log) return; - m_LogTimer->Stop(); + // m_LogTimer->Stop(); + // instead of stopping the timer, let's simply ignore its calls during UpdateLog, + // because repeatedly stopping and starting a timer churns memory (and potentially leaks it). + m_ignoreLogTimer = true; + if (!msgQueue.empty()) { - std::lock_guard lk(m_LogSection); - int msgQueueSize = (int)msgQueue.size(); - for (int i = 0; i < msgQueueSize; i++) - { - switch (msgQueue.front().first) + std::lock_guard lk(m_LogSection); + int msgQueueSize = (int)msgQueue.size(); + for (int i = 0; i < msgQueueSize; i++) { - - case ERROR_LEVEL: - m_Log->SetDefaultStyle(wxTextAttr(*wxRED)); - break; + switch (msgQueue.front().first) + { + case ERROR_LEVEL: + m_Log->SetDefaultStyle(wxTextAttr(*wxRED)); + break; - case WARNING_LEVEL: - m_Log->SetDefaultStyle(wxTextAttr(wxColour(255, 255, 0))); // YELLOW - break; + case WARNING_LEVEL: + m_Log->SetDefaultStyle(wxTextAttr(wxColour(255, 255, 0))); // YELLOW + break; - case NOTICE_LEVEL: - m_Log->SetDefaultStyle(wxTextAttr(*wxGREEN)); - break; + case NOTICE_LEVEL: + m_Log->SetDefaultStyle(wxTextAttr(*wxGREEN)); + break; - case INFO_LEVEL: - m_Log->SetDefaultStyle(wxTextAttr(*wxCYAN)); - break; + case INFO_LEVEL: + m_Log->SetDefaultStyle(wxTextAttr(*wxCYAN)); + break; - case DEBUG_LEVEL: - m_Log->SetDefaultStyle(wxTextAttr(*wxLIGHT_GREY)); - break; + case DEBUG_LEVEL: + m_Log->SetDefaultStyle(wxTextAttr(*wxLIGHT_GREY)); + break; - default: - m_Log->SetDefaultStyle(wxTextAttr(*wxWHITE)); - break; + default: + m_Log->SetDefaultStyle(wxTextAttr(*wxWHITE)); + break; + } + if (msgQueue.front().second.size()) + { + int j = m_Log->GetLastPosition(); + m_Log->AppendText(msgQueue.front().second); + // White timestamp + m_Log->SetStyle(j, j + 9, wxTextAttr(*wxWHITE)); + } + msgQueue.pop(); } - if (msgQueue.front().second.size()) - { - int j = m_Log->GetLastPosition(); - m_Log->AppendText(msgQueue.front().second); - // White timestamp - m_Log->SetStyle(j, j + 9, wxTextAttr(*wxWHITE)); - } - msgQueue.pop(); - } } // unlock log - m_LogTimer->Start(UPDATETIME); + // m_LogTimer->Start(UPDATETIME); + m_ignoreLogTimer = false; } void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text) diff --git a/Source/Core/DolphinWX/Src/LogWindow.h b/Source/Core/DolphinWX/Src/LogWindow.h index ba5724cb0c..a4b25f12c3 100644 --- a/Source/Core/DolphinWX/Src/LogWindow.h +++ b/Source/Core/DolphinWX/Src/LogWindow.h @@ -62,6 +62,7 @@ private: wxFont DefaultFont, MonoSpaceFont; std::vector LogFont; wxTimer *m_LogTimer; + bool m_ignoreLogTimer; LogManager *m_LogManager; std::queue > msgQueue; bool m_writeFile, m_writeConsole, m_writeWindow, m_LogAccess;