20#include <QtCore/qglobal.h>
22#if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) && !defined(Q_OS_ANDROID)
23#define QTESTLIB_USE_PERF_EVENTS
25#undef QTESTLIB_USE_PERF_EVENTS
28#include <QtTest/private/qbenchmarkmeasurement_p.h>
30#include <QtTest/qttestglobal.h>
31#if QT_CONFIG(valgrind)
32#include <QtTest/private/qbenchmarkvalgrind_p.h>
34#ifdef QTESTLIB_USE_PERF_EVENTS
35#include <QtTest/private/qbenchmarkperfevents_p.h>
37#include <QtTest/private/qbenchmarkevent_p.h>
38#include <QtTest/private/qbenchmarkmetric_p.h>
42struct QBenchmarkContext
48 int checkpointIndex = -1;
50 QString toString()
const
52 return QString::fromLatin1(
"%1,%2,%3")
53 .arg(slotName, tag, QString::number(checkpointIndex));
56 QBenchmarkContext() =
default;
71 const QBenchmarkContext &context, QBenchmarkMeasurerBase::Measurement m,
72 const int iterations,
bool setByMacro)
81 return (measurement.value / iterations) < (other.measurement.value / other.iterations);
87
88
89
90
94 static QBenchmarkGlobalData *current;
96 QBenchmarkGlobalData();
97 ~QBenchmarkGlobalData();
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();
104 QBenchmarkMeasurerBase *measurer =
nullptr;
105 QBenchmarkContext context;
106 int walltimeMinimum = -1;
107 int iterationCount = -1;
108 int medianIterationCount = -1;
109 bool createChart =
false;
110 bool verboseOutput =
false;
111 QString callgrindOutFileBase;
112 int minimumTotal = -1;
114 Mode mode_ = WallTime;
118
119
120
121
122
126 static QBenchmarkTestMethodData *current;
127 QBenchmarkTestMethodData();
128 ~QBenchmarkTestMethodData();
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); }
142 QList<QBenchmarkResult> results;
144 bool resultAccepted =
false;
145 bool runOnce =
false;
146 int iterationCount = -1;
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
void generateTestIdentifier(QTestCharBuffer *identifier, int parts)
bool appendCharBuffer(QTestCharBuffer *accumulator, const QTestCharBuffer &more)
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
QList< QBenchmarkMeasurerBase::Measurement > endBenchmarkMeasurement()
void setIterationCountHint(int count)
void setIterationCount(int count)
void beginBenchmarkMeasurement()
int iterationCount() noexcept
Q_DECLARE_TYPEINFO(QBenchmarkContext, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(QBenchmarkResult, Q_RELOCATABLE_TYPE)