| 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 "qqmlabstractprofileradapter_p.h" |
| 5 | |
| 6 | QT_BEGIN_NAMESPACE |
| 7 | |
| 8 | /*! |
| 9 | * \internal |
| 10 | * \class QQmlAbstractProfilerAdapter |
| 11 | * \inmodule QtQml |
| 12 | * Abstract base class for all adapters between profilers and the QQmlProfilerService. Adapters have |
| 13 | * to retrieve profiler-specific data and convert it to the format sent over the wire. Adapters must |
| 14 | * live in the QDebugServer thread but the actual profilers can live in different threads. The |
| 15 | * recommended way to deal with this is passing the profiling data through a signal/slot connection. |
| 16 | */ |
| 17 | |
| 18 | /*! |
| 19 | * \internal |
| 20 | * \fn void QQmlAbstractProfilerAdapter::dataRequested() |
| 21 | * Signals that data has been requested by the \c QQmlProfilerService. This signal should be |
| 22 | * connected to a slot in the profiler and the profiler should then transfer its currently available |
| 23 | * profiling data to the adapter as soon as possible. |
| 24 | */ |
| 25 | |
| 26 | /*! |
| 27 | * \internal |
| 28 | * \fn qint64 QQmlAbstractProfilerAdapter::sendMessages(qint64 until, QList<QByteArray> &messages) |
| 29 | * Append the messages up to the timestamp \a until, chronologically sorted, to \a messages. Keep |
| 30 | * track of the messages already sent and with each subsequent call to this method start with the |
| 31 | * first one not yet sent. Messages that have been sent can be deleted. When new data from the |
| 32 | * profiler arrives the information about the last sent message must be reset. Return the timestamp |
| 33 | * of the next message after \a until or \c -1 if there is no such message. |
| 34 | * The profiler service keeps a list of adapters, sorted by time of next message and keeps querying |
| 35 | * the first one to send messages up to the time of the second one. Like that we get chronologically |
| 36 | * sorted messages and can occasionally post the messages to exploit parallelism and save memory. |
| 37 | */ |
| 38 | |
| 39 | /*! |
| 40 | * \internal |
| 41 | * Emits either \c profilingEnabled(quint64) or \c profilingEnabledWhileWaiting(quint64), depending |
| 42 | * on \c waiting. If the profiler's thread is waiting for an initial start signal, we can emit the |
| 43 | * signal over a Qt::DirectConnection to avoid the delay of the event loop. The \a features are |
| 44 | * passed on to the signal. |
| 45 | */ |
| 46 | void QQmlAbstractProfilerAdapter::startProfiling(quint64 features) |
| 47 | { |
| 48 | if (waiting) |
| 49 | emit profilingEnabledWhileWaiting(features); |
| 50 | else |
| 51 | emit profilingEnabled(features); |
| 52 | featuresEnabled = features; |
| 53 | } |
| 54 | |
| 55 | /*! |
| 56 | * \internal |
| 57 | * Emits either \c profilingDisabled() or \c profilingDisabledWhileWaiting(), depending on |
| 58 | * \c waiting. If the profiler's thread is waiting for an initial start signal, we can emit the |
| 59 | * signal over a Qt::DirectConnection to avoid the delay of the event loop. This should trigger |
| 60 | * the profiler to report its collected data and subsequently delete it. |
| 61 | */ |
| 62 | void QQmlAbstractProfilerAdapter::stopProfiling() { |
| 63 | if (waiting) |
| 64 | emit profilingDisabledWhileWaiting(); |
| 65 | else |
| 66 | emit profilingDisabled(); |
| 67 | featuresEnabled = 0; |
| 68 | } |
| 69 | |
| 70 | /*! |
| 71 | * \internal |
| 72 | * \fn bool QQmlAbstractProfilerAdapter::isRunning() const |
| 73 | * Returns if the profiler is currently running. The profiler is considered to be running after |
| 74 | * \c startProfiling(quint64) has been called until \c stopProfiling() is called. That is |
| 75 | * independent of \c waiting. The profiler may be running and waiting at the same time. |
| 76 | */ |
| 77 | |
| 78 | /*! |
| 79 | * \internal |
| 80 | * \fn void QQmlAbstractProfilerAdapter::profilingDisabled() |
| 81 | * This signal is emitted if \c stopProfiling() is called while the profiler is not considered to |
| 82 | * be waiting. The profiler is expected to handle the signal asynchronously. |
| 83 | */ |
| 84 | |
| 85 | /*! |
| 86 | * \internal |
| 87 | * \fn void QQmlAbstractProfilerAdapter::profilingDisabledWhileWaiting() |
| 88 | * This signal is emitted if \c stopProfiling() is called while the profiler is considered to be |
| 89 | * waiting. In many cases this signal can be connected with a Qt::DirectConnection. |
| 90 | */ |
| 91 | |
| 92 | /*! |
| 93 | * \internal |
| 94 | * \fn void QQmlAbstractProfilerAdapter::profilingEnabled(quint64 features) |
| 95 | * This signal is emitted if \c startProfiling(quint64) is called while the profiler is not |
| 96 | * considered to be waiting. The profiler is expected to handle the signal asynchronously. The |
| 97 | * \a features are passed on from \c startProfiling(quint64). |
| 98 | */ |
| 99 | |
| 100 | /*! |
| 101 | * \internal |
| 102 | * \fn void QQmlAbstractProfilerAdapter::profilingEnabledWhileWaiting(quint64 features) |
| 103 | * This signal is emitted if \c startProfiling(quint64) is called while the profiler is considered |
| 104 | * to be waiting. In many cases this signal can be connected with a Qt::DirectConnection. By |
| 105 | * starting the profiler synchronously when the QML engine starts instead of waiting for the first |
| 106 | * iteration of the event loop the engine startup can be profiled. The \a features are passed on |
| 107 | * from \c startProfiling(quint64). |
| 108 | */ |
| 109 | |
| 110 | /*! |
| 111 | * \internal |
| 112 | * \fn void QQmlAbstractProfilerAdapter::referenceTimeKnown(const QElapsedTimer &timer) |
| 113 | * This signal is used to synchronize the profiler's timer to the QQmlProfilerservice's. The |
| 114 | * profiler is expected to save \a timer and use it for timestamps on its data. |
| 115 | */ |
| 116 | |
| 117 | /*! |
| 118 | * \internal |
| 119 | * \fn void QQmlAbstractProfilerAdapter::synchronize(const QElapsedTimer &timer) |
| 120 | * Synchronize the profiler to \a timer. This emits \c referenceTimeKnown(). |
| 121 | */ |
| 122 | |
| 123 | /*! |
| 124 | * \internal |
| 125 | * \fn void QQmlAbstractProfilerAdapter::reportData() |
| 126 | * Make the profiler report its current data without stopping the collection. The same (and |
| 127 | * additional) data can later be requested again with \c stopProfiling() or \c reportData(). |
| 128 | */ |
| 129 | |
| 130 | /*! |
| 131 | * \internal |
| 132 | * \fn void QQmlAbstractProfilerAdapter::startWaiting() |
| 133 | * Consider the profiler to be waiting from now on. While the profiler is waiting it can be directly |
| 134 | * accessed even if it is in a different thread. This method should only be called if it is actually |
| 135 | * safe to do so. |
| 136 | */ |
| 137 | |
| 138 | /*! |
| 139 | * \internal |
| 140 | * \fn void QQmlAbstractProfilerAdapter::stopWaiting() |
| 141 | * Consider the profiler not to be waiting anymore. If it lives in a different threads any requests |
| 142 | * for it have to be done via a queued connection then. |
| 143 | */ |
| 144 | |
| 145 | QT_END_NAMESPACE |
| 146 | |
| 147 | #include "moc_qqmlabstractprofileradapter_p.cpp" |
| 148 | |