/
callmodelperftest.cpp
234 lines (191 loc) · 7.88 KB
/
callmodelperftest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/******************************************************************************
**
** This file is part of libcommhistory.
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Reto Zingg <reto.zingg@nokia.com>
**
** This library is free software; you can redistribute it and/or modify it
** under the terms of the GNU Lesser General Public License version 2.1 as
** published by the Free Software Foundation.
**
** This library is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
** License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this library; if not, write to the Free Software Foundation, Inc.,
** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**
******************************************************************************/
#include <QtTest/QtTest>
#include <QDateTime>
#include <QDBusConnection>
#include <cstdlib>
#include "callmodelperftest.h"
#include "callmodel.h"
#include "common.h"
using namespace CommHistory;
void CallModelPerfTest::initTestCase()
{
initTestDatabase();
logFile = new QFile("libcommhistory-performance-test.log");
if(!logFile->open(QIODevice::Append)) {
qDebug() << "!!!! Failed to open log file !!!!";
logFile = 0;
}
qsrand( QDateTime::currentDateTime().toTime_t() );
}
void CallModelPerfTest::init()
{
}
void CallModelPerfTest::getEvents_data()
{
QTest::addColumn<int>("events");
QTest::addColumn<int>("contacts");
QTest::addColumn<int>("selected");
QTest::addColumn<bool>("resolve");
QTest::newRow("10 events, 1 of 3 contacts") << 10 << 3 << 1 << false;
QTest::newRow("10 events, 1 of 3 contacts with resolve") << 10 << 3 << 1 << true;
QTest::newRow("100 events, 1 of 3 contacts") << 100 << 3 << 1 << false;
QTest::newRow("100 events, 1 of 3 contacts with resolve") << 100 << 3 << 1 << true;
QTest::newRow("1000 events, 1 of 3 contacts") << 1000 << 3 << 1 << false;
QTest::newRow("1000 events, 1 of 3 contacts with resolve") << 1000 << 3 << 1 << true;
QTest::newRow("10 events, 3 of 3 contacts") << 10 << 3 << 3 << false;
QTest::newRow("10 events, 3 of 3 contacts with resolve") << 10 << 3 << 3 << true;
QTest::newRow("100 events, 3 of 3 contacts") << 100 << 3 << 3 << false;
QTest::newRow("100 events, 3 of 3 contacts with resolve") << 100 << 3 << 3 << true;
QTest::newRow("1000 events, 3 of 3 contacts") << 1000 << 3 << 3 << false;
QTest::newRow("1000 events, 3 of 3 contacts with resolve") << 1000 << 3 << 3 << true;
QTest::newRow("10 events, 1 of 300 contacts") << 10 << 300 << 1 << false;
QTest::newRow("10 events, 1 of 300 contacts with resolve") << 10 << 300 << 1 << true;
QTest::newRow("100 events, 1 of 300 contacts") << 100 << 300 << 1 << false;
QTest::newRow("100 events, 1 of 300 contacts with resolve") << 100 << 300 << 1 << true;
QTest::newRow("1000 events, 1 of 300 contacts") << 1000 << 300 << 1 << false;
QTest::newRow("1000 events, 1 of 300 contacts with resolve") << 1000 << 300 << 1 << true;
QTest::newRow("10 events, 300 of 300 contacts") << 10 << 300 << 300 << false;
QTest::newRow("10 events, 300 of 300 contacts with resolve") << 10 << 300 << 300 << true;
QTest::newRow("100 events, 300 of 300 contacts") << 100 << 300 << 300 << false;
QTest::newRow("100 events, 300 of 300 contacts with resolve") << 100 << 300 << 300 << true;
QTest::newRow("1000 events, 300 of 300 contacts") << 1000 << 300 << 300 << false;
QTest::newRow("1000 events, 300 of 300 contacts with resolve") << 1000 << 300 << 300 << true;
}
void CallModelPerfTest::getEvents()
{
QFETCH(int, events);
QFETCH(int, contacts);
QFETCH(int, selected);
QFETCH(bool, resolve);
QDateTime startTime = QDateTime::currentDateTime();
cleanupTestGroups();
cleanupTestEvents();
int commitBatchSize = 75;
#ifdef PERF_BATCH_SIZE
commitBatchSize = PERF_BATCH_SIZE;
#endif
EventModel addModel;
QDateTime when = QDateTime::currentDateTime();
qDebug() << Q_FUNC_INFO << "- Creating" << contacts << "contacts";
QList<QPair<QString, QPair<QString, QString> > > contactDetails;
int ci = remoteUids.count();
while(ci < contacts) {
QString phoneNumber;
do {
phoneNumber = QString().setNum(qrand() % 10000000);
} while (remoteUids.contains(phoneNumber));
remoteUids << phoneNumber;
contactIndices << ci;
ci++;
contactDetails.append(qMakePair(QString("Test Contact %1").arg(ci), qMakePair(phoneNumber, QString())));
if(ci % commitBatchSize == 0 && ci < contacts) {
qDebug() << Q_FUNC_INFO << "- adding" << commitBatchSize
<< "contacts (" << ci << "/" << contacts << ")";
addTestContacts(contactDetails);
contactDetails.clear();
}
}
if (!contactDetails.isEmpty()) {
qDebug() << Q_FUNC_INFO << "- adding rest of the contacts ("
<< ci << "/" << contacts << ")";
addTestContacts(contactDetails);
contactDetails.clear();
}
qDebug() << Q_FUNC_INFO << "- Creating" << events << "new events";
QList<Event> eventList;
// Randomize the contact indices
random_shuffle(contactIndices.begin(), contactIndices.end());
int ei = 0;
while(ei < events) {
ei++;
Event::EventDirection direction;
bool isMissed = false;
if(qrand() % 2 > 0) {
direction = Event::Inbound;
isMissed = (qrand() % 2 > 0);
} else {
direction = Event::Outbound;
}
Event e;
e.setType(Event::CallEvent);
e.setDirection(direction);
e.setGroupId(-1);
e.setStartTime(when.addSecs(ei));
e.setEndTime(when.addSecs(ei));
e.setLocalUid(RING_ACCOUNT);
e.setRecipients(Recipient(RING_ACCOUNT, remoteUids.at(contactIndices.at(qrand() % selected))));
e.setFreeText("");
e.setIsDraft(false);
e.setIsMissedCall(isMissed);
eventList << e;
if(ei % commitBatchSize == 0 && ei != events) {
qDebug() << Q_FUNC_INFO << "- adding" << commitBatchSize
<< "events (" << ei << "/" << events << ")";
QVERIFY(addModel.addEvents(eventList, false));
eventList.clear();
}
}
QVERIFY(addModel.addEvents(eventList, false));
qDebug() << Q_FUNC_INFO << "- adding rest of the events ("
<< ei << "/" << events << ")";
eventList.clear();
QList<int> times;
int iterations = 10;
#ifdef PERF_ITERATIONS
iterations = PERF_ITERATIONS;
#endif
char *iterVar = getenv("PERF_ITERATIONS");
if (iterVar) {
int iters = QString::fromLatin1(iterVar).toInt();
if (iters > 0) {
iterations = iters;
}
}
qDebug() << Q_FUNC_INFO << "- Fetching events." << iterations << "iterations";
for(int i = 0; i < iterations; i++) {
CallModel fetchModel;
fetchModel.setResolveContacts(resolve ? EventModel::ResolveImmediately : EventModel::DoNotResolve);
fetchModel.setFilter(CallModel::SortByContact);
QTime time;
time.start();
bool result = fetchModel.getEvents();
QVERIFY(result);
if (!fetchModel.isReady())
waitForSignal(&fetchModel, SIGNAL(modelReady(bool)));
int elapsed = time.elapsed();
times << elapsed;
qDebug("Time elapsed: %d ms", elapsed);
QVERIFY(fetchModel.rowCount() > 0);
}
summarizeResults(metaObject()->className(), times, logFile, startTime.secsTo(QDateTime::currentDateTime()));
}
void CallModelPerfTest::cleanupTestCase()
{
if(logFile) {
logFile->close();
delete logFile;
logFile = 0;
}
deleteAll();
}
QTEST_MAIN(CallModelPerfTest)