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 QQMLPROFILERSERVICE_P_H
5#define QQMLPROFILERSERVICE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qqmlconfigurabledebugservice_p.h>
19#include <private/qqmldebugserviceinterfaces_p.h>
20#include <private/qqmlprofilerdefinitions_p.h>
21#include <private/qqmlabstractprofileradapter_p.h>
22#include <private/qqmlboundsignal_p.h>
23#include <private/qqmldebugconnector_p.h>
24#include <private/qversionedpacket_p.h>
25
26#include <QtCore/qelapsedtimer.h>
27#include <QtCore/qmetaobject.h>
28#include <QtCore/qmutex.h>
29#include <QtCore/qvector.h>
30#include <QtCore/qstringbuilder.h>
31#include <QtCore/qwaitcondition.h>
32#include <QtCore/qtimer.h>
33
34#include <limits>
35
36QT_BEGIN_NAMESPACE
37
38class QUrl;
39using QQmlDebugPacket = QVersionedPacket<QQmlDebugConnector>;
40
41class QQmlProfilerServiceImpl :
42 public QQmlConfigurableDebugService<QQmlProfilerService>,
43 public QQmlProfilerDefinitions
44{
45 Q_OBJECT
46public:
47
48 void engineAboutToBeAdded(QJSEngine *engine) override;
49 void engineAboutToBeRemoved(QJSEngine *engine) override;
50 void engineAdded(QJSEngine *engine) override;
51 void engineRemoved(QJSEngine *engine) override;
52
53 void addGlobalProfiler(QQmlAbstractProfilerAdapter *profiler) override;
54 void removeGlobalProfiler(QQmlAbstractProfilerAdapter *profiler) override;
55
56 void startProfiling(QJSEngine *engine,
57 quint64 features = std::numeric_limits<quint64>::max()) override;
58 void stopProfiling(QJSEngine *engine) override;
59
60 QQmlProfilerServiceImpl(QObject *parent = nullptr);
61 ~QQmlProfilerServiceImpl() override;
62
63 void dataReady(QQmlAbstractProfilerAdapter *profiler) override;
64
65Q_SIGNALS:
66 void startFlushTimer();
67 void stopFlushTimer();
68
69protected:
70 void stateAboutToBeChanged(State state) override;
71 void messageReceived(const QByteArray &) override;
72
73private:
74 friend class QQmlProfilerServiceFactory;
75
76 void sendMessages();
77 void addEngineProfiler(QQmlAbstractProfilerAdapter *profiler, QJSEngine *engine);
78 void removeProfilerFromStartTimes(const QQmlAbstractProfilerAdapter *profiler);
79 void flush();
80
81 QElapsedTimer m_timer;
82 QTimer m_flushTimer;
83 bool m_waitingForStop;
84
85 bool m_globalEnabled;
86 quint64 m_globalFeatures;
87
88 QList<QQmlAbstractProfilerAdapter *> m_globalProfilers;
89 QMultiHash<QJSEngine *, QQmlAbstractProfilerAdapter *> m_engineProfilers;
90 QList<QJSEngine *> m_stoppingEngines;
91 QMultiMap<qint64, QQmlAbstractProfilerAdapter *> m_startTimes;
92};
93
94QT_END_NAMESPACE
95
96#endif // QQMLPROFILERSERVICE_P_H
97
98

source code of qtdeclarative/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.h