Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qbenchmark_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QBENCHMARK_P_H
5#define QBENCHMARK_P_H
6
7#include <stdlib.h>
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtCore/qglobal.h>
21
22#if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) && !defined(Q_OS_ANDROID)
23#define QTESTLIB_USE_PERF_EVENTS
24#else
25#undef QTESTLIB_USE_PERF_EVENTS
26#endif
27
28#include <QtTest/private/qbenchmarkmeasurement_p.h>
29#include <QtCore/QMap>
30#include <QtTest/qttestglobal.h>
31#if QT_CONFIG(valgrind)
32#include <QtTest/private/qbenchmarkvalgrind_p.h>
33#endif
34#ifdef QTESTLIB_USE_PERF_EVENTS
35#include <QtTest/private/qbenchmarkperfevents_p.h>
36#endif
37#include <QtTest/private/qbenchmarkevent_p.h>
38#include <QtTest/private/qbenchmarkmetric_p.h>
39
41
43{
44 // None of the strings below are assumed to contain commas (see toString() below)
46 QString tag; // from _data() function
47
49
51 {
52 return QString::fromLatin1("%1,%2,%3")
54 }
55
56 QBenchmarkContext() = default;
57};
59
61{
62public:
65 int iterations = -1;
66 bool setByMacro = true;
67
68 QBenchmarkResult() = default;
69
72 const int iterations, bool setByMacro)
74 , measurement(m)
77 { }
78
79 bool operator<(const QBenchmarkResult &other) const
80 {
81 return (measurement.value / iterations) < (other.measurement.value / other.iterations);
82 }
83};
85
86/*
87 The QBenchmarkGlobalData class stores global benchmark-related data.
88 QBenchmarkGlobalData:current is created at the beginning of qExec()
89 and cleared at the end.
90*/
91class Q_TESTLIB_EXPORT QBenchmarkGlobalData
92{
93public:
95
98 enum Mode { WallTime, CallgrindParentProcess, CallgrindChildProcess, PerfCounter, TickCounter, EventCounter };
99 void setMode(Mode mode);
100 Mode mode() const { return mode_; }
101 QBenchmarkMeasurerBase *createMeasurer();
102 int adjustMedianIterationCount();
103
104 QBenchmarkMeasurerBase *measurer = nullptr;
106 int walltimeMinimum = -1;
107 int iterationCount = -1;
108 int medianIterationCount = -1;
109 bool createChart = false;
110 bool verboseOutput = false;
112 int minimumTotal = -1;
113private:
114 Mode mode_ = WallTime;
115};
116
117/*
118 The QBenchmarkTestMethodData class stores all benchmark-related data for the
119 current test case. QBenchmarkTestMethodData:current is set to a local
120 instance at the beginning of TestMethods::invokeTest() and cleared by its
121 destructor when that instance drops out of scope.
122*/
123class Q_TESTLIB_EXPORT QBenchmarkTestMethodData
124{
125public:
129
130 // Called once for each data row created by the _data function,
131 // before and after calling the test function itself.
132 void beginDataRun();
133 void endDataRun();
134
135 bool isBenchmark() const { return valid; }
136 bool resultsAccepted() const { return resultAccepted; }
137 int adjustIterationCount(int suggestion);
138 void setResults(const QList<QBenchmarkMeasurerBase::Measurement> &m, bool setByMacro = true);
139 void setResult(QBenchmarkMeasurerBase::Measurement m, bool setByMacro = true)
140 { setResults({ m }, setByMacro); }
141
143 bool valid = false;
144 bool resultAccepted = false;
145 bool runOnce = false;
146 int iterationCount = -1;
147};
148
149// low-level API:
150namespace QTest
151{
152 int iterationCount();
154 void setIterationCount(int count);
155
158}
159
161
162#endif // QBENCHMARK_H
QBenchmarkContext context
static QBenchmarkGlobalData * current
QBenchmarkResult(const QBenchmarkContext &context, QBenchmarkMeasurerBase::Measurement m, const int iterations, bool setByMacro)
QBenchmarkContext context
bool operator<(const QBenchmarkResult &other) const
QBenchmarkMeasurerBase::Measurement measurement
QBenchmarkResult()=default
static QBenchmarkTestMethodData * current
QList< QBenchmarkResult > results
void setResult(QBenchmarkMeasurerBase::Measurement m, bool setByMacro=true)
Definition qlist.h:74
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5710
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Definition qstring.cpp:8606
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:7822
Combined button and popup list for selecting options.
QList< QBenchmarkMeasurerBase::Measurement > endBenchmarkMeasurement()
int iterationCount()
void setIterationCountHint(int count)
void setIterationCount(int count)
void beginBenchmarkMeasurement()
GLenum mode
const GLfloat * m
GLenum GLenum GLsizei count
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:145
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
QSharedPointer< T > other(t)
[5]
QString toString() const
QBenchmarkContext()=default