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 | #include <QtTest/private/qbenchmarkevent_p.h> |
5 | #include <QtTest/private/qbenchmark_p.h> |
6 | #include <QtTest/private/qbenchmarkmetric_p.h> |
7 | #include <qdebug.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | QBenchmarkEvent::QBenchmarkEvent() = default; |
12 | |
13 | QBenchmarkEvent::~QBenchmarkEvent() = default; |
14 | |
15 | void QBenchmarkEvent::start() |
16 | { |
17 | eventCounter = 0; |
18 | QAbstractEventDispatcher::instance()->installNativeEventFilter(filterObj: this); |
19 | } |
20 | |
21 | QList<QBenchmarkMeasurerBase::Measurement> QBenchmarkEvent::stop() |
22 | { |
23 | QAbstractEventDispatcher::instance()->removeNativeEventFilter(filterObj: this); |
24 | return { { .value: qreal(eventCounter), .metric: QTest::Events } }; |
25 | } |
26 | |
27 | // It's very tempting to simply reject a measurement if 0 events |
28 | // where counted, however that is a possible situation and returning |
29 | // false here will create a infinite loop. Do not change this. |
30 | bool QBenchmarkEvent::isMeasurementAccepted(QBenchmarkMeasurerBase::Measurement measurement) |
31 | { |
32 | Q_UNUSED(measurement); |
33 | return true; |
34 | } |
35 | |
36 | int QBenchmarkEvent::adjustIterationCount(int suggestion) |
37 | { |
38 | return suggestion; |
39 | } |
40 | |
41 | int QBenchmarkEvent::adjustMedianCount(int suggestion) |
42 | { |
43 | Q_UNUSED(suggestion); |
44 | return 1; |
45 | } |
46 | |
47 | // This could be done in a much better way, this is just the beginning. |
48 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
49 | bool QBenchmarkEvent::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) |
50 | #else |
51 | bool QBenchmarkEvent::nativeEventFilter(const QByteArray &eventType, void *message, long *result) |
52 | #endif |
53 | { |
54 | Q_UNUSED(eventType); |
55 | Q_UNUSED(message); |
56 | Q_UNUSED(result); |
57 | |
58 | eventCounter++; |
59 | return false; |
60 | } |
61 | |
62 | QT_END_NAMESPACE |
63 |