2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-05-16 12:16:45 +02:00
|
|
|
#include "qmlprofilerstatewidget.h"
|
|
|
|
|
|
2015-11-18 12:34:52 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2016-03-11 17:38:20 +01:00
|
|
|
#include <utils/theme/theme.h>
|
2015-11-18 12:34:52 +01:00
|
|
|
|
2012-05-16 12:16:45 +02:00
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QProgressBar>
|
|
|
|
|
#include <QTime>
|
2013-08-08 13:28:08 +02:00
|
|
|
#include <QDebug>
|
2016-05-11 14:43:26 +02:00
|
|
|
#include <QTimer>
|
2018-01-09 17:07:53 +01:00
|
|
|
#include <QPointer>
|
2012-05-16 12:16:45 +02:00
|
|
|
|
2018-04-20 18:06:38 +02:00
|
|
|
#include <functional>
|
|
|
|
|
|
2012-05-16 12:16:45 +02:00
|
|
|
namespace QmlProfiler {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class QmlProfilerStateWidget::QmlProfilerStateWidgetPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-07-27 14:01:06 +02:00
|
|
|
QmlProfilerStateWidgetPrivate(QmlProfilerStateWidget *qq) : text(nullptr) { Q_UNUSED(qq); }
|
2012-05-16 12:16:45 +02:00
|
|
|
|
|
|
|
|
QLabel *text;
|
|
|
|
|
|
2018-01-09 17:07:53 +01:00
|
|
|
QPointer<QmlProfilerStateManager> m_profilerState;
|
|
|
|
|
QPointer<QmlProfilerModelManager> m_modelManager;
|
2016-05-11 14:43:26 +02:00
|
|
|
QTimer timer;
|
2012-05-16 12:16:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QmlProfilerStateWidget::QmlProfilerStateWidget(QmlProfilerStateManager *stateManager,
|
2013-08-08 13:28:08 +02:00
|
|
|
QmlProfilerModelManager *modelManager, QWidget *parent)
|
2016-05-11 15:18:07 +02:00
|
|
|
: QFrame(parent), d(new QmlProfilerStateWidgetPrivate(this))
|
2012-05-16 12:16:45 +02:00
|
|
|
{
|
2012-11-26 21:18:13 +02:00
|
|
|
setObjectName(QLatin1String("QML Profiler State Display"));
|
2016-05-11 15:18:07 +02:00
|
|
|
setFrameStyle(QFrame::StyledPanel);
|
2012-05-16 12:16:45 +02:00
|
|
|
|
|
|
|
|
// UI elements
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
|
resize(200,70);
|
|
|
|
|
|
|
|
|
|
d->text = new QLabel(this);
|
|
|
|
|
d->text->setAlignment(Qt::AlignCenter);
|
2016-05-11 15:18:07 +02:00
|
|
|
setAutoFillBackground(true);
|
2012-05-16 12:16:45 +02:00
|
|
|
layout->addWidget(d->text);
|
|
|
|
|
|
|
|
|
|
setLayout(layout);
|
|
|
|
|
|
|
|
|
|
// profiler state
|
2013-08-08 13:28:08 +02:00
|
|
|
d->m_modelManager = modelManager;
|
2018-04-20 18:06:38 +02:00
|
|
|
|
|
|
|
|
modelManager->registerFeatures(0, QmlProfilerModelManager::QmlEventLoader(),
|
|
|
|
|
std::bind(&QmlProfilerStateWidget::initialize, this),
|
|
|
|
|
std::bind(&QmlProfilerStateWidget::clear, this),
|
|
|
|
|
std::bind(&QmlProfilerStateWidget::clear, this));
|
2012-05-16 12:16:45 +02:00
|
|
|
d->m_profilerState = stateManager;
|
2016-05-11 14:43:26 +02:00
|
|
|
connect(&d->timer, &QTimer::timeout, this, &QmlProfilerStateWidget::updateDisplay);
|
2012-05-16 12:16:45 +02:00
|
|
|
|
2016-05-11 14:43:26 +02:00
|
|
|
d->timer.setInterval(1000);
|
2018-04-20 18:06:38 +02:00
|
|
|
setVisible(false);
|
2012-05-16 12:16:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlProfilerStateWidget::~QmlProfilerStateWidget()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerStateWidget::reposition()
|
|
|
|
|
{
|
|
|
|
|
QWidget *parentWidget = qobject_cast<QWidget *>(parent());
|
|
|
|
|
// positioning it at 2/3 height (it looks better)
|
|
|
|
|
move(parentWidget->width()/2 - width()/2, parentWidget->height()/3 - height()/2);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-20 18:06:38 +02:00
|
|
|
void QmlProfilerStateWidget::initialize()
|
|
|
|
|
{
|
|
|
|
|
connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
|
|
|
|
|
this, &QmlProfilerStateWidget::updateDisplay);
|
|
|
|
|
connect(d->m_profilerState, &QmlProfilerStateManager::serverRecordingChanged,
|
|
|
|
|
this, &QmlProfilerStateWidget::updateDisplay);
|
|
|
|
|
d->timer.start();
|
|
|
|
|
updateDisplay();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 14:43:26 +02:00
|
|
|
void QmlProfilerStateWidget::showText(const QString &text)
|
2012-05-16 12:16:45 +02:00
|
|
|
{
|
2015-04-01 16:49:38 +02:00
|
|
|
setVisible(true);
|
|
|
|
|
d->text->setText(text);
|
2015-04-07 10:55:58 +02:00
|
|
|
resize(300, 70);
|
2015-04-01 16:49:38 +02:00
|
|
|
reposition();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-20 18:06:38 +02:00
|
|
|
void QmlProfilerStateWidget::clear()
|
|
|
|
|
{
|
|
|
|
|
disconnect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
|
|
|
|
|
this, &QmlProfilerStateWidget::updateDisplay);
|
|
|
|
|
disconnect(d->m_profilerState, &QmlProfilerStateManager::serverRecordingChanged,
|
|
|
|
|
this, &QmlProfilerStateWidget::updateDisplay);
|
|
|
|
|
d->timer.stop();
|
|
|
|
|
setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-01 16:49:38 +02:00
|
|
|
void QmlProfilerStateWidget::updateDisplay()
|
|
|
|
|
{
|
2018-04-20 18:06:38 +02:00
|
|
|
QTC_ASSERT(d->m_modelManager, return);
|
|
|
|
|
QTC_ASSERT(d->m_profilerState, return);
|
2018-01-09 17:07:53 +01:00
|
|
|
|
2012-05-16 12:16:45 +02:00
|
|
|
// When application is being profiled
|
2015-09-01 10:14:47 +02:00
|
|
|
if (d->m_profilerState->serverRecording()) {
|
2016-05-11 14:43:26 +02:00
|
|
|
// Heuristic to not show the number if the application will only send the events when it
|
|
|
|
|
// stops. The number is still > 0 then because we get some StartTrace etc.
|
2018-04-20 18:06:38 +02:00
|
|
|
const int numEvents = d->m_modelManager->numEvents();
|
2018-04-12 10:04:55 +02:00
|
|
|
showText(numEvents > 256 ? tr("Profiling application: %n events", nullptr, numEvents) :
|
2016-05-11 14:43:26 +02:00
|
|
|
tr("Profiling application"));
|
2018-04-20 18:06:38 +02:00
|
|
|
} else if (d->m_modelManager->traceDuration() > 0 && d->m_modelManager->isEmpty()) {
|
2015-09-01 10:14:47 +02:00
|
|
|
// After profiling, there is an empty trace
|
2018-04-20 18:06:38 +02:00
|
|
|
showText(tr("No QML events recorded"));
|
2016-05-11 13:58:20 +02:00
|
|
|
} else if (!d->m_modelManager->isEmpty()) {
|
2018-04-20 18:06:38 +02:00
|
|
|
// When datamodel is acquiring data
|
2018-03-27 15:58:43 +02:00
|
|
|
if (d->m_profilerState->currentState() != QmlProfilerStateManager::Idle) {
|
2018-04-20 18:06:38 +02:00
|
|
|
// we don't know how much more, so progress numbers are strange here
|
|
|
|
|
showText(tr("Loading buffered data: %n events", nullptr,
|
|
|
|
|
d->m_modelManager->numEvents()));
|
|
|
|
|
} else {
|
2015-11-18 12:34:52 +01:00
|
|
|
// Application died before all data could be read
|
2018-04-12 10:04:55 +02:00
|
|
|
showText(tr("Loading offline data: %n events", nullptr,
|
2018-03-28 09:42:28 +02:00
|
|
|
d->m_modelManager->numEvents()));
|
2015-11-18 12:34:52 +01:00
|
|
|
}
|
2018-04-20 18:06:38 +02:00
|
|
|
} else {
|
2015-09-01 10:14:47 +02:00
|
|
|
showText(tr("Waiting for data"));
|
2012-05-16 12:16:45 +02:00
|
|
|
}
|
2016-05-11 14:43:26 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-28 16:02:54 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProfiler
|