2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-06-28 15:51:20 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-06-28 15:51:20 +02:00
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-06-28 15:51:20 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-06-28 15:51:20 +02:00
|
|
|
|
|
|
|
#include "qmlprofilertraceclient.h"
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
namespace QmlDebug {
|
2011-08-05 12:58:43 +02:00
|
|
|
|
|
|
|
class QmlProfilerTraceClientPrivate {
|
|
|
|
public:
|
2011-08-24 14:38:54 +02:00
|
|
|
QmlProfilerTraceClientPrivate(QmlProfilerTraceClient *_q)
|
|
|
|
: q(_q)
|
|
|
|
, inProgressRanges(0)
|
2011-08-05 12:58:43 +02:00
|
|
|
, maximumTime(0)
|
|
|
|
, recording(false)
|
|
|
|
{
|
2014-06-03 16:57:32 +02:00
|
|
|
::memset(rangeCount, 0, MaximumRangeType * sizeof(int));
|
2011-08-05 12:58:43 +02:00
|
|
|
}
|
|
|
|
|
2011-08-24 14:38:54 +02:00
|
|
|
void sendRecordingStatus();
|
|
|
|
|
|
|
|
QmlProfilerTraceClient *q;
|
2011-08-05 12:58:43 +02:00
|
|
|
qint64 inProgressRanges;
|
2014-06-03 16:57:32 +02:00
|
|
|
QStack<qint64> rangeStartTimes[MaximumRangeType];
|
2014-06-13 16:33:30 +02:00
|
|
|
QStack<QString> rangeDatas[MaximumRangeType];
|
2014-06-03 16:57:32 +02:00
|
|
|
QStack<QmlEventLocation> rangeLocations[MaximumRangeType];
|
2012-05-02 17:53:50 +02:00
|
|
|
QStack<BindingType> bindingTypes;
|
2014-06-03 16:57:32 +02:00
|
|
|
int rangeCount[MaximumRangeType];
|
2011-08-05 12:58:43 +02:00
|
|
|
qint64 maximumTime;
|
|
|
|
bool recording;
|
|
|
|
};
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
} // namespace QmlDebug
|
2011-08-05 12:58:43 +02:00
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
using namespace QmlDebug;
|
2011-06-28 15:51:20 +02:00
|
|
|
|
|
|
|
static const int GAP_TIME = 150;
|
|
|
|
|
2011-08-24 14:38:54 +02:00
|
|
|
void QmlProfilerTraceClientPrivate::sendRecordingStatus()
|
|
|
|
{
|
|
|
|
QByteArray ba;
|
|
|
|
QDataStream stream(&ba, QIODevice::WriteOnly);
|
|
|
|
stream << recording;
|
|
|
|
q->sendMessage(ba);
|
|
|
|
}
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlProfilerTraceClient::QmlProfilerTraceClient(QmlDebugConnection *client)
|
|
|
|
: QmlDebugClient(QLatin1String("CanvasFrameRate"), client)
|
2011-08-24 14:38:54 +02:00
|
|
|
, d(new QmlProfilerTraceClientPrivate(this))
|
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
|
|
|
{
|
2014-06-03 16:57:32 +02:00
|
|
|
::memset(d->rangeCount, 0, MaximumRangeType * sizeof(int));
|
|
|
|
for (int eventType = 0; eventType < MaximumRangeType; eventType++) {
|
2012-02-13 15:26:57 +01:00
|
|
|
d->rangeDatas[eventType].clear();
|
|
|
|
d->rangeLocations[eventType].clear();
|
|
|
|
d->rangeStartTimes[eventType].clear();
|
|
|
|
}
|
2012-05-02 17:53:50 +02:00
|
|
|
d->bindingTypes.clear();
|
2011-08-05 12:58:43 +02:00
|
|
|
emit cleared();
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
|
2011-11-15 15:04:25 +01:00
|
|
|
void QmlProfilerTraceClient::sendRecordingStatus()
|
|
|
|
{
|
|
|
|
d->sendRecordingStatus();
|
|
|
|
}
|
|
|
|
|
2011-11-10 17:08:07 +01:00
|
|
|
bool QmlProfilerTraceClient::isEnabled() const
|
|
|
|
{
|
2014-05-05 16:11:43 +02:00
|
|
|
return state() == Enabled;
|
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);
|
|
|
|
}
|
|
|
|
|
2012-02-13 15:26:57 +01:00
|
|
|
void QmlProfilerTraceClient::setRecordingFromServer(bool v)
|
|
|
|
{
|
|
|
|
if (v == d->recording)
|
|
|
|
return;
|
|
|
|
d->recording = v;
|
|
|
|
emit recordingChanged(v);
|
|
|
|
}
|
|
|
|
|
2014-05-05 16:11:43 +02:00
|
|
|
void QmlProfilerTraceClient::stateChanged(State /*status*/)
|
2011-06-28 15:51:20 +02:00
|
|
|
{
|
2011-11-28 16:30:30 +01:00
|
|
|
emit enabledChanged();
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTraceClient::messageReceived(const QByteArray &data)
|
|
|
|
{
|
|
|
|
QByteArray rwData = data;
|
|
|
|
QDataStream stream(&rwData, QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
qint64 time;
|
|
|
|
int messageType;
|
|
|
|
|
|
|
|
stream >> time >> messageType;
|
|
|
|
|
|
|
|
if (messageType >= MaximumMessage)
|
|
|
|
return;
|
|
|
|
|
2011-08-05 12:58:43 +02:00
|
|
|
if (time > (d->maximumTime + GAP_TIME) && 0 == d->inProgressRanges)
|
2011-06-28 15:51:20 +02:00
|
|
|
emit gap(time);
|
|
|
|
|
|
|
|
if (messageType == Event) {
|
|
|
|
int event;
|
|
|
|
stream >> event;
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
// stop with the first data
|
|
|
|
if (d->recording && event != StartTrace)
|
|
|
|
setRecordingFromServer(false);
|
|
|
|
else if ((!d->recording) && event == StartTrace)
|
|
|
|
setRecordingFromServer(true);
|
|
|
|
|
2011-09-22 16:58:59 +02:00
|
|
|
if (event == EndTrace) {
|
|
|
|
emit this->traceFinished(time);
|
|
|
|
d->maximumTime = time;
|
2011-12-14 16:44:33 +01:00
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
|
|
|
} else if (event == AnimationFrame) {
|
|
|
|
int frameRate, animationCount;
|
2014-03-07 17:35:56 +01:00
|
|
|
int threadId;
|
2011-12-14 16:44:33 +01:00
|
|
|
stream >> frameRate >> animationCount;
|
2014-03-07 17:35:56 +01:00
|
|
|
if (!stream.atEnd())
|
|
|
|
stream >> threadId;
|
|
|
|
else
|
|
|
|
threadId = 0;
|
2014-06-13 16:33:30 +02:00
|
|
|
emit rangedEvent(Event, MaximumRangeType, AnimationFrame, time, 0, QString(),
|
2014-06-03 16:57:32 +02:00
|
|
|
QmlDebug::QmlEventLocation(), frameRate, animationCount, threadId,0,0);
|
2011-12-14 16:44:33 +01:00
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
2011-11-02 16:57:31 +01:00
|
|
|
} else if (event == StartTrace) {
|
|
|
|
emit this->traceStarted(time);
|
|
|
|
d->maximumTime = time;
|
2011-09-22 16:58:59 +02:00
|
|
|
} else if (event < MaximumEventType) {
|
2011-06-28 15:51:20 +02:00
|
|
|
emit this->event((EventType)event, time);
|
2011-08-05 12:58:43 +02:00
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
} else if (messageType == Complete) {
|
2014-04-03 12:33:14 +02:00
|
|
|
emit complete(d->maximumTime);
|
2013-08-08 13:28:08 +02:00
|
|
|
} else if (messageType == SceneGraphFrame) {
|
|
|
|
int sgEventType;
|
|
|
|
int count = 0;
|
|
|
|
qint64 params[5];
|
|
|
|
|
|
|
|
stream >> sgEventType;
|
|
|
|
while (!stream.atEnd()) {
|
|
|
|
stream >> params[count++];
|
|
|
|
}
|
|
|
|
while (count<5)
|
|
|
|
params[count++] = 0;
|
2014-06-03 16:57:32 +02:00
|
|
|
emit rangedEvent(SceneGraphFrame, QmlDebug::MaximumRangeType, sgEventType,time, 0,
|
2014-06-13 16:33:30 +02:00
|
|
|
QString(), QmlDebug::QmlEventLocation(), params[0], params[1],
|
2014-06-03 16:57:32 +02:00
|
|
|
params[2], params[3], params[4]);
|
2013-08-08 13:28:08 +02:00
|
|
|
} else if (messageType == PixmapCacheEvent) {
|
|
|
|
int pixEvTy, width = 0, height = 0, refcount = 0;
|
|
|
|
QString pixUrl;
|
|
|
|
stream >> pixEvTy >> pixUrl;
|
|
|
|
if (pixEvTy == (int)PixmapReferenceCountChanged || pixEvTy == (int)PixmapCacheCountChanged) {
|
|
|
|
stream >> refcount;
|
|
|
|
} else if (pixEvTy == (int)PixmapSizeKnown) {
|
|
|
|
stream >> width >> height;
|
|
|
|
refcount = 1;
|
|
|
|
}
|
2014-06-03 16:57:32 +02:00
|
|
|
emit rangedEvent(QmlDebug::PixmapCacheEvent, QmlDebug::MaximumRangeType, pixEvTy, time, 0,
|
2014-06-13 16:33:30 +02:00
|
|
|
QString(), QmlDebug::QmlEventLocation(pixUrl,0,0), width, height,
|
2014-06-03 16:57:32 +02:00
|
|
|
refcount, 0, 0);
|
2013-08-08 13:28:08 +02:00
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
2014-05-27 19:19:03 +02:00
|
|
|
} else if (messageType == MemoryAllocation) {
|
|
|
|
int type;
|
|
|
|
qint64 delta;
|
|
|
|
stream >> type >> delta;
|
|
|
|
emit rangedEvent(QmlDebug::MemoryAllocation, QmlDebug::MaximumRangeType, type, time, 0,
|
2014-06-13 16:33:30 +02:00
|
|
|
QString(), QmlDebug::QmlEventLocation(), delta, 0, 0, 0, 0);
|
2014-05-27 19:19:03 +02:00
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
2011-06-28 15:51:20 +02:00
|
|
|
} else {
|
|
|
|
int range;
|
|
|
|
stream >> range;
|
|
|
|
|
2014-06-03 16:57:32 +02:00
|
|
|
if (range >= MaximumRangeType)
|
2011-06-28 15:51:20 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (messageType == RangeStart) {
|
2011-08-05 12:58:43 +02:00
|
|
|
d->rangeStartTimes[range].push(time);
|
|
|
|
d->inProgressRanges |= (static_cast<qint64>(1) << range);
|
|
|
|
++d->rangeCount[range];
|
2012-05-02 17:53:50 +02:00
|
|
|
|
|
|
|
// read binding type
|
2014-06-03 16:57:32 +02:00
|
|
|
if ((RangeType)range == Binding) {
|
2012-05-02 17:53:50 +02:00
|
|
|
int bindingType = (int)QmlBinding;
|
|
|
|
if (!stream.atEnd())
|
|
|
|
stream >> bindingType;
|
|
|
|
d->bindingTypes.push((BindingType)bindingType);
|
|
|
|
}
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
// stop with the first data
|
|
|
|
if (d->recording)
|
|
|
|
setRecordingFromServer(false);
|
2011-06-28 15:51:20 +02:00
|
|
|
} else if (messageType == RangeData) {
|
|
|
|
QString data;
|
|
|
|
stream >> data;
|
|
|
|
|
2011-08-05 12:58:43 +02:00
|
|
|
int count = d->rangeCount[range];
|
2011-06-28 15:51:20 +02:00
|
|
|
if (count > 0) {
|
2011-08-05 12:58:43 +02:00
|
|
|
while (d->rangeDatas[range].count() < count)
|
2014-06-13 16:33:30 +02:00
|
|
|
d->rangeDatas[range].push(QString());
|
|
|
|
d->rangeDatas[range][count-1] = data;
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (messageType == RangeLocation) {
|
|
|
|
QString fileName;
|
|
|
|
int line;
|
2012-01-12 16:36:40 +01:00
|
|
|
int column = -1;
|
2011-06-28 15:51:20 +02:00
|
|
|
stream >> fileName >> line;
|
|
|
|
|
2012-01-12 16:36:40 +01:00
|
|
|
if (!stream.atEnd())
|
|
|
|
stream >> column;
|
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (d->rangeCount[range] > 0)
|
2012-01-12 16:36:40 +01:00
|
|
|
d->rangeLocations[range].push(QmlEventLocation(fileName, line, column));
|
2011-06-28 15:51:20 +02:00
|
|
|
} else {
|
2011-08-05 12:58:43 +02:00
|
|
|
if (d->rangeCount[range] > 0) {
|
|
|
|
--d->rangeCount[range];
|
|
|
|
if (d->inProgressRanges & (static_cast<qint64>(1) << range))
|
|
|
|
d->inProgressRanges &= ~(static_cast<qint64>(1) << range);
|
2011-06-28 15:51:20 +02:00
|
|
|
|
2011-08-05 12:58:43 +02:00
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
2014-06-13 16:33:30 +02:00
|
|
|
QString data = d->rangeDatas[range].count() ? d->rangeDatas[range].pop() : QString();
|
2012-01-12 16:36:40 +01:00
|
|
|
QmlEventLocation location = d->rangeLocations[range].count() ? d->rangeLocations[range].pop() : QmlEventLocation();
|
2011-06-28 15:51:20 +02:00
|
|
|
|
2011-08-05 12:58:43 +02:00
|
|
|
qint64 startTime = d->rangeStartTimes[range].pop();
|
2012-05-02 17:53:50 +02:00
|
|
|
BindingType bindingType = QmlBinding;
|
2014-06-03 16:57:32 +02:00
|
|
|
if ((RangeType)range == Binding)
|
2012-05-02 17:53:50 +02:00
|
|
|
bindingType = d->bindingTypes.pop();
|
2014-06-03 16:57:32 +02:00
|
|
|
if ((RangeType)range == Painting)
|
2013-08-08 13:28:08 +02:00
|
|
|
bindingType = QPainterEvent;
|
2014-06-03 16:57:32 +02:00
|
|
|
emit rangedEvent(MaximumMessage, (RangeType)range, bindingType, startTime,
|
|
|
|
time - startTime, data, location, 0, 0, 0, 0, 0);
|
2011-08-05 12:58:43 +02:00
|
|
|
if (d->rangeCount[range] == 0) {
|
|
|
|
int count = d->rangeDatas[range].count() +
|
|
|
|
d->rangeStartTimes[range].count() +
|
|
|
|
d->rangeLocations[range].count();
|
2011-06-28 15:51:20 +02:00
|
|
|
if (count != 0)
|
|
|
|
qWarning() << "incorrectly nested data";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|