diff options
Diffstat (limited to 'src/plugins/qmltooling/qmldbg_profiler/qv4profileradapter.cpp')
-rw-r--r-- | src/plugins/qmltooling/qmldbg_profiler/qv4profileradapter.cpp | 198 |
1 files changed, 124 insertions, 74 deletions
diff --git a/src/plugins/qmltooling/qmldbg_profiler/qv4profileradapter.cpp b/src/plugins/qmltooling/qmldbg_profiler/qv4profileradapter.cpp index 24e01f4c68..68a71a5524 100644 --- a/src/plugins/qmltooling/qmldbg_profiler/qv4profileradapter.cpp +++ b/src/plugins/qmltooling/qmldbg_profiler/qv4profileradapter.cpp @@ -1,31 +1,37 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQml module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -37,12 +43,17 @@ QT_BEGIN_NAMESPACE QV4ProfilerAdapter::QV4ProfilerAdapter(QQmlProfilerService *service, QV4::ExecutionEngine *engine) : - QQmlAbstractProfilerAdapter(service), dataPos(0), memoryPos(0) + m_functionCallPos(0), m_memoryPos(0) { + setService(service); engine->enableProfiler(); connect(this, SIGNAL(profilingEnabled(quint64)), - engine->profiler, SLOT(startProfiling(quint64))); + this, SLOT(forwardEnabled(quint64))); connect(this, SIGNAL(profilingEnabledWhileWaiting(quint64)), + this, SLOT(forwardEnabledWhileWaiting(quint64)), Qt::DirectConnection); + connect(this, SIGNAL(v4ProfilingEnabled(quint64)), + engine->profiler, SLOT(startProfiling(quint64))); + connect(this, SIGNAL(v4ProfilingEnabledWhileWaiting(quint64)), engine->profiler, SLOT(startProfiling(quint64)), Qt::DirectConnection); connect(this, SIGNAL(profilingDisabled()), engine->profiler, SLOT(stopProfiling())); connect(this, SIGNAL(profilingDisabledWhileWaiting()), engine->profiler, SLOT(stopProfiling()), @@ -50,38 +61,44 @@ QV4ProfilerAdapter::QV4ProfilerAdapter(QQmlProfilerService *service, QV4::Execut connect(this, SIGNAL(dataRequested()), engine->profiler, SLOT(reportData())); connect(this, SIGNAL(referenceTimeKnown(QElapsedTimer)), engine->profiler, SLOT(setTimer(QElapsedTimer))); - connect(engine->profiler, SIGNAL(dataReady(QVector<QV4::Profiling::FunctionCallProperties>, + connect(engine->profiler, SIGNAL(dataReady(QV4::Profiling::FunctionLocationHash, + QVector<QV4::Profiling::FunctionCallProperties>, QVector<QV4::Profiling::MemoryAllocationProperties>)), - this, SLOT(receiveData(QVector<QV4::Profiling::FunctionCallProperties>, + this, SLOT(receiveData(QV4::Profiling::FunctionLocationHash, + QVector<QV4::Profiling::FunctionCallProperties>, QVector<QV4::Profiling::MemoryAllocationProperties>))); } -qint64 QV4ProfilerAdapter::appendMemoryEvents(qint64 until, QList<QByteArray> &messages) +qint64 QV4ProfilerAdapter::appendMemoryEvents(qint64 until, QList<QByteArray> &messages, + QQmlDebugPacket &d) { - QByteArray message; - while (memory_data.length() > memoryPos && memory_data[memoryPos].timestamp <= until) { - QQmlDebugStream d(&message, QIODevice::WriteOnly); - QV4::Profiling::MemoryAllocationProperties &props = memory_data[memoryPos]; + // Make it const, so that we cannot accidentally detach it. + const QVector<QV4::Profiling::MemoryAllocationProperties> &memoryData = m_memoryData; + + while (memoryData.length() > m_memoryPos && memoryData[m_memoryPos].timestamp <= until) { + const QV4::Profiling::MemoryAllocationProperties &props = memoryData[m_memoryPos]; d << props.timestamp << MemoryAllocation << props.type << props.size; - ++memoryPos; - messages.append(message); + ++m_memoryPos; + messages.append(d.squeezedData()); + d.clear(); } - return memory_data.length() == memoryPos ? -1 : memory_data[memoryPos].timestamp; + return memoryData.length() == m_memoryPos ? -1 : memoryData[m_memoryPos].timestamp; } qint64 QV4ProfilerAdapter::finalizeMessages(qint64 until, QList<QByteArray> &messages, - qint64 callNext) + qint64 callNext, QQmlDebugPacket &d) { if (callNext == -1) { - data.clear(); - dataPos = 0; + m_functionLocations.clear(); + m_functionCallData.clear(); + m_functionCallPos = 0; } - qint64 memoryNext = appendMemoryEvents(until, messages); + qint64 memoryNext = appendMemoryEvents(until, messages, d); if (memoryNext == -1) { - memory_data.clear(); - memoryPos = 0; + m_memoryData.clear(); + m_memoryPos = 0; return callNext; } @@ -90,64 +107,97 @@ qint64 QV4ProfilerAdapter::finalizeMessages(qint64 until, QList<QByteArray> &mes qint64 QV4ProfilerAdapter::sendMessages(qint64 until, QList<QByteArray> &messages) { - QByteArray message; + QQmlDebugPacket d; + + // Make it const, so that we cannot accidentally detach it. + const QVector<QV4::Profiling::FunctionCallProperties> &functionCallData = m_functionCallData; + const QV4::Profiling::FunctionLocationHash &functionLocations = m_functionLocations; + while (true) { - while (!stack.isEmpty() && (dataPos == data.length() || - stack.top() <= data[dataPos].start)) { - if (stack.top() > until) - return finalizeMessages(until, messages, stack.top()); - - appendMemoryEvents(stack.top(), messages); - QQmlDebugStream d(&message, QIODevice::WriteOnly); - d << stack.pop() << RangeEnd << Javascript; - messages.append(message); + while (!m_stack.isEmpty() && + (m_functionCallPos == functionCallData.length() || + m_stack.top() <= functionCallData[m_functionCallPos].start)) { + if (m_stack.top() > until || messages.length() > s_numMessagesPerBatch) + return finalizeMessages(until, messages, m_stack.top(), d); + + appendMemoryEvents(m_stack.top(), messages, d); + d << m_stack.pop() << RangeEnd << Javascript; + messages.append(d.squeezedData()); + d.clear(); } - while (dataPos != data.length() && (stack.empty() || data[dataPos].start < stack.top())) { - const QV4::Profiling::FunctionCallProperties &props = data[dataPos]; - if (props.start > until) - return finalizeMessages(until, messages, props.start); - - appendMemoryEvents(props.start, messages); - - QQmlDebugStream d_start(&message, QIODevice::WriteOnly); - d_start << props.start << RangeStart << Javascript; - messages.push_back(message); - message.clear(); - QQmlDebugStream d_location(&message, QIODevice::WriteOnly); - d_location << props.start << RangeLocation << Javascript << props.file << props.line - << props.column; - messages.push_back(message); - message.clear(); - QQmlDebugStream d_data(&message, QIODevice::WriteOnly); - d_data << props.start << RangeData << Javascript << props.name; - messages.push_back(message); - message.clear(); - stack.push(props.end); - ++dataPos; + while (m_functionCallPos != functionCallData.length() && + (m_stack.empty() || functionCallData[m_functionCallPos].start < m_stack.top())) { + const QV4::Profiling::FunctionCallProperties &props = + functionCallData[m_functionCallPos]; + if (props.start > until || messages.length() > s_numMessagesPerBatch) + return finalizeMessages(until, messages, props.start, d); + + appendMemoryEvents(props.start, messages, d); + auto location = functionLocations.constFind(props.id); + Q_ASSERT(location != functionLocations.constEnd()); + + d << props.start << RangeStart << Javascript; + messages.push_back(d.squeezedData()); + d.clear(); + d << props.start << RangeLocation << Javascript << location->file << location->line + << location->column; + messages.push_back(d.squeezedData()); + d.clear(); + d << props.start << RangeData << Javascript << location->name; + messages.push_back(d.squeezedData()); + d.clear(); + m_stack.push(props.end); + ++m_functionCallPos; } - if (stack.empty() && dataPos == data.length()) - return finalizeMessages(until, messages, -1); + if (m_stack.empty() && m_functionCallPos == functionCallData.length()) + return finalizeMessages(until, messages, -1, d); } } void QV4ProfilerAdapter::receiveData( - const QVector<QV4::Profiling::FunctionCallProperties> &new_data, - const QVector<QV4::Profiling::MemoryAllocationProperties> &new_memory_data) + const QV4::Profiling::FunctionLocationHash &locations, + const QVector<QV4::Profiling::FunctionCallProperties> &functionCallData, + const QVector<QV4::Profiling::MemoryAllocationProperties> &memoryData) { // In rare cases it could be that another flush or stop event is processed while data from // the previous one is still pending. In that case we just append the data. + if (m_functionLocations.isEmpty()) + m_functionLocations = locations; + else + m_functionLocations.unite(locations); - if (data.isEmpty()) - data = new_data; + if (m_functionCallData.isEmpty()) + m_functionCallData = functionCallData; else - data.append(new_data); + m_functionCallData.append(functionCallData); - if (memory_data.isEmpty()) - memory_data = new_memory_data; + if (m_memoryData.isEmpty()) + m_memoryData = memoryData; else - memory_data.append(new_memory_data); + m_memoryData.append(memoryData); service->dataReady(this); } +quint64 QV4ProfilerAdapter::translateFeatures(quint64 qmlFeatures) +{ + quint64 v4Features = 0; + const quint64 one = 1; + if (qmlFeatures & (one << ProfileJavaScript)) + v4Features |= (one << QV4::Profiling::FeatureFunctionCall); + if (qmlFeatures & (one << ProfileMemory)) + v4Features |= (one << QV4::Profiling::FeatureMemoryAllocation); + return v4Features; +} + +void QV4ProfilerAdapter::forwardEnabled(quint64 features) +{ + emit v4ProfilingEnabled(translateFeatures(features)); +} + +void QV4ProfilerAdapter::forwardEnabledWhileWaiting(quint64 features) +{ + emit v4ProfilingEnabledWhileWaiting(translateFeatures(features)); +} + QT_END_NAMESPACE |