Commit 2163f789 authored by Christiaan Janssen's avatar Christiaan Janssen
Browse files

QmlProfiler: rewriting details for bindings



Change-Id: Ie180ecc8d336bca1713edd5eb5fff0681c641b9d
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent 4e9192fc
......@@ -43,6 +43,7 @@
#include <QtCore/QXmlStreamWriter>
#include <QtCore/QTimer>
#include <utils/qtcassert.h>
#include <QDebug>
......@@ -996,6 +997,7 @@ void QmlProfilerEventList::postProcess()
findAnimationLimits();
computeLevels();
linkEndsToStarts();
reloadDetails();
compileStatistics(traceStartTime(), traceEndTime());
prepareForDisplay();
}
......@@ -1015,6 +1017,39 @@ void QmlProfilerEventList::computeLevels()
computeNestingDepth();
}
void QmlProfilerEventList::reloadDetails()
{
// request binding/signal details from the AST
foreach (QmlEventData *event, d->m_eventDescriptions.values()) {
if (event->eventType != Binding && event->eventType != HandlingSignal)
continue;
// This skips anonymous bindings in Qt4.8 (we don't have valid location data for them)
if (event->location.filename.isEmpty())
continue;
// Skip non-anonymous bindings from Qt4.8 (we already have correct details for them)
if (event->location.column == -1)
continue;
emit requestDetailsForLocation(event->eventType, event->location);
}
emit reloadDocumentsForDetails();
}
void QmlProfilerEventList::rewriteDetailsString(int eventType, const QmlJsDebugClient::QmlEventLocation &location, const QString &newString)
{
QString eventHashStr = QString("%1:%2:%3:%4").arg(location.filename, QString::number(location.line), QString::number(location.column), QString::number(eventType));
QTC_ASSERT(d->m_eventDescriptions.contains(eventHashStr), return);
d->m_eventDescriptions.value(eventHashStr)->details = newString;
emit detailsChanged(d->m_eventDescriptions.value(eventHashStr)->eventId, newString);
}
void QmlProfilerEventList::finishedRewritingDetails()
{
emit reloadDetailLabels();
}
// get list of events between A and B:
// find fist event with endtime after A -> aa
// find last event with starttime before B -> bb
......
......@@ -171,6 +171,11 @@ signals:
void processingData();
void postProcessing();
void requestDetailsForLocation(int eventType, const QmlJsDebugClient::QmlEventLocation &location);
void detailsChanged(int eventId, const QString &newString);
void reloadDetailLabels();
void reloadDocumentsForDetails();
public slots:
void clear();
void addRangedEvent(int type, qint64 startTime, qint64 length,
......@@ -187,6 +192,9 @@ public slots:
void setTraceEndTime( qint64 time );
void setTraceStartTime( qint64 time );
void rewriteDetailsString(int eventType, const QmlJsDebugClient::QmlEventLocation &location, const QString &newString);
void finishedRewritingDetails();
private:
void postProcess();
void sortEndTimes();
......@@ -197,6 +205,7 @@ private:
void computeNestingDepth();
void prepareForDisplay();
void linkEndsToStarts();
void reloadDetails();
private:
class QmlProfilerEventListPrivate;
......
......@@ -63,22 +63,25 @@ Item {
(expanded ? qmlEventList.uniqueEventsOfType(typeIndex) : qmlEventList.maxNestingForType(typeIndex)));
}
function getDescriptions() {
var desc=[];
var ids=[];
var extdesc=[];
for (var i=0; i<qmlEventList.uniqueEventsOfType(typeIndex); i++) {
desc[i] = qmlEventList.eventTextForType(typeIndex, i);
ids[i] = qmlEventList.eventIdForType(typeIndex, i);
extdesc[i] = qmlEventList.eventDisplayNameForType(typeIndex, i) + " : " + desc[i];
}
descriptions = desc;
eventIds = ids;
extdescriptions = extdesc;
updateHeight();
}
Connections {
target: qmlEventList
onDataReady: {
var desc=[];
var ids=[];
var extdesc=[];
for (var i=0; i<qmlEventList.uniqueEventsOfType(typeIndex); i++) {
desc[i] = qmlEventList.eventTextForType(typeIndex, i);
ids[i] = qmlEventList.eventIdForType(typeIndex, i);
extdesc[i] = qmlEventList.eventDisplayNameForType(typeIndex, i) + " : " + desc[i];
}
descriptions = desc;
eventIds = ids;
extdescriptions = extdesc;
updateHeight();
}
onReloadDetailLabels: getDescriptions();
onDataReady: getDescriptions();
onDataClear: {
descriptions = [];
eventIds = [];
......
......@@ -13,7 +13,6 @@ include(../../plugins/qt4projectmanager/qt4projectmanager.pri)
include(../../plugins/remotelinux/remotelinux.pri)
include(../../libs/qmljsdebugclient/qmljsdebugclient.pri)
include(../../libs/extensionsystem/extensionsystem.pri)
include(canvas/canvas.pri)
SOURCES += \
......@@ -26,7 +25,8 @@ SOURCES += \
localqmlprofilerrunner.cpp \
codaqmlprofilerrunner.cpp \
remotelinuxqmlprofilerrunner.cpp \
qmlprofilereventview.cpp
qmlprofilereventview.cpp \
qmlprofilerdetailsrewriter.cpp
HEADERS += \
qmlprofilerconstants.h \
......@@ -41,7 +41,8 @@ HEADERS += \
localqmlprofilerrunner.h \
codaqmlprofilerrunner.h \
remotelinuxqmlprofilerrunner.h \
qmlprofilereventview.h
qmlprofilereventview.h \
qmlprofilerdetailsrewriter.h
RESOURCES += \
qml/qmlprofiler.qrc
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "qmlprofilerdetailsrewriter.h"
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljstools/qmljsmodelmanager.h>
#include <utils/qtcassert.h>
namespace QmlProfiler {
namespace Internal {
struct PendingEvent {
QmlJsDebugClient::QmlEventLocation location;
QString localFile;
int eventType;
};
class PropertyVisitor: protected QmlJS::AST::Visitor
{
QmlJS::AST::Node * _lastValidNode;
unsigned _line;
unsigned _col;
public:
QmlJS::AST::Node * operator()(QmlJS::AST::Node *node, unsigned line, unsigned col)
{
_line = line;
_col = col;
_lastValidNode = 0;
accept(node);
return _lastValidNode;
}
protected:
using QmlJS::AST::Visitor::visit;
void accept(QmlJS::AST::Node *node)
{
if (node)
node->accept(this);
}
bool containsLocation(QmlJS::AST::SourceLocation start, QmlJS::AST::SourceLocation end)
{
return (_line > start.startLine || (_line == start.startLine && _col >= start.startColumn)) &&
(_line < end.startLine || (_line == end.startLine && _col <= end.startColumn));
}
virtual bool preVisit(QmlJS::AST::Node *node)
{
if (QmlJS::AST::cast<QmlJS::AST::UiQualifiedId *>(node)) {
return false;
}
return containsLocation(node->firstSourceLocation(), node->lastSourceLocation());
}
virtual bool visit(QmlJS::AST::UiScriptBinding *ast)
{
_lastValidNode = ast;
return true;
}
virtual bool visit(QmlJS::AST::UiPublicMember *ast)
{
_lastValidNode = ast;
return true;
}
};
/////////////////////////////////////////////////////////////////////////////////
class QmlProfilerDetailsRewriter::QmlProfilerDetailsRewriterPrivate
{
public:
QmlProfilerDetailsRewriterPrivate(QmlProfilerDetailsRewriter *qq) : q(qq) {}
~QmlProfilerDetailsRewriterPrivate() {}
QList <PendingEvent> m_pendingEvents;
QStringList m_pendingDocs;
QmlProfilerDetailsRewriter *q;
};
QmlProfilerDetailsRewriter::QmlProfilerDetailsRewriter(QObject *parent) : QObject(parent),
d(new QmlProfilerDetailsRewriterPrivate(this))
{ }
QmlProfilerDetailsRewriter::~QmlProfilerDetailsRewriter()
{
delete d;
}
void QmlProfilerDetailsRewriter::requestDetailsForLocation(int type,
const QmlJsDebugClient::QmlEventLocation &location)
{
QString localFile = QUrl(location.filename).toLocalFile();
if (QmlJSTools::languageOfFile(localFile) != QmlJS::Document::QmlLanguage)
return;
PendingEvent ev = {location, localFile, type};
d->m_pendingEvents << ev;
if (!d->m_pendingDocs.contains(localFile)) {
if (d->m_pendingDocs.isEmpty())
connect(QmlJS::ModelManagerInterface::instance(),
SIGNAL(documentUpdated(QmlJS::Document::Ptr)),
this,
SLOT(documentReady(QmlJS::Document::Ptr)));
d->m_pendingDocs << localFile;
}
}
void QmlProfilerDetailsRewriter::reloadDocuments()
{
if (!d->m_pendingDocs.isEmpty())
QmlJS::ModelManagerInterface::instance()->updateSourceFiles(d->m_pendingDocs, false);
else
emit eventDetailsChanged();
}
void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(QTextStream &textDoc,
QmlJS::Document::Ptr doc, int type, const QmlJsDebugClient::QmlEventLocation &location)
{
PropertyVisitor propertyVisitor;
QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line, location.column);
QTC_ASSERT(node, return);
qint64 startPos = node->firstSourceLocation().begin();
qint64 len = node->lastSourceLocation().end() - startPos;
textDoc.seek(startPos);
QString details = textDoc.read(len).replace('\n'," ").simplified();
emit rewriteDetailsString(type, location, details);
}
void QmlProfilerDetailsRewriter::documentReady(QmlJS::Document::Ptr doc)
{
// this could be triggered by an unrelated reload in Creator
if (!d->m_pendingDocs.contains(doc->fileName()))
return;
// if the file could not be opened this slot is still triggered but source() will be an empty string
if (!doc->source().isEmpty()) {
QTextStream st(&doc->source(), QIODevice::ReadOnly);
for (int i = d->m_pendingEvents.count()-1; i>=0; i--) {
PendingEvent ev = d->m_pendingEvents[i];
if (ev.localFile == doc->fileName()) {
d->m_pendingEvents.removeAt(i);
rewriteDetailsForLocation(st, doc, ev.eventType, ev.location);
}
}
}
d->m_pendingDocs.removeOne(doc->fileName());
if (d->m_pendingDocs.isEmpty()) {
disconnect(QmlJS::ModelManagerInterface::instance(),
SIGNAL(documentUpdated(QmlJS::Document::Ptr)),
this,
SLOT(documentReady(QmlJS::Document::Ptr)));
emit eventDetailsChanged();
}
}
} // namespace Internal
} // namespace QmlProfiler
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef QMLPROFILERDETAILSREWRITER_H
#define QMLPROFILERDETAILSREWRITER_H
#include <QtCore/QObject>
#include "qmljsdebugclient/qmlprofilereventlocation.h"
#include <qmljs/qmljsdocument.h>
namespace QmlProfiler {
namespace Internal {
class QmlProfilerDetailsRewriter : public QObject
{
Q_OBJECT
public:
explicit QmlProfilerDetailsRewriter(QObject *parent);
~QmlProfilerDetailsRewriter();
private:
void rewriteDetailsForLocation(QTextStream &textDoc,QmlJS::Document::Ptr doc, int type,
const QmlJsDebugClient::QmlEventLocation &location);
public slots:
void requestDetailsForLocation(int type, const QmlJsDebugClient::QmlEventLocation &location);
void reloadDocuments();
void documentReady(QmlJS::Document::Ptr doc);
signals:
void rewriteDetailsString(int type, const QmlJsDebugClient::QmlEventLocation &location,
const QString &details);
void eventDetailsChanged();
private:
class QmlProfilerDetailsRewriterPrivate;
QmlProfilerDetailsRewriterPrivate *d;
};
} // namespace Internal
} // namespace QmlProfiler
#endif // QMLPROFILERDETAILSREWRITER_H
......@@ -216,6 +216,7 @@ public:
QStandardItemModel *m_model;
QList<bool> m_fieldShown;
int m_firstNumericColumn;
int m_detailsColumn;
};
......@@ -239,6 +240,7 @@ QmlProfilerEventsMainView::QmlProfilerEventsMainView(QmlProfilerEventList *model
setEventStatisticsModel(model);
d->m_firstNumericColumn = 0;
d->m_detailsColumn = 0;
// default view
setViewType(EventsView);
......@@ -252,11 +254,15 @@ QmlProfilerEventsMainView::~QmlProfilerEventsMainView()
void QmlProfilerEventsMainView::setEventStatisticsModel( QmlProfilerEventList *model )
{
if (d->m_eventStatistics)
if (d->m_eventStatistics) {
disconnect(d->m_eventStatistics,SIGNAL(dataReady()),this,SLOT(buildModel()));
disconnect(d->m_eventStatistics,SIGNAL(detailsChanged(int,QString)),this,SLOT(changeDetailsForEvent(int,QString)));
}
d->m_eventStatistics = model;
if (model)
if (model) {
connect(d->m_eventStatistics,SIGNAL(dataReady()),this,SLOT(buildModel()));
connect(d->m_eventStatistics,SIGNAL(detailsChanged(int,QString)),this,SLOT(changeDetailsForEvent(int,QString)));
}
}
void QmlProfilerEventsMainView::setFieldViewable(Fields field, bool show)
......@@ -344,8 +350,10 @@ void QmlProfilerEventsMainView::setHeaderLabels()
d->m_model->setHeaderData(fieldIndex++, Qt::Horizontal, QVariant(tr("Longest Time")));
if (d->m_fieldShown[MinTime])
d->m_model->setHeaderData(fieldIndex++, Qt::Horizontal, QVariant(tr("Shortest Time")));
if (d->m_fieldShown[Details])
if (d->m_fieldShown[Details]) {
d->m_detailsColumn = fieldIndex;
d->m_model->setHeaderData(fieldIndex++, Qt::Horizontal, QVariant(tr("Details")));
}
}
void QmlProfilerEventsMainView::clear()
......@@ -622,6 +630,22 @@ QModelIndex QmlProfilerEventsMainView::selectedItem() const
return sel.first();
}
void QmlProfilerEventsMainView::changeDetailsForEvent(int eventId, const QString &newString)
{
// available only for QML
if (d->m_viewType != EventsView)
return;
for (int i=0; i<d->m_model->rowCount(); i++) {
QStandardItem *infoItem = d->m_model->item(i, 0);
if (infoItem->data(EventIdRole).toInt() == eventId) {
d->m_model->item(i,d->m_detailsColumn)->setData(QVariant(newString),Qt::DisplayRole);
d->m_model->item(i,d->m_detailsColumn)->setData(QVariant(newString));
return;
}
}
}
QString QmlProfilerEventsMainView::QmlProfilerEventsMainViewPrivate::textForItem(QStandardItem *item, bool recursive = true) const
{
QString str;
......
......@@ -153,6 +153,7 @@ public slots:
void selectEvent(int eventId);
void selectEventByLocation(const QString &filename, int line);
void buildModel();
void changeDetailsForEvent(int eventId, const QString &newString);
private:
void setHeaderLabels();
......
......@@ -142,6 +142,12 @@ TraceWindow::TraceWindow(QWidget *parent)
m_mainView->rootContext()->setContextProperty("qmlEventList", m_eventList);
m_overview->rootContext()->setContextProperty("qmlEventList", m_eventList);
m_rewriter = new QmlProfilerDetailsRewriter(this);
connect(m_eventList, SIGNAL(requestDetailsForLocation(int,QmlJsDebugClient::QmlEventLocation)), m_rewriter, SLOT(requestDetailsForLocation(int,QmlJsDebugClient::QmlEventLocation)));
connect(m_rewriter, SIGNAL(rewriteDetailsString(int,QmlJsDebugClient::QmlEventLocation,QString)), m_eventList, SLOT(rewriteDetailsString(int,QmlJsDebugClient::QmlEventLocation,QString)));
connect(m_rewriter, SIGNAL(eventDetailsChanged()), m_eventList, SLOT(finishedRewritingDetails()));
connect(m_eventList, SIGNAL(reloadDocumentsForDetails()), m_rewriter, SLOT(reloadDocuments()));
connect(this, SIGNAL(v8range(int,QString,QString,int,double,double)), m_eventList, SLOT(addV8Event(int,QString,QString,int,double,double)));
// Minimum height: 5 rows of 20 pixels + scrollbar of 50 pixels + 20 pixels margin
......
......@@ -35,7 +35,7 @@
#include <qmljsdebugclient/qmlprofilertraceclient.h>
#include <qmljsdebugclient/qmlprofilereventlist.h>
#include "qmlprofilerdetailsrewriter.h"
#include <qmljsdebugclient/qv8profilerclient.h>
#include <QtCore/QPointer>
......@@ -173,6 +173,7 @@ private:
QDeclarativeView *m_timebar;
QDeclarativeView *m_overview;
QmlJsDebugClient::QmlProfilerEventList *m_eventList;
QmlProfilerDetailsRewriter *m_rewriter;
bool m_qmlDataReady;
bool m_v8DataReady;
double m_profiledTime;
......
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