QmlInspector: Use categorized debugging

Change-Id: I551d2b65bbd1734847b7e995e0f95e906d116497
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Kai Koehne
2014-07-14 14:45:51 +02:00
committed by hjk
parent aef20d43e1
commit 60d7b23d88

View File

@@ -36,6 +36,7 @@
#include <debugger/watchhandler.h> #include <debugger/watchhandler.h>
#include <qmldebug/qmldebugconstants.h> #include <qmldebug/qmldebugconstants.h>
#include <utils/logging.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/savedaction.h> #include <utils/savedaction.h>
#include <QElapsedTimer> #include <QElapsedTimer>
@@ -47,9 +48,7 @@ using namespace QmlDebug::Constants;
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
enum { Q_LOGGING_CATEGORY(qmlInspectorLog, "qtc.dbg.qmlinspector")
debug = false
};
/*! /*!
* DebuggerAgent updates the watchhandler with the object tree data. * DebuggerAgent updates the watchhandler with the object tree data.
@@ -76,8 +75,8 @@ quint32 QmlInspectorAgent::queryExpressionResult(int debugId,
if (!m_engineClient) if (!m_engineClient)
return 0; return 0;
if (debug) qCDebug(qmlInspectorLog)
qDebug() << __FUNCTION__ << '(' << debugId << expression << __FUNCTION__ << '(' << debugId << expression
<< m_engine.debugId() << ')'; << m_engine.debugId() << ')';
return m_engineClient->queryExpressionResult(debugId, expression, return m_engineClient->queryExpressionResult(debugId, expression,
@@ -87,8 +86,8 @@ quint32 QmlInspectorAgent::queryExpressionResult(int debugId,
void QmlInspectorAgent::assignValue(const WatchData *data, void QmlInspectorAgent::assignValue(const WatchData *data,
const QString &expr, const QVariant &valueV) const QString &expr, const QVariant &valueV)
{ {
if (debug) qCDebug(qmlInspectorLog)
qDebug() << __FUNCTION__ << '(' << data->id << ')' << data->iname; << __FUNCTION__ << '(' << data->id << ')' << data->iname;
if (data->id) { if (data->id) {
QString val(valueV.toString()); QString val(valueV.toString());
@@ -114,8 +113,7 @@ int parentIdForIname(const QByteArray &iname)
void QmlInspectorAgent::updateWatchData(const WatchData &data) void QmlInspectorAgent::updateWatchData(const WatchData &data)
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << data.id << ')';
qDebug() << __FUNCTION__ << '(' << data.id << ')';
if (data.id && !m_fetchDataIds.contains(data.id)) { if (data.id && !m_fetchDataIds.contains(data.id)) {
// objects // objects
@@ -126,8 +124,7 @@ void QmlInspectorAgent::updateWatchData(const WatchData &data)
void QmlInspectorAgent::watchDataSelected(const WatchData *data) void QmlInspectorAgent::watchDataSelected(const WatchData *data)
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << data->id << ')';
qDebug() << __FUNCTION__ << '(' << data->id << ')';
if (data->id) { if (data->id) {
QTC_ASSERT(m_debugIdLocations.keys().contains(data->id), return); QTC_ASSERT(m_debugIdLocations.keys().contains(data->id), return);
@@ -137,17 +134,14 @@ void QmlInspectorAgent::watchDataSelected(const WatchData *data)
bool QmlInspectorAgent::selectObjectInTree(int debugId) bool QmlInspectorAgent::selectObjectInTree(int debugId)
{ {
if (debug) { qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugId << ')' << endl
qDebug() << __FUNCTION__ << '(' << debugId << ')'; << " " << debugId << "already fetched? "
qDebug() << " " << debugId << "already fetched? "
<< m_debugIdToIname.contains(debugId); << m_debugIdToIname.contains(debugId);
}
if (m_debugIdToIname.contains(debugId)) { if (m_debugIdToIname.contains(debugId)) {
QByteArray iname = m_debugIdToIname.value(debugId); QByteArray iname = m_debugIdToIname.value(debugId);
QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname); QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname);
if (debug) qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
qDebug() << " selecting" << iname << "in tree";
m_debuggerEngine->watchHandler()->setCurrentItem(iname); m_debuggerEngine->watchHandler()->setCurrentItem(iname);
m_objectToSelect = 0; m_objectToSelect = 0;
return true; return true;
@@ -173,8 +167,8 @@ quint32 QmlInspectorAgent::setBindingForObject(int objectDebugId,
QString source, QString source,
int line) int line)
{ {
if (debug) qCDebug(qmlInspectorLog)
qDebug() << __FUNCTION__ << '(' << objectDebugId << propertyName << __FUNCTION__ << '(' << objectDebugId << propertyName
<< value.toString() << isLiteralValue << source << line << ')'; << value.toString() << isLiteralValue << source << line << ')';
if (objectDebugId == -1) if (objectDebugId == -1)
@@ -205,9 +199,9 @@ quint32 QmlInspectorAgent::setMethodBodyForObject(int objectDebugId,
const QString &methodName, const QString &methodName,
const QString &methodBody) const QString &methodBody)
{ {
if (debug) qCDebug(qmlInspectorLog)
qDebug() << __FUNCTION__ << '(' << objectDebugId << __FUNCTION__ << '(' << objectDebugId << methodName << methodBody
<< methodName << methodBody << ')'; << ')';
if (objectDebugId == -1) if (objectDebugId == -1)
return 0; return 0;
@@ -231,8 +225,8 @@ quint32 QmlInspectorAgent::setMethodBodyForObject(int objectDebugId,
quint32 QmlInspectorAgent::resetBindingForObject(int objectDebugId, quint32 QmlInspectorAgent::resetBindingForObject(int objectDebugId,
const QString &propertyName) const QString &propertyName)
{ {
if (debug) qCDebug(qmlInspectorLog)
qDebug() << __FUNCTION__ << '(' << objectDebugId << __FUNCTION__ << '(' << objectDebugId
<< propertyName << ')'; << propertyName << ')';
if (objectDebugId == -1) if (objectDebugId == -1)
@@ -332,8 +326,7 @@ QHash<int,QString> QmlInspectorAgent::rootObjectIds() const
bool QmlInspectorAgent::addObjectWatch(int objectDebugId) bool QmlInspectorAgent::addObjectWatch(int objectDebugId)
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << objectDebugId << ')';
qDebug() << __FUNCTION__ << '(' << objectDebugId << ')';
if (objectDebugId == -1) if (objectDebugId == -1)
return false; return false;
@@ -362,8 +355,7 @@ bool QmlInspectorAgent::isObjectBeingWatched(int objectDebugId)
bool QmlInspectorAgent::removeObjectWatch(int objectDebugId) bool QmlInspectorAgent::removeObjectWatch(int objectDebugId)
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << objectDebugId << ')';
qDebug() << __FUNCTION__ << '(' << objectDebugId << ')';
if (objectDebugId == -1) if (objectDebugId == -1)
return false; return false;
@@ -380,8 +372,7 @@ bool QmlInspectorAgent::removeObjectWatch(int objectDebugId)
void QmlInspectorAgent::removeAllObjectWatches() void QmlInspectorAgent::removeAllObjectWatches()
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << "()";
qDebug() << __FUNCTION__ << "()";
foreach (int watchedObject, m_objectWatches) foreach (int watchedObject, m_objectWatches)
removeObjectWatch(watchedObject); removeObjectWatch(watchedObject);
@@ -448,8 +439,7 @@ void QmlInspectorAgent::updateState()
void QmlInspectorAgent::onResult(quint32 queryId, const QVariant &value, void QmlInspectorAgent::onResult(quint32 queryId, const QVariant &value,
const QByteArray &type) const QByteArray &type)
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << "() ...";
qDebug() << __FUNCTION__ << "() ...";
if (type == "FETCH_OBJECT_R") { if (type == "FETCH_OBJECT_R") {
log(LogReceive, _("FETCH_OBJECT_R %1").arg( log(LogReceive, _("FETCH_OBJECT_R %1").arg(
@@ -494,15 +484,13 @@ void QmlInspectorAgent::onResult(quint32 queryId, const QVariant &value,
emit expressionResult(queryId, value); emit expressionResult(queryId, value);
} }
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << "done";
qDebug() << __FUNCTION__ << "done";
} }
void QmlInspectorAgent::newObject(int engineId, int /*objectId*/, int /*parentId*/) void QmlInspectorAgent::newObject(int engineId, int /*objectId*/, int /*parentId*/)
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << "()";
qDebug() << __FUNCTION__ << "()";
log(LogReceive, QLatin1String("OBJECT_CREATED")); log(LogReceive, QLatin1String("OBJECT_CREATED"));
@@ -520,8 +508,9 @@ void QmlInspectorAgent::onValueChanged(int debugId, const QByteArray &propertyNa
".[properties]." + propertyName; ".[properties]." + propertyName;
WatchHandler *watchHandler = m_debuggerEngine->watchHandler(); WatchHandler *watchHandler = m_debuggerEngine->watchHandler();
const WatchData *data = watchHandler->findData(iname); const WatchData *data = watchHandler->findData(iname);
if (debug) qCDebug(qmlInspectorLog)
qDebug() << __FUNCTION__ << '(' << debugId << ')' << iname << value.toString(); << __FUNCTION__ << '(' << debugId << ')' << iname
<< value.toString();
if (data) { if (data) {
WatchData d(*data); WatchData d(*data);
d.value = value.toString(); d.value = value.toString();
@@ -531,8 +520,7 @@ void QmlInspectorAgent::onValueChanged(int debugId, const QByteArray &propertyNa
void QmlInspectorAgent::reloadEngines() void QmlInspectorAgent::reloadEngines()
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << "()";
qDebug() << __FUNCTION__ << "()";
if (!isConnected()) if (!isConnected())
return; return;
@@ -560,8 +548,7 @@ int QmlInspectorAgent::parentIdForObject(int objectDebugId)
void QmlInspectorAgent::queryEngineContext() void QmlInspectorAgent::queryEngineContext()
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__;
qDebug() << __FUNCTION__;
if (!isConnected() if (!isConnected()
|| !debuggerCore()->boolSetting(ShowQmlObjectTree)) || !debuggerCore()->boolSetting(ShowQmlObjectTree))
@@ -575,8 +562,7 @@ void QmlInspectorAgent::queryEngineContext()
void QmlInspectorAgent::fetchObject(int debugId) void QmlInspectorAgent::fetchObject(int debugId)
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugId << ')';
qDebug() << __FUNCTION__ << '(' << debugId << ')';
if (!isConnected() if (!isConnected()
|| !debuggerCore()->boolSetting(ShowQmlObjectTree)) || !debuggerCore()->boolSetting(ShowQmlObjectTree))
@@ -584,8 +570,7 @@ void QmlInspectorAgent::fetchObject(int debugId)
log(LogSend, QLatin1String("FETCH_OBJECT ") + QString::number(debugId)); log(LogSend, QLatin1String("FETCH_OBJECT ") + QString::number(debugId));
quint32 queryId = m_engineClient->queryObject(debugId); quint32 queryId = m_engineClient->queryObject(debugId);
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugId << ')'
qDebug() << __FUNCTION__ << '(' << debugId << ')'
<< " - query id" << queryId; << " - query id" << queryId;
m_objectTreeQueryIds << queryId; m_objectTreeQueryIds << queryId;
} }
@@ -595,8 +580,7 @@ void QmlInspectorAgent::fetchContextObjectsForLocation(const QString &file,
{ {
// This can be an expensive operation as it may return multiple // This can be an expensive operation as it may return multiple
// objects. Use fetchContextObject() where possible. // objects. Use fetchContextObject() where possible.
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << file << ':' << lineNumber
qDebug() << __FUNCTION__ << '(' << file << ':' << lineNumber
<< ':' << columnNumber << ')'; << ':' << columnNumber << ')';
if (!isConnected() if (!isConnected()
@@ -607,8 +591,7 @@ void QmlInspectorAgent::fetchContextObjectsForLocation(const QString &file,
.arg(QString::number(lineNumber)).arg(QString::number(columnNumber))); .arg(QString::number(lineNumber)).arg(QString::number(columnNumber)));
quint32 queryId = m_engineClient->queryObjectsForLocation(QFileInfo(file).fileName(), quint32 queryId = m_engineClient->queryObjectsForLocation(QFileInfo(file).fileName(),
lineNumber, columnNumber); lineNumber, columnNumber);
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << file << ':' << lineNumber
qDebug() << __FUNCTION__ << '(' << file << ':' << lineNumber
<< ':' << columnNumber << ')' << " - query id" << queryId; << ':' << columnNumber << ')' << " - query id" << queryId;
m_objectTreeQueryIds << queryId; m_objectTreeQueryIds << queryId;
@@ -616,8 +599,7 @@ void QmlInspectorAgent::fetchContextObjectsForLocation(const QString &file,
void QmlInspectorAgent::updateObjectTree(const ContextReference &context) void QmlInspectorAgent::updateObjectTree(const ContextReference &context)
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << context << ')';
qDebug() << __FUNCTION__ << '(' << context << ')';
if (!isConnected() if (!isConnected()
|| !debuggerCore()->boolSetting(ShowQmlObjectTree)) || !debuggerCore()->boolSetting(ShowQmlObjectTree))
@@ -632,8 +614,7 @@ void QmlInspectorAgent::updateObjectTree(const ContextReference &context)
void QmlInspectorAgent::verifyAndInsertObjectInTree(const ObjectReference &object) void QmlInspectorAgent::verifyAndInsertObjectInTree(const ObjectReference &object)
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << object << ')';
qDebug() << __FUNCTION__ << '(' << object << ')';
if (!object.isValid()) if (!object.isValid())
return; return;
@@ -680,33 +661,32 @@ void QmlInspectorAgent::verifyAndInsertObjectInTree(const ObjectReference &objec
void QmlInspectorAgent::insertObjectInTree(const ObjectReference &object) void QmlInspectorAgent::insertObjectInTree(const ObjectReference &object)
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << object << ')';
qDebug() << __FUNCTION__ << '(' << object << ')';
const int objectDebugId = object.debugId(); const int objectDebugId = object.debugId();
const int parentId = parentIdForIname(m_debugIdToIname.value(objectDebugId)); const int parentId = parentIdForIname(m_debugIdToIname.value(objectDebugId));
QElapsedTimer timeElapsed; QElapsedTimer timeElapsed;
QList<WatchData> watchData; QList<WatchData> watchData;
if (debug)
bool printTime = qmlInspectorLog().isDebugEnabled();
if (printTime)
timeElapsed.start(); timeElapsed.start();
watchData.append(buildWatchData(object, m_debugIdToIname.value(parentId), true)); watchData.append(buildWatchData(object, m_debugIdToIname.value(parentId), true));
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << "Time: Build Watch Data took "
qDebug() << __FUNCTION__ << "Time: Build Watch Data took "
<< timeElapsed.elapsed() << " ms"; << timeElapsed.elapsed() << " ms";
if (debug) if (printTime)
timeElapsed.start(); timeElapsed.start();
buildDebugIdHashRecursive(object); buildDebugIdHashRecursive(object);
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << "Time: Build Debug Id Hash took "
qDebug() << __FUNCTION__ << "Time: Build Debug Id Hash took "
<< timeElapsed.elapsed() << " ms"; << timeElapsed.elapsed() << " ms";
WatchHandler *watchHandler = m_debuggerEngine->watchHandler(); WatchHandler *watchHandler = m_debuggerEngine->watchHandler();
if (debug) if (printTime)
timeElapsed.start(); timeElapsed.start();
watchHandler->insertData(watchData); watchHandler->insertData(watchData);
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << "Time: Insertion took "
qDebug() << __FUNCTION__ << "Time: Insertion took " << timeElapsed.elapsed() << " ms"; << timeElapsed.elapsed() << " ms";
emit objectTreeUpdated(); emit objectTreeUpdated();
emit objectFetched(object); emit objectFetched(object);
@@ -714,8 +694,7 @@ void QmlInspectorAgent::insertObjectInTree(const ObjectReference &object)
if (m_debugIdToIname.contains(m_objectToSelect)) { if (m_debugIdToIname.contains(m_objectToSelect)) {
// select item in view // select item in view
QByteArray iname = m_debugIdToIname.value(m_objectToSelect); QByteArray iname = m_debugIdToIname.value(m_objectToSelect);
if (debug) qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
qDebug() << " selecting" << iname << "in tree";
watchHandler->setCurrentItem(iname); watchHandler->setCurrentItem(iname);
m_objectToSelect = -1; m_objectToSelect = -1;
} }
@@ -723,8 +702,7 @@ void QmlInspectorAgent::insertObjectInTree(const ObjectReference &object)
void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref) void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
{ {
if (debug) qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << ref << ')';
qDebug() << __FUNCTION__ << '(' << ref << ')';
QUrl fileUrl = ref.source().url(); QUrl fileUrl = ref.source().url();
int lineNum = ref.source().lineNumber(); int lineNum = ref.source().lineNumber();
@@ -770,8 +748,7 @@ QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
const QByteArray &parentIname, const QByteArray &parentIname,
bool append) bool append)
{ {
if (debug) qCDebug(qmlInspectorLog) << '(' << obj << parentIname << ')';
qDebug() << __FUNCTION__ << '(' << obj << parentIname << ')';
QList<WatchData> list; QList<WatchData> list;