Commit d12c8806 authored by Ulf Hermann's avatar Ulf Hermann

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's avatarJoerg Bornemann <joerg.bornemann@qt.io>
parent 5df7b127
......@@ -30,18 +30,21 @@ namespace QmlProfiler {
QDataStream &operator>>(QDataStream &stream, QmlNote &note)
{
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 &note)
{
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 &note1, const QmlNote &note2)
{
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 &note1, const QmlNote &note2)
......
......@@ -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 &note);
friend QDataStream &operator<<(QDataStream &stream, const QmlNote &note);
int m_typeIndex;
int m_collapsedRow;
qint64 m_startTime;
qint64 m_duration;
QString m_text;
bool m_loaded;
};
bool operator==(const QmlNote &note1, const QmlNote &note2);
......
......@@ -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);
......
......@@ -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 &note = m_notes[i];
addQmlNote(note.typeIndex(), note.startTime(), note.duration(), note.text());
QmlNote &note = 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 &note) {
return note.startTime() > endTime || note.startTime() + note.duration() < startTime;
m_notes = Utils::filtered(m_notes, [](const QmlNote &note) {
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)
......
......@@ -38,7 +38,7 @@ public:
QmlProfilerNotesModel(QObject *parent);
void loadData();
void saveData(qint64 startTime, qint64 endTime);
void saveData();
const QVector<QmlNote> &notes() const;
void setNotes(const QVector<QmlNote> &notes);
......@@ -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
......@@ -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();
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment