forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user