1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtTest module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
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 [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QBENCHMARK_P_H
|
---|
43 | #define QBENCHMARK_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include <QtCore/qglobal.h>
|
---|
57 |
|
---|
58 | #if defined(Q_OS_LINUX) && !defined(QT_NO_PROCESS)
|
---|
59 | #define QTESTLIB_USE_VALGRIND
|
---|
60 | #else
|
---|
61 | #undef QTESTLIB_USE_VALGRIND
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | #include "QtTest/private/qbenchmarkmeasurement_p.h"
|
---|
65 | #include <QtCore/QMap>
|
---|
66 | #include <QtTest/qtest_global.h>
|
---|
67 | #ifdef QTESTLIB_USE_VALGRIND
|
---|
68 | #include "QtTest/private/qbenchmarkvalgrind_p.h"
|
---|
69 | #endif
|
---|
70 | #include "QtTest/private/qbenchmarkevent_p.h"
|
---|
71 |
|
---|
72 | QT_BEGIN_NAMESPACE
|
---|
73 |
|
---|
74 | struct QBenchmarkContext
|
---|
75 | {
|
---|
76 | // None of the strings below are assumed to contain commas (see toString() below)
|
---|
77 | QString slotName;
|
---|
78 | QString tag; // from _data() function
|
---|
79 |
|
---|
80 | int checkpointIndex;
|
---|
81 |
|
---|
82 | QString toString() const
|
---|
83 | {
|
---|
84 | QString s = QString(QLatin1String("%1,%2,%3")).arg(slotName).arg(tag).arg(checkpointIndex);
|
---|
85 | return s;
|
---|
86 | }
|
---|
87 |
|
---|
88 | QBenchmarkContext() : checkpointIndex(-1) {}
|
---|
89 | };
|
---|
90 |
|
---|
91 | class QBenchmarkResult
|
---|
92 | {
|
---|
93 | public:
|
---|
94 | QBenchmarkContext context;
|
---|
95 | qint64 value;
|
---|
96 | int iterations;
|
---|
97 | bool valid;
|
---|
98 |
|
---|
99 | QBenchmarkResult()
|
---|
100 | : value(-1)
|
---|
101 | , iterations(-1)
|
---|
102 | , valid(false)
|
---|
103 | { }
|
---|
104 |
|
---|
105 | QBenchmarkResult(const QBenchmarkContext &context, const qint64 value, const int iterations)
|
---|
106 | : context(context)
|
---|
107 | , value(value)
|
---|
108 | , iterations(iterations)
|
---|
109 | , valid(true)
|
---|
110 | {
|
---|
111 | }
|
---|
112 |
|
---|
113 | bool operator<(const QBenchmarkResult &other) const
|
---|
114 | {
|
---|
115 | return (value / iterations) < (other.value / other.iterations);
|
---|
116 | }
|
---|
117 | };
|
---|
118 |
|
---|
119 | /*
|
---|
120 | The QBenchmarkGlobalData class stores global benchmark-related data.
|
---|
121 | QBenchmarkGlobalData:current is created at the beginning of qExec()
|
---|
122 | and cleared at the end.
|
---|
123 | */
|
---|
124 | class QBenchmarkGlobalData
|
---|
125 | {
|
---|
126 | public:
|
---|
127 | static QBenchmarkGlobalData *current;
|
---|
128 |
|
---|
129 | QBenchmarkGlobalData();
|
---|
130 | ~QBenchmarkGlobalData();
|
---|
131 | enum Mode { WallTime, CallgrindParentProcess, CallgrindChildProcess, TickCounter, EventCounter };
|
---|
132 | void setMode(Mode mode);
|
---|
133 | Mode mode() const { return mode_; }
|
---|
134 | QBenchmarkMeasurerBase *createMeasurer();
|
---|
135 | int adjustMedianIterationCount();
|
---|
136 |
|
---|
137 | QBenchmarkMeasurerBase *measurer;
|
---|
138 | QBenchmarkContext context;
|
---|
139 | int walltimeMinimum;
|
---|
140 | int iterationCount;
|
---|
141 | int medianIterationCount;
|
---|
142 | bool createChart;
|
---|
143 | bool verboseOutput;
|
---|
144 | QString callgrindOutFileBase;
|
---|
145 | private:
|
---|
146 | Mode mode_;
|
---|
147 | };
|
---|
148 |
|
---|
149 | /*
|
---|
150 | The QBenchmarkTestMethodData class stores all benchmark-related data
|
---|
151 | for the current test case. QBenchmarkTestMethodData:current is
|
---|
152 | created at the beginning of qInvokeTestMethod() and cleared at
|
---|
153 | the end.
|
---|
154 | */
|
---|
155 | class QBenchmarkTestMethodData
|
---|
156 | {
|
---|
157 | public:
|
---|
158 | static QBenchmarkTestMethodData *current;
|
---|
159 | QBenchmarkTestMethodData();
|
---|
160 | ~QBenchmarkTestMethodData();
|
---|
161 |
|
---|
162 | // Called once for each data row created by the _data function,
|
---|
163 | // before and after calling the test function itself.
|
---|
164 | void beginDataRun();
|
---|
165 | void endDataRun();
|
---|
166 |
|
---|
167 | bool isBenchmark() const { return result.valid; }
|
---|
168 | bool resultsAccepted() const { return resultAccepted; }
|
---|
169 | int adjustIterationCount(int suggestion);
|
---|
170 | void setResult(qint64 value);
|
---|
171 |
|
---|
172 | QBenchmarkResult result;
|
---|
173 | bool resultAccepted;
|
---|
174 | int iterationCount;
|
---|
175 | };
|
---|
176 |
|
---|
177 | // low-level API:
|
---|
178 | namespace QTest
|
---|
179 | {
|
---|
180 | int iterationCount();
|
---|
181 | void setIterationCountHint(int count);
|
---|
182 | void setIterationCount(int count);
|
---|
183 |
|
---|
184 | Q_TESTLIB_EXPORT void beginBenchmarkMeasurement();
|
---|
185 | Q_TESTLIB_EXPORT qint64 endBenchmarkMeasurement();
|
---|
186 |
|
---|
187 | void setResult(qint64 result);
|
---|
188 | void setResult(const QString &tag, qint64 result);
|
---|
189 | }
|
---|
190 |
|
---|
191 | QT_END_NAMESPACE
|
---|
192 |
|
---|
193 | #endif // QBENCHMARK_H
|
---|