19#include <QtQml/private/qv4global_p.h>
23#include <QElapsedTimer>
25#if !QT_CONFIG(qml_debug)
27#define Q_V4_PROFILE_ALLOC(engine, size, type) Q_UNUSED(engine)
28#define Q_V4_PROFILE_DEALLOC(engine, size, type) Q_UNUSED(engine)
46#define Q_V4_PROFILE_ALLOC(engine, size, type)
47 (engine->profiler() &&
48 (engine->profiler()->featuresEnabled & (1
<< Profiling::FeatureMemoryAllocation)) ?
49 engine->profiler()->trackAlloc(size, type) : false)
51#define Q_V4_PROFILE_DEALLOC(engine, size, type)
52 (engine->profiler() &&
53 (engine->profiler()->featuresEnabled & (1
<< Profiling::FeatureMemoryAllocation)) ?
54 engine->profiler()->trackDealloc(size, type) : false)
64 FeatureMemoryAllocation
73struct FunctionCallProperties {
79struct FunctionLocation {
80 FunctionLocation(
const QString &name = QString(),
const QString &file = QString(),
81 int line = -1,
int column = -1) :
82 name(name), file(file), line(line), column(column)
87 return !name.isEmpty();
96typedef QHash<quintptr, QV4::Profiling::FunctionLocation> FunctionLocationHash;
98struct MemoryAllocationProperties {
106 FunctionCall() : m_function(
nullptr), m_start(0), m_end(0) {}
108 FunctionCall(Function *function, qint64 start, qint64 end) :
109 m_function(function), m_start(start), m_end(end)
110 { m_function->executableCompilationUnit()->addref(); }
112 FunctionCall(
const FunctionCall &other) :
113 m_function(other.m_function), m_start(other.m_start), m_end(other.m_end)
114 { m_function->executableCompilationUnit()->addref(); }
116 FunctionCall(FunctionCall &&other)
noexcept
117 : m_function(std::exchange(other.m_function,
nullptr))
118 , m_start(std::exchange(other.m_start, 0))
119 , m_end(std::exchange(other.m_end, 0))
125 m_function->executableCompilationUnit()->release();
128 FunctionCall &operator=(
const FunctionCall &other) {
129 if (&other !=
this) {
130 if (other.m_function)
131 other.m_function->executableCompilationUnit()->addref();
133 m_function->executableCompilationUnit()->release();
134 m_function = other.m_function;
135 m_start = other.m_start;
141 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(FunctionCall)
143 void swap(FunctionCall &other)
noexcept
145 qt_ptr_swap(m_function, other.m_function);
146 std::swap(m_start, other.m_start);
147 std::swap(m_end, other.m_end);
150 Function *function()
const
155 FunctionLocation resolveLocation()
const;
156 FunctionCallProperties properties()
const;
159 friend bool operator<(
const FunctionCall &call1,
const FunctionCall &call2);
161 Function *m_function;
166class Q_QML_EXPORT Profiler :
public QObject {
186 if (&
other !=
this) {
255class FunctionCallProfiler {
256 Q_DISABLE_COPY(FunctionCallProfiler)
261 FunctionCallProfiler(ExecutionEngine *engine, Function *f)
263 Profiler *p = engine->profiler();
264 if (Q_UNLIKELY(p) && (p->featuresEnabled & (1 << Profiling::FeatureFunctionCall))) {
267 startTime = profiler->m_timer.nsecsElapsed();
271 ~FunctionCallProfiler()
274 profiler->m_data.append(FunctionCall(function, startTime, profiler->m_timer.nsecsElapsed()));
277 Profiler *profiler =
nullptr;
278 Function *function =
nullptr;
279 qint64 startTime = 0;
286Q_DECLARE_TYPEINFO(
QV4::
Profiling::MemoryAllocationProperties, Q_RELOCATABLE_TYPE);
287Q_DECLARE_TYPEINFO(
QV4::
Profiling::FunctionCallProperties, Q_RELOCATABLE_TYPE);
288Q_DECLARE_TYPEINFO(
QV4::
Profiling::FunctionCall, Q_RELOCATABLE_TYPE);
289Q_DECLARE_TYPEINFO(
QV4::
Profiling::FunctionLocation, Q_RELOCATABLE_TYPE);
293Q_DECLARE_METATYPE(QV4::Profiling::FunctionLocationHash)
294Q_DECLARE_METATYPE(QVector<QV4::Profiling::FunctionCallProperties>)
295Q_DECLARE_METATYPE(QVector<QV4::Profiling::MemoryAllocationProperties>)
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)