summaryrefslogtreecommitdiffstats
path: root/tests/dummyresourcebenchmark.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dummyresourcebenchmark.cpp')
-rw-r--r--tests/dummyresourcebenchmark.cpp78
1 files changed, 38 insertions, 40 deletions
diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp
index 77b87fb..124abc1 100644
--- a/tests/dummyresourcebenchmark.cpp
+++ b/tests/dummyresourcebenchmark.cpp
@@ -44,40 +44,38 @@ private slots:
44 { 44 {
45 } 45 }
46 46
47 static KAsync::Job<void> waitForCompletion(QList<KAsync::Future<void> > &futures) 47 static KAsync::Job<void> waitForCompletion(QList<KAsync::Future<void>> &futures)
48 { 48 {
49 auto context = new QObject; 49 auto context = new QObject;
50 return KAsync::start<void>([futures, context](KAsync::Future<void> &future) { 50 return KAsync::start<void>([futures, context](KAsync::Future<void> &future) {
51 const auto total = futures.size(); 51 const auto total = futures.size();
52 auto count = QSharedPointer<int>::create(); 52 auto count = QSharedPointer<int>::create();
53 int i = 0; 53 int i = 0;
54 for (KAsync::Future<void> subFuture : futures) { 54 for (KAsync::Future<void> subFuture : futures) {
55 i++; 55 i++;
56 if (subFuture.isFinished()) { 56 if (subFuture.isFinished()) {
57 *count += 1; 57 *count += 1;
58 continue; 58 continue;
59 } 59 }
60 //FIXME bind lifetime all watcher to future (repectively the main job 60 // FIXME bind lifetime all watcher to future (repectively the main job
61 auto watcher = QSharedPointer<KAsync::FutureWatcher<void> >::create(); 61 auto watcher = QSharedPointer<KAsync::FutureWatcher<void>>::create();
62 QObject::connect(watcher.data(), &KAsync::FutureWatcher<void>::futureReady, 62 QObject::connect(watcher.data(), &KAsync::FutureWatcher<void>::futureReady, [count, total, &future]() {
63 [count, total, &future](){ 63 *count += 1;
64 *count += 1; 64 if (*count == total) {
65 if (*count == total) { 65 future.setFinished();
66 future.setFinished(); 66 }
67 } 67 });
68 }); 68 watcher->setFuture(subFuture);
69 watcher->setFuture(subFuture); 69 context->setProperty(QString("future%1").arg(i).toLatin1().data(), QVariant::fromValue(watcher));
70 context->setProperty(QString("future%1").arg(i).toLatin1().data(), QVariant::fromValue(watcher)); 70 }
71 } 71 })
72 }).then<void>([context]() { 72 .then<void>([context]() { delete context; });
73 delete context;
74 });
75 } 73 }
76 74
77 //Ensure we can process a command in less than 0.1s 75 // Ensure we can process a command in less than 0.1s
78 void testCommandResponsiveness() 76 void testCommandResponsiveness()
79 { 77 {
80 //Test responsiveness including starting the process. 78 // Test responsiveness including starting the process.
81 Sink::Store::removeDataFromDisk("org.kde.dummy.instance1").exec().waitForFinished(); 79 Sink::Store::removeDataFromDisk("org.kde.dummy.instance1").exec().waitForFinished();
82 80
83 QTime time; 81 QTime time;
@@ -100,7 +98,7 @@ private slots:
100 98
101 Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec(); 99 Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec();
102 100
103 //Wait for notification 101 // Wait for notification
104 QTRY_VERIFY(gotNotification); 102 QTRY_VERIFY(gotNotification);
105 103
106 QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1()); 104 QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1());
@@ -114,7 +112,7 @@ private slots:
114 112
115 QTime time; 113 QTime time;
116 time.start(); 114 time.start();
117 QList<KAsync::Future<void> > waitCondition; 115 QList<KAsync::Future<void>> waitCondition;
118 for (int i = 0; i < num; i++) { 116 for (int i = 0; i < num; i++) {
119 Sink::ApplicationDomain::Event event("org.kde.dummy.instance1"); 117 Sink::ApplicationDomain::Event event("org.kde.dummy.instance1");
120 event.setProperty("uid", "testuid"); 118 event.setProperty("uid", "testuid");
@@ -125,7 +123,7 @@ private slots:
125 waitForCompletion(waitCondition).exec().waitForFinished(); 123 waitForCompletion(waitCondition).exec().waitForFinished();
126 auto appendTime = time.elapsed(); 124 auto appendTime = time.elapsed();
127 125
128 //Ensure everything is processed 126 // Ensure everything is processed
129 { 127 {
130 Sink::Query query; 128 Sink::Query query;
131 query.resources << "org.kde.dummy.instance1"; 129 query.resources << "org.kde.dummy.instance1";
@@ -137,13 +135,13 @@ private slots:
137 HAWD::Dataset::Row row = dataset.row(); 135 HAWD::Dataset::Row row = dataset.row();
138 136
139 row.setValue("rows", num); 137 row.setValue("rows", num);
140 row.setValue("append", (qreal)num/appendTime); 138 row.setValue("append", (qreal)num / appendTime);
141 row.setValue("total", (qreal)num/allProcessedTime); 139 row.setValue("total", (qreal)num / allProcessedTime);
142 dataset.insertRow(row); 140 dataset.insertRow(row);
143 HAWD::Formatter::print(dataset); 141 HAWD::Formatter::print(dataset);
144 142
145 auto diskUsage = DummyResource::diskUsage("org.kde.dummy.instance1"); 143 auto diskUsage = DummyResource::diskUsage("org.kde.dummy.instance1");
146 qDebug() << "Database size [kb]: " << diskUsage/1024; 144 qDebug() << "Database size [kb]: " << diskUsage / 1024;
147 145
148 // Print memory layout, RSS is what is in memory 146 // Print memory layout, RSS is what is in memory
149 // std::system("exec pmap -x \"$PPID\""); 147 // std::system("exec pmap -x \"$PPID\"");
@@ -153,7 +151,7 @@ private slots:
153 { 151 {
154 QTime time; 152 QTime time;
155 time.start(); 153 time.start();
156 //Measure query 154 // Measure query
157 { 155 {
158 time.start(); 156 time.start();
159 Sink::Query query; 157 Sink::Query query;
@@ -168,7 +166,7 @@ private slots:
168 HAWD::Dataset dataset("dummy_query_by_uid", m_hawdState); 166 HAWD::Dataset dataset("dummy_query_by_uid", m_hawdState);
169 HAWD::Dataset::Row row = dataset.row(); 167 HAWD::Dataset::Row row = dataset.row();
170 row.setValue("rows", num); 168 row.setValue("rows", num);
171 row.setValue("read", (qreal)num/queryTime); 169 row.setValue("read", (qreal)num / queryTime);
172 dataset.insertRow(row); 170 dataset.insertRow(row);
173 HAWD::Formatter::print(dataset); 171 HAWD::Formatter::print(dataset);
174 } 172 }
@@ -220,7 +218,7 @@ private slots:
220 } 218 }
221 auto appendTime = time.elapsed(); 219 auto appendTime = time.elapsed();
222 220
223 //Wait until all messages have been processed 221 // Wait until all messages have been processed
224 resource.processAllMessages().exec().waitForFinished(); 222 resource.processAllMessages().exec().waitForFinished();
225 223
226 auto allProcessedTime = time.elapsed(); 224 auto allProcessedTime = time.elapsed();
@@ -229,8 +227,8 @@ private slots:
229 HAWD::Dataset::Row row = dataset.row(); 227 HAWD::Dataset::Row row = dataset.row();
230 228
231 row.setValue("rows", num); 229 row.setValue("rows", num);
232 row.setValue("append", (qreal)num/appendTime); 230 row.setValue("append", (qreal)num / appendTime);
233 row.setValue("total", (qreal)num/allProcessedTime); 231 row.setValue("total", (qreal)num / allProcessedTime);
234 dataset.insertRow(row); 232 dataset.insertRow(row);
235 HAWD::Formatter::print(dataset); 233 HAWD::Formatter::print(dataset);
236 234
@@ -250,7 +248,7 @@ private slots:
250 248
251 static flatbuffers::FlatBufferBuilder fbb; 249 static flatbuffers::FlatBufferBuilder fbb;
252 fbb.Clear(); 250 fbb.Clear();
253 //This is the resource buffer type and not the domain type 251 // This is the resource buffer type and not the domain type
254 auto entityId = fbb.CreateString(""); 252 auto entityId = fbb.CreateString("");
255 auto type = fbb.CreateString("event"); 253 auto type = fbb.CreateString("event");
256 // auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); 254 // auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize());
@@ -260,7 +258,7 @@ private slots:
260 } 258 }
261 } 259 }
262 260
263 //This allows to run individual parts without doing a cleanup, but still cleaning up normally 261 // This allows to run individual parts without doing a cleanup, but still cleaning up normally
264 void testCleanupForCompleteTest() 262 void testCleanupForCompleteTest()
265 { 263 {
266 Sink::Store::removeDataFromDisk("org.kde.dummy.instance1").exec().waitForFinished(); 264 Sink::Store::removeDataFromDisk("org.kde.dummy.instance1").exec().waitForFinished();