Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
[qt-netbsd.git] / src / testlib / qbenchmark_p.h
blob50329e17754843012075fc1a09fcbae52f693a46
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtTest module 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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #ifndef QBENCHMARK_P_H
43 #define QBENCHMARK_P_H
45 #include <stdlib.h>
48 // W A R N I N G
49 // -------------
51 // This file is not part of the Qt API. It exists purely as an
52 // implementation detail. This header file may change from version to
53 // version without notice, or even be removed.
55 // We mean it.
58 #include <QtCore/qglobal.h>
60 #if (defined(Q_OS_LINUX) || defined Q_OS_MAC) && !defined(QT_NO_PROCESS)
61 #define QTESTLIB_USE_VALGRIND
62 #else
63 #undef QTESTLIB_USE_VALGRIND
64 #endif
66 #include "QtTest/private/qbenchmarkmeasurement_p.h"
67 #include <QtCore/QMap>
68 #include <QtTest/qtest_global.h>
69 #ifdef QTESTLIB_USE_VALGRIND
70 #include "QtTest/private/qbenchmarkvalgrind_p.h"
71 #endif
72 #include "QtTest/private/qbenchmarkevent_p.h"
73 #include "QtTest/private/qbenchmarkmetric_p.h"
75 QT_BEGIN_NAMESPACE
77 struct QBenchmarkContext
79 // None of the strings below are assumed to contain commas (see toString() below)
80 QString slotName;
81 QString tag; // from _data() function
83 int checkpointIndex;
85 QString toString() const
87 QString s = QString::fromLatin1("%1,%2,%3").arg(slotName).arg(tag).arg(checkpointIndex);
88 return s;
91 QBenchmarkContext() : checkpointIndex(-1) {}
94 class QBenchmarkResult
96 public:
97 QBenchmarkContext context;
98 qreal value;
99 int iterations;
100 QTest::QBenchmarkMetric metric;
101 bool setByMacro;
102 bool valid;
104 QBenchmarkResult()
105 : value(-1)
106 , iterations(-1)
107 , setByMacro(true)
108 , valid(false)
111 QBenchmarkResult(
112 const QBenchmarkContext &context, const qreal value, const int iterations,
113 QTest::QBenchmarkMetric metric, bool setByMacro)
114 : context(context)
115 , value(value)
116 , iterations(iterations)
117 , metric(metric)
118 , setByMacro(setByMacro)
119 , valid(true)
122 bool operator<(const QBenchmarkResult &other) const
124 return (value / iterations) < (other.value / other.iterations);
129 The QBenchmarkGlobalData class stores global benchmark-related data.
130 QBenchmarkGlobalData:current is created at the beginning of qExec()
131 and cleared at the end.
133 class QBenchmarkGlobalData
135 public:
136 static QBenchmarkGlobalData *current;
138 QBenchmarkGlobalData();
139 ~QBenchmarkGlobalData();
140 enum Mode { WallTime, CallgrindParentProcess, CallgrindChildProcess, TickCounter, EventCounter };
141 void setMode(Mode mode);
142 Mode mode() const { return mode_; }
143 QBenchmarkMeasurerBase *createMeasurer();
144 int adjustMedianIterationCount();
146 QBenchmarkMeasurerBase *measurer;
147 QBenchmarkContext context;
148 int walltimeMinimum;
149 int iterationCount;
150 int medianIterationCount;
151 bool createChart;
152 bool verboseOutput;
153 QString callgrindOutFileBase;
154 private:
155 Mode mode_;
159 The QBenchmarkTestMethodData class stores all benchmark-related data
160 for the current test case. QBenchmarkTestMethodData:current is
161 created at the beginning of qInvokeTestMethod() and cleared at
162 the end.
164 class QBenchmarkTestMethodData
166 public:
167 static QBenchmarkTestMethodData *current;
168 QBenchmarkTestMethodData();
169 ~QBenchmarkTestMethodData();
171 // Called once for each data row created by the _data function,
172 // before and after calling the test function itself.
173 void beginDataRun();
174 void endDataRun();
176 bool isBenchmark() const { return result.valid; }
177 bool resultsAccepted() const { return resultAccepted; }
178 int adjustIterationCount(int suggestion);
179 void setResult(qreal value, QTest::QBenchmarkMetric metric, bool setByMacro = true);
181 QBenchmarkResult result;
182 bool resultAccepted;
183 bool runOnce;
184 int iterationCount;
187 // low-level API:
188 namespace QTest
190 int iterationCount();
191 void setIterationCountHint(int count);
192 void setIterationCount(int count);
194 Q_TESTLIB_EXPORT void beginBenchmarkMeasurement();
195 Q_TESTLIB_EXPORT quint64 endBenchmarkMeasurement();
198 QT_END_NAMESPACE
200 #endif // QBENCHMARK_H