diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2016-07-06 11:34:15 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-07-06 10:26:12 +0000 |
commit | d12c8806ac8f02ad7f9ed741e90fd1c52c5dd3b9 (patch) | |
tree | 915cad32f7239349335eb68d28927e91f6e23983 /src | |
parent | 5df7b1272d490d8f0cd3ff19f2fc1b6929f22514 (diff) | |
download | qt-creator-d12c8806ac8f02ad7f9ed741e90fd1c52c5dd3b9.tar.gz |
QmlProfiler: Add extra metadata to notes
This way we can improve the heuristic used for mapping notes to
timeline events, by taking the row into account. Also, by marking
notes as loaded when loading them we avoid accidentally dropping
them by restricting to ranges.
Change-Id: I031389880571805788c910728ee89333a5cd4727
Task-number: QTCREATORBUG-16542
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/qmlprofiler/qmlnote.cpp | 11 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlnote.h | 10 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp | 4 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilernotesmodel.cpp | 43 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilernotesmodel.h | 5 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilertracefile.cpp | 5 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/tests/qmlnote_test.cpp | 4 |
8 files changed, 61 insertions, 23 deletions
diff --git a/src/plugins/qmlprofiler/qmlnote.cpp b/src/plugins/qmlprofiler/qmlnote.cpp index 30509cb961..9752ef209a 100644 --- a/src/plugins/qmlprofiler/qmlnote.cpp +++ b/src/plugins/qmlprofiler/qmlnote.cpp @@ -30,18 +30,21 @@ namespace QmlProfiler { QDataStream &operator>>(QDataStream &stream, QmlNote ¬e) { - return stream >> note.m_typeIndex >> note.m_startTime >> note.m_duration >> note.m_text; + return stream >> note.m_typeIndex >> note.m_collapsedRow >> note.m_startTime >> note.m_duration + >> note.m_text; } QDataStream &operator<<(QDataStream &stream, const QmlNote ¬e) { - return stream << note.m_typeIndex << note.m_startTime << note.m_duration << note.m_text; + return stream << note.m_typeIndex << note.m_collapsedRow << note.m_startTime << note.m_duration + << note.m_text; } bool operator==(const QmlNote ¬e1, const QmlNote ¬e2) { - return note1.typeIndex() == note2.typeIndex() && note1.startTime() == note2.startTime() - && note1.duration() == note2.duration() && note1.text() == note2.text(); + return note1.typeIndex() == note2.typeIndex() && note1.collapsedRow() == note2.collapsedRow() + && note1.startTime() == note2.startTime() && note1.duration() == note2.duration() + && note1.text() == note2.text(); } bool operator!=(const QmlNote ¬e1, const QmlNote ¬e2) diff --git a/src/plugins/qmlprofiler/qmlnote.h b/src/plugins/qmlprofiler/qmlnote.h index 20dac22d09..d57af60bed 100644 --- a/src/plugins/qmlprofiler/qmlnote.h +++ b/src/plugins/qmlprofiler/qmlnote.h @@ -32,26 +32,32 @@ namespace QmlProfiler { class QmlNote { public: - QmlNote(int typeIndex = -1, qint64 startTime = -1, qint64 duration = 0, + QmlNote(int typeIndex = -1, int collapsedRow = -1, qint64 startTime = -1, qint64 duration = 0, const QString &text = QString()) : - m_typeIndex(typeIndex), m_startTime(startTime), m_duration(duration), m_text(text) + m_typeIndex(typeIndex), m_collapsedRow(collapsedRow), m_startTime(startTime), + m_duration(duration), m_text(text), m_loaded(false) {} int typeIndex() const { return m_typeIndex; } + int collapsedRow() const { return m_collapsedRow; } qint64 startTime() const { return m_startTime; } qint64 duration() const { return m_duration; } QString text() const { return m_text; } + bool loaded() const { return m_loaded; } void setText(const QString &text) { m_text = text; } + void setLoaded(bool loaded) { m_loaded = loaded; } private: friend QDataStream &operator>>(QDataStream &stream, QmlNote ¬e); friend QDataStream &operator<<(QDataStream &stream, const QmlNote ¬e); int m_typeIndex; + int m_collapsedRow; qint64 m_startTime; qint64 m_duration; QString m_text; + bool m_loaded; }; bool operator==(const QmlNote ¬e1, const QmlNote ¬e2); diff --git a/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp b/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp index 6ab22a9b19..067af444b4 100644 --- a/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp @@ -314,7 +314,7 @@ void QmlProfilerModelManager::save(const QString &filename) return; } - d->notesModel->saveData(d->traceTime->startTime(), d->traceTime->endTime()); + d->notesModel->saveData(); QmlProfilerFileWriter *writer = new QmlProfilerFileWriter(this); writer->setTraceTime(traceTime()->startTime(), traceTime()->endTime(), @@ -442,7 +442,7 @@ void QmlProfilerModelManager::clear() void QmlProfilerModelManager::restrictToRange(qint64 startTime, qint64 endTime) { - d->notesModel->saveData(d->traceTime->startTime(), d->traceTime->endTime()); + d->notesModel->saveData(); setState(ClearingData); setVisibleFeatures(0); diff --git a/src/plugins/qmlprofiler/qmlprofilernotesmodel.cpp b/src/plugins/qmlprofiler/qmlprofilernotesmodel.cpp index 6711229e49..e559884f45 100644 --- a/src/plugins/qmlprofiler/qmlprofilernotesmodel.cpp +++ b/src/plugins/qmlprofiler/qmlprofilernotesmodel.cpp @@ -34,9 +34,11 @@ QmlProfilerNotesModel::QmlProfilerNotesModel(QObject *parent) : TimelineNotesMod { } -int QmlProfilerNotesModel::addQmlNote(int typeId, qint64 start, qint64 duration, +int QmlProfilerNotesModel::addQmlNote(int typeId, int collapsedRow, qint64 start, qint64 duration, const QString &text) { + qint64 difference = std::numeric_limits<qint64>::max(); + int foundTypeId = -1; int timelineModel = -1; int timelineIndex = -1; foreach (const Timeline::TimelineModel *model, timelineModels()) { @@ -44,14 +46,33 @@ int QmlProfilerNotesModel::addQmlNote(int typeId, qint64 start, qint64 duration, for (int i = model->firstIndex(start); i <= model->lastIndex(start + duration); ++i) { if (i < 0) continue; - if (model->typeId(i) == typeId && model->startTime(i) == start && - model->duration(i) == duration) { + if (collapsedRow != -1 && collapsedRow != model->collapsedRow(i)) + continue; + + qint64 modelStart = model->startTime(i); + qint64 modelDuration = model->duration(i); + + if (modelStart + modelDuration < start || start + duration < modelStart) + continue; + + // Accept different type IDs if row and time stamps match. + // Some models base their type IDs on data from secondary events which may get + // stripped by range restrictions. + int modelTypeId = model->typeId(i); + if (foundTypeId == typeId && modelTypeId != typeId) + continue; + + qint64 newDifference = qAbs(modelStart - start) + qAbs(modelDuration - duration); + if (newDifference < difference) { timelineModel = model->modelId(); timelineIndex = i; - break; + difference = newDifference; + foundTypeId = modelTypeId; + if (difference == 0 && modelTypeId == typeId) + break; } } - if (timelineIndex != -1) + if (difference == 0 && foundTypeId == typeId) break; } } @@ -68,19 +89,20 @@ void QmlProfilerNotesModel::loadData() blockSignals(true); TimelineNotesModel::clear(); for (int i = 0; i != m_notes.size(); ++i) { - const QmlNote ¬e = m_notes[i]; - addQmlNote(note.typeIndex(), note.startTime(), note.duration(), note.text()); + QmlNote ¬e = m_notes[i]; + note.setLoaded(addQmlNote(note.typeIndex(), note.collapsedRow(), note.startTime(), + note.duration(), note.text()) != -1); } resetModified(); blockSignals(false); emit changed(-1, -1, -1); } -void QmlProfilerNotesModel::saveData(qint64 startTime, qint64 endTime) +void QmlProfilerNotesModel::saveData() { // Keep notes that are outside the given range, overwrite the ones inside the range. - m_notes = Utils::filtered(m_notes, [startTime, endTime](const QmlNote ¬e) { - return note.startTime() > endTime || note.startTime() + note.duration() < startTime; + m_notes = Utils::filtered(m_notes, [](const QmlNote ¬e) { + return !note.loaded(); }); for (int i = 0; i < count(); ++i) { @@ -91,6 +113,7 @@ void QmlProfilerNotesModel::saveData(qint64 startTime, qint64 endTime) int index = timelineIndex(i); QmlNote save = { model->typeId(index), + model->collapsedRow(index), model->startTime(index), model->duration(index), text(i) diff --git a/src/plugins/qmlprofiler/qmlprofilernotesmodel.h b/src/plugins/qmlprofiler/qmlprofilernotesmodel.h index e6cb228744..e2b683fd79 100644 --- a/src/plugins/qmlprofiler/qmlprofilernotesmodel.h +++ b/src/plugins/qmlprofiler/qmlprofilernotesmodel.h @@ -38,7 +38,7 @@ public: QmlProfilerNotesModel(QObject *parent); void loadData(); - void saveData(qint64 startTime, qint64 endTime); + void saveData(); const QVector<QmlNote> ¬es() const; void setNotes(const QVector<QmlNote> ¬es); @@ -47,6 +47,7 @@ public: protected: QVector<QmlNote> m_notes; - int addQmlNote(int typeId, qint64 startTime, qint64 duration, const QString &text); + int addQmlNote(int typeId, int collapsedRow, qint64 startTime, qint64 duration, + const QString &text); }; } // namespace QmlProfiler diff --git a/src/plugins/qmlprofiler/qmlprofilertracefile.cpp b/src/plugins/qmlprofiler/qmlprofilertracefile.cpp index 3b8ea4ff8c..67188e32fa 100644 --- a/src/plugins/qmlprofiler/qmlprofilertracefile.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertracefile.cpp @@ -525,7 +525,11 @@ void QmlProfilerFileReader::loadNotes(QXmlStreamReader &stream) if (elementName == _("note")) { updateProgress(stream.device()); QXmlStreamAttributes attrs = stream.attributes(); + int collapsedRow = attrs.hasAttribute(_("collapsedRow")) ? + attrs.value(_("collapsedRow")).toInt() : -1; + currentNote = QmlNote(attrs.value(_("eventIndex")).toInt(), + collapsedRow, attrs.value(_("startTime")).toLongLong(), attrs.value(_("duration")).toLongLong()); } @@ -751,6 +755,7 @@ void QmlProfilerFileWriter::saveQtd(QIODevice *device) stream.writeAttribute(_("startTime"), QString::number(note.startTime())); stream.writeAttribute(_("duration"), QString::number(note.duration())); stream.writeAttribute(_("eventIndex"), QString::number(note.typeIndex())); + stream.writeAttribute(_("collapsedRow"), QString::number(note.collapsedRow())); stream.writeCharacters(note.text()); stream.writeEndElement(); // note incrementProgress(); diff --git a/src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp b/src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp index 78bbfee830..c8a6beaeae 100644 --- a/src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp +++ b/src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp @@ -84,7 +84,7 @@ void FlameGraphModelTest::generateData(QmlProfilerModelManager *manager) manager->acquiringDone(); - manager->notesModel()->setNotes(QVector<QmlNote>({QmlNote(0, 1, 20, "dings")})); + manager->notesModel()->setNotes(QVector<QmlNote>({QmlNote(0, 2, 1, 20, "dings")})); manager->notesModel()->loadData(); QCOMPARE(manager->state(), QmlProfilerModelManager::Done); diff --git a/src/plugins/qmlprofiler/tests/qmlnote_test.cpp b/src/plugins/qmlprofiler/tests/qmlnote_test.cpp index e4e455095a..7e6ca6ef80 100644 --- a/src/plugins/qmlprofiler/tests/qmlnote_test.cpp +++ b/src/plugins/qmlprofiler/tests/qmlnote_test.cpp @@ -45,7 +45,7 @@ void QmlNoteTest::testAccessors() note.setText("blah"); QCOMPARE(note.text(), QString("blah")); - QmlNote note2(8, 9, 10, "semmeln"); + QmlNote note2(8, 5, 9, 10, "semmeln"); QCOMPARE(note2.typeIndex(), 8); QCOMPARE(note2.startTime(), 9); QCOMPARE(note2.duration(), 10); @@ -54,7 +54,7 @@ void QmlNoteTest::testAccessors() void QmlNoteTest::testStreamOps() { - QmlNote note(4, 5, 6, "eheheh"); + QmlNote note(4, 1, 5, 6, "eheheh"); QBuffer wbuffer; wbuffer.open(QIODevice::WriteOnly); |