From d56286283dc41d1e97502f48ded754c059951060 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 15 Sep 2015 15:14:40 +0200 Subject: qmlprofiler: Simplify QmlProfilerClient We only need one class for it now. Change-Id: Iea2715993c0ce168a3ceeecbb694f1ad3585da68 Reviewed-by: Simon Hausmann --- tools/qmlprofiler/qmlprofilerapplication.cpp | 24 +++++-------- tools/qmlprofiler/qmlprofilerapplication.h | 3 +- tools/qmlprofiler/qmlprofilerclient.cpp | 54 +++++++++------------------- tools/qmlprofiler/qmlprofilerclient.h | 35 +++--------------- 4 files changed, 32 insertions(+), 84 deletions(-) diff --git a/tools/qmlprofiler/qmlprofilerapplication.cpp b/tools/qmlprofiler/qmlprofilerapplication.cpp index 74356c21a3..010e82ce5a 100644 --- a/tools/qmlprofiler/qmlprofilerapplication.cpp +++ b/tools/qmlprofiler/qmlprofilerapplication.cpp @@ -93,7 +93,8 @@ QmlProfilerApplication::QmlProfilerApplication(int &argc, char **argv) : connect(&m_connection, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(connectionStateChanged(QAbstractSocket::SocketState))); connect(&m_connection, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectionError(QAbstractSocket::SocketError))); - connect(&m_qmlProfilerClient, SIGNAL(enabledChanged()), this, SLOT(traceClientEnabled())); + connect(&m_qmlProfilerClient, SIGNAL(enabledChanged(bool)), + this, SLOT(traceClientEnabledChanged(bool))); connect(&m_qmlProfilerClient, SIGNAL(range(QQmlProfilerDefinitions::RangeType,QQmlProfilerDefinitions::BindingType,qint64,qint64,QStringList,QmlEventLocation)), &m_profilerData, SLOT(addQmlEvent(QQmlProfilerDefinitions::RangeType,QQmlProfilerDefinitions::BindingType,qint64,qint64,QStringList,QmlEventLocation))); connect(&m_qmlProfilerClient, SIGNAL(traceFinished(qint64)), &m_profilerData, SLOT(setTraceEndTime(qint64))); @@ -554,21 +555,14 @@ void QmlProfilerApplication::processFinished() exit(exitCode); } -void QmlProfilerApplication::traceClientEnabled() +void QmlProfilerApplication::traceClientEnabledChanged(bool enabled) { - logStatus("Trace client is attached."); - // blocked server is waiting for recording message from both clients - // once the last one is connected, both messages should be sent - m_qmlProfilerClient.sendRecordingStatus(m_recording); -} - -void QmlProfilerApplication::profilerClientEnabled() -{ - logStatus("Profiler client is attached."); - - // blocked server is waiting for recording message from both clients - // once the last one is connected, both messages should be sent - m_qmlProfilerClient.sendRecordingStatus(m_recording); + if (enabled) { + logStatus("Trace client is attached."); + // blocked server is waiting for recording message from both clients + // once the last one is connected, both messages should be sent + m_qmlProfilerClient.sendRecordingStatus(m_recording); + } } void QmlProfilerApplication::traceFinished() diff --git a/tools/qmlprofiler/qmlprofilerapplication.h b/tools/qmlprofiler/qmlprofilerapplication.h index bd3e51aa03..1f06108673 100644 --- a/tools/qmlprofiler/qmlprofilerapplication.h +++ b/tools/qmlprofiler/qmlprofilerapplication.h @@ -78,8 +78,7 @@ private slots: void processHasOutput(); void processFinished(); - void traceClientEnabled(); - void profilerClientEnabled(); + void traceClientEnabledChanged(bool enabled); void traceFinished(); void prompt(const QString &line = QString(), bool ready = true); diff --git a/tools/qmlprofiler/qmlprofilerclient.cpp b/tools/qmlprofiler/qmlprofilerclient.cpp index ff723381bc..bd7b98379f 100644 --- a/tools/qmlprofiler/qmlprofilerclient.cpp +++ b/tools/qmlprofiler/qmlprofilerclient.cpp @@ -39,42 +39,11 @@ #include -ProfilerClient::ProfilerClient(const QString &clientName, - QQmlDebugConnection *client) - : QQmlDebugClient(clientName, client), - m_enabled(false) -{ -} - -ProfilerClient::~ProfilerClient() -{ -} - -void ProfilerClient::clearData() -{ - emit cleared(); -} - -bool ProfilerClient::isEnabled() const -{ - return m_enabled; -} - -void ProfilerClient::stateChanged(State status) -{ - if ((m_enabled && status != Enabled) || - (!m_enabled && status == Enabled)) - emit enabledChanged(); - - m_enabled = status == Enabled; - -} - class QmlProfilerClientPrivate { public: QmlProfilerClientPrivate() - : inProgressRanges(0) , features(std::numeric_limits::max()) + : inProgressRanges(0) , features(std::numeric_limits::max()), enabled(false) { ::memset(rangeCount, 0, QQmlProfilerDefinitions::MaximumRangeType * sizeof(int)); } @@ -87,11 +56,11 @@ public: int rangeCount[QQmlProfilerDefinitions::MaximumRangeType]; quint64 features; + bool enabled; }; -QmlProfilerClient::QmlProfilerClient( - QQmlDebugConnection *client) - : ProfilerClient(QStringLiteral("CanvasFrameRate"), client), +QmlProfilerClient::QmlProfilerClient(QQmlDebugConnection *client) + : QQmlDebugClient(QStringLiteral("CanvasFrameRate"), client), d(new QmlProfilerClientPrivate) { } @@ -108,9 +77,12 @@ void QmlProfilerClient::setFeatures(quint64 features) void QmlProfilerClient::clearData() { - ::memset(d->rangeCount, 0, QQmlProfilerDefinitions::MaximumRangeType * sizeof(int)); + for (int i = 0; i < QQmlProfilerDefinitions::MaximumRangeType; ++i) { + d->rangeCount[i] = 0; + d->rangeDatas[i].clear(); + d->rangeLocations[i].clear(); + } d->bindingTypes.clear(); - ProfilerClient::clearData(); } void QmlProfilerClient::sendRecordingStatus(bool record) @@ -142,6 +114,14 @@ inline QQmlProfilerDefinitions::ProfileFeature featureFromRangeType( } } +void QmlProfilerClient::stateChanged(State state) +{ + if ((d->enabled && state != Enabled) || (!d->enabled && state == Enabled)) { + d->enabled = (state == Enabled); + emit enabledChanged(d->enabled); + } +} + void QmlProfilerClient::messageReceived(const QByteArray &data) { QByteArray rwData = data; diff --git a/tools/qmlprofiler/qmlprofilerclient.h b/tools/qmlprofiler/qmlprofilerclient.h index 72423ea676..b4bf97fdf3 100644 --- a/tools/qmlprofiler/qmlprofilerclient.h +++ b/tools/qmlprofiler/qmlprofilerclient.h @@ -38,35 +38,7 @@ #include "qmlprofilereventlocation.h" #include -class ProfilerClientPrivate; -class ProfilerClient : public QQmlDebugClient -{ - Q_OBJECT - - Q_PROPERTY(bool enabled READ isEnabled NOTIFY enabledChanged) -public: - ProfilerClient(const QString &clientName, - QQmlDebugConnection *client); - ~ProfilerClient(); - - bool isEnabled() const; - -public slots: - virtual void clearData(); - -signals: - void complete(); - void enabledChanged(); - void cleared(); - -protected: - virtual void stateChanged(State); - -protected: - bool m_enabled; -}; - -class QmlProfilerClient : public ProfilerClient +class QmlProfilerClient : public QQmlDebugClient { Q_OBJECT @@ -75,9 +47,9 @@ public: ~QmlProfilerClient(); void setFeatures(quint64 features); + void clearData(); public slots: - void clearData(); void sendRecordingStatus(bool record); signals: @@ -96,8 +68,11 @@ signals: const QmlEventLocation &location, int width, int height, int refCount); void memoryAllocation(QQmlProfilerDefinitions::MemoryType type, qint64 time, qint64 amount); void inputEvent(QQmlProfilerDefinitions::EventType, qint64 time); + void complete(); + void enabledChanged(bool enabled); protected: + virtual void stateChanged(State state); virtual void messageReceived(const QByteArray &); private: -- cgit v1.2.3