|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
5 ** |
|
6 ** This file is part of the examples of the Qt Toolkit. |
|
7 ** |
|
8 ** $QT_BEGIN_LICENSE:LGPL$ |
|
9 ** No Commercial Usage |
|
10 ** This file contains pre-release code and may not be distributed. |
|
11 ** You may use this file in accordance with the terms and conditions |
|
12 ** contained in the either Technology Preview License Agreement or the |
|
13 ** Beta Release License Agreement. |
|
14 ** |
|
15 ** GNU Lesser General Public License Usage |
|
16 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
17 ** General Public License version 2.1 as published by the Free Software |
|
18 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
19 ** packaging of this file. Please review the following information to |
|
20 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
22 ** |
|
23 ** In addition, as a special exception, Nokia gives you certain |
|
24 ** additional rights. These rights are described in the Nokia Qt LGPL |
|
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this |
|
26 ** package. |
|
27 ** |
|
28 ** GNU General Public License Usage |
|
29 ** Alternatively, this file may be used under the terms of the GNU |
|
30 ** General Public License version 3.0 as published by the Free Software |
|
31 ** Foundation and appearing in the file LICENSE.GPL included in the |
|
32 ** packaging of this file. Please review the following information to |
|
33 ** ensure the GNU General Public License version 3.0 requirements will be |
|
34 ** met: http://www.gnu.org/copyleft/gpl.html. |
|
35 ** |
|
36 ** If you are unsure which license is appropriate for your use, please |
|
37 ** contact the sales department at http://qt.nokia.com/contact. |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QDebug> |
|
43 #include <QMutex> |
|
44 #include <QWaitCondition> |
|
45 #include <QApplication> |
|
46 #include <QDir> |
|
47 #include <QPluginLoader> |
|
48 |
|
49 #include "testcontroller.h" |
|
50 #include "itemrecyclinglist.h" |
|
51 #include "simplelist.h" |
|
52 #include "scrollbar.h" |
|
53 #include "mainview.h" |
|
54 #include "theme.h" |
|
55 #include "themeevent.h" |
|
56 #include "filllists.h" |
|
57 |
|
58 static const int EmitDoneTimeout = 1000; |
|
59 |
|
60 Q_DECLARE_METATYPE(TestController*) |
|
61 |
|
62 TestController::TestController(const QString &fname, MainView *mv, ResultLogger::ResultFormat format, QObject *parent) |
|
63 : QObject(parent), |
|
64 mMainView(mv), |
|
65 mCurrentSimpleList(0), |
|
66 mCurrentRecyclingList(0), |
|
67 mTestDuration(), |
|
68 mMaxTestDurationTime(0), |
|
69 mScrollDirection(1), |
|
70 mFileName(fname), |
|
71 mResultFormat(format), |
|
72 mDataGenerator(), |
|
73 mResMon(0), |
|
74 mSubtreeCacheEnabled(false), |
|
75 mScrollStep(36), |
|
76 mCpuMemLogging(true), |
|
77 mLastElapsed(0) |
|
78 { |
|
79 qRegisterMetaType<TestController*>(); |
|
80 connect(QApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit())); |
|
81 |
|
82 if(loadPlugin()) { |
|
83 //qDebug() << "Loaded plugin!"; |
|
84 if (mResMon->Prepare("tst_GraphicsViewBenchmark")) { |
|
85 } |
|
86 } |
|
87 else { |
|
88 qDebug() << "Failed to load plugin!"; |
|
89 } |
|
90 } |
|
91 |
|
92 |
|
93 TestController::~TestController() |
|
94 { |
|
95 delete mResMon; |
|
96 } |
|
97 |
|
98 void TestController::printResourceLoad() |
|
99 { |
|
100 #if defined Q_OS_LINUX |
|
101 if (mResMon) { |
|
102 ResourceMonitorInterface::CpuUsage usage = mResMon->CPULoad(); |
|
103 ResourceMonitorInterface::MemoryAllocation allocation = mResMon->MemoryLoad(); |
|
104 qDebug() << "CPULoad: total" << usage.systemUsage << "(%), app" << usage.appTreadUsage << "(%)"; |
|
105 qDebug() << "MemoryLoad: occupied by app chunks" << allocation.allocatedInAppThread << "(bytes), number of free app chunks" << allocation.numberOfAllocatedCellsInAppThread << ", avaliable in app heap" << allocation.availableMemoryInAppThreadHeap <<"(bytes), total memory" << allocation.totalMemoryInSystem << "(bytes), free memory" << allocation.availableMemoryInSystem << "(bytes)"; |
|
106 } |
|
107 #endif |
|
108 } |
|
109 |
|
110 QString TestController::resultFileName() |
|
111 { |
|
112 return mFileName; |
|
113 } |
|
114 |
|
115 ResultLogger::ResultFormat TestController::resultFileFormat() |
|
116 { |
|
117 return mResultFormat; |
|
118 } |
|
119 |
|
120 void TestController::setSubtreeCache(const bool enabled) |
|
121 { |
|
122 mSubtreeCacheEnabled = enabled; |
|
123 } |
|
124 bool TestController::subtreeCache() const |
|
125 { |
|
126 return mSubtreeCacheEnabled; |
|
127 } |
|
128 |
|
129 void TestController::setScrollStep(const int step) |
|
130 { |
|
131 mScrollStep = step; |
|
132 } |
|
133 int TestController::scrollStep() const |
|
134 { |
|
135 return mScrollStep; |
|
136 } |
|
137 |
|
138 void TestController::rotateMainWindow(const int angle) |
|
139 { |
|
140 if (mMainView) |
|
141 mMainView->rotateContent(angle); |
|
142 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
143 } |
|
144 |
|
145 int TestController::mainWindowRotationAngle() const |
|
146 { |
|
147 if (mMainView) |
|
148 return mMainView->rotationAngle(); |
|
149 return 0; |
|
150 } |
|
151 |
|
152 void TestController::setCpuMemLogging(const bool enabled) |
|
153 { |
|
154 mCpuMemLogging = enabled; |
|
155 } |
|
156 |
|
157 void TestController::aboutToQuit() |
|
158 { |
|
159 testIsDone(); |
|
160 emit stop(); |
|
161 } |
|
162 |
|
163 void TestController::changeTheme(Theme::Themes theme) |
|
164 { |
|
165 Theme::p()->setTheme(theme); |
|
166 } |
|
167 |
|
168 void TestController::testIsDone() |
|
169 { |
|
170 mScrollDirection = 1; |
|
171 mCurrentRecyclingList = 0; |
|
172 mCurrentSimpleList = 0; |
|
173 mMaxTestDurationTime = 0; |
|
174 if (mMainView) |
|
175 mMainView->fpsReset(); |
|
176 |
|
177 emit testDone(); |
|
178 } |
|
179 |
|
180 void TestController::fillList(int itemCount, Benchmark::ListType listType, |
|
181 TestFunctionResult *testFunctionResult, const QString &tag) |
|
182 { |
|
183 if (!mMainView) { |
|
184 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
185 return; |
|
186 } |
|
187 |
|
188 Benchmark *b = testFunctionResult->createBenchmark(); |
|
189 b->setRotation(mainWindowRotationAngle()); |
|
190 b->setListSize(itemCount); |
|
191 b->setUseListItemCache(mSubtreeCacheEnabled); |
|
192 b->setImageBasedRendering(mMainView->imageBasedRendering()); |
|
193 b->setTheme(Theme::p()->currentThemeName()); |
|
194 b->setListType(listType); |
|
195 b->setTag(tag); |
|
196 |
|
197 if (listType==Benchmark::RecyclingListType){ |
|
198 if(mResMon && mCpuMemLogging) { |
|
199 //CPU/MEM begin |
|
200 mResMon->BeginMeasureCPULoad(); |
|
201 mResMon->BeginMeasureMemoryLoad(); |
|
202 } |
|
203 |
|
204 QTime t; |
|
205 t.start(); |
|
206 ItemRecyclingList *list = new ItemRecyclingList(); |
|
207 |
|
208 list->setListItemCaching(mSubtreeCacheEnabled); |
|
209 |
|
210 mMainView->setTestWidget(list); |
|
211 |
|
212 mDataGenerator.Reset(); |
|
213 |
|
214 fillRecyclingList(mDataGenerator, itemCount, list); |
|
215 |
|
216 int took = t.elapsed(); |
|
217 |
|
218 b->setValue(took); |
|
219 if(mResMon && mCpuMemLogging) { |
|
220 //CPU/MEM end |
|
221 createCpuBenchmark(testFunctionResult, tag, itemCount, listType,Theme::p()->currentThemeName(), mResMon->EndMeasureCPULoad()); |
|
222 createMemoryBenchmark(testFunctionResult, tag, itemCount, listType,Theme::p()->currentThemeName(), mResMon->EndMeasureMemoryLoad()); |
|
223 } |
|
224 } |
|
225 else { |
|
226 if(mResMon && mCpuMemLogging) { |
|
227 //CPU/MEM begin |
|
228 mResMon->BeginMeasureCPULoad(); |
|
229 mResMon->BeginMeasureMemoryLoad(); |
|
230 } |
|
231 |
|
232 QTime t; |
|
233 t.start(); |
|
234 SimpleList *list = new SimpleList(); |
|
235 list->setListItemCaching(mSubtreeCacheEnabled); |
|
236 mMainView->setTestWidget(list); |
|
237 |
|
238 mDataGenerator.Reset(); |
|
239 |
|
240 fillSimpleList(mDataGenerator, itemCount, list); |
|
241 |
|
242 int took = t.elapsed(); |
|
243 b->setValue(took); |
|
244 |
|
245 if(mResMon && mCpuMemLogging) { |
|
246 //CPU/MEM end |
|
247 createCpuBenchmark(testFunctionResult, tag, itemCount, listType,Theme::p()->currentThemeName(), mResMon->EndMeasureCPULoad()); |
|
248 createMemoryBenchmark(testFunctionResult, tag, itemCount, listType,Theme::p()->currentThemeName(), mResMon->EndMeasureMemoryLoad()); |
|
249 } |
|
250 } |
|
251 |
|
252 // Make sure we record the correct view size |
|
253 b->setWidth(mMainView->size().width()); |
|
254 b->setHeight(mMainView->size().height()); |
|
255 |
|
256 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
257 } |
|
258 |
|
259 void TestController::scrollList(int maxTimeMs, TestFunctionResult *testFunctionResult, const QString &tag) |
|
260 { |
|
261 if (!mMainView) { |
|
262 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
263 return; |
|
264 } |
|
265 |
|
266 mMaxTestDurationTime = maxTimeMs; |
|
267 |
|
268 QGraphicsWidget *tw = mMainView->testWidget(); |
|
269 ItemRecyclingList *list = dynamic_cast<ItemRecyclingList *>(tw); |
|
270 if (list) { |
|
271 if (mMainView) |
|
272 mMainView->fpsReset(); |
|
273 mTestDuration.start(); |
|
274 mLastElapsed = 0; |
|
275 mCurrentRecyclingList = list; |
|
276 connect(this, SIGNAL(doScrollRecyclingList(TestFunctionResult*, const QString &)), |
|
277 this, SLOT(scrollRecyclingList(TestFunctionResult*, const QString &)), Qt::QueuedConnection); |
|
278 |
|
279 if(mResMon && mCpuMemLogging) { |
|
280 //CPU/MEM begin |
|
281 mResMon->BeginMeasureCPULoad(); |
|
282 mResMon->BeginMeasureMemoryLoad(); |
|
283 } |
|
284 |
|
285 emit doScrollRecyclingList(testFunctionResult, tag); |
|
286 } |
|
287 else { |
|
288 SimpleList *list = dynamic_cast<SimpleList*>(tw); |
|
289 if (list) { |
|
290 if (mMainView) |
|
291 mMainView->fpsReset(); |
|
292 mTestDuration.start(); |
|
293 mLastElapsed = 0; |
|
294 mCurrentSimpleList = list; |
|
295 connect(this, SIGNAL(doScrollSimpleList(TestFunctionResult*, const QString &)), |
|
296 this, SLOT(scrollSimpleList(TestFunctionResult*, const QString &)), Qt::QueuedConnection); |
|
297 |
|
298 if(mResMon && mCpuMemLogging) { |
|
299 //CPU/MEM begin |
|
300 mResMon->BeginMeasureCPULoad(); |
|
301 mResMon->BeginMeasureMemoryLoad(); |
|
302 } |
|
303 |
|
304 emit doScrollSimpleList(testFunctionResult, tag); |
|
305 } |
|
306 else { |
|
307 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
308 } |
|
309 } |
|
310 } |
|
311 |
|
312 void TestController::addToBeginningOfList(int itemCount, TestFunctionResult *testFunctionResult, const QString &tag) |
|
313 { |
|
314 if (!mMainView) { |
|
315 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
316 return; |
|
317 } |
|
318 |
|
319 Benchmark *b = testFunctionResult->createBenchmark(); |
|
320 b->setTag(tag); |
|
321 b->setRotation(mainWindowRotationAngle()); |
|
322 b->setListSize(itemCount); |
|
323 b->setUseListItemCache(mSubtreeCacheEnabled); |
|
324 b->setImageBasedRendering(mMainView->imageBasedRendering()); |
|
325 b->setTheme(Theme::p()->currentThemeName()); |
|
326 b->setWidth(mMainView->size().width()); |
|
327 b->setHeight(mMainView->size().height()); |
|
328 |
|
329 QGraphicsWidget *tw = mMainView->testWidget(); |
|
330 ItemRecyclingList *list = dynamic_cast<ItemRecyclingList *>(tw); |
|
331 |
|
332 if (list) { |
|
333 QString type = list->objectName(); |
|
334 |
|
335 if(mResMon && mCpuMemLogging) { |
|
336 //CPU/MEM begin |
|
337 mResMon->BeginMeasureCPULoad(); |
|
338 mResMon->BeginMeasureMemoryLoad(); |
|
339 } |
|
340 |
|
341 QTime t; |
|
342 t.start(); |
|
343 for (int i=0; i<itemCount; ++i ) |
|
344 list->insertItem(0, newRecyclingListItem(mDataGenerator, i)); |
|
345 int took = t.elapsed(); |
|
346 |
|
347 if(mResMon && mCpuMemLogging) { |
|
348 //CPU/MEM end |
|
349 createCpuBenchmark(testFunctionResult, tag, itemCount, Benchmark::RecyclingListType,Theme::p()->currentThemeName(), mResMon->EndMeasureCPULoad()); |
|
350 createMemoryBenchmark(testFunctionResult, tag, itemCount, Benchmark::RecyclingListType,Theme::p()->currentThemeName(), mResMon->EndMeasureMemoryLoad()); |
|
351 } |
|
352 |
|
353 b->setValue(took); |
|
354 b->setListType(Benchmark::RecyclingListType); |
|
355 } |
|
356 else { |
|
357 SimpleList *list = dynamic_cast<SimpleList*>(tw); |
|
358 if (list) { |
|
359 QString type = list->objectName(); |
|
360 |
|
361 if(mResMon && mCpuMemLogging) { |
|
362 //CPU/MEM begin |
|
363 mResMon->BeginMeasureCPULoad(); |
|
364 mResMon->BeginMeasureMemoryLoad(); |
|
365 } |
|
366 |
|
367 QTime t; |
|
368 t.start(); |
|
369 for (int i=0; i<itemCount; ++i ) |
|
370 list->insertItem(0,newSimpleListItem(mDataGenerator, i)); |
|
371 int took = t.elapsed(); |
|
372 |
|
373 if(mResMon && mCpuMemLogging) { |
|
374 //CPU/MEM end |
|
375 createCpuBenchmark(testFunctionResult, tag, itemCount, Benchmark::SimpleListType, Theme::p()->currentThemeName(), mResMon->EndMeasureCPULoad()); |
|
376 createMemoryBenchmark(testFunctionResult, tag, itemCount, Benchmark::SimpleListType, Theme::p()->currentThemeName(), mResMon->EndMeasureMemoryLoad()); |
|
377 } |
|
378 |
|
379 b->setValue(took); |
|
380 b->setListType(Benchmark::SimpleListType); |
|
381 } |
|
382 } |
|
383 |
|
384 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
385 } |
|
386 |
|
387 void TestController::removeFromBeginningOfList(int itemCount, TestFunctionResult *testFunctionResult, const QString &tag) |
|
388 { |
|
389 if (!mMainView) { |
|
390 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
391 return; |
|
392 } |
|
393 |
|
394 Benchmark *b = testFunctionResult->createBenchmark(); |
|
395 b->setTag(tag); |
|
396 b->setRotation(mainWindowRotationAngle()); |
|
397 b->setListSize(itemCount); |
|
398 b->setUseListItemCache(mSubtreeCacheEnabled); |
|
399 b->setImageBasedRendering(mMainView->imageBasedRendering()); |
|
400 b->setTheme(Theme::p()->currentThemeName()); |
|
401 b->setWidth(mMainView->size().width()); |
|
402 b->setHeight(mMainView->size().height()); |
|
403 |
|
404 QGraphicsWidget *tw = mMainView->testWidget(); |
|
405 ItemRecyclingList *list = dynamic_cast<ItemRecyclingList *>(tw); |
|
406 |
|
407 if (list) { |
|
408 QString type = list->objectName(); |
|
409 |
|
410 if(mResMon && mCpuMemLogging) { |
|
411 //CPU/MEM begin |
|
412 mResMon->BeginMeasureCPULoad(); |
|
413 mResMon->BeginMeasureMemoryLoad(); |
|
414 } |
|
415 |
|
416 QTime t; |
|
417 t.start(); |
|
418 |
|
419 for (int i=0; i<itemCount; ++i) |
|
420 delete list->takeItem(0); |
|
421 |
|
422 int took = t.elapsed(); |
|
423 |
|
424 if(mResMon && mCpuMemLogging) { |
|
425 //CPU/MEM end |
|
426 createCpuBenchmark(testFunctionResult, tag, itemCount, Benchmark::RecyclingListType,Theme::p()->currentThemeName(), mResMon->EndMeasureCPULoad()); |
|
427 createMemoryBenchmark(testFunctionResult, tag, itemCount, Benchmark::RecyclingListType, Theme::p()->currentThemeName(), mResMon->EndMeasureMemoryLoad()); |
|
428 } |
|
429 |
|
430 b->setValue(took); |
|
431 b->setListType(Benchmark::RecyclingListType); |
|
432 } |
|
433 else { |
|
434 SimpleList *list = dynamic_cast<SimpleList*>(tw); |
|
435 if (list) { |
|
436 QString type = list->objectName(); |
|
437 |
|
438 if(mResMon && mCpuMemLogging) { |
|
439 //CPU/MEM begin |
|
440 mResMon->BeginMeasureCPULoad(); |
|
441 mResMon->BeginMeasureMemoryLoad(); |
|
442 } |
|
443 |
|
444 QTime t; |
|
445 t.start(); |
|
446 |
|
447 for (int i=0; i<itemCount; ++i) |
|
448 delete list->takeItem(0); |
|
449 |
|
450 int took = t.elapsed(); |
|
451 |
|
452 if(mResMon && mCpuMemLogging) { |
|
453 //CPU/MEM end |
|
454 createCpuBenchmark(testFunctionResult, tag, itemCount, Benchmark::SimpleListType, Theme::p()->currentThemeName(), mResMon->EndMeasureCPULoad()); |
|
455 createMemoryBenchmark(testFunctionResult, tag, itemCount, Benchmark::SimpleListType,Theme::p()->currentThemeName(), mResMon->EndMeasureMemoryLoad()); |
|
456 } |
|
457 |
|
458 b->setValue(took); |
|
459 b->setListType(Benchmark::SimpleListType); |
|
460 } |
|
461 } |
|
462 |
|
463 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
464 } |
|
465 |
|
466 |
|
467 |
|
468 void TestController::themeChange(int theme, TestFunctionResult *testFunctionResult, const QString &tag) |
|
469 { |
|
470 if (!mMainView) { |
|
471 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
472 return; |
|
473 } |
|
474 |
|
475 QString listName = ""; |
|
476 int itemCount = 0; |
|
477 Benchmark::ListType type = Benchmark::ListTypeNone; |
|
478 |
|
479 QGraphicsWidget *tw = mMainView->testWidget(); |
|
480 ItemRecyclingList *list = dynamic_cast<ItemRecyclingList *>(tw); |
|
481 if (list) { |
|
482 type = Benchmark::RecyclingListType; |
|
483 itemCount = list->indexCount(); |
|
484 } |
|
485 else { |
|
486 SimpleList *list = dynamic_cast<SimpleList*>(tw); |
|
487 if (list) { |
|
488 type = Benchmark::SimpleListType; |
|
489 itemCount = list->itemCount(); |
|
490 } |
|
491 else { |
|
492 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
493 return; |
|
494 } |
|
495 } |
|
496 |
|
497 Benchmark *b = testFunctionResult->createBenchmark(); |
|
498 b->setTag(tag); |
|
499 b->setTheme(Theme::p()->currentThemeName()); |
|
500 |
|
501 //CPU/MEM begin |
|
502 QString currentTheme = Theme::p()->currentThemeName(); |
|
503 if(mResMon && mCpuMemLogging) { |
|
504 mResMon->BeginMeasureCPULoad(); |
|
505 mResMon->BeginMeasureMemoryLoad(); |
|
506 } |
|
507 |
|
508 QTime t; |
|
509 t.start(); |
|
510 Theme::p()->setTheme(Theme::Themes(theme)); |
|
511 int took = t.elapsed(); |
|
512 b->setValue(took); |
|
513 b->setRotation(mainWindowRotationAngle()); |
|
514 b->setListType(type); |
|
515 b->setListSize(itemCount); |
|
516 b->setUseListItemCache(mSubtreeCacheEnabled); |
|
517 b->setImageBasedRendering(mMainView->imageBasedRendering()); |
|
518 b->setWidth(mMainView->size().width()); |
|
519 b->setHeight(mMainView->size().height()); |
|
520 |
|
521 if(mResMon && mCpuMemLogging) { |
|
522 //CPU/MEM end |
|
523 createCpuBenchmark(testFunctionResult, tag, itemCount, type, currentTheme, mResMon->EndMeasureCPULoad()); |
|
524 createMemoryBenchmark(testFunctionResult, tag, itemCount, type,currentTheme, mResMon->EndMeasureMemoryLoad()); |
|
525 } |
|
526 |
|
527 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
528 } |
|
529 |
|
530 void TestController::forceUpdate(int maxTimeMs, TestFunctionResult *testFunctionResult, const QString &tag) |
|
531 { |
|
532 if (!mMainView) { |
|
533 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
534 return; |
|
535 } |
|
536 |
|
537 QGraphicsWidget *tw = mMainView->testWidget(); |
|
538 ItemRecyclingList *list = dynamic_cast<ItemRecyclingList *>(tw); |
|
539 if (list) { |
|
540 mCurrentRecyclingList = list; |
|
541 } |
|
542 else { |
|
543 SimpleList *list = dynamic_cast<SimpleList*>(tw); |
|
544 if (list) { |
|
545 mCurrentSimpleList = list; |
|
546 } |
|
547 else { |
|
548 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
549 } |
|
550 } |
|
551 connect(this, SIGNAL(doForceUpdate(TestFunctionResult*, const QString &)), |
|
552 this, SLOT(doForceUpdateViewport(TestFunctionResult*, const QString &)), Qt::QueuedConnection); |
|
553 mMaxTestDurationTime = maxTimeMs; |
|
554 mMainView->fpsReset(); |
|
555 mTestDuration.start(); |
|
556 |
|
557 emit doForceUpdate(testFunctionResult, tag); |
|
558 } |
|
559 |
|
560 void TestController::applicationExit() |
|
561 { |
|
562 QApplication::exit(); |
|
563 } |
|
564 |
|
565 void TestController::deleteList(TestFunctionResult *testFunctionResult, const QString &tag) |
|
566 { |
|
567 Benchmark *b = testFunctionResult->createBenchmark(); |
|
568 b->setTag(tag); |
|
569 b->setRotation(mainWindowRotationAngle()); |
|
570 b->setUseListItemCache(mSubtreeCacheEnabled); |
|
571 b->setImageBasedRendering(mMainView->imageBasedRendering()); |
|
572 b->setTheme(Theme::p()->currentThemeName()); |
|
573 b->setWidth(mMainView->size().width()); |
|
574 b->setHeight(mMainView->size().height()); |
|
575 |
|
576 int itemCount = 0; |
|
577 QGraphicsWidget *tw = mMainView->takeTestWidget(); |
|
578 ItemRecyclingList *list = dynamic_cast<ItemRecyclingList *>(tw); |
|
579 if (list) { |
|
580 itemCount = list->indexCount(); |
|
581 |
|
582 if(mResMon && mCpuMemLogging) { |
|
583 //CPU/MEM begin |
|
584 mResMon->BeginMeasureCPULoad(); |
|
585 mResMon->BeginMeasureMemoryLoad(); |
|
586 } |
|
587 |
|
588 QTime t; |
|
589 t.start(); |
|
590 delete list; |
|
591 int took = t.elapsed(); |
|
592 b->setValue(took); |
|
593 b->setListSize(itemCount); |
|
594 b->setListType(Benchmark::RecyclingListType); |
|
595 |
|
596 if(mResMon && mCpuMemLogging) { |
|
597 //CPU/MEM end |
|
598 createCpuBenchmark(testFunctionResult, tag, itemCount, Benchmark::RecyclingListType,Theme::p()->currentThemeName(), mResMon->EndMeasureCPULoad()); |
|
599 createMemoryBenchmark(testFunctionResult, tag, itemCount, Benchmark::RecyclingListType,Theme::p()->currentThemeName(), mResMon->EndMeasureMemoryLoad()); |
|
600 } |
|
601 |
|
602 } |
|
603 else { |
|
604 SimpleList *list = dynamic_cast<SimpleList*>(tw); |
|
605 if (list) { |
|
606 itemCount = list->itemCount(); |
|
607 |
|
608 if(mResMon && mCpuMemLogging) { |
|
609 //CPU/MEM begin |
|
610 mResMon->BeginMeasureCPULoad(); |
|
611 mResMon->BeginMeasureMemoryLoad(); |
|
612 } |
|
613 |
|
614 QTime t; |
|
615 t.start(); |
|
616 delete list; |
|
617 int took = t.elapsed(); |
|
618 b->setValue(took); |
|
619 b->setListSize(itemCount); |
|
620 b->setListType(Benchmark::SimpleListType); |
|
621 |
|
622 if(mResMon && mCpuMemLogging) { |
|
623 //CPU/MEM end |
|
624 createCpuBenchmark(testFunctionResult, tag, itemCount, Benchmark::SimpleListType,Theme::p()->currentThemeName(), mResMon->EndMeasureCPULoad()); |
|
625 createMemoryBenchmark(testFunctionResult, tag, itemCount, Benchmark::SimpleListType,Theme::p()->currentThemeName(), mResMon->EndMeasureMemoryLoad()); |
|
626 } |
|
627 } |
|
628 } |
|
629 |
|
630 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
631 } |
|
632 |
|
633 void TestController::scrollSimpleList(TestFunctionResult *testFunctionResult, const QString &tag) |
|
634 { |
|
635 int elapsed = mTestDuration.elapsed(); |
|
636 if(!mCurrentSimpleList || |
|
637 elapsed > mMaxTestDurationTime) { |
|
638 if (mMainView) { |
|
639 qreal fps = mMainView->fps(); |
|
640 |
|
641 Benchmark *b = testFunctionResult->createBenchmark(); |
|
642 b->setTag(tag); |
|
643 b->setValue(fps); |
|
644 if (mCurrentSimpleList) |
|
645 b->setListSize(mCurrentSimpleList->itemCount()); |
|
646 b->setRotation(mainWindowRotationAngle()); |
|
647 b->setImageBasedRendering(mMainView->imageBasedRendering()); |
|
648 b->setTheme(Theme::p()->currentThemeName()); |
|
649 b->setUseListItemCache(mSubtreeCacheEnabled); |
|
650 b->setListType(Benchmark::SimpleListType); |
|
651 b->setWidth(mMainView->size().width()); |
|
652 b->setHeight(mMainView->size().height()); |
|
653 |
|
654 if(mResMon && mCpuMemLogging) { |
|
655 //CPU/MEM end |
|
656 createCpuBenchmark(testFunctionResult, tag, mCurrentSimpleList->itemCount(), Benchmark::SimpleListType,Theme::p()->currentThemeName(), mResMon->EndMeasureCPULoad()); |
|
657 createMemoryBenchmark(testFunctionResult, tag, mCurrentSimpleList->itemCount(), Benchmark::SimpleListType,Theme::p()->currentThemeName(), mResMon->EndMeasureMemoryLoad()); |
|
658 } |
|
659 } |
|
660 disconnect(SIGNAL(doScrollSimpleList(TestFunctionResult*, const QString &)), |
|
661 this, SLOT(scrollSimpleList(TestFunctionResult*, const QString &))); |
|
662 |
|
663 if (mCurrentSimpleList) { // Scroll to begin before next case. |
|
664 ScrollBar *sb = mCurrentSimpleList->verticalScrollBar(); |
|
665 |
|
666 if (sb) { |
|
667 sb->setSliderPosition(0); |
|
668 } |
|
669 } |
|
670 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
671 return; |
|
672 } |
|
673 |
|
674 ScrollBar *sb = mCurrentSimpleList->verticalScrollBar(); |
|
675 |
|
676 if (sb) { |
|
677 int sinceLast = elapsed - mLastElapsed; |
|
678 qreal sliderSize = sb->sliderSize(); |
|
679 qreal currentVal = sb->sliderPosition(); |
|
680 qreal increment = (mScrollDirection*mScrollStep*sinceLast)/16.6666; // Targeting 1.0 = 1 per 60FPS frame |
|
681 qreal target = currentVal + increment; |
|
682 while (target<0.0 || target>sliderSize) { |
|
683 if (target < 0.0) { |
|
684 target = -target; // Reflect |
|
685 mScrollDirection = -1*mScrollDirection; |
|
686 } |
|
687 else if (target > sliderSize) { |
|
688 target = sliderSize - (target-sliderSize); // Reflect |
|
689 mScrollDirection = -1*mScrollDirection; |
|
690 } |
|
691 } |
|
692 |
|
693 sb->setSliderPosition(target); |
|
694 } |
|
695 |
|
696 mLastElapsed = elapsed; |
|
697 |
|
698 emit doScrollSimpleList(testFunctionResult, tag); |
|
699 } |
|
700 |
|
701 void TestController::scrollRecyclingList(TestFunctionResult *testFunctionResult, const QString &tag) |
|
702 { |
|
703 int elapsed = mTestDuration.elapsed(); |
|
704 if(!mCurrentRecyclingList || |
|
705 elapsed > mMaxTestDurationTime) { |
|
706 if (mMainView) { |
|
707 qreal fps = mMainView->fps(); |
|
708 |
|
709 Benchmark *b = testFunctionResult->createBenchmark(); |
|
710 b->setTag(tag); |
|
711 b->setValue(fps); |
|
712 if (mCurrentRecyclingList) |
|
713 b->setListSize(mCurrentRecyclingList->indexCount()); |
|
714 b->setRotation(mainWindowRotationAngle()); |
|
715 b->setImageBasedRendering(mMainView->imageBasedRendering()); |
|
716 b->setTheme(Theme::p()->currentThemeName()); |
|
717 b->setUseListItemCache(mSubtreeCacheEnabled); |
|
718 b->setListType(Benchmark::RecyclingListType); |
|
719 b->setWidth(mMainView->size().width()); |
|
720 b->setHeight(mMainView->size().height()); |
|
721 |
|
722 if(mResMon && mCpuMemLogging) { |
|
723 //CPU/MEM end |
|
724 createCpuBenchmark(testFunctionResult, tag, mCurrentRecyclingList->indexCount(), Benchmark::RecyclingListType,Theme::p()->currentThemeName(), mResMon->EndMeasureCPULoad()); |
|
725 createMemoryBenchmark(testFunctionResult, tag, mCurrentRecyclingList->indexCount(), Benchmark::RecyclingListType,Theme::p()->currentThemeName(), mResMon->EndMeasureMemoryLoad()); |
|
726 } |
|
727 |
|
728 } |
|
729 disconnect(SIGNAL(doScrollRecyclingList(TestFunctionResult*, const QString &)), |
|
730 this, SLOT(scrollRecyclingList(TestFunctionResult*, const QString &))); |
|
731 |
|
732 if (mCurrentRecyclingList) { // Scroll to begin before next case. |
|
733 ScrollBar *sb = mCurrentRecyclingList->verticalScrollBar(); |
|
734 |
|
735 if (sb) { |
|
736 sb->setSliderPosition(0); |
|
737 } |
|
738 } |
|
739 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
740 return; |
|
741 } |
|
742 |
|
743 ScrollBar *sb = mCurrentRecyclingList->verticalScrollBar(); |
|
744 |
|
745 if (sb) { |
|
746 int sinceLast = elapsed - mLastElapsed; |
|
747 qreal sliderSize = sb->sliderSize(); |
|
748 qreal currentVal = sb->sliderPosition(); |
|
749 qreal increment = (mScrollDirection*mScrollStep*sinceLast)/16.6666; // Targeting 1.0 = 1 per 60FPS frame |
|
750 qreal target = currentVal + increment; |
|
751 while (target<0.0 || target>sliderSize) { |
|
752 if (target < 0.0) { |
|
753 target = -target; // Reflect |
|
754 mScrollDirection = -1*mScrollDirection; |
|
755 } |
|
756 else if (target > sliderSize) { |
|
757 target = sliderSize - (target-sliderSize); // Reflect |
|
758 mScrollDirection = -1*mScrollDirection; |
|
759 } |
|
760 } |
|
761 |
|
762 sb->setSliderPosition(target); |
|
763 } |
|
764 |
|
765 mLastElapsed = elapsed; |
|
766 |
|
767 emit doScrollRecyclingList(testFunctionResult, tag); |
|
768 } |
|
769 |
|
770 void TestController::doForceUpdateViewport(TestFunctionResult *testFunctionResult, const QString &tag) |
|
771 { |
|
772 if (mTestDuration.elapsed() > mMaxTestDurationTime) { |
|
773 if (mMainView) { |
|
774 qreal fps = mMainView->fps(); |
|
775 Benchmark::ListType type = Benchmark::ListTypeNone; |
|
776 int items = 0; |
|
777 |
|
778 QGraphicsWidget *tw = mMainView->testWidget(); |
|
779 ItemRecyclingList *list = dynamic_cast<ItemRecyclingList *>(tw); |
|
780 if (list) { |
|
781 type = Benchmark::RecyclingListType; |
|
782 items = list->indexCount(); |
|
783 } |
|
784 else { |
|
785 SimpleList *list = dynamic_cast<SimpleList*>(tw); |
|
786 if (list) { |
|
787 type = Benchmark::SimpleListType; |
|
788 items = list->itemCount(); |
|
789 } |
|
790 } |
|
791 Benchmark *b = testFunctionResult->createBenchmark(); |
|
792 b->setTag(tag); |
|
793 b->setValue(fps); |
|
794 b->setRotation(mainWindowRotationAngle()); |
|
795 b->setListSize(items); |
|
796 b->setImageBasedRendering(mMainView->imageBasedRendering()); |
|
797 b->setTheme(Theme::p()->currentThemeName()); |
|
798 b->setUseListItemCache(mSubtreeCacheEnabled); |
|
799 b->setListType(type); |
|
800 b->setWidth(mMainView->size().width()); |
|
801 b->setHeight(mMainView->size().height()); |
|
802 |
|
803 mMainView->fpsReset(); |
|
804 } |
|
805 disconnect(SIGNAL(doForceUpdate(TestFunctionResult*, const QString &)), |
|
806 this, SLOT(doForceUpdateViewport(TestFunctionResult*, const QString &))); |
|
807 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
808 return; |
|
809 } |
|
810 else if (mMainView) { |
|
811 mMainView->viewport()->update(); |
|
812 emit doForceUpdate(testFunctionResult, tag); |
|
813 return; |
|
814 } |
|
815 else { |
|
816 mMainView->fpsReset(); |
|
817 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
818 return; |
|
819 } |
|
820 } |
|
821 |
|
822 void TestController::setImageBasedRendering(const bool imageBasedRendering) |
|
823 { |
|
824 if (mMainView) |
|
825 mMainView->setImageBasedRendering(imageBasedRendering); |
|
826 } |
|
827 bool TestController::imageBasedRendering() const |
|
828 { |
|
829 if (mMainView) |
|
830 return mMainView->imageBasedRendering(); |
|
831 return false; |
|
832 } |
|
833 |
|
834 void TestController::setTwoColumns(const bool twoCols) |
|
835 { |
|
836 QGraphicsWidget *tw = mMainView->testWidget(); |
|
837 ItemRecyclingList *list = dynamic_cast<ItemRecyclingList *>(tw); |
|
838 if (list) { |
|
839 list->setTwoColumns(twoCols); |
|
840 } |
|
841 else { |
|
842 SimpleList *list = dynamic_cast<SimpleList*>(tw); |
|
843 if (list) { |
|
844 list->setTwoColumns(twoCols); |
|
845 } |
|
846 } |
|
847 |
|
848 QTimer::singleShot(EmitDoneTimeout, this, SLOT(testIsDone())); |
|
849 } |
|
850 |
|
851 bool TestController::twoColumns() const |
|
852 { |
|
853 QGraphicsWidget *tw = mMainView->takeTestWidget(); |
|
854 ItemRecyclingList *list = dynamic_cast<ItemRecyclingList *>(tw); |
|
855 if (list) { |
|
856 return list->twoColumns(); |
|
857 } |
|
858 else { |
|
859 SimpleList *list = dynamic_cast<SimpleList*>(tw); |
|
860 if (list) |
|
861 return list->twoColumns(); |
|
862 } |
|
863 return false; |
|
864 } |
|
865 |
|
866 bool TestController::loadPlugin() |
|
867 { |
|
868 QDir pluginsDir(qApp->applicationDirPath()); |
|
869 #if defined Q_OS_LINUX |
|
870 pluginsDir.cdUp(); |
|
871 pluginsDir.cd("plugins"); |
|
872 #endif |
|
873 foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { |
|
874 QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); |
|
875 QObject *plugin = pluginLoader.instance(); |
|
876 if (plugin) { |
|
877 mResMon = qobject_cast<ResourceMonitorInterface *>(plugin); |
|
878 if (mResMon) |
|
879 return true; |
|
880 } |
|
881 else { |
|
882 qDebug() << "Error while loading plugin: " |
|
883 << pluginsDir.absoluteFilePath(fileName) |
|
884 << ". Error: " << pluginLoader.errorString(); |
|
885 } |
|
886 } |
|
887 return false; |
|
888 } |
|
889 |
|
890 void TestController::createCpuBenchmark(TestFunctionResult *testFunctionResult, const QString &tag, int listItems, Benchmark::ListType type, const QString &theme, ResourceMonitorInterface::CpuUsage cpuUsage) |
|
891 { |
|
892 Benchmark* bThread = testFunctionResult->createBenchmark(); |
|
893 Benchmark* bSystem = testFunctionResult->createBenchmark(); |
|
894 |
|
895 bThread->setTag(QString("CPU AppThread " + tag)); |
|
896 bThread->setRotation(mainWindowRotationAngle()); |
|
897 bThread->setListSize(listItems); |
|
898 bThread->setListType(type); |
|
899 bThread->setTheme(theme); |
|
900 bThread->setValue(cpuUsage.appTreadUsage); |
|
901 bThread->setWidth(mMainView->size().width()); |
|
902 bThread->setHeight(mMainView->size().height()); |
|
903 bSystem->setTag(QString("CPU System " + tag)); |
|
904 bSystem->setRotation(mainWindowRotationAngle()); |
|
905 bSystem->setListSize(listItems); |
|
906 bSystem->setListType(type); |
|
907 bSystem->setTheme(theme); |
|
908 bSystem->setValue(cpuUsage.systemUsage); |
|
909 bSystem->setWidth(mMainView->size().width()); |
|
910 bSystem->setHeight(mMainView->size().height()); |
|
911 } |
|
912 |
|
913 void TestController::createMemoryBenchmark(TestFunctionResult *testFunctionResult, const QString &tag, int listItems, Benchmark::ListType type, const QString &theme, ResourceMonitorInterface::MemoryAllocation allocation) |
|
914 { |
|
915 Benchmark* bAllocated = testFunctionResult->createBenchmark(); |
|
916 Benchmark* bAppHeap = testFunctionResult->createBenchmark(); |
|
917 Benchmark* bAvailableSystem = testFunctionResult->createBenchmark(); |
|
918 |
|
919 bAllocated->setTag(QString("Memory AppAllocInCells " + tag)); |
|
920 bAllocated->setRotation(mainWindowRotationAngle()); |
|
921 bAllocated->setListSize(listItems); |
|
922 bAllocated->setListType(type); |
|
923 bAllocated->setTheme(theme); |
|
924 bAllocated->setUseListItemCache(mSubtreeCacheEnabled); |
|
925 if (mMainView) |
|
926 bAllocated->setImageBasedRendering(mMainView->imageBasedRendering()); |
|
927 bAllocated->setValue(allocation.allocatedInAppThread); |
|
928 bAllocated->setWidth(mMainView->size().width()); |
|
929 bAllocated->setHeight(mMainView->size().height()); |
|
930 bAppHeap->setTag(QString("Memory AvailAppHeap " + tag)); |
|
931 bAppHeap->setRotation(mainWindowRotationAngle()); |
|
932 bAppHeap->setListSize(listItems); |
|
933 bAppHeap->setListType(type); |
|
934 bAppHeap->setTheme(theme); |
|
935 bAppHeap->setUseListItemCache(mSubtreeCacheEnabled); |
|
936 if (mMainView) |
|
937 bAppHeap->setImageBasedRendering(mMainView->imageBasedRendering()); |
|
938 bAppHeap->setValue(allocation.availableMemoryInAppThreadHeap); |
|
939 bAppHeap->setWidth(mMainView->size().width()); |
|
940 bAppHeap->setHeight(mMainView->size().height()); |
|
941 bAvailableSystem->setTag(QString("Memory AvailSystem " + tag)); |
|
942 bAvailableSystem->setRotation(mainWindowRotationAngle()); |
|
943 bAvailableSystem->setListSize(listItems); |
|
944 bAvailableSystem->setListType(type); |
|
945 bAvailableSystem->setTheme(theme); |
|
946 bAvailableSystem->setUseListItemCache(mSubtreeCacheEnabled); |
|
947 if (mMainView) |
|
948 bAvailableSystem->setImageBasedRendering(mMainView->imageBasedRendering()); |
|
949 bAvailableSystem->setValue(allocation.availableMemoryInSystem); |
|
950 bAvailableSystem->setWidth(mMainView->size().width()); |
|
951 bAvailableSystem->setHeight(mMainView->size().height()); |
|
952 } |
|
953 |