2011-03-11 12:22:57 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-03-25 09:25:17 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2011-03-11 12:22:57 +01:00
|
|
|
**
|
2011-05-06 15:05:37 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2011-03-11 12:22:57 +01:00
|
|
|
**
|
2011-03-25 09:25:17 +01:00
|
|
|
** No Commercial Usage
|
2011-03-11 12:22:57 +01:00
|
|
|
**
|
2011-03-25 09:25:17 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
2011-03-11 12:22:57 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, 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.
|
|
|
|
|
**
|
2011-03-25 09:25:17 +01:00
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2011-03-11 12:22:57 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
2011-03-25 09:25:17 +01:00
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
#include "tracewindow.h"
|
|
|
|
|
|
|
|
|
|
#include <QtCore/qdebug.h>
|
|
|
|
|
#include <QtCore/qstringlist.h>
|
|
|
|
|
#include <QtCore/qdatastream.h>
|
|
|
|
|
#include <QtCore/qmargins.h>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/qapplication.h>
|
|
|
|
|
#include <QtGui/qpainter.h>
|
|
|
|
|
#include <QtGui/qboxlayout.h>
|
|
|
|
|
#include <QtGui/qevent.h>
|
|
|
|
|
#include <QtCore/qstack.h>
|
|
|
|
|
|
|
|
|
|
#include <QGraphicsObject>
|
|
|
|
|
|
|
|
|
|
#include <QtDeclarative/qdeclarativeview.h>
|
|
|
|
|
#include <QtDeclarative/qdeclarativecontext.h>
|
|
|
|
|
#include <QtDeclarative/qdeclarative.h>
|
|
|
|
|
|
|
|
|
|
#include "qmlprofilerplugin.h"
|
|
|
|
|
//#include <jsdebuggeragent.h>
|
|
|
|
|
//#include <qdeclarativeviewobserver.h>
|
|
|
|
|
|
|
|
|
|
#define GAP_TIME 150
|
|
|
|
|
|
2011-04-14 15:49:12 +02:00
|
|
|
using QmlJsDebugClient::QDeclarativeDebugClient;
|
|
|
|
|
|
2011-03-25 09:21:00 +01:00
|
|
|
namespace QmlProfiler {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
struct Location
|
|
|
|
|
{
|
|
|
|
|
Location() : line(-1) {}
|
|
|
|
|
Location(const QString &file, int lineNumber) : fileName(file), line(lineNumber) {}
|
|
|
|
|
QString fileName;
|
|
|
|
|
int line;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TracePlugin : public QDeclarativeDebugClient
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PROPERTY(bool recording READ recording WRITE setRecording NOTIFY recordingChanged)
|
2011-05-20 12:43:29 +02:00
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
public:
|
|
|
|
|
TracePlugin(QDeclarativeDebugConnection *client);
|
|
|
|
|
|
|
|
|
|
enum EventType {
|
|
|
|
|
FramePaint,
|
|
|
|
|
Mouse,
|
|
|
|
|
Key,
|
|
|
|
|
|
|
|
|
|
MaximumEventType
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum Message {
|
|
|
|
|
Event,
|
|
|
|
|
RangeStart,
|
|
|
|
|
RangeData,
|
|
|
|
|
RangeLocation,
|
|
|
|
|
RangeEnd,
|
|
|
|
|
Complete,
|
|
|
|
|
|
|
|
|
|
MaximumMessage
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum RangeType {
|
|
|
|
|
Painting,
|
|
|
|
|
Compiling,
|
|
|
|
|
Creating,
|
|
|
|
|
Binding,
|
|
|
|
|
HandlingSignal,
|
|
|
|
|
|
|
|
|
|
MaximumRangeType
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool recording() const
|
|
|
|
|
{
|
|
|
|
|
return m_recording;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
void setRecording(bool);
|
2011-04-06 16:04:18 +02:00
|
|
|
void clearView();
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void complete();
|
|
|
|
|
void gap(qint64);
|
|
|
|
|
void event(int event, qint64 time);
|
|
|
|
|
void range(int type, qint64 startTime, qint64 length, const QStringList &data, const QString &fileName, int line);
|
|
|
|
|
|
|
|
|
|
void sample(int, int, int, bool);
|
|
|
|
|
|
|
|
|
|
void recordingChanged(bool arg);
|
|
|
|
|
|
|
|
|
|
void enabled();
|
2011-04-06 16:04:18 +02:00
|
|
|
void clear();
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void statusChanged(Status);
|
|
|
|
|
virtual void messageReceived(const QByteArray &);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
qint64 m_inProgressRanges;
|
|
|
|
|
QStack<qint64> m_rangeStartTimes[MaximumRangeType];
|
|
|
|
|
QStack<QStringList> m_rangeDatas[MaximumRangeType];
|
|
|
|
|
QStack<Location> m_rangeLocations[MaximumRangeType];
|
|
|
|
|
int m_rangeCount[MaximumRangeType];
|
|
|
|
|
qint64 m_maximumTime;
|
|
|
|
|
bool m_recording;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-25 09:21:00 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProfiler
|
|
|
|
|
|
|
|
|
|
using namespace QmlProfiler::Internal;
|
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
TracePlugin::TracePlugin(QDeclarativeDebugConnection *client)
|
|
|
|
|
: QDeclarativeDebugClient(QLatin1String("CanvasFrameRate"), client), m_inProgressRanges(0), m_maximumTime(0), m_recording(false)
|
|
|
|
|
{
|
|
|
|
|
::memset(m_rangeCount, 0, MaximumRangeType * sizeof(int));
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 16:04:18 +02:00
|
|
|
void TracePlugin::clearView()
|
|
|
|
|
{
|
|
|
|
|
::memset(m_rangeCount, 0, MaximumRangeType * sizeof(int));
|
|
|
|
|
emit clear();
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
void TracePlugin::setRecording(bool v)
|
|
|
|
|
{
|
|
|
|
|
if (v == m_recording)
|
|
|
|
|
return;
|
2011-04-14 15:23:17 +02:00
|
|
|
|
|
|
|
|
if (status() == Enabled) {
|
|
|
|
|
QByteArray ba;
|
|
|
|
|
QDataStream stream(&ba, QIODevice::WriteOnly);
|
|
|
|
|
stream << v;
|
|
|
|
|
sendMessage(ba);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
m_recording = v;
|
|
|
|
|
emit recordingChanged(v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TracePlugin::statusChanged(Status status)
|
|
|
|
|
{
|
|
|
|
|
if (status == Enabled) {
|
|
|
|
|
m_recording = !m_recording;
|
|
|
|
|
setRecording(!m_recording);
|
|
|
|
|
emit enabled();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TracePlugin::messageReceived(const QByteArray &data)
|
|
|
|
|
{
|
|
|
|
|
QByteArray rwData = data;
|
|
|
|
|
QDataStream stream(&rwData, QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
|
|
qint64 time;
|
|
|
|
|
int messageType;
|
|
|
|
|
|
|
|
|
|
stream >> time >> messageType;
|
|
|
|
|
|
|
|
|
|
// qDebug() << __FUNCTION__ << messageType;
|
|
|
|
|
|
|
|
|
|
if (messageType >= MaximumMessage)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (time > (m_maximumTime + GAP_TIME) && 0 == m_inProgressRanges)
|
|
|
|
|
emit gap(time);
|
|
|
|
|
|
|
|
|
|
if (messageType == Event) {
|
|
|
|
|
int event;
|
|
|
|
|
stream >> event;
|
|
|
|
|
|
|
|
|
|
if (event < MaximumEventType) {
|
|
|
|
|
emit this->event((EventType)event, time);
|
|
|
|
|
m_maximumTime = qMax(time, m_maximumTime);
|
|
|
|
|
}
|
|
|
|
|
} else if (messageType == Complete) {
|
|
|
|
|
emit complete();
|
|
|
|
|
} else {
|
|
|
|
|
int range;
|
|
|
|
|
stream >> range;
|
|
|
|
|
|
|
|
|
|
if (range >= MaximumRangeType)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (messageType == RangeStart) {
|
|
|
|
|
m_rangeStartTimes[range].push(time);
|
2011-05-16 14:50:54 +02:00
|
|
|
m_inProgressRanges |= (static_cast<qint64>(1) << range);
|
2011-03-11 12:22:57 +01:00
|
|
|
++m_rangeCount[range];
|
|
|
|
|
} else if (messageType == RangeData) {
|
|
|
|
|
QString data;
|
|
|
|
|
stream >> data;
|
|
|
|
|
|
|
|
|
|
int count = m_rangeCount[range];
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
while (m_rangeDatas[range].count() < count)
|
|
|
|
|
m_rangeDatas[range].push(QStringList());
|
|
|
|
|
m_rangeDatas[range][count-1] << data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (messageType == RangeLocation) {
|
|
|
|
|
QString fileName;
|
|
|
|
|
int line;
|
|
|
|
|
stream >> fileName >> line;
|
|
|
|
|
|
|
|
|
|
if (m_rangeCount[range] > 0) {
|
|
|
|
|
m_rangeLocations[range].push(Location(fileName, line));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (m_rangeCount[range] > 0) {
|
|
|
|
|
--m_rangeCount[range];
|
2011-05-16 14:50:54 +02:00
|
|
|
if (m_inProgressRanges & (static_cast<qint64>(1) << range))
|
|
|
|
|
m_inProgressRanges &= ~(static_cast<qint64>(1) << range);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
|
m_maximumTime = qMax(time, m_maximumTime);
|
|
|
|
|
QStringList data = m_rangeDatas[range].count() ? m_rangeDatas[range].pop() : QStringList();
|
|
|
|
|
Location location = m_rangeLocations[range].count() ? m_rangeLocations[range].pop() : Location();
|
|
|
|
|
|
|
|
|
|
qint64 startTime = m_rangeStartTimes[range].pop();
|
|
|
|
|
emit this->range((RangeType)range, startTime, time - startTime, data, location.fileName, location.line);
|
|
|
|
|
if (m_rangeCount[range] == 0) {
|
|
|
|
|
int count = m_rangeDatas[range].count() +
|
|
|
|
|
m_rangeStartTimes[range].count() +
|
|
|
|
|
m_rangeLocations[range].count();
|
|
|
|
|
if (count != 0)
|
|
|
|
|
qWarning() << "incorrectly nested data";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TraceWindow::TraceWindow(QWidget *parent)
|
2011-04-14 17:18:32 +02:00
|
|
|
: QWidget(parent)
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-04-26 14:08:09 +02:00
|
|
|
setObjectName(tr("QML Performance Monitor"));
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
|
QVBoxLayout *groupLayout = new QVBoxLayout;
|
|
|
|
|
groupLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
groupLayout->setSpacing(0);
|
|
|
|
|
|
|
|
|
|
m_view = new QDeclarativeView(this);
|
|
|
|
|
|
2011-03-25 09:21:00 +01:00
|
|
|
if (QmlProfilerPlugin::debugOutput) {
|
2011-03-11 12:22:57 +01:00
|
|
|
//new QmlJSDebugger::JSDebuggerAgent(m_view->engine());
|
|
|
|
|
//new QmlJSDebugger::QDeclarativeViewObserver(m_view, m_view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
|
|
|
|
|
m_view->setFocus();
|
|
|
|
|
groupLayout->addWidget(m_view);
|
|
|
|
|
|
|
|
|
|
setLayout(groupLayout);
|
|
|
|
|
|
|
|
|
|
// Maximum height: 5 rows of 50 pixels + scrollbar of 50 pixels
|
2011-05-17 18:03:59 +02:00
|
|
|
// setFixedHeight(300);
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TraceWindow::~TraceWindow()
|
|
|
|
|
{
|
2011-04-14 17:18:32 +02:00
|
|
|
delete m_plugin.data();
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TraceWindow::reset(QDeclarativeDebugConnection *conn)
|
|
|
|
|
{
|
|
|
|
|
if (m_plugin)
|
2011-04-14 17:18:32 +02:00
|
|
|
disconnect(m_plugin.data(), SIGNAL(complete()), this, SIGNAL(viewUpdated()));
|
|
|
|
|
delete m_plugin.data();
|
2011-03-11 12:22:57 +01:00
|
|
|
m_plugin = new TracePlugin(conn);
|
2011-04-14 17:18:32 +02:00
|
|
|
connect(m_plugin.data(), SIGNAL(complete()), this, SIGNAL(viewUpdated()));
|
|
|
|
|
connect(m_plugin.data(), SIGNAL(range(int,qint64,qint64,QStringList,QString,int)),
|
|
|
|
|
this, SIGNAL(range(int,qint64,qint64,QStringList,QString,int)));
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-04-14 17:18:32 +02:00
|
|
|
m_view->rootContext()->setContextProperty("connection", m_plugin.data());
|
2011-04-04 10:52:04 +02:00
|
|
|
m_view->setSource(QUrl("qrc:/qmlprofiler/MainView.qml"));
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
|
connect(m_view->rootObject(), SIGNAL(updateCursorPosition()), this, SLOT(updateCursorPosition()));
|
2011-03-24 12:42:15 +01:00
|
|
|
connect(m_view->rootObject(), SIGNAL(updateTimer()), this, SLOT(updateTimer()));
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TraceWindow::updateCursorPosition()
|
|
|
|
|
{
|
|
|
|
|
emit gotoSourceLocation(m_view->rootObject()->property("fileName").toString(),
|
|
|
|
|
m_view->rootObject()->property("lineNumber").toInt());
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-24 12:42:15 +01:00
|
|
|
void TraceWindow::updateTimer()
|
|
|
|
|
{
|
|
|
|
|
emit timeChanged(m_view->rootObject()->property("elapsedTime").toDouble());
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 16:04:18 +02:00
|
|
|
void TraceWindow::clearDisplay()
|
|
|
|
|
{
|
|
|
|
|
if (m_plugin)
|
2011-04-14 17:18:32 +02:00
|
|
|
m_plugin.data()->clearView();
|
2011-04-06 16:04:18 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
void TraceWindow::setRecording(bool recording)
|
|
|
|
|
{
|
2011-04-15 14:51:49 +02:00
|
|
|
if (m_plugin)
|
|
|
|
|
m_plugin.data()->setRecording(recording);
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-06 12:26:19 +02:00
|
|
|
bool TraceWindow::isRecording() const
|
|
|
|
|
{
|
2011-04-14 17:18:32 +02:00
|
|
|
return (m_plugin.data()->recording());
|
2011-04-06 12:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
#include "tracewindow.moc"
|