source: trunk/src/testlib/qbenchmark_p.h@ 769

Last change on this file since 769 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 5.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtTest module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** 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 have questions regarding the use of this file, please contact
37** Nokia 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 Q_OS_MAC) && !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
72QT_BEGIN_NAMESPACE
73
74struct 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::fromLatin1("%1,%2,%3").arg(slotName).arg(tag).arg(checkpointIndex);
85 return s;
86 }
87
88 QBenchmarkContext() : checkpointIndex(-1) {}
89};
90
91class QBenchmarkResult
92{
93public:
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*/
124class QBenchmarkGlobalData
125{
126public:
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;
145private:
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*/
155class QBenchmarkTestMethodData
156{
157public:
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 bool runOnce;
175 int iterationCount;
176};
177
178// low-level API:
179namespace QTest
180{
181 int iterationCount();
182 void setIterationCountHint(int count);
183 void setIterationCount(int count);
184
185 Q_TESTLIB_EXPORT void beginBenchmarkMeasurement();
186 Q_TESTLIB_EXPORT qint64 endBenchmarkMeasurement();
187
188 void setResult(qint64 result);
189 void setResult(const QString &tag, qint64 result);
190}
191
192QT_END_NAMESPACE
193
194#endif // QBENCHMARK_H
Note: See TracBrowser for help on using the repository browser.