Commit 3b5380de authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: save and load notes

Change-Id: Id566bdd2c2a00b886779e04efbda5b49ed87a85d
Reviewed-by: default avatarKai Koehne <kai.koehne@theqtcompany.com>
parent 350615cc
......@@ -383,6 +383,7 @@ void QmlProfilerModelManager::save(const QString &filename)
writer.setTraceTime(traceTime()->startTime(), traceTime()->endTime(), traceTime()->duration());
writer.setV8DataModel(d->v8Model);
writer.setQmlEvents(d->model->getEventTypes(), d->model->getEvents());
writer.setNotes(d->model->getEventNotes());
writer.save(&file);
}
......
......@@ -170,6 +170,11 @@ bool QmlProfilerFileReader::load(QIODevice *device)
break;
}
if (elementName == _("noteData")) {
loadNoteData(stream);
break;
}
if (elementName == _("v8profile")) {
if (m_v8Model)
m_v8Model->load(stream);
......@@ -187,6 +192,7 @@ bool QmlProfilerFileReader::load(QIODevice *device)
return false;
} else {
m_qmlModel->setData(m_qmlEvents, m_ranges);
m_qmlModel->setNoteData(m_notes);
return true;
}
}
......@@ -377,6 +383,41 @@ void QmlProfilerFileReader::loadProfilerDataModel(QXmlStreamReader &stream)
}
}
void QmlProfilerFileReader::loadNoteData(QXmlStreamReader &stream)
{
QmlProfilerDataModel::QmlEventNoteData currentNote;
while (!stream.atEnd() && !stream.hasError()) {
QXmlStreamReader::TokenType token = stream.readNext();
const QStringRef elementName = stream.name();
switch (token) {
case QXmlStreamReader::StartElement: {
if (elementName == _("note")) {
QXmlStreamAttributes attrs = stream.attributes();
currentNote.startTime = attrs.value(_("startTime")).toString().toLongLong();
currentNote.duration = attrs.value(_("duration")).toString().toLongLong();
currentNote.typeIndex = attrs.value(_("eventIndex")).toString().toInt();
}
break;
}
case QXmlStreamReader::Characters: {
currentNote.text = stream.text().toString();
break;
}
case QXmlStreamReader::EndElement: {
if (elementName == _("note")) {
m_notes.append(currentNote);
} else if (elementName == _("noteData")) {
return;
}
break;
}
default:
break;
}
}
}
QmlProfilerFileWriter::QmlProfilerFileWriter(QObject *parent) :
QObject(parent),
m_startTime(0),
......@@ -405,6 +446,11 @@ void QmlProfilerFileWriter::setQmlEvents(const QVector<QmlProfilerDataModel::Qml
m_ranges = events;
}
void QmlProfilerFileWriter::setNotes(const QVector<QmlProfilerDataModel::QmlEventNoteData> &notes)
{
m_notes = notes;
}
void QmlProfilerFileWriter::save(QIODevice *device)
{
QXmlStreamWriter stream(device);
......@@ -505,6 +551,18 @@ void QmlProfilerFileWriter::save(QIODevice *device)
}
stream.writeEndElement(); // profilerDataModel
stream.writeStartElement(_("noteData"));
for (int noteIndex = 0; noteIndex < m_notes.size(); ++noteIndex) {
const QmlProfilerDataModel::QmlEventNoteData &notes = m_notes[noteIndex];
stream.writeStartElement(_("note"));
stream.writeAttribute(_("startTime"), QString::number(notes.startTime));
stream.writeAttribute(_("duration"), QString::number(notes.duration));
stream.writeAttribute(_("eventIndex"), QString::number(notes.typeIndex));
stream.writeCharacters(notes.text);
stream.writeEndElement(); // note
}
stream.writeEndElement(); // noteData
m_v8Model->save(stream);
stream.writeEndElement(); // trace
......
......@@ -69,11 +69,13 @@ signals:
private:
void loadEventData(QXmlStreamReader &reader);
void loadProfilerDataModel(QXmlStreamReader &reader);
void loadNoteData(QXmlStreamReader &reader);
QV8ProfilerDataModel *m_v8Model;
QmlProfilerDataModel *m_qmlModel;
QVector<QmlProfilerDataModel::QmlEventTypeData> m_qmlEvents;
QVector<QmlProfilerDataModel::QmlEventData> m_ranges;
QVector<QmlProfilerDataModel::QmlEventNoteData> m_notes;
};
......@@ -88,17 +90,18 @@ public:
void setV8DataModel(QV8ProfilerDataModel *dataModel);
void setQmlEvents(const QVector<QmlProfilerDataModel::QmlEventTypeData> &types,
const QVector<QmlProfilerDataModel::QmlEventData> &events);
void setNotes(const QVector<QmlProfilerDataModel::QmlEventNoteData> &notes);
void save(QIODevice *device);
private:
void calculateMeasuredTime();
qint64 m_startTime, m_endTime, m_measuredTime;
QV8ProfilerDataModel *m_v8Model;
QVector<QmlProfilerDataModel::QmlEventTypeData> m_qmlEvents;
QVector<QmlProfilerDataModel::QmlEventData> m_ranges;
QVector<QmlProfilerDataModel::QmlEventNoteData> m_notes;
};
......
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