author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
child 5 | d3bac044e0f0 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the tools applications of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtGui> |
|
43 |
#include <QtDebug> |
|
44 |
||
45 |
#include <private/qpaintengineex_p.h> |
|
46 |
#include <private/qpaintbuffer_p.h> |
|
47 |
||
48 |
class ReplayWidget : public QWidget |
|
49 |
{ |
|
50 |
Q_OBJECT |
|
51 |
public: |
|
52 |
ReplayWidget(const QString &filename); |
|
53 |
||
54 |
void paintEvent(QPaintEvent *event); |
|
55 |
||
56 |
public slots: |
|
57 |
void updateRect(); |
|
58 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
59 |
public: |
0 | 60 |
QList<QRegion> updates; |
61 |
QPaintBuffer buffer; |
|
62 |
||
63 |
int currentFrame; |
|
64 |
int currentIteration; |
|
65 |
QTime timer; |
|
66 |
||
67 |
QList<uint> iterationTimes; |
|
68 |
QString filename; |
|
69 |
}; |
|
70 |
||
71 |
void ReplayWidget::updateRect() |
|
72 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
if (!updates.isEmpty()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
update(updates.at(currentFrame)); |
0 | 75 |
} |
76 |
||
77 |
void ReplayWidget::paintEvent(QPaintEvent *) |
|
78 |
{ |
|
79 |
QPainter p(this); |
|
80 |
||
81 |
// p.setClipRegion(frames.at(currentFrame).updateRegion); |
|
82 |
||
83 |
buffer.draw(&p, currentFrame); |
|
84 |
||
85 |
++currentFrame; |
|
86 |
if (currentFrame >= buffer.numFrames()) { |
|
87 |
currentFrame = 0; |
|
88 |
++currentIteration; |
|
89 |
||
90 |
if (currentIteration == 3) |
|
91 |
timer.start(); |
|
92 |
else if (currentIteration > 3) { |
|
93 |
iterationTimes << timer.elapsed(); |
|
94 |
timer.restart(); |
|
95 |
||
96 |
if (iterationTimes.size() >= 3) { |
|
97 |
qreal mean = 0; |
|
98 |
qreal stddev = 0; |
|
99 |
uint min = INT_MAX; |
|
100 |
||
101 |
for (int i = 0; i < iterationTimes.size(); ++i) { |
|
102 |
mean += iterationTimes.at(i); |
|
103 |
min = qMin(min, iterationTimes.at(i)); |
|
104 |
} |
|
105 |
||
106 |
mean /= qreal(iterationTimes.size()); |
|
107 |
||
108 |
for (int i = 0; i < iterationTimes.size(); ++i) { |
|
109 |
qreal delta = iterationTimes.at(i) - mean; |
|
110 |
stddev += delta * delta; |
|
111 |
} |
|
112 |
||
113 |
stddev = qSqrt(stddev / iterationTimes.size()); |
|
114 |
||
115 |
qSort(iterationTimes.begin(), iterationTimes.end()); |
|
116 |
uint median = iterationTimes.at(iterationTimes.size() / 2); |
|
117 |
||
118 |
stddev = 100 * stddev / mean; |
|
119 |
||
120 |
if (iterationTimes.size() >= 10 || stddev < 4) { |
|
121 |
printf("%s, iterations: %d, frames: %d, min(ms): %d, median(ms): %d, stddev: %f %%, max(fps): %f\n", qPrintable(filename), |
|
122 |
iterationTimes.size(), updates.size(), min, median, stddev, 1000. * updates.size() / min); |
|
123 |
deleteLater(); |
|
124 |
return; |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
QTimer::singleShot(0, this, SLOT(updateRect())); |
|
131 |
} |
|
132 |
||
133 |
ReplayWidget::ReplayWidget(const QString &filename_) |
|
134 |
: currentFrame(0) |
|
135 |
, currentIteration(0) |
|
136 |
, filename(filename_) |
|
137 |
{ |
|
138 |
setWindowTitle(filename); |
|
139 |
QFile file(filename); |
|
140 |
||
141 |
QRect bounds; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
if (!file.open(QIODevice::ReadOnly)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
printf("Failed to load input file '%s'\n", qPrintable(filename_)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
return; |
0 | 145 |
} |
146 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
QDataStream in(&file); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
char *data; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
uint size; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
in.readBytes(data, size); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
bool isTraceFile = size == 7 && qstrncmp(data, "qttrace", 7) == 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
delete [] data; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
if (!isTraceFile) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
printf("File '%s' is not a trace file\n", qPrintable(filename_)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
in >> buffer >> updates; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
printf("Read paint buffer with %d frames\n", buffer.numFrames()); |
0 | 161 |
|
162 |
resize(buffer.boundingRect().size().toSize()); |
|
163 |
||
164 |
setAutoFillBackground(false); |
|
165 |
setAttribute(Qt::WA_NoSystemBackground); |
|
166 |
||
167 |
QTimer::singleShot(10, this, SLOT(updateRect())); |
|
168 |
} |
|
169 |
||
170 |
int main(int argc, char **argv) |
|
171 |
{ |
|
172 |
QApplication app(argc, argv); |
|
173 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
if (argc <= 1 || qstrcmp(argv[1], "-h") == 0 || qstrcmp(argv[1], "--help") == 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
printf("Replays a tracefile generated with '-graphicssystem trace'\n"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
printf("Usage:\n > %s [traceFile]\n", argv[0]); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
return 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
QFile file(argv[1]); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
if (!file.exists()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
printf("%s does not exist\n", argv[1]); |
0 | 183 |
return 1; |
184 |
} |
|
185 |
||
186 |
ReplayWidget *widget = new ReplayWidget(argv[1]); |
|
187 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
if (!widget->updates.isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
widget->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
return app.exec(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
|
0 | 193 |
} |
194 |
#include "main.moc" |