summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-08 18:44:31 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-08 18:44:31 +0100
commit65be895825a61ae463d09604634b064570febdc2 (patch)
tree790ceda8e9372405a0473a0534128ad24198b1fb
parentb8200434209c317ebc4883b9f87513991bae33e3 (diff)
downloadsink-65be895825a61ae463d09604634b064570febdc2.tar.gz
sink-65be895825a61ae463d09604634b064570febdc2.zip
Trace some timings.
-rw-r--r--common/clientapi.cpp22
-rw-r--r--common/genericresource.cpp8
-rw-r--r--common/log.h12
-rw-r--r--common/resourceaccess.cpp6
4 files changed, 37 insertions, 11 deletions
diff --git a/common/clientapi.cpp b/common/clientapi.cpp
index a13456b..413abd3 100644
--- a/common/clientapi.cpp
+++ b/common/clientapi.cpp
@@ -22,6 +22,7 @@
22 22
23#include <QtConcurrent/QtConcurrentRun> 23#include <QtConcurrent/QtConcurrentRun>
24#include <QTimer> 24#include <QTimer>
25#include <QTime>
25#include <QEventLoop> 26#include <QEventLoop>
26#include <QAbstractItemModel> 27#include <QAbstractItemModel>
27#include <QDir> 28#include <QDir>
@@ -162,13 +163,15 @@ KAsync::Job<void> Store::remove(const DomainType &domainObject)
162KAsync::Job<void> Store::shutdown(const QByteArray &identifier) 163KAsync::Job<void> Store::shutdown(const QByteArray &identifier)
163{ 164{
164 Trace() << "shutdown " << identifier; 165 Trace() << "shutdown " << identifier;
165 return ResourceAccess::connectToServer(identifier).then<void, QSharedPointer<QLocalSocket>>([identifier](QSharedPointer<QLocalSocket> socket, KAsync::Future<void> &future) { 166 auto time = QSharedPointer<QTime>::create();
167 time->start();
168 return ResourceAccess::connectToServer(identifier).then<void, QSharedPointer<QLocalSocket>>([identifier, time](QSharedPointer<QLocalSocket> socket, KAsync::Future<void> &future) {
166 //We can't currently reuse the socket 169 //We can't currently reuse the socket
167 socket->close(); 170 socket->close();
168 auto resourceAccess = QSharedPointer<Sink::ResourceAccess>::create(identifier); 171 auto resourceAccess = QSharedPointer<Sink::ResourceAccess>::create(identifier);
169 resourceAccess->open(); 172 resourceAccess->open();
170 resourceAccess->sendCommand(Sink::Commands::ShutdownCommand).then<void>([&future, resourceAccess]() { 173 resourceAccess->sendCommand(Sink::Commands::ShutdownCommand).then<void>([&future, resourceAccess, time]() {
171 Trace() << "Shutdown complete"; 174 Trace() << "Shutdown complete." << Log::TraceTime(time->elapsed());
172 future.setFinished(); 175 future.setFinished();
173 }).exec(); 176 }).exec();
174 }, 177 },
@@ -183,10 +186,12 @@ KAsync::Job<void> Store::shutdown(const QByteArray &identifier)
183KAsync::Job<void> Store::start(const QByteArray &identifier) 186KAsync::Job<void> Store::start(const QByteArray &identifier)
184{ 187{
185 Trace() << "start " << identifier; 188 Trace() << "start " << identifier;
189 auto time = QSharedPointer<QTime>::create();
190 time->start();
186 auto resourceAccess = QSharedPointer<Sink::ResourceAccess>::create(identifier); 191 auto resourceAccess = QSharedPointer<Sink::ResourceAccess>::create(identifier);
187 resourceAccess->open(); 192 resourceAccess->open();
188 return resourceAccess->sendCommand(Sink::Commands::PingCommand).then<void>([resourceAccess]() { 193 return resourceAccess->sendCommand(Sink::Commands::PingCommand).then<void>([resourceAccess, time]() {
189 Trace() << "Start complete"; 194 Trace() << "Start complete." << Log::TraceTime(time->elapsed());
190 }); 195 });
191} 196}
192 197
@@ -303,15 +308,18 @@ KAsync::Job<void> Resources::inspect(const Inspection &inspectionCommand)
303{ 308{
304 auto resource = inspectionCommand.resourceIdentifier; 309 auto resource = inspectionCommand.resourceIdentifier;
305 310
311 auto time = QSharedPointer<QTime>::create();
312 time->start();
306 Trace() << "Sending inspection " << resource; 313 Trace() << "Sending inspection " << resource;
307 auto resourceAccess = QSharedPointer<Sink::ResourceAccess>::create(resource); 314 auto resourceAccess = QSharedPointer<Sink::ResourceAccess>::create(resource);
308 resourceAccess->open(); 315 resourceAccess->open();
309 auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess); 316 auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess);
310 auto id = QUuid::createUuid().toByteArray(); 317 auto id = QUuid::createUuid().toByteArray();
311 return resourceAccess->sendInspectionCommand(id, ApplicationDomain::getTypeName<DomainType>(), inspectionCommand.entityIdentifier, inspectionCommand.property, inspectionCommand.expectedValue) 318 return resourceAccess->sendInspectionCommand(id, ApplicationDomain::getTypeName<DomainType>(), inspectionCommand.entityIdentifier, inspectionCommand.property, inspectionCommand.expectedValue)
312 .template then<void>([resourceAccess, notifier, id](KAsync::Future<void> &future) { 319 .template then<void>([resourceAccess, notifier, id, time](KAsync::Future<void> &future) {
313 notifier->registerHandler([&future, id](const Notification &notification) { 320 notifier->registerHandler([&future, id, time](const Notification &notification) {
314 if (notification.id == id) { 321 if (notification.id == id) {
322 Trace() << "Inspection complete." << Log::TraceTime(time->elapsed());
315 if (notification.code) { 323 if (notification.code) {
316 future.setError(-1, "Inspection returned an error: " + notification.message); 324 future.setError(-1, "Inspection returned an error: " + notification.message);
317 } else { 325 } else {
diff --git a/common/genericresource.cpp b/common/genericresource.cpp
index b49ca94..ffb323d 100644
--- a/common/genericresource.cpp
+++ b/common/genericresource.cpp
@@ -17,6 +17,7 @@
17 17
18#include <QUuid> 18#include <QUuid>
19#include <QDataStream> 19#include <QDataStream>
20#include <QTime>
20 21
21static int sBatchSize = 100; 22static int sBatchSize = 100;
22 23
@@ -273,9 +274,12 @@ private slots:
273 return KAsync::dowhile( 274 return KAsync::dowhile(
274 [it]() { return it->hasNext(); }, 275 [it]() { return it->hasNext(); },
275 [it, this](KAsync::Future<void> &future) { 276 [it, this](KAsync::Future<void> &future) {
277 auto time = QSharedPointer<QTime>::create();
278 time->start();
279
276 auto queue = it->next(); 280 auto queue = it->next();
277 processQueue(queue).then<void>([&future]() { 281 processQueue(queue).then<void>([&future, time]() {
278 Trace() << "Queue processed"; 282 Trace() << "Queue processed." << Log::TraceTime(time->elapsed());
279 future.setFinished(); 283 future.setFinished();
280 }).exec(); 284 }).exec();
281 } 285 }
diff --git a/common/log.h b/common/log.h
index 7d02634..bf133c4 100644
--- a/common/log.h
+++ b/common/log.h
@@ -55,6 +55,18 @@ QByteArrayList SINKCOMMON_EXPORT debugOutputFields();
55 55
56QDebug SINKCOMMON_EXPORT debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea = 0); 56QDebug SINKCOMMON_EXPORT debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea = 0);
57 57
58struct SINKCOMMON_EXPORT TraceTime
59{
60 TraceTime(int i) : time(i){};
61 const int time;
62};
63
64inline QDebug SINKCOMMON_EXPORT operator<<(QDebug d, const TraceTime &time)
65{
66 d << time.time << "[ms]";
67 return d;
68}
69
58} 70}
59} 71}
60 72
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp
index 345622c..dd862c8 100644
--- a/common/resourceaccess.cpp
+++ b/common/resourceaccess.cpp
@@ -381,9 +381,11 @@ void ResourceAccess::open()
381 if (d->openingSocket) { 381 if (d->openingSocket) {
382 return; 382 return;
383 } 383 }
384 auto time = QSharedPointer<QTime>::create();
385 time->start();
384 d->openingSocket = true; 386 d->openingSocket = true;
385 d->initializeSocket().then<void>([this]() { 387 d->initializeSocket().then<void>([this, time]() {
386 Trace() << "Socket is initialized"; 388 Trace() << "Socket is initialized." << Log::TraceTime(time->elapsed());
387 d->openingSocket = false; 389 d->openingSocket = false;
388 QObject::connect(d->socket.data(), &QLocalSocket::disconnected, 390 QObject::connect(d->socket.data(), &QLocalSocket::disconnected,
389 this, &ResourceAccess::disconnected); 391 this, &ResourceAccess::disconnected);