From 12a02c75341745777487574775b299193af6c2d7 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 4 Apr 2011 15:03:31 +0200 Subject: [PATCH] QmlProfiler: Add attach/detach menu entry This allows one to also profile apps on device (as long as there is a working TCP/IP connection). --- src/plugins/qmlprofiler/qmlprofiler.pro | 9 +- .../qmlprofiler/qmlprofilerattachdialog.cpp | 40 +++++++ .../qmlprofiler/qmlprofilerattachdialog.h | 34 ++++++ .../qmlprofiler/qmlprofilerattachdialog.ui | 109 ++++++++++++++++++ .../qmlprofiler/qmlprofilerconstants.h | 6 +- src/plugins/qmlprofiler/qmlprofilerengine.cpp | 19 +++ src/plugins/qmlprofiler/qmlprofilertool.cpp | 64 +++++++++- src/plugins/qmlprofiler/qmlprofilertool.h | 2 + 8 files changed, 275 insertions(+), 8 deletions(-) create mode 100644 src/plugins/qmlprofiler/qmlprofilerattachdialog.cpp create mode 100644 src/plugins/qmlprofiler/qmlprofilerattachdialog.h create mode 100644 src/plugins/qmlprofiler/qmlprofilerattachdialog.ui diff --git a/src/plugins/qmlprofiler/qmlprofiler.pro b/src/plugins/qmlprofiler/qmlprofiler.pro index 261ea8e30e1..304da3d5dd2 100644 --- a/src/plugins/qmlprofiler/qmlprofiler.pro +++ b/src/plugins/qmlprofiler/qmlprofiler.pro @@ -18,7 +18,8 @@ SOURCES += \ qmlprofilertool.cpp \ qmlprofilerengine.cpp \ tracewindow.cpp \ - timelineview.cpp + timelineview.cpp \ + qmlprofilerattachdialog.cpp HEADERS += \ qmlprofilerconstants.h \ @@ -27,7 +28,8 @@ HEADERS += \ qmlprofilertool.h \ qmlprofilerengine.h \ tracewindow.h \ - timelineview.h + timelineview.h \ + qmlprofilerattachdialog.h RESOURCES += \ qml/qml.qrc @@ -42,3 +44,6 @@ OTHER_FILES += \ RecordButton.qml \ ToolButton.qml \ MainView.js + +FORMS += \ + qmlprofilerattachdialog.ui diff --git a/src/plugins/qmlprofiler/qmlprofilerattachdialog.cpp b/src/plugins/qmlprofiler/qmlprofilerattachdialog.cpp new file mode 100644 index 00000000000..d4d08180b77 --- /dev/null +++ b/src/plugins/qmlprofiler/qmlprofilerattachdialog.cpp @@ -0,0 +1,40 @@ +#include "qmlprofilerattachdialog.h" +#include "ui_qmlprofilerattachdialog.h" + +namespace QmlProfiler { +namespace Internal { + +QmlProfilerAttachDialog::QmlProfilerAttachDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::QmlProfilerAttachDialog) +{ + ui->setupUi(this); +} + +QmlProfilerAttachDialog::~QmlProfilerAttachDialog() +{ + delete ui; +} + +QString QmlProfilerAttachDialog::address() const +{ + return ui->addressLineEdit->text(); +} + +uint QmlProfilerAttachDialog::port() const +{ + return ui->portSpinBox->value(); +} + +void QmlProfilerAttachDialog::setAddress(const QString &address) +{ + ui->addressLineEdit->setText(address); +} + +void QmlProfilerAttachDialog::setPort(uint port) +{ + ui->portSpinBox->setValue(port); +} + +} // namespace Internal +} // namespace QmlProfiler diff --git a/src/plugins/qmlprofiler/qmlprofilerattachdialog.h b/src/plugins/qmlprofiler/qmlprofilerattachdialog.h new file mode 100644 index 00000000000..ac85df79185 --- /dev/null +++ b/src/plugins/qmlprofiler/qmlprofilerattachdialog.h @@ -0,0 +1,34 @@ +#ifndef QMLPROFILERATTACHDIALOG_H +#define QMLPROFILERATTACHDIALOG_H + +#include + +namespace QmlProfiler { +namespace Internal { + +namespace Ui { + class QmlProfilerAttachDialog; +} + +class QmlProfilerAttachDialog : public QDialog +{ + Q_OBJECT + +public: + explicit QmlProfilerAttachDialog(QWidget *parent = 0); + ~QmlProfilerAttachDialog(); + + QString address() const; + uint port() const; + + void setAddress(const QString &address); + void setPort(uint port); + +private: + Ui::QmlProfilerAttachDialog *ui; +}; + +} // namespace Internal +} // namespace QmlProfiler + +#endif // QMLPROFILERATTACHDIALOG_H diff --git a/src/plugins/qmlprofiler/qmlprofilerattachdialog.ui b/src/plugins/qmlprofiler/qmlprofilerattachdialog.ui new file mode 100644 index 00000000000..5bae9fee4cb --- /dev/null +++ b/src/plugins/qmlprofiler/qmlprofilerattachdialog.ui @@ -0,0 +1,109 @@ + + + QmlProfiler::Internal::QmlProfilerAttachDialog + + + + 0 + 0 + 164 + 96 + + + + Dialog + + + + + + + + Address: + + + + + + + 127.0.0.1 + + + + + + + Port: + + + + + + + 1 + + + 65535 + + + 3768 + + + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + QmlProfiler::Internal::QmlProfilerAttachDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + QmlProfiler::Internal::QmlProfilerAttachDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/plugins/qmlprofiler/qmlprofilerconstants.h b/src/plugins/qmlprofiler/qmlprofilerconstants.h index 453df79393c..dbb2b0c9eec 100644 --- a/src/plugins/qmlprofiler/qmlprofilerconstants.h +++ b/src/plugins/qmlprofiler/qmlprofilerconstants.h @@ -37,11 +37,9 @@ namespace QmlProfiler { namespace Constants { - const char * const ACTION_ID = "QmlProfilerPlugin.Action"; - const char * const MENU_ID = "QmlProfilerPlugin.Menu"; +const char * const ATTACH = "Menu.Analyzer.Attach"; -} // namespace QmlProfiler } // namespace Constants +} // namespace QmlProfiler #endif // QMLPROFILERCONSTANTS_H - diff --git a/src/plugins/qmlprofiler/qmlprofilerengine.cpp b/src/plugins/qmlprofiler/qmlprofilerengine.cpp index 357d5588ca4..74f2e076cdc 100644 --- a/src/plugins/qmlprofiler/qmlprofilerengine.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerengine.cpp @@ -69,6 +69,7 @@ public: ~QmlProfilerEnginePrivate() {} bool launchperfmonitor(); + bool attach(const QString &address, uint port); QmlProfilerEngine *q; @@ -178,3 +179,21 @@ bool QmlProfilerEngine::QmlProfilerEnginePrivate::launchperfmonitor() return true; } + + + + + + + + + + + + + + + + + + diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index 67a0e5a8f4c..3a4b858baf6 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -34,6 +34,8 @@ #include "qmlprofilertool.h" #include "qmlprofilerengine.h" #include "qmlprofilerplugin.h" +#include "qmlprofilerconstants.h" +#include "qmlprofilerattachdialog.h" #include "tracewindow.h" #include @@ -56,7 +58,11 @@ #include #include +#include +#include +#include #include +#include #include @@ -107,6 +113,9 @@ public: QmlProfilerOutputPaneAdapter *m_outputPaneAdapter; ProjectExplorer::Project *m_project; Utils::FileInProjectFinder m_projectFinder; + ProjectExplorer::RunConfiguration *m_runConfiguration; + bool m_isAttached; + QAction *m_attachAction; }; QmlProfilerTool::QmlProfilerTool(QObject *parent) @@ -116,6 +125,9 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent) d->m_traceWindow = 0; d->m_outputPaneAdapter = 0; d->m_project = 0; + d->m_runConfiguration = 0; + d->m_isAttached = false; + d->m_attachAction = 0; } QmlProfilerTool::~QmlProfilerTool() @@ -148,6 +160,7 @@ IAnalyzerEngine *QmlProfilerTool::createEngine(const AnalyzerStartParameters &sp { QmlProfilerEngine *engine = new QmlProfilerEngine(sp, runConfiguration); + d->m_runConfiguration = runConfiguration; d->m_project = runConfiguration->target()->project(); if (d->m_project) { d->m_projectFinder.setProjectDirectory(d->m_project->projectDirectory()); @@ -159,8 +172,6 @@ IAnalyzerEngine *QmlProfilerTool::createEngine(const AnalyzerStartParameters &sp 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))); - connect(d->m_traceWindow, SIGNAL(timeChanged(qreal)), this, SLOT(updateTimer(qreal))); return engine; } @@ -178,6 +189,22 @@ void QmlProfilerTool::initialize(ExtensionSystem::IPlugin */*plugin*/) d->m_client = new QDeclarativeDebugConnection; d->m_traceWindow = new TraceWindow(); d->m_traceWindow->reset(d->m_client); + + connect(d->m_traceWindow, SIGNAL(gotoSourceLocation(QString,int)), this, SLOT(gotoSourceLocation(QString,int))); + connect(d->m_traceWindow, SIGNAL(timeChanged(qreal)), this, SLOT(updateTimer(qreal))); + + Core::ICore *core = Core::ICore::instance(); + Core::ActionManager *am = core->actionManager(); + Core::ActionContainer *manalyzer = am->actionContainer(Analyzer::Constants::M_DEBUG_ANALYZER); + const Core::Context globalcontext(Core::Constants::C_GLOBAL); + + d->m_attachAction = new QAction(tr("Attach ..."), manalyzer); + Core::Command *command = am->registerAction(d->m_attachAction, + Constants::ATTACH, globalcontext); + command->setAttribute(Core::Command::CA_UpdateText); + manalyzer->addAction(command, Analyzer::Constants::G_ANALYZER_STARTSTOP); + connect(d->m_attachAction, SIGNAL(triggered()), this, SLOT(attach())); + updateAttachAction(); } void QmlProfilerTool::extensionsInitialized() @@ -285,3 +312,36 @@ bool QmlProfilerTool::canRunRemotely() const // TODO: Is this correct? return true; } + +void QmlProfilerTool::attach() +{ + if (!d->m_isAttached) { + QmlProfilerAttachDialog dialog; + int result = dialog.exec(); + + if (result == QDialog::Rejected) + return; + + port = dialog.port(); + host = dialog.address(); + + connectClient(); + AnalyzerManager::instance()->showMode(); + } else { + stopRecording(); + } + + d->m_isAttached = !d->m_isAttached; + updateAttachAction(); +} + +void QmlProfilerTool::updateAttachAction() +{ + if (d->m_attachAction) { + if (d->m_isAttached) { + d->m_attachAction->setText(tr("Detach")); + } else { + d->m_attachAction->setText(tr("Attach...")); + } + } +} diff --git a/src/plugins/qmlprofiler/qmlprofilertool.h b/src/plugins/qmlprofiler/qmlprofilertool.h index 8663e974d82..ad347b143ff 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.h +++ b/src/plugins/qmlprofiler/qmlprofilertool.h @@ -82,6 +82,8 @@ public: private slots: void updateProjectFileList(); + void attach(); + void updateAttachAction(); private: class QmlProfilerToolPrivate;