Commit 5525e7d2 authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlProfiler: Rename TracePlugin to QmlProfileTraceClient

Also move it into it's own file.

Change-Id: If063b0a4c6642b1e209e6a0026fedffd01603eb9
Reviewed-on: http://codereview.qt.nokia.com/841

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent 5fb18dcc
......@@ -29,7 +29,8 @@ SOURCES += \
codaqmlprofilerrunner.cpp \
remotelinuxqmlprofilerrunner.cpp \
qmlprofilercalleeview.cpp \
qmlprofilercallerview.cpp
qmlprofilercallerview.cpp \
qmlprofilertraceclient.cpp
HEADERS += \
qmlprofilerconstants.h \
......@@ -47,7 +48,8 @@ HEADERS += \
codaqmlprofilerrunner.h \
remotelinuxqmlprofilerrunner.h \
qmlprofilercalleeview.h \
qmlprofilercallerview.h
qmlprofilercallerview.h \
qmlprofilertraceclient.h
RESOURCES += \
qml/qml.qrc
......
......@@ -33,35 +33,22 @@
#include "qmlprofilerengine.h"
#include "qmlprofilerplugin.h"
#include "qmlprofilertool.h"
#include "localqmlprofilerrunner.h"
#include "canvas/qdeclarativecanvas_p.h"
#include "canvas/qdeclarativecontext2d_p.h"
#include "canvas/qdeclarativetiledcanvas_p.h"
#include "codaqmlprofilerrunner.h"
#include "localqmlprofilerrunner.h"
#include "remotelinuxqmlprofilerrunner.h"
#include "qmlprofilerplugin.h"
#include "qmlprofilertool.h"
#include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerconstants.h>
#include <projectexplorer/applicationlauncher.h>
#include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h>
#include <qmljsdebugclient/qdeclarativedebugclient_p.h>
#include <qt4projectmanager/qt-s60/s60devicerunconfiguration.h>
#include <remotelinux/remotelinuxrunconfiguration.h>
#include <utils/qtcassert.h>
#include <coreplugin/helpmanager.h>
#include "timelineview.h"
#include "tracewindow.h"
#include <QDebug>
#include <QtGui/QMessageBox>
#include <QtGui/QMainWindow>
#include "canvas/qdeclarativecanvas_p.h"
#include "canvas/qdeclarativecontext2d_p.h"
#include "canvas/qdeclarativetiledcanvas_p.h"
#include <QtGui/QMessageBox>
namespace QmlProfiler {
namespace Internal {
......
......@@ -82,6 +82,7 @@
using namespace Analyzer;
using namespace QmlProfiler::Internal;
using namespace QmlJsDebugClient;
class QmlProfilerTool::QmlProfilerToolPrivate
{
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
** No Commercial Usage
**
** 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.
**
** 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.
**
** 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
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "qmlprofilertraceclient.h"
using namespace QmlProfiler::Internal;
using namespace QmlJsDebugClient;
static const int GAP_TIME = 150;
QmlProfilerTraceClient::QmlProfilerTraceClient(QDeclarativeDebugConnection *client)
: QDeclarativeDebugClient(QLatin1String("CanvasFrameRate"), client),
m_inProgressRanges(0), m_maximumTime(0), m_recording(false), m_nestingLevel(0)
{
::memset(m_rangeCount, 0, MaximumRangeType * sizeof(int));
::memset(m_nestingInType, 0, MaximumRangeType * sizeof(int));
}
void QmlProfilerTraceClient::clearView()
{
::memset(m_rangeCount, 0, MaximumRangeType * sizeof(int));
::memset(m_nestingInType, 0, MaximumRangeType * sizeof(int));
m_nestingLevel = 0;
emit clear();
}
void QmlProfilerTraceClient::setRecording(bool v)
{
if (v == m_recording)
return;
if (status() == Enabled) {
QByteArray ba;
QDataStream stream(&ba, QIODevice::WriteOnly);
stream << v;
sendMessage(ba);
}
m_recording = v;
emit recordingChanged(v);
}
void QmlProfilerTraceClient::statusChanged(Status status)
{
if (status == Enabled) {
m_recording = !m_recording;
setRecording(!m_recording);
emit enabled();
}
}
void QmlProfilerTraceClient::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);
m_inProgressRanges |= (static_cast<qint64>(1) << range);
++m_rangeCount[range];
++m_nestingLevel;
++m_nestingInType[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];
if (m_inProgressRanges & (static_cast<qint64>(1) << range))
m_inProgressRanges &= ~(static_cast<qint64>(1) << range);
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, m_nestingLevel, m_nestingInType[range], startTime,
time - startTime, data, location.fileName, location.line);
--m_nestingLevel;
--m_nestingInType[range];
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";
}
}
}
}
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
** No Commercial Usage
**
** 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.
**
** 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.
**
** 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
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef QMLPROFILERTRACECLIENT_H
#define QMLPROFILERTRACECLIENT_H
#include <qmljsdebugclient/qdeclarativedebugclient_p.h>
#include <QtCore/QStack>
#include <QtCore/QStringList>
namespace QmlProfiler {
namespace Internal {
struct Location
{
Location() : line(-1) {}
Location(const QString &file, int lineNumber) : fileName(file), line(lineNumber) {}
QString fileName;
int line;
};
class QmlProfilerTraceClient : public QmlJsDebugClient::QDeclarativeDebugClient
{
Q_OBJECT
Q_PROPERTY(bool recording READ isRecording WRITE setRecording NOTIFY recordingChanged)
public:
QmlProfilerTraceClient(QmlJsDebugClient::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 isRecording() const { return m_recording; }
public slots:
void setRecording(bool);
void clearView();
signals:
void complete();
void gap(qint64);
void event(int event, qint64 time);
void range(int type, int nestingLevel, int nestingInType, qint64 startTime, qint64 length,
const QStringList &data, const QString &fileName, int line);
void sample(int, int, int, bool);
void recordingChanged(bool arg);
void enabled();
void clear();
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;
int m_nestingLevel;
int m_nestingInType[MaximumRangeType];
};
} // namespace Internal
} // namespace QmlProfiler
#endif // QMLPROFILERTRACECLIENT_H
......@@ -34,243 +34,24 @@
#include "tracewindow.h"
#include "qmlprofilerplugin.h"
#include <utils/styledbar.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 <QToolButton>
#include <QtDeclarative/qdeclarativeview.h>
#include <QtDeclarative/qdeclarativecontext.h>
#include <QtDeclarative/qdeclarative.h>
#include "qmlprofilertraceclient.h"
static const int GAP_TIME = 150;
#include <qmljsdebugclient/qdeclarativedebugclient_p.h>
#include <utils/styledbar.h>
using QmlJsDebugClient::QDeclarativeDebugClient;
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeContext>
#include <QtGui/QVBoxLayout>
#include <QtGui/QToolButton>
#include <QtGui/QGraphicsObject>
namespace QmlProfiler {
namespace Internal {
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 isRecording WRITE setRecording NOTIFY recordingChanged)
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 isRecording() const { return m_recording; }
public slots:
void setRecording(bool);
void clearView();
signals:
void complete();
void gap(qint64);
void event(int event, qint64 time);
void range(int type, int nestingLevel, int nestingInType, qint64 startTime, qint64 length, const QStringList &data, const QString &fileName, int line);
void sample(int, int, int, bool);
void recordingChanged(bool arg);
void enabled();
void clear();
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;
int m_nestingLevel;
int m_nestingInType[MaximumRangeType];
};
TracePlugin::TracePlugin(QDeclarativeDebugConnection *client)
: QDeclarativeDebugClient(QLatin1String("CanvasFrameRate"), client),
m_inProgressRanges(0), m_maximumTime(0), m_recording(false), m_nestingLevel(0)
{
::memset(m_rangeCount, 0, MaximumRangeType * sizeof(int));
::memset(m_nestingInType, 0, MaximumRangeType * sizeof(int));
}
void TracePlugin::clearView()
{
::memset(m_rangeCount, 0, MaximumRangeType * sizeof(int));
::memset(m_nestingInType, 0, MaximumRangeType * sizeof(int));
m_nestingLevel = 0;
emit clear();
}
void TracePlugin::setRecording(bool v)
{
if (v == m_recording)
return;
if (status() == Enabled) {
QByteArray ba;
QDataStream stream(&ba, QIODevice::WriteOnly);
stream << v;
sendMessage(ba);
}
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);
m_inProgressRanges |= (static_cast<qint64>(1) << range);
++m_rangeCount[range];
++m_nestingLevel;
++m_nestingInType[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];
if (m_inProgressRanges & (static_cast<qint64>(1) << range))
m_inProgressRanges &= ~(static_cast<qint64>(1) << range);
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, m_nestingLevel, m_nestingInType[range], startTime, time - startTime, data, location.fileName, location.line);
--m_nestingLevel;
--m_nestingInType[range];
if (m_rangeCount[range] == 0) {
int count = m_rangeDatas[range].count() +
m_rangeStartTimes[