Line | Source | Count |
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 | #include <QtTest/qbenchmark.h> | - |
41 | #include <QtTest/private/qbenchmark_p.h> | - |
42 | #include <QtTest/private/qbenchmarkmetric_p.h> | - |
43 | | - |
44 | #include <QtCore/qprocess.h> | - |
45 | #include <QtCore/qdir.h> | - |
46 | #include <QtCore/qset.h> | - |
47 | #include <QtCore/qdebug.h> | - |
48 | | - |
49 | QT_BEGIN_NAMESPACE | - |
50 | | - |
51 | QBenchmarkGlobalData *QBenchmarkGlobalData::current; | - |
52 | | - |
53 | QBenchmarkGlobalData::QBenchmarkGlobalData() | - |
54 | : measurer(0) | - |
55 | , walltimeMinimum(-1) | - |
56 | , iterationCount(-1) | - |
57 | , medianIterationCount(-1) | - |
58 | , createChart(false) | - |
59 | , verboseOutput(false) | - |
60 | , minimumTotal(-1) | - |
61 | , mode_(WallTime) | - |
62 | { | - |
63 | setMode(mode_); | - |
64 | } | - |
65 | | - |
66 | QBenchmarkGlobalData::~QBenchmarkGlobalData() | - |
67 | { | - |
68 | delete measurer; | - |
69 | QBenchmarkGlobalData::current = 0; | - |
70 | } | - |
71 | | - |
72 | void QBenchmarkGlobalData::setMode(Mode mode) | - |
73 | { | - |
74 | mode_ = mode; | - |
75 | | - |
76 | if (measurer) | - |
77 | delete measurer; | - |
78 | measurer = createMeasurer(); | - |
79 | } | - |
80 | | - |
81 | QBenchmarkMeasurerBase * QBenchmarkGlobalData::createMeasurer() | - |
82 | { | - |
83 | QBenchmarkMeasurerBase *measurer = 0; | - |
84 | if (0) { dead code: { } | - |
85 | #ifdef QTESTLIB_USE_VALGRIND dead code: { } | - |
86 | } else if (mode_ == CallgrindChildProcess || mode_ == CallgrindParentProcess) { dead code: { } | - |
87 | measurer = new QBenchmarkCallgrindMeasurer; | - |
88 | #endif | - |
89 | #ifdef QTESTLIB_USE_PERF_EVENTS | - |
90 | } else if (mode_ == PerfCounter) { | - |
91 | measurer = new QBenchmarkPerfEventsMeasurer; | - |
92 | #endif | - |
93 | #ifdef HAVE_TICK_COUNTER | - |
94 | } else if (mode_ == TickCounter) { | - |
95 | measurer = new QBenchmarkTickMeasurer; | - |
96 | #endif | - |
97 | } else if (mode_ == EventCounter) { | - |
98 | measurer = new QBenchmarkEvent; | - |
99 | } else { | - |
100 | measurer = new QBenchmarkTimeMeasurer; | - |
101 | } | - |
102 | measurer->init(); | - |
103 | return measurer; | - |
104 | } | - |
105 | | - |
106 | int QBenchmarkGlobalData::adjustMedianIterationCount() | - |
107 | { | - |
108 | if (medianIterationCount != -1) { | - |
109 | return medianIterationCount; | - |
110 | } else { | - |
111 | return measurer->adjustMedianCount(1); | - |
112 | } | - |
113 | } | - |
114 | | - |
115 | | - |
116 | QBenchmarkTestMethodData *QBenchmarkTestMethodData::current; | - |
117 | | - |
118 | QBenchmarkTestMethodData::QBenchmarkTestMethodData() | - |
119 | :resultAccepted(false), runOnce(false), iterationCount(-1) | - |
120 | { | - |
121 | } | - |
122 | | - |
123 | QBenchmarkTestMethodData::~QBenchmarkTestMethodData() | - |
124 | { | - |
125 | QBenchmarkTestMethodData::current = 0; | - |
126 | } | - |
127 | | - |
128 | void QBenchmarkTestMethodData::beginDataRun() | - |
129 | { | - |
130 | iterationCount = adjustIterationCount(1); | - |
131 | } | - |
132 | | - |
133 | void QBenchmarkTestMethodData::endDataRun() | - |
134 | { | - |
135 | } | - |
136 | | - |
137 | int QBenchmarkTestMethodData::adjustIterationCount(int suggestion) | - |
138 | { | - |
139 | | - |
140 | if (QBenchmarkGlobalData::current->iterationCount != -1) { | - |
141 | iterationCount = QBenchmarkGlobalData::current->iterationCount; | - |
142 | } else { | - |
143 | iterationCount = QBenchmarkGlobalData::current->measurer->adjustIterationCount(suggestion); | - |
144 | } | - |
145 | | - |
146 | return iterationCount; | - |
147 | } | - |
148 | | - |
149 | void QBenchmarkTestMethodData::setResult( | - |
150 | qreal value, QTest::QBenchmarkMetric metric, bool setByMacro) | - |
151 | { | - |
152 | bool accepted = false; | - |
153 | | - |
154 | | - |
155 | | - |
156 | if (QBenchmarkGlobalData::current->iterationCount != -1) | - |
157 | accepted = true; | - |
158 | | - |
159 | else if (QBenchmarkTestMethodData::current->runOnce || !setByMacro) { | - |
160 | iterationCount = 1; | - |
161 | accepted = true; | - |
162 | } | - |
163 | | - |
164 | | - |
165 | | - |
166 | else if (QBenchmarkGlobalData::current->walltimeMinimum != -1) | - |
167 | accepted = (value > QBenchmarkGlobalData::current->walltimeMinimum); | - |
168 | else | - |
169 | accepted = QBenchmarkGlobalData::current->measurer->isMeasurementAccepted(value); | - |
170 | | - |
171 | | - |
172 | if (accepted) | - |
173 | resultAccepted = true; | - |
174 | else | - |
175 | iterationCount *= 2; | - |
176 | | - |
177 | this->result = QBenchmarkResult( | - |
178 | QBenchmarkGlobalData::current->context, value, iterationCount, metric, setByMacro); | - |
179 | } | - |
180 | | - |
181 | | - |
182 | | - |
183 | | - |
184 | | - |
185 | | - |
186 | | - |
187 | | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | QTest::QBenchmarkIterationController::QBenchmarkIterationController(RunMode runMode) | - |
193 | { | - |
194 | i = 0; | - |
195 | if (runMode == RunOnce) | - |
196 | QBenchmarkTestMethodData::current->runOnce = true; | - |
197 | QTest::beginBenchmarkMeasurement(); | - |
198 | } | - |
199 | | - |
200 | QTest::QBenchmarkIterationController::QBenchmarkIterationController() | - |
201 | { | - |
202 | i = 0; | - |
203 | QTest::beginBenchmarkMeasurement(); | - |
204 | } | - |
205 | | - |
206 | | - |
207 | | - |
208 | QTest::QBenchmarkIterationController::~QBenchmarkIterationController() | - |
209 | { | - |
210 | const qreal result = QTest::endBenchmarkMeasurement(); | - |
211 | QBenchmarkTestMethodData::current->setResult(result, QBenchmarkGlobalData::current->measurer->metricType()); | - |
212 | } | - |
213 | | - |
214 | | - |
215 | | - |
216 | bool QTest::QBenchmarkIterationController::isDone() | - |
217 | { | - |
218 | if (QBenchmarkTestMethodData::current->runOnce) | - |
219 | return i > 0; | - |
220 | return i >= QTest::iterationCount(); | - |
221 | } | - |
222 | | - |
223 | | - |
224 | | - |
225 | void QTest::QBenchmarkIterationController::next() | - |
226 | { | - |
227 | ++i; | - |
228 | } | - |
229 | | - |
230 | | - |
231 | | - |
232 | int QTest::iterationCount() | - |
233 | { | - |
234 | return QBenchmarkTestMethodData::current->iterationCount; | - |
235 | } | - |
236 | | - |
237 | | - |
238 | | - |
239 | void QTest::setIterationCountHint(int count) | - |
240 | { | - |
241 | QBenchmarkTestMethodData::current->adjustIterationCount(count); | - |
242 | } | - |
243 | | - |
244 | | - |
245 | | - |
246 | void QTest::setIterationCount(int count) | - |
247 | { | - |
248 | QBenchmarkTestMethodData::current->iterationCount = count; | - |
249 | QBenchmarkTestMethodData::current->resultAccepted = true; | - |
250 | } | - |
251 | | - |
252 | | - |
253 | | - |
254 | void QTest::beginBenchmarkMeasurement() | - |
255 | { | - |
256 | QBenchmarkGlobalData::current->measurer->start(); | - |
257 | | - |
258 | } | - |
259 | | - |
260 | | - |
261 | | - |
262 | quint64 QTest::endBenchmarkMeasurement() | - |
263 | { | - |
264 | | - |
265 | return QBenchmarkGlobalData::current->measurer->stop(); | - |
266 | } | - |
267 | | - |
268 | | - |
269 | | - |
270 | | - |
271 | | - |
272 | | - |
273 | | - |
274 | | - |
275 | | - |
276 | | - |
277 | | - |
278 | | - |
279 | | - |
280 | | - |
281 | | - |
282 | | - |
283 | | - |
284 | | - |
285 | void QTest::setBenchmarkResult(qreal result, QTest::QBenchmarkMetric metric) | - |
286 | { | - |
287 | QBenchmarkTestMethodData::current->setResult(result, metric, false); | - |
288 | } | - |
289 | | - |
290 | template <typename T> | - |
291 | typename T::value_type qAverage(const T &container) | - |
292 | { | - |
293 | typename T::const_iterator it = container.constBegin(); | - |
294 | typename T::const_iterator end = container.constEnd(); | - |
295 | typename T::value_type acc = typename T::value_type(); | - |
296 | int count = 0; | - |
297 | while (it != end) { | - |
298 | acc += *it; | - |
299 | ++it; | - |
300 | ++count; | - |
301 | } | - |
302 | return acc / count; | - |
303 | } | - |
304 | | - |
305 | QT_END_NAMESPACE | - |
| | |