From d4a0e1356a2aedeece940fa8c0bfb6b86a7b214a Mon Sep 17 00:00:00 2001 From: RatzzFatzz Date: Mon, 29 May 2023 14:11:20 +0200 Subject: [PATCH 1/2] Improve memory usage for regex matches --- src/LogParser.cpp | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/LogParser.cpp b/src/LogParser.cpp index 8c19d1a..7c7ca27 100644 --- a/src/LogParser.cpp +++ b/src/LogParser.cpp @@ -20,6 +20,17 @@ #include "LogProfile.h" #include +namespace +{ + const QString MATCH_GROUP_DATE = "date"; + const QString MATCH_GROUP_TIME = "time"; + const QString MATCH_GROUP_THREAD = "thread"; + const QString MATCH_GROUP_SUBSYS = "subsys"; + const QString MATCH_GROUP_MESSAGE = "message"; + const QString MATCH_GROUP_WHERE = "where"; + const QString MATCH_GROUP_LEVEL = "level"; +} + LogParser::~LogParser() { if (ownsFile) @@ -119,6 +130,12 @@ QString LogParser::GetNextMessage(QTextStream& inputStream) return message; } +QString GetMatchFromRawData(const QRegularExpressionMatch& match, const QString& group) +{ + QStringView view = match.capturedView(group); + return QString::fromRawData((QChar*)view.utf16(), view.length()); +} + LogEntry LogParser::ParseMessage(const QString& message, uint64_t startLineNumber) { LogEntry e; @@ -126,17 +143,20 @@ LogEntry LogParser::ParseMessage(const QString& message, uint64_t startLineNumbe e.lineNumber = startLineNumber; const auto match = logEntryRegex.match(message); TryExtractEnvironment(message); + + e.originalMessage = message; + if (match.hasMatch()) { - e.date = match.captured("date"); - e.time = match.captured("time"); - e.thread = match.captured("thread"); - e.subSystem = match.captured("subsys"); - e.message = match.captured("message"); - e.where = match.captured("where"); + e.date = GetMatchFromRawData(match, MATCH_GROUP_DATE); + e.time = GetMatchFromRawData(match, MATCH_GROUP_TIME); + e.thread = GetMatchFromRawData(match, MATCH_GROUP_THREAD); + e.subSystem = GetMatchFromRawData(match, MATCH_GROUP_SUBSYS); + e.message = GetMatchFromRawData(match, MATCH_GROUP_MESSAGE); + e.where = GetMatchFromRawData(match, MATCH_GROUP_WHERE); // Read log level - const QString type = match.captured("level"); + const QString type = GetMatchFromRawData(match, MATCH_GROUP_LEVEL); if (logLevelMap.contains(type)) { e.level = logLevelMap[type]; @@ -154,7 +174,6 @@ LogEntry LogParser::ParseMessage(const QString& message, uint64_t startLineNumbe { e.message = message; } - e.originalMessage = message; e.Process(); return e; From dd38143ab1af32524f8a8c1212fed1c6596f857a Mon Sep 17 00:00:00 2001 From: RatzzFatzz Date: Thu, 1 Jun 2023 20:43:24 +0200 Subject: [PATCH 2/2] Add comments about memory consumption --- src/LogViewer.cpp | 4 ++++ src/LogViewerTab.cpp | 1 + 2 files changed, 5 insertions(+) diff --git a/src/LogViewer.cpp b/src/LogViewer.cpp index ffd5c0f..26fefd1 100644 --- a/src/LogViewer.cpp +++ b/src/LogViewer.cpp @@ -41,6 +41,9 @@ LogViewer::LogViewer(QWidget *parent) : InfoAreaEnabledPlainTextEdit(parent) QFont font("Monospace"); font.setStyleHint(QFont::TypeWriter); setFont(font); + + setUndoRedoEnabled(false); + setUpdatesEnabled(false); } void LogViewer::SetLogHolder(LogHolder* holder) @@ -68,6 +71,7 @@ void LogViewer::UpdateLogView() } { BlockProfiler setProfiler("Set log view"); + // Based on application_621.log: The method call below causes a memory consumption of 54MB setPlainText(string); } } diff --git a/src/LogViewerTab.cpp b/src/LogViewerTab.cpp index cd96a9d..8d36d98 100644 --- a/src/LogViewerTab.cpp +++ b/src/LogViewerTab.cpp @@ -97,6 +97,7 @@ void LogViewerTab::Load(QFile* file) file->close(); { BlockProfiler profilerSetFullLog("Set full log view"); + // Based on application_621.log: Below method call causes 94MB of memory usage ui.fullLogView->setPlainText(log); }