Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory optimization #8

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/LogParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
#include <QRegularExpression>
#include <memory>

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)
Expand Down Expand Up @@ -119,24 +130,34 @@ 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;
e.entryNumber = ++entryCount;
e.lineNumber = startLineNumber;
const auto match = logEntryRegex.match(message);
TryExtractEnvironment(message);

e.components[LogComponent::ORIGINAL_MESSAGE] = message;

if (match.hasMatch())
{
e.components[LogComponent::DATE] = match.captured("date");
e.components[LogComponent::TIME] = match.captured("time");
e.components[LogComponent::THREAD] = match.captured("thread");
e.components[LogComponent::SUB_SYS] = match.captured("subsys");
e.components[LogComponent::MESSAGE] = match.captured("message");
e.components[LogComponent::WHERE] = match.captured("where");
e.components[LogComponent::DATE] = GetMatchFromRawData(match, MATCH_GROUP_DATE);
e.components[LogComponent::TIME] = GetMatchFromRawData(match, MATCH_GROUP_TIME);
e.components[LogComponent::THREAD] = GetMatchFromRawData(match, MATCH_GROUP_THREAD);
e.components[LogComponent::SUB_SYS] = GetMatchFromRawData(match, MATCH_GROUP_SUBSYS);
e.components[LogComponent::MESSAGE] = GetMatchFromRawData(match, MATCH_GROUP_MESSAGE);
e.components[LogComponent::WHERE] = GetMatchFromRawData(match, MATCH_GROUP_WHERE);

// Read log level
e.level = GetLogLevel(match.captured("level"));
const QString type = GetMatchFromRawData(match, MATCH_GROUP_LEVEL);
e.level = GetLogLevel(type);

//TODO
e.timeStamp = QDateTime::fromString("20" + e.components[LogComponent::DATE] + ' ' + e.components[LogComponent::TIME], Qt::ISODateWithMs);
Expand All @@ -146,7 +167,6 @@ LogEntry LogParser::ParseMessage(const QString& message, uint64_t startLineNumbe
e.components[LogComponent::MESSAGE] = message;
e.level = GetLogLevel("");
}
e.components[LogComponent::ORIGINAL_MESSAGE] = message;

return e;
}
Expand Down
4 changes: 4 additions & 0 deletions src/LogViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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)
Expand Down Expand Up @@ -72,6 +75,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);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/LogViewerTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down