Skip to content

Commit 17410d9

Browse files
committed
Review Fixes
Review Fixes
1 parent 5da903e commit 17410d9

15 files changed

Lines changed: 179 additions & 132 deletions

qdlt/dltmessagematcher.cpp

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,30 @@ bool DltMessageMatcher::match(const QDltMsg &msg, const QString &searchText) con
1616

1717
bool DltMessageMatcher::match(const QDltMsg &msg, const Pattern& pattern) const
1818
{
19-
if (!matchAppId(msg.getApid()) || !matchCtxId(msg.getCtid()))
19+
if (!passesPreFilters(msg))
2020
return false;
2121

22-
if (!matchTimestampRange(msg.getTimestamp())) {
23-
return false;
24-
}
25-
26-
if (m_timeRangeMs)
27-
{
28-
const qint64 timestampMSecsSinceEpoch = msg.getTime() * 1000 + msg.getMicroseconds() / 1000;
29-
if (!matchTimeRangeMs(timestampMSecsSinceEpoch))
30-
return false;
31-
}
22+
if (std::holds_alternative<QRegularExpression>(pattern))
23+
return matchHeaderAndPayload(msg, std::get<QRegularExpression>(pattern));
3224

33-
if (std::holds_alternative<QRegularExpression>(pattern)) {
34-
bool matchFound = false;
35-
if (m_headerSearchEnabled) {
36-
auto header = msg.toStringHeader();
37-
if (m_messageIdFormat)
38-
header += ' ' + QString::asprintf(m_messageIdFormat->toUtf8(), msg.getMessageId());
39-
matchFound = header.contains(std::get<QRegularExpression>(pattern));
40-
}
41-
42-
if (matchFound)
43-
return true;
44-
45-
if (m_payloadSearchEnabled) {
46-
const auto payload = msg.toStringPayload();
47-
matchFound = payload.contains(std::get<QRegularExpression>(pattern));
48-
}
25+
return matchHeaderAndPayload(msg, std::get<QString>(pattern));
26+
}
4927

50-
return matchFound;
51-
}
28+
bool DltMessageMatcher::matchText(const QDltMsg &msg, const QString &searchText) const
29+
{
30+
if (!passesPreFilters(msg))
31+
return false;
5232

53-
return matchText(msg, std::get<QString>(pattern));
33+
return matchHeaderAndPayload(msg, searchText);
5434
}
5535

56-
bool DltMessageMatcher::matchText(const QDltMsg &msg, const QString &searchText) const
36+
bool DltMessageMatcher::passesPreFilters(const QDltMsg &msg) const
5737
{
5838
if (!matchAppId(msg.getApid()) || !matchCtxId(msg.getCtid()))
5939
return false;
6040

61-
if (!matchTimestampRange(msg.getTimestamp())) {
41+
if (!matchTimestampRange(msg.getTimestamp()))
6242
return false;
63-
}
6443

6544
if (m_timeRangeMs)
6645
{
@@ -69,6 +48,11 @@ bool DltMessageMatcher::matchText(const QDltMsg &msg, const QString &searchText)
6948
return false;
7049
}
7150

51+
return true;
52+
}
53+
54+
bool DltMessageMatcher::matchHeaderAndPayload(const QDltMsg &msg, const QString &searchText) const
55+
{
7256
if (m_headerSearchEnabled) {
7357
auto header = msg.toStringHeader();
7458
if (m_messageIdFormat)
@@ -85,6 +69,24 @@ bool DltMessageMatcher::matchText(const QDltMsg &msg, const QString &searchText)
8569
return false;
8670
}
8771

72+
bool DltMessageMatcher::matchHeaderAndPayload(const QDltMsg &msg, const QRegularExpression &pattern) const
73+
{
74+
if (m_headerSearchEnabled) {
75+
auto header = msg.toStringHeader();
76+
if (m_messageIdFormat)
77+
header += ' ' + QString::asprintf(m_messageIdFormat->toUtf8(), msg.getMessageId());
78+
if (header.contains(pattern))
79+
return true;
80+
}
81+
82+
if (m_payloadSearchEnabled) {
83+
const auto payload = msg.toStringPayload();
84+
return payload.contains(pattern);
85+
}
86+
87+
return false;
88+
}
89+
8890
bool DltMessageMatcher::matchAppId(const QString& appId) const
8991
{
9092
return m_appId.isEmpty() || appId.compare(m_appId, m_caseSensitivity) == 0;

qdlt/dltmessagematcher.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class QDLT_EXPORT DltMessageMatcher
5656
bool match(const QDltMsg& message, const Pattern& pattern) const;
5757
private:
5858
bool matchText(const QDltMsg& message, const QString& searchText) const;
59+
// Common appId/ctxId/timestamp/time-range checks shared by the regex and text match paths.
60+
bool passesPreFilters(const QDltMsg& message) const;
61+
bool matchHeaderAndPayload(const QDltMsg& message, const QString& searchText) const;
62+
bool matchHeaderAndPayload(const QDltMsg& message, const QRegularExpression& pattern) const;
5963
bool matchAppId(const QString& appId) const;
6064
bool matchCtxId(const QString& ctxId) const;
6165
bool matchTimestampRange(unsigned int ts) const;

qdlt/qdltfile.cpp

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void QDltFile::setDltIndex(QVector<qint64> &_indexAll, int num)
110110
bumpSearchSnapshotGenerationLocked();
111111
}
112112

113-
int QDltFile::size() const
113+
int QDltFile::sizeLocked() const
114114
{
115115
int size=0;
116116
for(int num=0;num<files.size();num++)
@@ -122,8 +122,15 @@ int QDltFile::size() const
122122
return size;
123123
}
124124

125+
int QDltFile::size() const
126+
{
127+
QMutexLocker locker(&mutexQDlt);
128+
return sizeLocked();
129+
}
130+
125131
qint64 QDltFile::fileSize() const
126132
{
133+
QMutexLocker locker(&mutexQDlt);
127134
qint64 size=0;
128135

129136
for(int num=0;num<files.size();num++)
@@ -141,11 +148,7 @@ int QDltFile::sizeFilter() const
141148
if(filterFlag)
142149
return indexFilter.size();
143150

144-
int total = 0;
145-
for(int num = 0; num < files.size(); ++num)
146-
total += files[num]->indexAll.size();
147-
148-
return total;
151+
return sizeLocked();
149152
}
150153

151154
int QDltFile::calculateHeaderSize(quint8 htyp)
@@ -203,13 +206,20 @@ bool QDltFile::open(QString _filename, bool append)
203206

204207
/* create new file item */
205208
QDltFileItem *item = new QDltFileItem();
206-
files.append(item);
207209

208210
/* set new filename */
209211
item->infile.setFileName(_filename);
210212

211213
/* open the log file read only */
212-
if(item->infile.open(QIODevice::ReadOnly)==false)
214+
const bool opened = item->infile.open(QIODevice::ReadOnly);
215+
216+
{
217+
QMutexLocker locker(&mutexQDlt);
218+
files.append(item);
219+
bumpSearchSnapshotGenerationLocked();
220+
}
221+
222+
if(!opened)
213223
{
214224
/* open file failed */
215225
qWarning() << "open of file" << _filename << "failed";
@@ -638,6 +648,7 @@ void QDltFile::addFilterIndex (int index)
638648

639649
QString QDltFile::getFileName(int num)
640650
{
651+
QMutexLocker locker(&mutexQDlt);
641652
if(num<0 || num>=files.size())
642653
return QString();
643654

@@ -646,6 +657,7 @@ QString QDltFile::getFileName(int num)
646657

647658
int QDltFile::getFileMsgNumber(int num) const
648659
{
660+
QMutexLocker locker(&mutexQDlt);
649661
if(num<0 || num>=files.size())
650662
return -1;
651663

@@ -663,6 +675,12 @@ void QDltFile::close()
663675
}
664676

665677
QByteArray QDltFile::getMsg(int index) const
678+
{
679+
QMutexLocker locker(&mutexQDlt);
680+
return getMsgLocked(index);
681+
}
682+
683+
QByteArray QDltFile::getMsgLocked(int index) const
666684
{
667685
QByteArray buf;
668686
int num = 0;
@@ -702,8 +720,6 @@ QByteArray QDltFile::getMsg(int index) const
702720
return QByteArray();
703721
}
704722

705-
mutexQDlt.lock();
706-
707723
QDltFileItem* file = files[num];
708724
const QDltFileItem* const_file = file;
709725
qint64 positionForIndex = const_file->indexAll[index];
@@ -712,7 +728,6 @@ QByteArray QDltFile::getMsg(int index) const
712728
if ( false == file->infile.seek(positionForIndex) )
713729
{
714730
qDebug() << "Seek error on " << positionForIndex << file->infile.fileName() << __FILE__ << __LINE__;
715-
mutexQDlt.unlock();
716731
buf.clear();
717732
return buf;
718733
}
@@ -738,8 +753,6 @@ QByteArray QDltFile::getMsg(int index) const
738753
buf = file->infile.read(cal_index);
739754
}
740755

741-
mutexQDlt.unlock();
742-
743756
/* return DLT message buffer */
744757
return buf;
745758
}
@@ -1003,7 +1016,8 @@ QVector<qint64> QDltFile::mergeIndexFilterBaseWithMarkers(const QSet<qint64> &ma
10031016
if(markerSet.isEmpty())
10041017
return indexFilterBase;
10051018

1006-
const qint64 maxIdx = static_cast<qint64>(size());
1019+
// Called under mutexQDlt via recomputeEffectiveIndexFilterLocked(); use lock-free helpers.
1020+
const qint64 maxIdx = static_cast<qint64>(sizeLocked());
10071021

10081022
// Fast membership check: which indices are already present in the base filter output.
10091023
QSet<qint64> present;
@@ -1047,7 +1061,7 @@ QVector<qint64> QDltFile::mergeIndexFilterBaseWithMarkers(const QSet<qint64> &ma
10471061

10481062
if(idx >= 0 && idx < maxIdx && (sortByTime || sortByTimestamp))
10491063
{
1050-
const QByteArray data = getMsg(static_cast<int>(idx));
1064+
const QByteArray data = getMsgLocked(static_cast<int>(idx));
10511065
if(!data.isEmpty())
10521066
{
10531067
QDltMsg msg;

qdlt/qdltfile.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,12 @@ class QDLT_EXPORT QDltFile : public QDlt
363363
private:
364364
// Calculates total storage, message, and payload sizes for all indexed DLT messages.
365365
void calculateTotalSizes();
366-
void recomputeEffectiveIndexFilterLocked();
367-
void bumpSearchSnapshotGenerationLocked();
366+
void recomputeEffectiveIndexFilterLocked();
367+
void bumpSearchSnapshotGenerationLocked();
368+
// Lock-free counterparts of size()/getMsg(int) for callers that already hold mutexQDlt
369+
// (e.g. mergeIndexFilterBaseWithMarkers, invoked from the *Locked recompute path).
370+
int sizeLocked() const;
371+
QByteArray getMsgLocked(int index) const;
368372

369373
//! Mutex to lock critical path for infile
370374
mutable QMutex mutexQDlt;

qdlt/searchsnapshot.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,3 @@ std::shared_ptr<const SearchSnapshot> SearchSnapshotManager::capture(const QDltF
6262
m_cachedSnapshot = snapshot;
6363
return snapshot;
6464
}
65-
66-
void SearchSnapshotManager::invalidate(const QDltFile *file)
67-
{
68-
QMutexLocker locker(&m_mutex);
69-
if(file != nullptr && m_cachedFile != file)
70-
return;
71-
72-
m_cachedFile = nullptr;
73-
m_cachedSnapshot.reset();
74-
}

qdlt/searchsnapshot.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ class QDLT_EXPORT SearchSnapshotManager
6161
{
6262
public:
6363
std::shared_ptr<const SearchSnapshot> capture(const QDltFile *file);
64-
void invalidate(const QDltFile *file = nullptr);
6564

6665
private:
6766
mutable QMutex m_mutex;
6867
const QDltFile *m_cachedFile{nullptr};
6968
std::shared_ptr<const SearchSnapshot> m_cachedSnapshot;
7069
};
7170

72-
#endif // SEARCHSNAPSHOT_H
71+
#endif // SEARCHSNAPSHOT_H

0 commit comments

Comments
 (0)