7#include <private/qqmldebugserviceinterfaces_p.h>
11QQmlProfilerAdapter::QQmlProfilerAdapter(QQmlProfilerService *service, QQmlEnginePrivate *engine)
13 engine->profiler =
new QQmlProfiler;
14 init(service, engine->profiler);
17QQmlProfilerAdapter::QQmlProfilerAdapter(QQmlProfilerService *service, QQmlTypeLoader *loader)
19 QQmlProfiler *profiler =
new QQmlProfiler;
20 loader->setProfiler(profiler);
21 init(service, profiler);
24void QQmlProfilerAdapter::init(QQmlProfilerService *service, QQmlProfiler *profiler)
28 connect(
this, &QQmlProfilerAdapter::profilingEnabled,
29 profiler, &QQmlProfiler::startProfiling);
30 connect(
this, &QQmlAbstractProfilerAdapter::profilingEnabledWhileWaiting,
31 profiler, &QQmlProfiler::startProfiling, Qt::DirectConnection);
32 connect(
this, &QQmlAbstractProfilerAdapter::profilingDisabled,
33 profiler, &QQmlProfiler::stopProfiling);
34 connect(
this, &QQmlAbstractProfilerAdapter::profilingDisabledWhileWaiting,
35 profiler, &QQmlProfiler::stopProfiling, Qt::DirectConnection);
36 connect(
this, &QQmlAbstractProfilerAdapter::dataRequested,
37 profiler, &QQmlProfiler::reportData);
38 connect(
this, &QQmlAbstractProfilerAdapter::referenceTimeKnown,
39 profiler, &QQmlProfiler::setTimer);
40 connect(profiler, &QQmlProfiler::dataReady,
41 this, &QQmlProfilerAdapter::receiveData);
46 QQmlProfiler::LocationHash &locations,
47 QList<QByteArray> &messages)
50 Q_ASSERT_X((d.messageType & (1 << 31)) == 0, Q_FUNC_INFO,
51 "You can use at most 31 message types.");
52 for (quint32 decodedMessageType = 0; (d.messageType >> decodedMessageType) != 0;
53 ++decodedMessageType) {
54 if (decodedMessageType == QQmlProfilerDefinitions::RangeData
55 || (d.messageType & (1 << decodedMessageType)) == 0) {
59 if (decodedMessageType == QQmlProfilerDefinitions::RangeEnd
60 || decodedMessageType == QQmlProfilerDefinitions::RangeStart) {
61 ds << d.time << decodedMessageType <<
static_cast<quint32>(d.detailType);
62 if (d.locationId != 0)
63 ds <<
static_cast<qint64>(d.locationId);
65 auto i = locations.constFind(d.locationId);
66 if (i != locations.cend()) {
67 ds << d.time << decodedMessageType <<
static_cast<quint32>(d.detailType);
68 ds << (i->url.isEmpty() ? i->location.sourceFile : i->url.toString())
69 <<
static_cast<qint32>(i->location.line)
70 <<
static_cast<qint32>(i->location.column);
71 if (d.messageType & (1 << QQmlProfilerDefinitions::RangeData)) {
73 ds <<
static_cast<qint64>(d.locationId);
74 messages.append(ds.squeezedData());
76 ds << d.time <<
int(QQmlProfilerDefinitions::RangeData)
77 <<
static_cast<quint32>(d.detailType)
78 << (i->location.sourceFile.isEmpty() ? i->url.toString() :
79 i->location.sourceFile);
81 ds <<
static_cast<qint64>(d.locationId);
88 messages.append(ds.squeezedData());
93qint64 QQmlProfilerAdapter::sendMessages(qint64 until, QList<QByteArray> &messages)
95 while (next != data.size()) {
96 const QQmlProfilerData &nextData = data.at(next);
97 if (nextData.time > until || messages.size() > s_numMessagesPerBatch)
99 qQmlProfilerDataToByteArrays(nextData, locations, messages);
109void QQmlProfilerAdapter::receiveData(
const QVector<QQmlProfilerData> &new_data,
110 const QQmlProfiler::LocationHash &new_locations)
115 data.append(new_data);
117 if (locations.isEmpty())
118 locations = new_locations;
120 locations.insert(new_locations);
122 service->dataReady(
this);
127#include "moc_qqmlprofileradapter.cpp"
static void qQmlProfilerDataToByteArrays(const QQmlProfilerData &d, QQmlProfiler::LocationHash &locations, QList< QByteArray > &messages)