forked from qt-creator/qt-creator
QmlJSInspector: Improve performance
Populating watchhandler can be expensive. Update with just the necessary data. Change-Id: I06c28e1c8f5437cc05d3f9cef139d3df9da10c81 Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
This commit is contained in:
@@ -62,11 +62,12 @@ QmlInspectorAgent::QmlInspectorAgent(DebuggerEngine *engine, QObject *parent)
|
|||||||
, m_engineQueryId(0)
|
, m_engineQueryId(0)
|
||||||
, m_rootContextQueryId(0)
|
, m_rootContextQueryId(0)
|
||||||
, m_objectToSelect(-1)
|
, m_objectToSelect(-1)
|
||||||
|
, m_newObjectsCreated(false)
|
||||||
{
|
{
|
||||||
connect(debuggerCore()->action(ShowQmlObjectTree),
|
connect(debuggerCore()->action(ShowQmlObjectTree),
|
||||||
SIGNAL(valueChanged(QVariant)), SLOT(updateStatus()));
|
SIGNAL(valueChanged(QVariant)), SLOT(updateStatus()));
|
||||||
m_delayQueryTimer.setSingleShot(true);
|
m_delayQueryTimer.setSingleShot(true);
|
||||||
m_delayQueryTimer.setInterval(500);
|
m_delayQueryTimer.setInterval(100);
|
||||||
connect(&m_delayQueryTimer, SIGNAL(timeout()), SLOT(queryEngineContext()));
|
connect(&m_delayQueryTimer, SIGNAL(timeout()), SLOT(queryEngineContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +230,8 @@ ObjectReference QmlInspectorAgent::objectForName(
|
|||||||
QHashIterator<int, QByteArray> iter(m_debugIdToIname);
|
QHashIterator<int, QByteArray> iter(m_debugIdToIname);
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
iter.next();
|
iter.next();
|
||||||
if (m_debuggerEngine->watchHandler()->findData(iter.value())->name == objectId)
|
const WatchData *wd = m_debuggerEngine->watchHandler()->findData(iter.value());
|
||||||
|
if (wd && wd->name == objectId)
|
||||||
return ObjectReference(iter.key());
|
return ObjectReference(iter.key());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -467,6 +469,8 @@ void QmlInspectorAgent::newObject(int engineId, int objectId, int /*parentId*/)
|
|||||||
|
|
||||||
if (m_engine.debugId() != engineId)
|
if (m_engine.debugId() != engineId)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_newObjectsCreated = true;
|
||||||
if (m_engineClient->objectName() == QmlDebug::Constants::QML_DEBUGGER)
|
if (m_engineClient->objectName() == QmlDebug::Constants::QML_DEBUGGER)
|
||||||
fetchObject(objectId);
|
fetchObject(objectId);
|
||||||
else
|
else
|
||||||
@@ -530,6 +534,7 @@ void QmlInspectorAgent::queryEngineContext()
|
|||||||
|
|
||||||
m_rootContextQueryId
|
m_rootContextQueryId
|
||||||
= m_engineClient->queryRootContexts(m_engine);
|
= m_engineClient->queryRootContexts(m_engine);
|
||||||
|
m_newObjectsCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::fetchObject(int debugId)
|
void QmlInspectorAgent::fetchObject(int debugId)
|
||||||
@@ -608,69 +613,82 @@ void QmlInspectorAgent::objectTreeFetched(const ObjectReference &object)
|
|||||||
|
|
||||||
m_objectStack.push(object);
|
m_objectStack.push(object);
|
||||||
|
|
||||||
if (m_engineClient->objectName() == QmlDebug::Constants::QML_DEBUGGER) {
|
if (m_objectTreeQueryIds.count()) {
|
||||||
if (object.parentId() != -1 && !m_debugIdToIname.contains(object.parentId())) {
|
|
||||||
fetchObject(object.parentId());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (m_objectTreeQueryIds.count()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QElapsedTimer timeElapsed;
|
||||||
// sync tree with watchhandler
|
// sync tree with watchhandler
|
||||||
QList<WatchData> watchData;
|
QList<WatchData> watchData;
|
||||||
ObjectReference last;
|
ObjectReference last;
|
||||||
if (m_engineClient->objectName() == QmlDebug::Constants::QML_DEBUGGER) {
|
QStack<QmlDebug::ObjectReference> stack;
|
||||||
while (!m_objectStack.isEmpty()) {
|
|
||||||
last = m_objectStack.pop();
|
// 4.x
|
||||||
QByteArray parentIname;
|
if (m_newObjectsCreated && m_engineClient->objectName() != QmlDebug::Constants::QML_DEBUGGER) {
|
||||||
if (last.parentId() != -1) {
|
// We need to reverse the stack as the root objects
|
||||||
QTC_ASSERT(m_debugIdToIname.contains(last.parentId()), return);
|
// are pushed to the bottom since they are fetched first.
|
||||||
parentIname = m_debugIdToIname.value(last.parentId());
|
// The child objects need to placed in the correct position and therefore
|
||||||
}
|
// the m_debugIdChildIds needs to be populated first.
|
||||||
watchData.append(buildWatchData(last, parentIname));
|
while (!m_objectStack.isEmpty())
|
||||||
buildDebugIdHashRecursive(last);
|
stack.push(m_objectStack.pop());
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
QVectorIterator<ObjectReference> iter(m_objectStack);
|
stack = m_objectStack;
|
||||||
while (iter.hasNext()) {
|
|
||||||
const ObjectReference &r = iter.next();
|
|
||||||
int pid = -1;
|
|
||||||
QHashIterator<int, QList<int> > i(m_debugIdChildIds);
|
|
||||||
while (i.hasNext()) {
|
|
||||||
QList<int> cids = i.value();
|
|
||||||
foreach (int cid, cids) {
|
|
||||||
if (cid == r.debugId()) {
|
|
||||||
pid = i.key();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pid != -1)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
QByteArray parentIname;
|
|
||||||
if (m_debugIdToIname.contains(pid))
|
|
||||||
parentIname = m_debugIdToIname.value(r.parentId());
|
|
||||||
watchData.append(buildWatchData(r, parentIname));
|
|
||||||
buildDebugIdHashRecursive(r);
|
|
||||||
}
|
|
||||||
m_objectStack.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_debuggerEngine->watchHandler()->insertData(watchData);
|
while (!stack.isEmpty()) {
|
||||||
emit objectTreeUpdated();
|
last = stack.pop();
|
||||||
|
int parentId = last.parentId();
|
||||||
|
QByteArray parentIname;
|
||||||
|
|
||||||
if (m_engineClient->objectName() == QmlDebug::Constants::QML_DEBUGGER) {
|
// 4.x
|
||||||
emit objectFetched(last);
|
if (m_engineClient->objectName() != QmlDebug::Constants::QML_DEBUGGER) {
|
||||||
|
QHashIterator<int, QList<int> > i(m_debugIdChildIds);
|
||||||
if (m_objectToSelect == last.debugId()) {
|
while (i.hasNext()) {
|
||||||
// select item in view
|
i.next();
|
||||||
QByteArray iname = m_debugIdToIname.value(last.debugId());
|
if (i.value().contains(last.debugId())) {
|
||||||
if (debug)
|
parentId = i.key();
|
||||||
qDebug() << " selecting" << iname << "in tree";
|
break;
|
||||||
m_debuggerEngine->watchHandler()->setCurrentItem(iname);
|
}
|
||||||
m_objectToSelect = -1;
|
}
|
||||||
}
|
}
|
||||||
|
if (m_debugIdToIname.contains(parentId))
|
||||||
|
parentIname = m_debugIdToIname.value(parentId);
|
||||||
|
if (!m_newObjectsCreated && parentId != -1 && parentIname.isEmpty()) {
|
||||||
|
fetchObject(parentId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (debug)
|
||||||
|
timeElapsed.start();
|
||||||
|
watchData.append(buildWatchData(last, parentIname, true));
|
||||||
|
if (debug)
|
||||||
|
qDebug() << __FUNCTION__ << "Time: Build Watch Data took "
|
||||||
|
<< timeElapsed.elapsed() << " ms";
|
||||||
|
if (debug)
|
||||||
|
timeElapsed.start();
|
||||||
|
buildDebugIdHashRecursive(last);
|
||||||
|
if (debug)
|
||||||
|
qDebug() << __FUNCTION__ << "Time: Build Debug Id Hash took "
|
||||||
|
<< timeElapsed.elapsed() << " ms";
|
||||||
|
}
|
||||||
|
m_newObjectsCreated = false;
|
||||||
|
m_objectStack.clear();
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
timeElapsed.start();
|
||||||
|
m_debuggerEngine->watchHandler()->insertData(watchData);
|
||||||
|
if (debug)
|
||||||
|
qDebug() << __FUNCTION__ << "Time: Insertion took " << timeElapsed.elapsed() << " ms";
|
||||||
|
|
||||||
|
emit objectTreeUpdated();
|
||||||
|
emit objectFetched(last);
|
||||||
|
|
||||||
|
if (m_objectToSelect == last.debugId()) {
|
||||||
|
// select item in view
|
||||||
|
QByteArray iname = m_debugIdToIname.value(last.debugId());
|
||||||
|
if (debug)
|
||||||
|
qDebug() << " selecting" << iname << "in tree";
|
||||||
|
m_debuggerEngine->watchHandler()->setCurrentItem(iname);
|
||||||
|
m_objectToSelect = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -702,6 +720,18 @@ void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
|
|||||||
if (!m_debugIdHash[file][location].contains(ref.debugId()))
|
if (!m_debugIdHash[file][location].contains(ref.debugId()))
|
||||||
m_debugIdHash[file][location].append(ref.debugId());
|
m_debugIdHash[file][location].append(ref.debugId());
|
||||||
m_debugIdLocations.insert(ref.debugId(), FileReference(filePath, lineNum, colNum));
|
m_debugIdLocations.insert(ref.debugId(), FileReference(filePath, lineNum, colNum));
|
||||||
|
|
||||||
|
// 4.x
|
||||||
|
if (m_newObjectsCreated && m_engineClient->objectName() != QmlDebug::Constants::QML_DEBUGGER) {
|
||||||
|
QList<int> childIds;
|
||||||
|
foreach (const ObjectReference &c, ref.children()) {
|
||||||
|
childIds << c.debugId();
|
||||||
|
}
|
||||||
|
// For 4.x, we do not get the parentId. Hence, store the child ids
|
||||||
|
// to look up correct insertion places later
|
||||||
|
m_debugIdChildIds.insert(ref.debugId(), childIds);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (const ObjectReference &it, ref.children())
|
foreach (const ObjectReference &it, ref.children())
|
||||||
buildDebugIdHashRecursive(it);
|
buildDebugIdHashRecursive(it);
|
||||||
}
|
}
|
||||||
@@ -719,46 +749,46 @@ static QByteArray buildIName(const QByteArray &parentIname, const QString &name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
||||||
const QByteArray &parentIname)
|
const QByteArray &parentIname,
|
||||||
|
bool append)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << __FUNCTION__ << "(" << obj << parentIname << ")";
|
qDebug() << __FUNCTION__ << "(" << obj << parentIname << ")";
|
||||||
|
|
||||||
QList<WatchData> list;
|
QList<WatchData> list;
|
||||||
|
|
||||||
WatchData objWatch;
|
int objDebugId = obj.debugId();
|
||||||
QString name = obj.idString();
|
QByteArray objIname = buildIName(parentIname, objDebugId);
|
||||||
if (name.isEmpty())
|
|
||||||
name = obj.className();
|
|
||||||
|
|
||||||
if (name.isEmpty())
|
if (append) {
|
||||||
return list;
|
WatchData objWatch;
|
||||||
|
QString name = obj.idString();
|
||||||
|
if (name.isEmpty())
|
||||||
|
name = obj.className();
|
||||||
|
|
||||||
// object
|
if (name.isEmpty())
|
||||||
objWatch.id = obj.debugId();
|
return list;
|
||||||
objWatch.exp = name.toLatin1();
|
|
||||||
objWatch.name = name;
|
|
||||||
objWatch.iname = buildIName(parentIname, obj.debugId());
|
|
||||||
objWatch.type = obj.className().toLatin1();
|
|
||||||
objWatch.value = _("object");
|
|
||||||
objWatch.setHasChildren(true);
|
|
||||||
objWatch.setAllUnneeded();
|
|
||||||
|
|
||||||
list.append(objWatch);
|
// object
|
||||||
m_debugIdToIname.insert(objWatch.id, objWatch.iname);
|
objWatch.id = objDebugId;
|
||||||
addObjectWatch(objWatch.id);
|
objWatch.exp = name.toLatin1();
|
||||||
|
objWatch.name = name;
|
||||||
|
objWatch.iname = objIname;
|
||||||
|
objWatch.type = obj.className().toLatin1();
|
||||||
|
objWatch.value = _("object");
|
||||||
|
objWatch.setHasChildren(true);
|
||||||
|
objWatch.setAllUnneeded();
|
||||||
|
|
||||||
if (m_engineClient->objectName() != QmlDebug::Constants::QML_DEBUGGER) {
|
list.append(objWatch);
|
||||||
QList<int> childIds;
|
addObjectWatch(objWatch.id);
|
||||||
foreach (const ObjectReference &c, obj.children()) {
|
|
||||||
childIds << c.debugId();
|
|
||||||
}
|
|
||||||
// For 4.x, we do not get the parentId. Hence, store the child ids
|
|
||||||
// to look up correct insertion places later
|
|
||||||
m_debugIdChildIds.insert(objWatch.id, childIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_debuggerEngine->watchHandler()->isExpandedIName(objWatch.iname)
|
// To improve performance, we do not insert data for items
|
||||||
|
// that have not been previously queried when the object tree is refreshed.
|
||||||
|
if (!m_debuggerEngine->watchHandler()->isExpandedIName(objIname) && m_newObjectsCreated)
|
||||||
|
append = false;
|
||||||
|
|
||||||
|
if (!m_debuggerEngine->watchHandler()->isExpandedIName(objIname)
|
||||||
&& obj.needsMoreData()) {
|
&& obj.needsMoreData()) {
|
||||||
// we don't know the children yet. Not adding the 'properties'
|
// we don't know the children yet. Not adding the 'properties'
|
||||||
// element makes sure we're queried on expansion.
|
// element makes sure we're queried on expansion.
|
||||||
@@ -766,12 +796,12 @@ QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// properties
|
// properties
|
||||||
if (obj.properties().count()) {
|
if (append && obj.properties().count()) {
|
||||||
WatchData propertiesWatch;
|
WatchData propertiesWatch;
|
||||||
propertiesWatch.id = objWatch.id;
|
propertiesWatch.id = objDebugId;
|
||||||
propertiesWatch.exp = "";
|
propertiesWatch.exp = "";
|
||||||
propertiesWatch.name = tr("properties");
|
propertiesWatch.name = tr("properties");
|
||||||
propertiesWatch.iname = objWatch.iname + ".[properties]";
|
propertiesWatch.iname = objIname + ".[properties]";
|
||||||
propertiesWatch.type = "";
|
propertiesWatch.type = "";
|
||||||
propertiesWatch.value = _("list");
|
propertiesWatch.value = _("list");
|
||||||
propertiesWatch.setHasChildren(true);
|
propertiesWatch.setHasChildren(true);
|
||||||
@@ -781,7 +811,7 @@ QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
|||||||
|
|
||||||
foreach (const PropertyReference &property, obj.properties()) {
|
foreach (const PropertyReference &property, obj.properties()) {
|
||||||
WatchData propertyWatch;
|
WatchData propertyWatch;
|
||||||
propertyWatch.id = objWatch.id;
|
propertyWatch.id = objDebugId;
|
||||||
propertyWatch.exp = property.name().toLatin1();
|
propertyWatch.exp = property.name().toLatin1();
|
||||||
propertyWatch.name = property.name();
|
propertyWatch.name = property.name();
|
||||||
propertyWatch.iname = buildIName(propertiesWatch.iname, property.name());
|
propertyWatch.iname = buildIName(propertiesWatch.iname, property.name());
|
||||||
@@ -791,11 +821,12 @@ QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
|||||||
propertyWatch.setHasChildren(false);
|
propertyWatch.setHasChildren(false);
|
||||||
list.append(propertyWatch);
|
list.append(propertyWatch);
|
||||||
}
|
}
|
||||||
|
m_debugIdToIname.insert(objDebugId, objIname);
|
||||||
}
|
}
|
||||||
|
|
||||||
// recurse
|
// recurse
|
||||||
foreach (const ObjectReference &child, obj.children())
|
foreach (const ObjectReference &child, obj.children())
|
||||||
list.append(buildWatchData(child, objWatch.iname));
|
list.append(buildWatchData(child, objIname, append));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -58,7 +58,6 @@ class QmlInspectorAgent : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit QmlInspectorAgent(DebuggerEngine *engine, QObject *parent = 0);
|
explicit QmlInspectorAgent(DebuggerEngine *engine, QObject *parent = 0);
|
||||||
|
|
||||||
|
|
||||||
void fetchObject(int debugId);
|
void fetchObject(int debugId);
|
||||||
quint32 queryExpressionResult(int debugId, const QString &expression);
|
quint32 queryExpressionResult(int debugId, const QString &expression);
|
||||||
|
|
||||||
@@ -118,7 +117,7 @@ private:
|
|||||||
|
|
||||||
void buildDebugIdHashRecursive(const QmlDebug::ObjectReference &ref);
|
void buildDebugIdHashRecursive(const QmlDebug::ObjectReference &ref);
|
||||||
QList<WatchData> buildWatchData(const QmlDebug::ObjectReference &obj,
|
QList<WatchData> buildWatchData(const QmlDebug::ObjectReference &obj,
|
||||||
const QByteArray &parentIname);
|
const QByteArray &parentIname, bool append);
|
||||||
|
|
||||||
enum LogDirection {
|
enum LogDirection {
|
||||||
LogSend,
|
LogSend,
|
||||||
@@ -147,6 +146,7 @@ private:
|
|||||||
QList<int> m_objectWatches;
|
QList<int> m_objectWatches;
|
||||||
QList<int> m_fetchDataIds;
|
QList<int> m_fetchDataIds;
|
||||||
QTimer m_delayQueryTimer;
|
QTimer m_delayQueryTimer;
|
||||||
|
bool m_newObjectsCreated;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
Reference in New Issue
Block a user