9#include <private/qjsengine_p.h>
10#include <private/qqmldebugpluginmanager_p.h>
12#include <QtCore/qurl.h>
13#include <QtCore/qtimer.h>
14#include <QtCore/qthread.h>
15#include <QtCore/qcoreapplication.h>
25 m_waitingForStop(
false), m_globalEnabled(
false), m_globalFeatures(0)
29 loadQQmlAbstractProfilerAdapter(
QLatin1String(
"QQuickProfilerAdapter"));
31 addGlobalProfiler(quickAdapter);
37 loadQQmlAbstractProfilerAdapter(
QLatin1String(
"QQuick3DProfilerAdapter"));
39 addGlobalProfiler(quick3DAdapter);
57 bool dataComplete =
true;
59 if (
i.value() == profiler) {
67 m_startTimes.
insert(0, profiler);
71 const auto range = std::as_const(m_engineProfilers).equal_range(
engine);
72 const auto startTimesEnd = m_startTimes.
cend();
74 if (std::find(m_startTimes.
cbegin(), startTimesEnd, *
it) != startTimesEnd) {
91 "QML profilers have to be added from the engine thread");
97 addEngineProfiler(qmlAdapter,
engine);
100 addEngineProfiler(compileAdapter,
engine);
103 addEngineProfiler(v4Adapter,
engine);
110 "QML profilers have to be added from the engine thread");
117 const auto range = std::as_const(m_engineProfilers).equal_range(
engine);
119 (*it)->stopWaiting();
125 "QML profilers have to be removed from the engine thread");
129 const auto range = std::as_const(m_engineProfilers).equal_range(
engine);
147 "QML profilers have to be removed from the engine thread");
150 const auto range = std::as_const(m_engineProfilers).equal_range(
engine);
153 removeProfilerFromStartTimes(profiler);
170 m_globalProfilers.
append(profiler);
176 features |= engineProfiler->features();
185 removeProfilerFromStartTimes(profiler);
192 i != m_startTimes.
end();) {
193 if (
i.value() == profiler) {
215 messageService->synchronizeTime(m_timer);
221 bool startedAny =
false;
223 const auto range = std::as_const(m_engineProfilers).equal_range(
engine);
234 m_globalEnabled =
true;
235 m_globalFeatures = features;
239 i != m_engineProfilers.
end(); ++
i) {
240 if (!
i.value()->isRunning()) {
242 i.value()->startProfiling(features);
246 for (
QJSEngine *profiledEngine : std::as_const(engines))
247 d << idForObject(profiledEngine);
275 m_globalEnabled =
false;
277 bool stillRunning =
false;
279 i != m_engineProfilers.
end(); ++
i) {
280 if (
i.value()->isRunning()) {
281 m_startTimes.
insert(-1,
i.value());
283 stopping <<
i.value();
285 reporting <<
i.value();
297 m_startTimes.
insert(-1, profiler);
299 reporting << profiler;
301 stopping << profiler;
306 m_waitingForStop =
true;
318void QQmlProfilerServiceImpl::sendMessages()
323 if (m_waitingForStop) {
330 i != m_engineProfilers.
end(); ++
i) {
331 if (
i.value() == profiler && !seen.
contains(
i.key())) {
333 traceEnd << idForObject(
i.key());
339 while (!m_startTimes.
empty()) {
343 std::numeric_limits<qint64>::max() :
344 m_startTimes.
begin().
key(), messages);
349 emit messagesToClient(
name(), messages);
354 bool stillRunning =
false;
362 if (m_waitingForStop) {
364 messages << traceEnd.
data();
370 messages << ds.
data();
371 m_waitingForStop =
false;
375 emit messagesToClient(
name(), messages);
405 quint64 features = std::numeric_limits<quint64>::max();
416 static_cast<int>(
qMin(flushInterval,
417 static_cast<quint32>(std::numeric_limits<int>::max()))));
419 if (flushInterval > 0) {
431 bool useMessageTypes =
false;
433 stream >> useMessageTypes;
436 if (
enabled && useMessageTypes)
437 startProfiling(qobject_cast<QJSEngine *>(objectForId(engineId)), features);
439 stopProfiling(qobject_cast<QJSEngine *>(objectForId(engineId)));
444void QQmlProfilerServiceImpl::flush()
451 m_startTimes.
insert(-1, profiler);
452 reporting.
append(profiler);
458 m_startTimes.
insert(-1, profiler);
459 reporting.
append(profiler);
464 profiler->reportData();
469#include "moc_qqmlprofilerservice.cpp"
qint64 nsecsElapsed() const noexcept
The QJSEngine class provides an environment for evaluating JavaScript code.
QV4::ExecutionEngine * handle() const
qsizetype size() const noexcept
bool isEmpty() const noexcept
bool removeOne(const AT &t)
void append(parameter_type t)
key_iterator keyBegin() const noexcept
qsizetype remove(const Key &key)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
key_iterator keyEnd() const noexcept
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
iterator insert(const Key &key, const T &value)
iterator erase(const_iterator it)
const_iterator cbegin() const
const_iterator cend() const
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
QThread * thread() const
Returns the thread in which the object lives.
const QByteArray & data() const
Returns a reference to the raw packet data.
void startProfiling(quint64 features)
void setService(QQmlProfilerService *new_service)
static const int s_numMessagesPerBatch
void synchronize(const QElapsedTimer &t)
QRecursiveMutex m_configMutex
void engineAboutToBeAdded(QJSEngine *engine) override
static QQmlDebugConnector * instance()
QQmlTypeLoader typeLoader
static QQmlEnginePrivate * get(QQmlEngine *e)
The QQmlEngine class provides an environment for instantiating QML components.
void engineAboutToBeRemoved(QJSEngine *engine) override
void engineAboutToBeAdded(QJSEngine *engine) override
void engineAdded(QJSEngine *engine) override
void messageReceived(const QByteArray &) override
void stateAboutToBeChanged(State state) override
void addGlobalProfiler(QQmlAbstractProfilerAdapter *profiler) override
void dataReady(QQmlAbstractProfilerAdapter *profiler) override
void engineRemoved(QJSEngine *engine) override
void stopProfiling(QJSEngine *engine) override
Stop profiling the given engine.
void removeGlobalProfiler(QQmlAbstractProfilerAdapter *profiler) override
void startProfiling(QJSEngine *engine, quint64 features=std::numeric_limits< quint64 >::max()) override
Start profiling the given engine.
~QQmlProfilerServiceImpl() override
bool contains(const T &value) const
static QThread * currentThread()
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
void setInterval(int msec)
void stop()
Stops the timer.
void timeout(QPrivateSignal)
This signal is emitted when the timer times out.
qDeleteAll(list.begin(), list.end())
QSet< QString >::iterator it
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
constexpr const T & qMin(const T &a, const T &b)
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLuint GLsizei const GLchar * message
QQmlEngine * qmlEngine(const QObject *obj)
#define Q_QML_DEBUG_PLUGIN_LOADER(interfaceName)
#define Q_ASSERT_X(cond, x, msg)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
QLatin1StringView QLatin1String
unsigned long long quint64
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
myObject disconnect()
[26]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent