2011-03-25 09:25:17 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
**
|
|
|
|
** Contact: Nokia Corporation (qt-info@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 qt-info@nokia.com.
|
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
#include "qmlprofilertool.h"
|
|
|
|
#include "qmlprofilerengine.h"
|
|
|
|
#include "qmlprofilerplugin.h"
|
|
|
|
|
|
|
|
#include "tracewindow.h"
|
|
|
|
#include <private/qdeclarativedebugclient_p.h>
|
|
|
|
|
|
|
|
#include <analyzerbase/analyzermanager.h>
|
|
|
|
#include <analyzerbase/analyzerconstants.h>
|
2011-04-04 14:39:28 +02:00
|
|
|
#include <analyzerbase/ianalyzeroutputpaneadapter.h>
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
#include "timelineview.h"
|
|
|
|
|
|
|
|
#include "canvas/qdeclarativecanvas_p.h"
|
|
|
|
#include "canvas/qdeclarativecontext2d_p.h"
|
|
|
|
#include "canvas/qdeclarativetiledcanvas_p.h"
|
|
|
|
|
|
|
|
#include <qmlprojectmanager/qmlprojectrunconfiguration.h>
|
|
|
|
#include <utils/fileinprojectfinder.h>
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
#include <projectexplorer/project.h>
|
2011-04-01 13:48:10 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
#include <texteditor/itexteditor.h>
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
|
|
|
#include <QtCore/QFile>
|
|
|
|
|
2011-03-24 12:42:15 +01:00
|
|
|
#include <QtGui/QHBoxLayout>
|
|
|
|
#include <QtGui/QLabel>
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
using namespace Analyzer;
|
2011-03-25 09:21:00 +01:00
|
|
|
using namespace QmlProfiler::Internal;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
QString QmlProfilerTool::host = QLatin1String("localhost");
|
2011-03-24 12:42:15 +01:00
|
|
|
quint16 QmlProfilerTool::port = 33456;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Adapter for output pane.
|
|
|
|
class QmlProfilerOutputPaneAdapter : public Analyzer::IAnalyzerOutputPaneAdapter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit QmlProfilerOutputPaneAdapter(QmlProfilerTool *mct) :
|
|
|
|
IAnalyzerOutputPaneAdapter(mct), m_tool(mct) {}
|
|
|
|
|
|
|
|
virtual QWidget *toolBarWidget() { return m_tool->createToolBarWidget(); }
|
|
|
|
virtual QWidget *paneWidget() { return m_tool->createTimeLineWidget(); }
|
|
|
|
virtual void clearContents() { /*TODO*/ }
|
|
|
|
virtual void setFocus() { /*TODO*/ }
|
|
|
|
virtual bool hasFocus() const { return false; /*TODO*/ }
|
|
|
|
virtual bool canFocus() const { return false; /*TODO*/ }
|
|
|
|
virtual bool canNavigate() const { return false; /*TODO*/ }
|
|
|
|
virtual bool canNext() const { return false; /*TODO*/ }
|
|
|
|
virtual bool canPrevious() const { return false; /*TODO*/ }
|
|
|
|
virtual void goToNext() { /*TODO*/ }
|
|
|
|
virtual void goToPrev() { /*TODO*/ }
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
QmlProfilerTool *m_tool;
|
|
|
|
};
|
|
|
|
|
|
|
|
class QmlProfilerTool::QmlProfilerToolPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QmlProfilerToolPrivate(QmlProfilerTool *qq) : q(qq) {}
|
|
|
|
~QmlProfilerToolPrivate() {}
|
|
|
|
|
|
|
|
QmlProfilerTool *q;
|
|
|
|
|
|
|
|
QDeclarativeDebugConnection *m_client;
|
|
|
|
TraceWindow *m_traceWindow;
|
|
|
|
QmlProfilerOutputPaneAdapter *m_outputPaneAdapter;
|
2011-04-01 13:48:10 +02:00
|
|
|
ProjectExplorer::Project *m_project;
|
|
|
|
Utils::FileInProjectFinder m_projectFinder;
|
2011-03-11 12:22:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
QmlProfilerTool::QmlProfilerTool(QObject *parent)
|
|
|
|
: IAnalyzerTool(parent), d(new QmlProfilerToolPrivate(this))
|
|
|
|
{
|
|
|
|
d->m_client = 0;
|
|
|
|
d->m_traceWindow = 0;
|
|
|
|
d->m_outputPaneAdapter = 0;
|
2011-04-01 13:48:10 +02:00
|
|
|
d->m_project = 0;
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerTool::~QmlProfilerTool()
|
|
|
|
{
|
|
|
|
if (d->m_client->isConnected())
|
|
|
|
d->m_client->disconnectFromHost();
|
|
|
|
delete d->m_traceWindow;
|
|
|
|
delete d->m_outputPaneAdapter;
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QmlProfilerTool::id() const
|
|
|
|
{
|
|
|
|
return "QmlProfiler";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QmlProfilerTool::displayName() const
|
|
|
|
{
|
|
|
|
return tr("Qml Performance Monitor");
|
|
|
|
}
|
|
|
|
|
|
|
|
IAnalyzerTool::ToolMode QmlProfilerTool::mode() const
|
|
|
|
{
|
|
|
|
return DebugMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-04 14:39:28 +02:00
|
|
|
IAnalyzerEngine *QmlProfilerTool::createEngine(const AnalyzerStartParameters &sp,
|
|
|
|
ProjectExplorer::RunConfiguration *runConfiguration)
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-04-04 14:39:28 +02:00
|
|
|
QmlProfilerEngine *engine = new QmlProfilerEngine(sp, runConfiguration);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-04-01 13:48:10 +02:00
|
|
|
d->m_project = runConfiguration->target()->project();
|
|
|
|
if (d->m_project) {
|
|
|
|
d->m_projectFinder.setProjectDirectory(d->m_project->projectDirectory());
|
|
|
|
updateProjectFileList();
|
|
|
|
connect(d->m_project, SIGNAL(fileListChanged()), this, SLOT(updateProjectFileList()));
|
|
|
|
}
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
connect(engine, SIGNAL(processRunning()), this, SLOT(connectClient()));
|
|
|
|
connect(engine, SIGNAL(processTerminated()), this, SLOT(disconnectClient()));
|
|
|
|
connect(engine, SIGNAL(stopRecording()), this, SLOT(stopRecording()));
|
|
|
|
connect(d->m_traceWindow, SIGNAL(viewUpdated()), engine, SLOT(viewUpdated()));
|
|
|
|
connect(d->m_traceWindow, SIGNAL(gotoSourceLocation(QString,int)), this, SLOT(gotoSourceLocation(QString,int)));
|
2011-03-24 12:42:15 +01:00
|
|
|
connect(d->m_traceWindow, SIGNAL(timeChanged(qreal)), this, SLOT(updateTimer(qreal)));
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
return engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::initialize(ExtensionSystem::IPlugin */*plugin*/)
|
|
|
|
{
|
2011-04-01 13:49:36 +02:00
|
|
|
qmlRegisterType<Canvas>("Monitor", 1, 0, "Canvas");
|
2011-03-25 09:26:55 +01:00
|
|
|
qmlRegisterType<TiledCanvas>("Monitor", 1, 0, "TiledCanvas");
|
2011-03-11 12:22:57 +01:00
|
|
|
qmlRegisterType<Context2D>();
|
|
|
|
qmlRegisterType<CanvasImage>();
|
|
|
|
qmlRegisterType<CanvasGradient>();
|
|
|
|
|
2011-03-25 09:26:55 +01:00
|
|
|
qmlRegisterType<TimelineView>("Monitor", 1, 0,"TimelineView");
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
d->m_client = new QDeclarativeDebugConnection;
|
|
|
|
d->m_traceWindow = new TraceWindow();
|
|
|
|
d->m_traceWindow->reset(d->m_client);
|
|
|
|
}
|
|
|
|
|
2011-04-04 14:39:28 +02:00
|
|
|
void QmlProfilerTool::extensionsInitialized()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
IAnalyzerOutputPaneAdapter *QmlProfilerTool::outputPaneAdapter()
|
|
|
|
{
|
|
|
|
if (!d->m_outputPaneAdapter)
|
|
|
|
d->m_outputPaneAdapter = new QmlProfilerOutputPaneAdapter(this);
|
|
|
|
return d->m_outputPaneAdapter;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *QmlProfilerTool::createToolBarWidget()
|
|
|
|
{
|
|
|
|
// custom toolbar (TODO)
|
2011-03-24 12:42:15 +01:00
|
|
|
QWidget *toolbarWidget = new QWidget;
|
|
|
|
toolbarWidget->setObjectName(QLatin1String("QmlProfilerToolBarWidget"));
|
|
|
|
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout;
|
|
|
|
layout->setMargin(0);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
|
|
|
QLabel *timeLabel = new QLabel(tr("elapsed: 0 s"));
|
|
|
|
QPalette palette = timeLabel->palette();
|
|
|
|
palette.setColor(QPalette::WindowText, Qt::white);
|
|
|
|
timeLabel->setPalette(palette);
|
|
|
|
|
|
|
|
connect(this,SIGNAL(setTimeLabel(QString)),timeLabel,SLOT(setText(QString)));
|
|
|
|
layout->addWidget(timeLabel);
|
|
|
|
toolbarWidget->setLayout(layout);
|
|
|
|
|
|
|
|
return toolbarWidget;
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *QmlProfilerTool::createTimeLineWidget()
|
|
|
|
{
|
|
|
|
return d->m_traceWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::connectClient()
|
|
|
|
{
|
|
|
|
QDeclarativeDebugConnection *newClient = new QDeclarativeDebugConnection;
|
|
|
|
d->m_traceWindow->reset(newClient);
|
|
|
|
delete d->m_client;
|
|
|
|
d->m_client = newClient;
|
|
|
|
|
|
|
|
d->m_client->connectToHost(host, port);
|
|
|
|
d->m_client->waitForConnected();
|
|
|
|
|
|
|
|
if (d->m_client->state() == QDeclarativeDebugConnection::ConnectedState) {
|
|
|
|
d->m_traceWindow->setRecording(true);
|
|
|
|
if (QmlProfilerPlugin::debugOutput)
|
|
|
|
qWarning("QmlProfiler: connected and running");
|
|
|
|
} else {
|
|
|
|
if (QmlProfilerPlugin::debugOutput)
|
|
|
|
qWarning("QmlProfiler: Failed to connect: %s", qPrintable(d->m_client->errorString()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::disconnectClient()
|
|
|
|
{
|
|
|
|
d->m_client->disconnectFromHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::stopRecording()
|
|
|
|
{
|
|
|
|
d->m_traceWindow->setRecording(false);
|
|
|
|
}
|
|
|
|
|
2011-04-01 13:57:49 +02:00
|
|
|
void QmlProfilerTool::gotoSourceLocation(const QString &fileUrl, int lineNumber)
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-04-01 13:57:49 +02:00
|
|
|
if (lineNumber < 0 || fileUrl.isEmpty())
|
2011-03-11 12:22:57 +01:00
|
|
|
return;
|
|
|
|
|
2011-04-01 13:57:49 +02:00
|
|
|
const QString fileName = QUrl(fileUrl).toLocalFile();
|
|
|
|
const QString projectFileName = d->m_projectFinder.findFile(fileName);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
|
|
|
Core::IEditor *editor = editorManager->openEditor(projectFileName);
|
|
|
|
TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor);
|
|
|
|
|
|
|
|
if (textEditor) {
|
|
|
|
editorManager->addCurrentPositionToNavigationHistory();
|
|
|
|
textEditor->gotoLine(lineNumber);
|
|
|
|
textEditor->widget()->setFocus();
|
|
|
|
}
|
|
|
|
}
|
2011-03-24 12:42:15 +01:00
|
|
|
|
|
|
|
void QmlProfilerTool::updateTimer(qreal elapsedSeconds)
|
|
|
|
{
|
|
|
|
QString timeString = QString::number(elapsedSeconds,'f',1);
|
|
|
|
timeString = QString(" ").left(6-timeString.length()) + timeString;
|
|
|
|
emit setTimeLabel(tr("elapsed: ")+timeString+QLatin1String(" s"));
|
|
|
|
}
|
2011-04-01 13:48:10 +02:00
|
|
|
|
|
|
|
void QmlProfilerTool::updateProjectFileList()
|
|
|
|
{
|
|
|
|
d->m_projectFinder.setProjectFiles(
|
|
|
|
d->m_project->files(ProjectExplorer::Project::ExcludeGeneratedFiles));
|
|
|
|
}
|
2011-04-04 14:39:28 +02:00
|
|
|
|
|
|
|
bool QmlProfilerTool::canRunRemotely() const
|
|
|
|
{
|
|
|
|
// TODO: Is this correct?
|
|
|
|
return true;
|
|
|
|
}
|