8#include <private/qqmldebugserviceinterfaces_p.h>
12QQmlProfilerAdapter::QQmlProfilerAdapter(QQmlProfilerService *service, QQmlEnginePrivate *engine)
14 engine->profiler =
new QQmlProfiler;
15 init(service, engine->profiler);
18QQmlProfilerAdapter::QQmlProfilerAdapter(QQmlProfilerService *service, QQmlTypeLoader *loader)
20 QQmlProfiler *profiler =
new QQmlProfiler;
21 loader->setProfiler(profiler);
22 init(service, profiler);
25void QQmlProfilerAdapter::init(QQmlProfilerService *service, QQmlProfiler *profiler)
29 connect(
this, &QQmlProfilerAdapter::profilingEnabled,
30 profiler, &QQmlProfiler::startProfiling);
31 connect(
this, &QQmlAbstractProfilerAdapter::profilingEnabledWhileWaiting,
32 profiler, &QQmlProfiler::startProfiling, Qt::DirectConnection);
33 connect(
this, &QQmlAbstractProfilerAdapter::profilingDisabled,
34 profiler, &QQmlProfiler::stopProfiling);
35 connect(
this, &QQmlAbstractProfilerAdapter::profilingDisabledWhileWaiting,
36 profiler, &QQmlProfiler::stopProfiling, Qt::DirectConnection);
37 connect(
this, &QQmlAbstractProfilerAdapter::dataRequested,
38 profiler, &QQmlProfiler::reportData);
39 connect(
this, &QQmlAbstractProfilerAdapter::referenceTimeKnown,
40 profiler, &QQmlProfiler::setTimer);
41 connect(profiler, &QQmlProfiler::dataReady,
42 this, &QQmlProfilerAdapter::receiveData);
47 QQmlProfiler::LocationHash &locations,
48 QList<QByteArray> &messages)
51 Q_ASSERT_X((d.messageType & (1 << 31)) == 0, Q_FUNC_INFO,
52 "You can use at most 31 message types.");
53 for (quint32 decodedMessageType = 0; (d.messageType >> decodedMessageType) != 0;
54 ++decodedMessageType) {
55 if (decodedMessageType == QQmlProfilerDefinitions::RangeData
56 || (d.messageType & (1 << decodedMessageType)) == 0) {
60 if (decodedMessageType == QQmlProfilerDefinitions::RangeEnd
61 || decodedMessageType == QQmlProfilerDefinitions::RangeStart) {
62 ds << d.time << decodedMessageType <<
static_cast<quint32>(d.detailType);
63 if (d.locationId != 0)
64 ds <<
static_cast<qint64>(d.locationId);
66 auto i = locations.constFind(d.locationId);
67 if (i != locations.cend()) {
68 ds << d.time << decodedMessageType <<
static_cast<quint32>(d.detailType);
69 ds << (i->url.isEmpty() ? i->location.sourceFile : i->url.toString())
70 <<
static_cast<qint32>(i->location.line)
71 <<
static_cast<qint32>(i->location.column);
72 if (d.messageType & (1 << QQmlProfilerDefinitions::RangeData)) {
74 ds <<
static_cast<qint64>(d.locationId);
75 messages.append(ds.squeezedData());
77 ds << d.time <<
int(QQmlProfilerDefinitions::RangeData)
78 <<
static_cast<quint32>(d.detailType)
79 << (i->location.sourceFile.isEmpty() ? i->url.toString() :
80 i->location.sourceFile);
82 ds <<
static_cast<qint64>(d.locationId);
89 messages.append(ds.squeezedData());
94qint64 QQmlProfilerAdapter::sendMessages(qint64 until, QList<QByteArray> &messages)
96 while (next != data.size()) {
97 const QQmlProfilerData &nextData = data.at(next);
98 if (nextData.time > until || messages.size() > s_numMessagesPerBatch)
100 qQmlProfilerDataToByteArrays(nextData, locations, messages);
110void QQmlProfilerAdapter::receiveData(
const QVector<QQmlProfilerData> &new_data,
111 const QQmlProfiler::LocationHash &new_locations)
116 data.append(new_data);
118 if (locations.isEmpty())
119 locations = new_locations;
121 locations.insert(new_locations);
123 service->dataReady(
this);
128#include "moc_qqmlprofileradapter.cpp"
Combined button and popup list for selecting options.
static void qQmlProfilerDataToByteArrays(const QQmlProfilerData &d, QQmlProfiler::LocationHash &locations, QList< QByteArray > &messages)