forked from qt-creator/qt-creator
QmlProfiler: Delay creation of views until activation
We don't need to waste the time and memory required to create the views if they are never shown. Change-Id: I56add08981c90263e6735f5b7e6fac2140b457e4 Fixes: QTCREATORBUG-21894 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -91,11 +91,7 @@ public:
|
||||
bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorString)
|
||||
{
|
||||
Q_UNUSED(arguments)
|
||||
|
||||
if (!Utils::HostOsInfo::canCreateOpenGLContext(errorString))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return Utils::HostOsInfo::canCreateOpenGLContext(errorString);
|
||||
}
|
||||
|
||||
void QmlProfilerPlugin::extensionsInitialized()
|
||||
|
@@ -52,11 +52,14 @@ void QmlProfilerTextMark::addTypeId(int typeId)
|
||||
|
||||
void QmlProfilerTextMark::paintIcon(QPainter *painter, const QRect &paintRect) const
|
||||
{
|
||||
const QmlProfilerStatisticsView *statisticsView = m_viewManager->statisticsView();
|
||||
QTC_ASSERT(statisticsView, return);
|
||||
|
||||
painter->save();
|
||||
painter->setPen(Qt::black);
|
||||
painter->fillRect(paintRect, Qt::white);
|
||||
painter->drawRect(paintRect);
|
||||
painter->drawText(paintRect, m_viewManager->statisticsView()->summary(m_typeIds),
|
||||
painter->drawText(paintRect, statisticsView->summary(m_typeIds),
|
||||
Qt::AlignRight | Qt::AlignVCenter);
|
||||
painter->restore();
|
||||
}
|
||||
@@ -133,10 +136,13 @@ void QmlProfilerTextMarkModel::hideTextMarks()
|
||||
|
||||
bool QmlProfilerTextMark::addToolTipContent(QLayout *target) const
|
||||
{
|
||||
const QmlProfilerStatisticsView *statisticsView = m_viewManager->statisticsView();
|
||||
QTC_ASSERT(statisticsView, return false);
|
||||
|
||||
auto layout = new QGridLayout;
|
||||
layout->setHorizontalSpacing(10);
|
||||
for (int row = 0, rowEnd = m_typeIds.length(); row != rowEnd; ++row) {
|
||||
const QStringList typeDetails = m_viewManager->statisticsView()->details(m_typeIds[row]);
|
||||
const QStringList typeDetails = statisticsView->details(m_typeIds[row]);
|
||||
for (int column = 0, columnEnd = typeDetails.length(); column != columnEnd; ++column) {
|
||||
QLabel *label = new QLabel;
|
||||
label->setAlignment(column == columnEnd - 1 ? Qt::AlignRight : Qt::AlignLeft);
|
||||
|
@@ -195,9 +195,12 @@ QmlProfilerTool::QmlProfilerTool()
|
||||
d->m_searchButton = new QToolButton;
|
||||
d->m_searchButton->setIcon(Utils::Icons::ZOOM_TOOLBAR.icon());
|
||||
d->m_searchButton->setToolTip(tr("Search timeline event notes."));
|
||||
d->m_searchButton->setEnabled(false);
|
||||
|
||||
connect(d->m_searchButton, &QToolButton::clicked, this, &QmlProfilerTool::showTimeLineSearch);
|
||||
d->m_searchButton->setEnabled(d->m_viewContainer->traceView()->isUsable());
|
||||
connect(d->m_viewContainer, &QmlProfilerViewManager::viewsCreated, this, [this]() {
|
||||
d->m_searchButton->setEnabled(d->m_viewContainer->traceView()->isUsable());
|
||||
});
|
||||
|
||||
d->m_displayFeaturesButton = new QToolButton;
|
||||
d->m_displayFeaturesButton->setIcon(Utils::Icons::FILTER.icon());
|
||||
@@ -451,6 +454,7 @@ void QmlProfilerTool::updateTimeDisplay()
|
||||
void QmlProfilerTool::showTimeLineSearch()
|
||||
{
|
||||
QmlProfilerTraceView *traceView = d->m_viewContainer->traceView();
|
||||
QTC_ASSERT(traceView, return);
|
||||
QTC_ASSERT(qobject_cast<QDockWidget *>(traceView->parentWidget()), return);
|
||||
traceView->parentWidget()->raise();
|
||||
traceView->setFocus();
|
||||
@@ -482,7 +486,8 @@ void QmlProfilerTool::setButtonsEnabled(bool enable)
|
||||
{
|
||||
d->m_clearButton->setEnabled(enable);
|
||||
d->m_displayFeaturesButton->setEnabled(enable);
|
||||
d->m_searchButton->setEnabled(d->m_viewContainer->traceView()->isUsable() && enable);
|
||||
const QmlProfilerTraceView *traceView = d->m_viewContainer->traceView();
|
||||
d->m_searchButton->setEnabled(traceView && traceView->isUsable() && enable);
|
||||
d->m_recordFeaturesMenu->setEnabled(enable);
|
||||
}
|
||||
|
||||
|
@@ -51,6 +51,12 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent,
|
||||
QTC_ASSERT(m_profilerModelManager, return);
|
||||
QTC_ASSERT(m_profilerState, return);
|
||||
|
||||
m_perspective = new Utils::Perspective(Constants::QmlProfilerPerspectiveId, tr("QML Profiler"));
|
||||
m_perspective->setAboutToActivateCallback([this]() { createViews(); });
|
||||
}
|
||||
|
||||
void QmlProfilerViewManager::createViews()
|
||||
{
|
||||
m_traceView = new QmlProfilerTraceView(nullptr, this, m_profilerModelManager);
|
||||
connect(m_traceView, &QmlProfilerTraceView::gotoSourceLocation,
|
||||
this, &QmlProfilerViewManager::gotoSourceLocation);
|
||||
@@ -61,8 +67,6 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent,
|
||||
|
||||
new QmlProfilerStateWidget(m_profilerState, m_profilerModelManager, m_traceView);
|
||||
|
||||
m_perspective = new Utils::Perspective(Constants::QmlProfilerPerspectiveId, tr("QML Profiler"));
|
||||
|
||||
auto prepareEventsView = [this](QmlProfilerEventsView *view) {
|
||||
connect(view, &QmlProfilerEventsView::typeSelected,
|
||||
this, &QmlProfilerViewManager::typeSelected);
|
||||
@@ -93,6 +97,8 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent,
|
||||
}
|
||||
m_perspective->addWindow(m_statisticsView, Perspective::AddToTab, anchorDock);
|
||||
m_perspective->addWindow(anchorDock, Perspective::Raise, nullptr);
|
||||
m_perspective->setAboutToActivateCallback(Perspective::Callback());
|
||||
emit viewsCreated();
|
||||
}
|
||||
|
||||
QmlProfilerViewManager::~QmlProfilerViewManager()
|
||||
@@ -105,7 +111,8 @@ QmlProfilerViewManager::~QmlProfilerViewManager()
|
||||
|
||||
void QmlProfilerViewManager::clear()
|
||||
{
|
||||
m_traceView->clear();
|
||||
if (m_traceView)
|
||||
m_traceView->clear();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -58,8 +58,11 @@ public:
|
||||
signals:
|
||||
void typeSelected(int typeId);
|
||||
void gotoSourceLocation(QString,int,int);
|
||||
void viewsCreated();
|
||||
|
||||
private:
|
||||
void createViews();
|
||||
|
||||
QmlProfilerTraceView *m_traceView = nullptr;
|
||||
QmlProfilerStatisticsView *m_statisticsView = nullptr;
|
||||
FlameGraphView *m_flameGraphView = nullptr;
|
||||
|
Reference in New Issue
Block a user