Qt 4.8
qbenchmark_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtTest module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QBENCHMARK_P_H
43 #define QBENCHMARK_P_H
44 
45 #include <stdlib.h>
46 
47 //
48 // W A R N I N G
49 // -------------
50 //
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.
54 //
55 // We mean it.
56 //
57 
58 #include <QtCore/qglobal.h>
59 
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
65 
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"
74 
76 
78 {
79  // None of the strings below are assumed to contain commas (see toString() below)
81  QString tag; // from _data() function
82 
84 
85  QString toString() const
86  {
87  QString s = QString::fromLatin1("%1,%2,%3").arg(slotName).arg(tag).arg(checkpointIndex);
88  return s;
89  }
90 
91  QBenchmarkContext() : checkpointIndex(-1) {}
92 };
93 
95 {
96 public:
102  bool valid;
103 
105  : value(-1)
106  , iterations(-1)
107  , setByMacro(true)
108  , valid(false)
109  { }
110 
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)
120  { }
121 
122  bool operator<(const QBenchmarkResult &other) const
123  {
124  return (value / iterations) < (other.value / other.iterations);
125  }
126 };
127 
128 /*
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.
132 */
134 {
135 public:
137 
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();
145 
154 private:
156 };
157 
158 /*
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.
163 */
165 {
166 public:
170 
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();
175 
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);
180 
183  bool runOnce;
185 };
186 
187 // low-level API:
188 namespace QTest
189 {
190  int iterationCount();
191  void setIterationCountHint(int count);
192  void setIterationCount(int count);
193 
196 }
197 
199 
200 #endif // QBENCHMARK_H
#define Q_TESTLIB_EXPORT
Definition: qtest_global.h:56
QString toString() const
Definition: qbenchmark_p.h:85
QTest::QBenchmarkMetric metric
Definition: qbenchmark_p.h:100
static QBenchmarkGlobalData * current
Definition: qbenchmark_p.h:136
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QBenchmarkResult result
Definition: qbenchmark_p.h:181
bool operator<(const QBenchmarkResult &other) const
Definition: qbenchmark_p.h:122
QBenchmarkMetric
This enum lists all the things that can be benchmarked.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QBenchmarkMeasurerBase * measurer
Definition: qbenchmark_p.h:146
void setIterationCount(int count)
Definition: qbenchmark.cpp:252
QString callgrindOutFileBase
Definition: qbenchmark_p.h:153
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Q_TESTLIB_EXPORT quint64 endBenchmarkMeasurement()
Definition: qbenchmark.cpp:268
unsigned __int64 quint64
Definition: qglobal.h:943
void setIterationCountHint(int count)
Definition: qbenchmark.cpp:245
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
bool resultsAccepted() const
Definition: qbenchmark_p.h:177
int iterationCount()
Definition: qbenchmark.cpp:238
QBenchmarkResult(const QBenchmarkContext &context, const qreal value, const int iterations, QTest::QBenchmarkMetric metric, bool setByMacro)
Definition: qbenchmark_p.h:111
static QBenchmarkTestMethodData * current
Definition: qbenchmark_p.h:167
QBenchmarkContext context
Definition: qbenchmark_p.h:147
Q_TESTLIB_EXPORT void beginBenchmarkMeasurement()
Definition: qbenchmark.cpp:260
QBenchmarkContext context
Definition: qbenchmark_p.h:97
The QTest namespace contains all the functions and declarations that are related to the QTestLib tool...