2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-06-28 15:51:20 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-06-28 15:51:20 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-06-28 15:51:20 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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:58:39 +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.
|
2011-06-28 15:51:20 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +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.
|
2011-06-28 15:51:20 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-06-28 15:51:20 +02:00
|
|
|
|
|
|
|
|
#include "qmlprofilertraceclient.h"
|
2016-04-28 16:13:16 +02:00
|
|
|
#include "qmltypedevent.h"
|
|
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
#include <qmldebug/qmlenginecontrolclient.h>
|
|
|
|
|
#include <qmldebug/qdebugmessageclient.h>
|
|
|
|
|
#include <qmldebug/qpacketprotocol.h>
|
2011-06-28 15:51:20 +02:00
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
namespace QmlProfiler {
|
2011-08-05 12:58:43 +02:00
|
|
|
|
|
|
|
|
class QmlProfilerTraceClientPrivate {
|
|
|
|
|
public:
|
2016-05-02 12:18:57 +02:00
|
|
|
QmlProfilerTraceClientPrivate(QmlProfilerTraceClient *_q, QmlDebug::QmlDebugConnection *client)
|
2011-08-24 14:38:54 +02:00
|
|
|
: q(_q)
|
2014-03-12 17:20:52 +01:00
|
|
|
, engineControl(client)
|
2011-08-05 12:58:43 +02:00
|
|
|
, maximumTime(0)
|
|
|
|
|
, recording(false)
|
2015-06-30 15:55:33 +02:00
|
|
|
, requestedFeatures(0)
|
|
|
|
|
, recordedFeatures(0)
|
2015-08-28 12:50:46 +02:00
|
|
|
, flushInterval(0)
|
2011-08-05 12:58:43 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-12 17:20:52 +01:00
|
|
|
void sendRecordingStatus(int engineId);
|
2016-05-02 12:18:57 +02:00
|
|
|
bool updateFeatures(ProfileFeature feature);
|
2011-08-24 14:38:54 +02:00
|
|
|
|
|
|
|
|
QmlProfilerTraceClient *q;
|
2016-05-02 12:18:57 +02:00
|
|
|
QmlDebug::QmlEngineControlClient engineControl;
|
|
|
|
|
QScopedPointer<QmlDebug::QDebugMessageClient> messageClient;
|
2011-08-05 12:58:43 +02:00
|
|
|
qint64 maximumTime;
|
|
|
|
|
bool recording;
|
2015-06-30 15:55:33 +02:00
|
|
|
quint64 requestedFeatures;
|
|
|
|
|
quint64 recordedFeatures;
|
2015-08-28 12:50:46 +02:00
|
|
|
quint32 flushInterval;
|
2016-04-28 16:13:16 +02:00
|
|
|
|
|
|
|
|
// Reuse the same event, so that we don't have to constantly reallocate all the data.
|
|
|
|
|
QmlTypedEvent currentEvent;
|
2011-08-05 12:58:43 +02:00
|
|
|
};
|
|
|
|
|
|
2014-03-12 17:20:52 +01:00
|
|
|
void QmlProfilerTraceClientPrivate::sendRecordingStatus(int engineId)
|
2011-08-24 14:38:54 +02:00
|
|
|
{
|
2016-05-02 12:18:57 +02:00
|
|
|
QmlDebug::QPacket stream(q->connection()->currentDataStreamVersion());
|
2014-09-09 18:22:58 +02:00
|
|
|
stream << recording << engineId; // engineId -1 is OK. It means "all of them"
|
|
|
|
|
if (recording)
|
2015-08-28 12:50:46 +02:00
|
|
|
stream << requestedFeatures << flushInterval;
|
2015-11-16 16:46:51 +01:00
|
|
|
q->sendMessage(stream.data());
|
2011-08-24 14:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
QmlProfilerTraceClient::QmlProfilerTraceClient(QmlDebug::QmlDebugConnection *client,
|
|
|
|
|
quint64 features)
|
2012-04-18 12:06:10 +02:00
|
|
|
: QmlDebugClient(QLatin1String("CanvasFrameRate"), client)
|
2014-03-12 17:20:52 +01:00
|
|
|
, d(new QmlProfilerTraceClientPrivate(this, client))
|
2011-08-05 12:58:43 +02:00
|
|
|
{
|
2015-11-13 17:55:58 +01:00
|
|
|
setRequestedFeatures(features);
|
2016-05-02 12:18:57 +02:00
|
|
|
connect(&d->engineControl, &QmlDebug::QmlEngineControlClient::engineAboutToBeAdded,
|
2015-11-18 15:18:58 +01:00
|
|
|
this, &QmlProfilerTraceClient::newEngine);
|
2011-08-05 12:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlProfilerTraceClient::~QmlProfilerTraceClient()
|
|
|
|
|
{
|
2011-11-15 15:04:25 +01:00
|
|
|
//Disable profiling if started by client
|
|
|
|
|
//Profiling data will be lost!!
|
|
|
|
|
if (isRecording())
|
|
|
|
|
setRecording(false);
|
2011-08-05 12:58:43 +02:00
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerTraceClient::clearData()
|
2011-06-28 15:51:20 +02:00
|
|
|
{
|
2015-06-30 15:55:33 +02:00
|
|
|
if (d->recordedFeatures != 0) {
|
|
|
|
|
d->recordedFeatures = 0;
|
|
|
|
|
emit recordedFeaturesChanged(0);
|
|
|
|
|
}
|
2011-08-05 12:58:43 +02:00
|
|
|
emit cleared();
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-18 15:18:58 +01:00
|
|
|
void QmlProfilerTraceClient::sendRecordingStatus(int engineId)
|
2011-11-15 15:04:25 +01:00
|
|
|
{
|
2015-11-18 15:18:58 +01:00
|
|
|
d->sendRecordingStatus(engineId);
|
2011-11-10 17:08:07 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-05 12:58:43 +02:00
|
|
|
bool QmlProfilerTraceClient::isRecording() const
|
2011-06-28 15:51:20 +02:00
|
|
|
{
|
2011-08-05 12:58:43 +02:00
|
|
|
return d->recording;
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerTraceClient::setRecording(bool v)
|
|
|
|
|
{
|
2011-08-05 12:58:43 +02:00
|
|
|
if (v == d->recording)
|
2011-06-28 15:51:20 +02:00
|
|
|
return;
|
|
|
|
|
|
2011-08-24 14:38:54 +02:00
|
|
|
d->recording = v;
|
|
|
|
|
|
2014-05-05 16:11:43 +02:00
|
|
|
if (state() == Enabled)
|
2011-11-15 15:04:25 +01:00
|
|
|
sendRecordingStatus();
|
2011-06-28 15:51:20 +02:00
|
|
|
|
|
|
|
|
emit recordingChanged(v);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-30 15:55:33 +02:00
|
|
|
quint64 QmlProfilerTraceClient::recordedFeatures() const
|
|
|
|
|
{
|
|
|
|
|
return d->recordedFeatures;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerTraceClient::setRequestedFeatures(quint64 features)
|
2014-09-09 18:22:58 +02:00
|
|
|
{
|
2015-06-30 15:55:33 +02:00
|
|
|
d->requestedFeatures = features;
|
2015-11-13 17:55:58 +01:00
|
|
|
if (features & static_cast<quint64>(1) << ProfileDebugMessages) {
|
2016-05-02 12:18:57 +02:00
|
|
|
d->messageClient.reset(new QmlDebug::QDebugMessageClient(connection()));
|
|
|
|
|
connect(d->messageClient.data(), &QmlDebug::QDebugMessageClient::message, this,
|
|
|
|
|
[this](QtMsgType type, const QString &text,
|
|
|
|
|
const QmlDebug::QDebugContextInfo &context)
|
2015-11-13 17:55:58 +01:00
|
|
|
{
|
2016-04-27 16:10:31 +02:00
|
|
|
d->updateFeatures(ProfileDebugMessages);
|
2016-04-28 16:13:16 +02:00
|
|
|
d->currentEvent.event.setTimestamp(context.timestamp);
|
|
|
|
|
d->currentEvent.event.setTypeIndex(-1);
|
|
|
|
|
d->currentEvent.event.setString(text);
|
|
|
|
|
d->currentEvent.type.location.filename = context.file;
|
|
|
|
|
d->currentEvent.type.location.line = context.line;
|
|
|
|
|
d->currentEvent.type.location.column = 1;
|
|
|
|
|
d->currentEvent.type.displayName.clear();
|
|
|
|
|
d->currentEvent.type.data.clear();
|
|
|
|
|
d->currentEvent.type.message = DebugMessage;
|
|
|
|
|
d->currentEvent.type.rangeType = MaximumRangeType;
|
|
|
|
|
d->currentEvent.type.detailType = type;
|
|
|
|
|
emit qmlEvent(d->currentEvent.event, d->currentEvent.type);
|
2015-11-13 17:55:58 +01:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
d->messageClient.reset();
|
|
|
|
|
}
|
2014-09-09 18:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-28 12:50:46 +02:00
|
|
|
void QmlProfilerTraceClient::setFlushInterval(quint32 flushInterval)
|
|
|
|
|
{
|
|
|
|
|
d->flushInterval = flushInterval;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-13 15:26:57 +01:00
|
|
|
void QmlProfilerTraceClient::setRecordingFromServer(bool v)
|
|
|
|
|
{
|
|
|
|
|
if (v == d->recording)
|
|
|
|
|
return;
|
|
|
|
|
d->recording = v;
|
|
|
|
|
emit recordingChanged(v);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-30 15:55:33 +02:00
|
|
|
bool QmlProfilerTraceClientPrivate::updateFeatures(ProfileFeature feature)
|
|
|
|
|
{
|
|
|
|
|
quint64 flag = 1ULL << feature;
|
|
|
|
|
if (!(requestedFeatures & flag))
|
|
|
|
|
return false;
|
|
|
|
|
if (!(recordedFeatures & flag)) {
|
2016-04-27 16:10:31 +02:00
|
|
|
recordedFeatures |= flag;
|
2015-06-30 15:55:33 +02:00
|
|
|
emit q->recordedFeaturesChanged(recordedFeatures);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-18 15:18:58 +01:00
|
|
|
void QmlProfilerTraceClient::stateChanged(State status)
|
2011-06-28 15:51:20 +02:00
|
|
|
{
|
2015-11-18 15:18:58 +01:00
|
|
|
if (status == Enabled)
|
|
|
|
|
sendRecordingStatus(-1);
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerTraceClient::messageReceived(const QByteArray &data)
|
|
|
|
|
{
|
2016-05-02 12:18:57 +02:00
|
|
|
QmlDebug::QPacket stream(connection()->currentDataStreamVersion(), data);
|
2011-06-28 15:51:20 +02:00
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
stream >> d->currentEvent;
|
2014-09-10 13:51:36 +02:00
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
d->maximumTime = qMax(d->currentEvent.event.timestamp(), d->maximumTime);
|
|
|
|
|
if (d->currentEvent.type.message == Complete) {
|
2014-04-03 12:33:14 +02:00
|
|
|
emit complete(d->maximumTime);
|
2015-07-28 12:53:51 +02:00
|
|
|
setRecordingFromServer(false);
|
2016-04-28 16:13:16 +02:00
|
|
|
} else if (d->currentEvent.type.message == Event
|
|
|
|
|
&& d->currentEvent.type.detailType == StartTrace) {
|
|
|
|
|
if (!d->recording)
|
|
|
|
|
setRecordingFromServer(true);
|
|
|
|
|
emit traceStarted(d->currentEvent.event.timestamp(),
|
|
|
|
|
d->currentEvent.event.numbers<QList<int>, qint32>());
|
|
|
|
|
} else if (d->currentEvent.type.message == Event
|
|
|
|
|
&& d->currentEvent.type.detailType == EndTrace) {
|
|
|
|
|
emit traceFinished(d->currentEvent.event.timestamp(),
|
|
|
|
|
d->currentEvent.event.numbers<QList<int>, qint32>());
|
|
|
|
|
} else if (d->updateFeatures(d->currentEvent.type.feature())) {
|
|
|
|
|
emit qmlEvent(d->currentEvent.event, d->currentEvent.type);
|
2014-09-10 13:51:36 +02:00
|
|
|
}
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
2016-04-28 16:02:54 +02:00
|
|
|
|
|
|
|
|
} // namespace QmlProfiler
|