From 16bfbceebaf7d0159d2a8436026dc7bbe4200150 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 6 Mar 2014 16:12:02 +0100 Subject: [PATCH] QmlProfiler: Allow filtering either JS or QML from the events view As a lot of events show up as QML bindings and signals and as JavaScript functions the events view can be hard to navigate. This change allows the user to either filter out JavaScript events and make it look like the old QML events view or filter out QML events and make it look like the old V8 JavaScript view. Change-Id: I9e0c1184da21263ae174f322b8fcd8ee5ca13f6d Reviewed-by: Leena Miettinen Reviewed-by: Kai Koehne --- .../qmlprofilereventsmodelproxy.cpp | 26 ++++++-- .../qmlprofiler/qmlprofilereventsmodelproxy.h | 8 +-- .../qmlprofiler/qmlprofilereventview.cpp | 59 +++++++++++++++++-- .../qmlprofiler/qmlprofilereventview.h | 5 ++ .../qmlprofiler/qmlprofilertraceview.cpp | 2 +- 5 files changed, 82 insertions(+), 18 deletions(-) diff --git a/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.cpp b/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.cpp index cfda67feee2..9ffac562717 100644 --- a/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.cpp +++ b/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.cpp @@ -58,7 +58,7 @@ public: int modelId; - QVector acceptedTypes; + QList acceptedTypes; QSet eventsInBindingLoop; }; @@ -80,6 +80,19 @@ QmlProfilerEventsModelProxy::~QmlProfilerEventsModelProxy() delete d; } +void QmlProfilerEventsModelProxy::setEventTypeAccepted(QmlDebug::QmlEventType type, bool accepted) +{ + if (accepted && !d->acceptedTypes.contains(type)) + d->acceptedTypes << type; + else if (!accepted && d->acceptedTypes.contains(type)) + d->acceptedTypes.removeOne(type); +} + +bool QmlProfilerEventsModelProxy::eventTypeAccepted(QmlDebug::QmlEventType type) const +{ + return d->acceptedTypes.contains(type); +} + const QList QmlProfilerEventsModelProxy::getData() const { return d->data.values(); @@ -131,7 +144,7 @@ void QmlProfilerEventsModelProxy::loadData(qint64 rangeStart, qint64 rangeEnd) for (int i = 0; i < eventList.size(); ++i) { const QmlProfilerDataModel::QmlEventData *event = &eventList[i]; - if (!d->acceptedTypes.contains(event->eventType)) + if (!d->acceptedTypes.contains((QmlDebug::QmlEventType)event->eventType)) continue; if (checkRanges) { @@ -275,12 +288,13 @@ QmlProfilerEventRelativesModelProxy::QmlProfilerEventRelativesModelProxy(QmlProf { QTC_CHECK(modelManager); m_modelManager = modelManager; - connect(modelManager->qmlModel(), SIGNAL(changed()), this, SLOT(dataChanged())); QTC_CHECK(eventsModel); m_eventsModel = eventsModel; - m_acceptedTypes << QmlDebug::Compiling << QmlDebug::Creating << QmlDebug::Binding << QmlDebug::HandlingSignal << QmlDebug::Javascript; + // Load the child models whenever the parent model is done to get the filtering for JS/QML + // right. + connect(m_eventsModel, SIGNAL(dataAvailable()), this, SLOT(dataChanged())); } QmlProfilerEventRelativesModelProxy::~QmlProfilerEventRelativesModelProxy() @@ -356,7 +370,7 @@ void QmlProfilerEventParentsModelProxy::loadData() const QVector eventList = simpleModel->getEvents(); foreach (const QmlProfilerDataModel::QmlEventData &event, eventList) { // whitelist - if (!m_acceptedTypes.contains(event.eventType)) + if (!m_eventsModel->eventTypeAccepted((QmlDebug::QmlEventType)event.eventType)) continue; // level computation @@ -436,7 +450,7 @@ void QmlProfilerEventChildrenModelProxy::loadData() const QVector eventList = simpleModel->getEvents(); foreach (const QmlProfilerDataModel::QmlEventData &event, eventList) { // whitelist - if (!m_acceptedTypes.contains(event.eventType)) + if (!m_eventsModel->eventTypeAccepted((QmlDebug::QmlEventType)event.eventType)) continue; // level computation diff --git a/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.h b/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.h index 080bd2eecba..cc57a096f5f 100644 --- a/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.h +++ b/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.h @@ -70,6 +70,9 @@ public: QmlProfilerEventsModelProxy(QmlProfilerModelManager *modelManager, QObject *parent = 0); ~QmlProfilerEventsModelProxy(); + void setEventTypeAccepted(QmlDebug::QmlEventType type, bool accepted); + bool eventTypeAccepted(QmlDebug::QmlEventType) const; + const QList getData() const; int count() const; void clear(); @@ -133,7 +136,6 @@ protected: QHash m_data; QmlProfilerModelManager *m_modelManager; QmlProfilerEventsModelProxy *m_eventsModel; - QVector m_acceptedTypes; }; class QmlProfilerEventParentsModelProxy : public QmlProfilerEventRelativesModelProxy @@ -147,8 +149,6 @@ public: protected: virtual void loadData(); -signals: - void dataAvailable(); }; class QmlProfilerEventChildrenModelProxy : public QmlProfilerEventRelativesModelProxy @@ -162,8 +162,6 @@ public: protected: virtual void loadData(); -signals: - void dataAvailable(); }; } diff --git a/src/plugins/qmlprofiler/qmlprofilereventview.cpp b/src/plugins/qmlprofiler/qmlprofilereventview.cpp index 0a3f685ef58..7fdbc614584 100644 --- a/src/plugins/qmlprofiler/qmlprofilereventview.cpp +++ b/src/plugins/qmlprofiler/qmlprofilereventview.cpp @@ -111,7 +111,8 @@ public: QmlProfilerEventRelativesView *m_eventParents; QmlProfilerEventsModelProxy *modelProxy; - bool globalStats; + qint64 rangeStart; + qint64 rangeEnd; }; QmlProfilerEventsWidget::QmlProfilerEventsWidget(QWidget *parent, @@ -164,7 +165,7 @@ QmlProfilerEventsWidget::QmlProfilerEventsWidget(QWidget *parent, d->m_profilerTool = profilerTool; d->m_viewContainer = container; - d->globalStats = true; + d->rangeStart = d->rangeEnd = -1; } QmlProfilerEventsWidget::~QmlProfilerEventsWidget() @@ -186,8 +187,9 @@ void QmlProfilerEventsWidget::clear() void QmlProfilerEventsWidget::getStatisticsInRange(qint64 rangeStart, qint64 rangeEnd) { + d->rangeStart = rangeStart; + d->rangeEnd = rangeEnd; d->modelProxy->limitToRange(rangeStart, rangeEnd); - d->globalStats = (rangeStart == -1) && (rangeEnd == -1); } QModelIndex QmlProfilerEventsWidget::selectedItem() const @@ -203,6 +205,8 @@ void QmlProfilerEventsWidget::contextMenuEvent(QContextMenuEvent *ev) QAction *copyRowAction = 0; QAction *copyTableAction = 0; QAction *showExtendedStatsAction = 0; + QAction *showJavaScriptAction = 0; + QAction *showQmlAction = 0; QAction *getLocalStatsAction = 0; QAction *getGlobalStatsAction = 0; @@ -227,13 +231,21 @@ void QmlProfilerEventsWidget::contextMenuEvent(QContextMenuEvent *ev) } menu.addSeparator(); - getLocalStatsAction = menu.addAction(tr("Limit Events Pane to Current Range")); + getLocalStatsAction = menu.addAction(tr("Limit to Current Range")); if (!d->m_viewContainer->hasValidSelection()) getLocalStatsAction->setEnabled(false); - getGlobalStatsAction = menu.addAction(tr("Reset Events Pane")); + getGlobalStatsAction = menu.addAction(tr("Show Full Range")); if (hasGlobalStats()) getGlobalStatsAction->setEnabled(false); + showJavaScriptAction = menu.addAction(tr("Show JavaScript Events")); + showJavaScriptAction->setCheckable(true); + showJavaScriptAction->setChecked(showJavaScript()); + + showQmlAction = menu.addAction(tr("Show QML Events")); + showQmlAction->setCheckable(true); + showQmlAction->setChecked(showQml()); + QAction *selectedAction = menu.exec(position); if (selectedAction) { @@ -249,6 +261,10 @@ void QmlProfilerEventsWidget::contextMenuEvent(QContextMenuEvent *ev) getStatisticsInRange(-1, -1); if (selectedAction == showExtendedStatsAction) setShowExtendedStatistics(!showExtendedStatistics()); + if (selectedAction == showJavaScriptAction) + setShowJavaScript(showJavaScriptAction->isChecked()); + if (selectedAction == showQmlAction) + setShowQml(showQmlAction->isChecked()); } } @@ -288,7 +304,7 @@ void QmlProfilerEventsWidget::selectBySourceLocation(const QString &filename, in bool QmlProfilerEventsWidget::hasGlobalStats() const { - return d->globalStats; + return d->rangeStart == -1 && d->rangeEnd == -1; } void QmlProfilerEventsWidget::setShowExtendedStatistics(bool show) @@ -301,6 +317,34 @@ bool QmlProfilerEventsWidget::showExtendedStatistics() const return d->m_eventTree->showExtendedStatistics(); } +void QmlProfilerEventsWidget::setShowJavaScript(bool show) +{ + d->modelProxy->setEventTypeAccepted(QmlDebug::Javascript, show); + d->modelProxy->limitToRange(d->rangeStart, d->rangeEnd); +} + +void QmlProfilerEventsWidget::setShowQml(bool show) +{ + d->modelProxy->setEventTypeAccepted(QmlDebug::Binding, show); + d->modelProxy->setEventTypeAccepted(QmlDebug::HandlingSignal, show); + d->modelProxy->setEventTypeAccepted(QmlDebug::Compiling, show); + d->modelProxy->setEventTypeAccepted(QmlDebug::Creating, show); + d->modelProxy->limitToRange(d->rangeStart, d->rangeEnd); +} + +bool QmlProfilerEventsWidget::showJavaScript() const +{ + return d->modelProxy->eventTypeAccepted(QmlDebug::Javascript); +} + +bool QmlProfilerEventsWidget::showQml() const +{ + return d->modelProxy->eventTypeAccepted(QmlDebug::Binding) && + d->modelProxy->eventTypeAccepted(QmlDebug::HandlingSignal) && + d->modelProxy->eventTypeAccepted(QmlDebug::Compiling) && + d->modelProxy->eventTypeAccepted(QmlDebug::Creating); +} + //////////////////////////////////////////////////////////////////////////////////// class QmlProfilerEventsMainView::QmlProfilerEventsMainViewPrivate @@ -781,6 +825,9 @@ QmlProfilerEventRelativesView::QmlProfilerEventRelativesView(QmlProfilerModelMan updateHeader(); connect(this,SIGNAL(clicked(QModelIndex)), this,SLOT(jumpToItem(QModelIndex))); + + // Clear when new data available as the selection may be invalid now. + connect(d->modelProxy, SIGNAL(dataAvailable()), this, SLOT(clear())); } QmlProfilerEventRelativesView::~QmlProfilerEventRelativesView() diff --git a/src/plugins/qmlprofiler/qmlprofilereventview.h b/src/plugins/qmlprofiler/qmlprofilereventview.h index 066e224ab3f..d5d9c2baf2b 100644 --- a/src/plugins/qmlprofiler/qmlprofilereventview.h +++ b/src/plugins/qmlprofiler/qmlprofilereventview.h @@ -78,6 +78,11 @@ public: void setShowExtendedStatistics(bool show); bool showExtendedStatistics() const; + void setShowJavaScript(bool show); + bool showJavaScript() const; + + void setShowQml(bool show); + bool showQml() const; signals: void gotoSourceLocation(const QString &fileName, int lineNumber, int columnNumber); diff --git a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp index f426a088c92..a9b00493f6b 100644 --- a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp @@ -428,7 +428,7 @@ void QmlProfilerTraceView::showContextMenu(QPoint position) if (!d->m_viewContainer->hasValidSelection()) getLocalStatsAction->setEnabled(false); - QAction *getGlobalStatsAction = menu.addAction(tr("Reset Events Pane")); + QAction *getGlobalStatsAction = menu.addAction(tr("Show Full Range in Events Pane")); if (d->m_viewContainer->hasGlobalStats()) getGlobalStatsAction->setEnabled(false);