Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Debugger: Allow transmissions of network packets in one go
We did call a flush() after every single packet, which was slowing down
things especially for the QDeclarativeDebugTrace service.

Change-Id: Idab074941a22364e154502eb12afa43b4dd33c22
Reviewed-by: Aurindam Jana <aurindam.jana@nokia.com>
Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
  • Loading branch information
Kai Koehne authored and Qt by Nokia committed Dec 21, 2011
1 parent 3d8986d commit 3c21155
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 24 deletions.
26 changes: 15 additions & 11 deletions src/declarative/debugger/qdeclarativedebugserver.cpp
Expand Up @@ -106,7 +106,7 @@ class QDeclarativeDebugServerPrivate : public QObjectPrivate

private:
// private slot
void _q_sendMessage(const QByteArray &message);
void _q_sendMessages(const QList<QByteArray> &messages);
};

class QDeclarativeDebugServerThread : public QThread
Expand Down Expand Up @@ -134,6 +134,8 @@ QDeclarativeDebugServerPrivate::QDeclarativeDebugServerPrivate() :
gotHello(false),
thread(0)
{
// used in _q_sendMessages
qRegisterMetaType<QList<QByteArray> >("QList<QByteArray>");
}

void QDeclarativeDebugServerPrivate::advertisePlugins()
Expand All @@ -155,7 +157,7 @@ void QDeclarativeDebugServerPrivate::advertisePlugins()
out << QString(QLatin1String("QDeclarativeDebugClient")) << 1 << pluginNames << pluginVersions;
}

QMetaObject::invokeMethod(q, "_q_sendMessage", Qt::QueuedConnection, Q_ARG(QByteArray, message));
QMetaObject::invokeMethod(q, "_q_sendMessages", Qt::QueuedConnection, Q_ARG(QList<QByteArray>, QList<QByteArray>() << message));
}

QDeclarativeDebugServerConnection *QDeclarativeDebugServerPrivate::loadConnectionPlugin(
Expand Down Expand Up @@ -368,7 +370,7 @@ void QDeclarativeDebugServer::receiveMessage(const QByteArray &message)

out << QString(QLatin1String("QDeclarativeDebugClient")) << 0 << protocolVersion << pluginNames << pluginVersions;
}
d->connection->send(helloAnswer);
d->connection->send(QList<QByteArray>() << helloAnswer);

d->gotHello = true;

Expand Down Expand Up @@ -434,10 +436,10 @@ void QDeclarativeDebugServer::receiveMessage(const QByteArray &message)
}
}

void QDeclarativeDebugServerPrivate::_q_sendMessage(const QByteArray &message)
void QDeclarativeDebugServerPrivate::_q_sendMessages(const QList<QByteArray> &messages)
{
if (connection)
connection->send(message);
connection->send(messages);
}

QList<QDeclarativeDebugService*> QDeclarativeDebugServer::services() const
Expand Down Expand Up @@ -495,16 +497,18 @@ bool QDeclarativeDebugServer::removeService(QDeclarativeDebugService *service)
return true;
}

void QDeclarativeDebugServer::sendMessage(QDeclarativeDebugService *service,
const QByteArray &message)
void QDeclarativeDebugServer::sendMessages(QDeclarativeDebugService *service,
const QList<QByteArray> &messages)
{
QByteArray msg;
{
QDataStream out(&msg, QIODevice::WriteOnly);
QList<QByteArray> prefixedMessages;
foreach (const QByteArray &message, messages) {
QByteArray prefixed;
QDataStream out(&prefixed, QIODevice::WriteOnly);
out << service->name() << message;
prefixedMessages << prefixed;
}

QMetaObject::invokeMethod(this, "_q_sendMessage", Qt::QueuedConnection, Q_ARG(QByteArray, msg));
QMetaObject::invokeMethod(this, "_q_sendMessages", Qt::QueuedConnection, Q_ARG(QList<QByteArray>, prefixedMessages));
}

bool QDeclarativeDebugServer::waitForMessage(QDeclarativeDebugService *service)
Expand Down
4 changes: 2 additions & 2 deletions src/declarative/debugger/qdeclarativedebugserver_p.h
Expand Up @@ -89,14 +89,14 @@ class Q_DECLARATIVE_EXPORT QDeclarativeDebugServer : public QObject
void receiveMessage(const QByteArray &message);

bool waitForMessage(QDeclarativeDebugService *service);
void sendMessage(QDeclarativeDebugService *service, const QByteArray &message);
void sendMessages(QDeclarativeDebugService *service, const QList<QByteArray> &messages);

private:
friend class QDeclarativeDebugService;
friend class QDeclarativeDebugServicePrivate;
friend class QDeclarativeDebugServerThread;
QDeclarativeDebugServer();
Q_PRIVATE_SLOT(d_func(), void _q_sendMessage(QByteArray))
Q_PRIVATE_SLOT(d_func(), void _q_sendMessages(QList<QByteArray>))
};

QT_END_NAMESPACE
Expand Down
Expand Up @@ -71,7 +71,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeDebugServerConnection
virtual void setServer(QDeclarativeDebugServer *server) = 0;
virtual void setPort(int port, bool bock) = 0;
virtual bool isConnected() const = 0;
virtual void send(const QByteArray &message) = 0;
virtual void send(const QList<QByteArray> &messages) = 0;
virtual void disconnect() = 0;
virtual bool waitForMessage() = 0;
};
Expand Down
7 changes: 6 additions & 1 deletion src/declarative/debugger/qdeclarativedebugservice.cpp
Expand Up @@ -229,13 +229,18 @@ QString QDeclarativeDebugService::objectToString(QObject *obj)
}

void QDeclarativeDebugService::sendMessage(const QByteArray &message)
{
sendMessages(QList<QByteArray>() << message);
}

void QDeclarativeDebugService::sendMessages(const QList<QByteArray> &messages)
{
Q_D(QDeclarativeDebugService);

if (status() != Enabled)
return;

d->server->sendMessage(this, message);
d->server->sendMessages(this, messages);
}

bool QDeclarativeDebugService::waitForMessage()
Expand Down
1 change: 1 addition & 0 deletions src/declarative/debugger/qdeclarativedebugservice_p.h
Expand Up @@ -81,6 +81,7 @@ class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugService : public QObject
Status status() const;

void sendMessage(const QByteArray &);
void sendMessages(const QList<QByteArray> &);
bool waitForMessage();

static int idForObject(QObject *);
Expand Down
5 changes: 3 additions & 2 deletions src/declarative/debugger/qdeclarativedebugtrace.cpp
Expand Up @@ -280,9 +280,10 @@ void QDeclarativeDebugTrace::setProfilingEnabled(bool enable)
void QDeclarativeDebugTrace::sendMessages()
{
QMutexLocker locker(&m_mutex);
//### this is a suboptimal way to send batched messages
QList<QByteArray> messages;
for (int i = 0; i < m_data.count(); ++i)
sendMessage(m_data.at(i).toByteArray());
messages << m_data.at(i).toByteArray();
QDeclarativeDebugService::sendMessages(messages);
m_data.clear();

//indicate completion
Expand Down
4 changes: 3 additions & 1 deletion src/declarative/debugger/qv8profilerservice.cpp
Expand Up @@ -241,8 +241,10 @@ void QV8ProfilerServicePrivate::sendMessages()
{
Q_Q(QV8ProfilerService);

QList<QByteArray> messages;
for (int i = 0; i < m_data.count(); ++i)
q->sendMessage(m_data.at(i).toByteArray());
messages << m_data.at(i).toByteArray();
q->sendMessages(messages);
m_data.clear();

//indicate completion
Expand Down
11 changes: 6 additions & 5 deletions src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp
Expand Up @@ -96,18 +96,19 @@ bool QTcpServerConnection::isConnected() const
return d->socket && d->socket->state() == QTcpSocket::ConnectedState;
}

void QTcpServerConnection::send(const QByteArray &message)
void QTcpServerConnection::send(const QList<QByteArray> &messages)
{
Q_D(QTcpServerConnection);

if (!isConnected()
|| !d->protocol || !d->socket)
return;

QPacket pack;
pack.writeRawData(message.data(), message.length());

d->protocol->send(pack);
foreach (const QByteArray &message, messages) {
QPacket pack;
pack.writeRawData(message.data(), message.length());
d->protocol->send(pack);
}
d->socket->flush();
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h
Expand Up @@ -65,7 +65,7 @@ class QTcpServerConnection : public QObject, public QDeclarativeDebugServerConne
void setPort(int port, bool bock);

bool isConnected() const;
void send(const QByteArray &message);
void send(const QList<QByteArray> &messages);
void disconnect();
bool waitForMessage();

Expand Down

0 comments on commit 3c21155

Please sign in to comment.