From d2c089eb11d3ad6a9917efde8f13b36931b35baf Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Mon, 29 Apr 2019 10:46:02 +0200 Subject: Add Q_TRACE calls to QtQml for QML profiler trace points This adds tracepoints for LTTng/ETW at the positions that are also used by the QML profiler within QtQml. I.e. with the tracepoints here, you'll see which QML function is being executed which is already quite helpful. This will allow us to bridge the gap between C++ and QML when tracing with LTTng/ETW. Additionally, you'll also be able to see kernel tracepoints which bridges another gap. Combined, this approach can give much deeper insights into what the (embedded) system is doing compared to just looking at the QML profiler alone. Change-Id: Ia8f71bf6d44b7f51c3c5aaa38f032675604aeca6 Reviewed-by: Ulf Hermann Reviewed-by: Rafael Roquetto --- src/qml/jsruntime/qv4vme_moth.cpp | 6 ++++++ src/qml/qml.pro | 3 +++ src/qml/qml/qqmlobjectcreator.cpp | 20 +++++++++++++------- src/qml/qtqml.tracepoints | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 src/qml/qtqml.tracepoints (limited to 'src/qml') diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index ea2217499f..c69bb67061 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -63,6 +63,8 @@ #include +#include + #undef COUNT_INSTRUCTIONS extern "C" { @@ -418,6 +420,10 @@ ReturnedValue VME::exec(CppStackFrame *frame, ExecutionEngine *engine) CHECK_STACK_LIMITS(engine); Function *function = frame->v4Function; + Q_TRACE_SCOPE(QQmlV4_function_call, engine, function->name()->toQString(), + function->compilationUnit->fileName(), + function->compiledFunction->location.line, + function->compiledFunction->location.column); Profiling::FunctionCallProfiler profiler(engine, function); // start execution profiling QV4::Debugging::Debugger *debugger = engine->debugger(); diff --git a/src/qml/qml.pro b/src/qml/qml.pro index db59140f06..d2170ac40b 100644 --- a/src/qml/qml.pro +++ b/src/qml/qml.pro @@ -4,6 +4,9 @@ QT = core-private qtConfig(qml-network): \ QT += network +TRACEPOINT_PROVIDER = $$PWD/qtqml.tracepoints +CONFIG += qt_tracepoints + DEFINES += QT_NO_URL_CAST_FROM_STRING QT_NO_INTEGER_EVENT_COORDINATES msvc:equals(QT_ARCH, i386): QMAKE_LFLAGS += /BASE:0x66000000 diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index b62b07e39c..d5b15a7a5a 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -57,6 +57,8 @@ #include #include +#include + QT_USE_NAMESPACE namespace { @@ -1130,6 +1132,9 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo { const QV4::CompiledData::Object *obj = compilationUnit->objectAt(index); QQmlObjectCreationProfiler profiler(sharedState->profiler.profiler, obj); + Q_TRACE(QQmlObjectCreator_createInstance_entry, compilationUnit.data(), obj, context->url()); + QString typeName; + Q_TRACE_EXIT(QQmlObjectCreator_createInstance_exit, typeName); ActiveOCRestorer ocRestorer(this, QQmlEnginePrivate::get(engine)); @@ -1143,8 +1148,7 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo if (obj->flags & QV4::CompiledData::Object::IsComponent) { isComponent = true; QQmlComponent *component = new QQmlComponent(engine, compilationUnit.data(), index, parent); - Q_QML_OC_PROFILE(sharedState->profiler, profiler.update( - compilationUnit.data(), obj, QStringLiteral(""), context->url())); + typeName = QStringLiteral(""); QQmlComponentPrivate::get(component)->creationContext = context; instance = component; ddata = QQmlData::get(instance, /*create*/true); @@ -1155,8 +1159,7 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo installPropertyCache = !typeRef->isFullyDynamicType; QQmlType type = typeRef->type; if (type.isValid()) { - Q_QML_OC_PROFILE(sharedState->profiler, profiler.update( - compilationUnit.data(), obj, type.qmlTypeName(), context->url())); + typeName = type.qmlTypeName(); void *ddataMemory = nullptr; type.create(&instance, &ddataMemory, sizeof(QQmlData)); @@ -1188,9 +1191,7 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo sharedState->allCreatedObjects.push(instance); } else { Q_ASSERT(typeRef->compilationUnit); - Q_QML_OC_PROFILE(sharedState->profiler, profiler.update( - compilationUnit.data(), obj, typeRef->compilationUnit->fileName(), - context->url())); + typeName = typeRef->compilationUnit->fileName(); if (typeRef->compilationUnit->unitData()->isSingleton()) { recordError(obj->location, tr("Composite Singleton Type %1 is not creatable").arg(stringAt(obj->inheritedTypeNameIndex))); @@ -1217,6 +1218,11 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo ddata = QQmlData::get(instance, /*create*/true); } + + Q_QML_OC_PROFILE(sharedState->profiler, profiler.update( + compilationUnit.data(), obj, typeName, context->url())); + Q_UNUSED(typeName); // only relevant for tracing + ddata->lineNumber = obj->location.line; ddata->columnNumber = obj->location.column; diff --git a/src/qml/qtqml.tracepoints b/src/qml/qtqml.tracepoints new file mode 100644 index 0000000000..841748f201 --- /dev/null +++ b/src/qml/qtqml.tracepoints @@ -0,0 +1,14 @@ +{ +namespace QV4 { +class ExecutionEngine; +namespace CompiledData { +class CompilationUnit; +class Object; +} // CompiledData +} // QV4 +} + +QQmlObjectCreator_createInstance_entry(const QV4::CompiledData::CompilationUnit *compilationUnit, const QV4::CompiledData::Object *object, const QUrl &url) +QQmlObjectCreator_createInstance_exit(const QString &typeName) +QQmlV4_function_call_entry(const QV4::ExecutionEngine *engine, const QString &function, const QString &fileName, int line, int column) +QQmlV4_function_call_exit() -- cgit v1.2.3 From 3df85008591dffc64427095b022421469cb9a866 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 30 Apr 2019 11:22:23 +0200 Subject: Avoid std::function in qqmlirbuilder.cpp Some compilers seem to miscompile this construction. Furthermore, it doesn't really add to the readability of the code. Inline the code in question at the only place it's used and avoid most of the const_cast by adding a non-const accessor to CompiledData::Unit. Fixes: QTBUG-75392 Change-Id: I015317f28a92817d08d616cc35956745758d7847 Reviewed-by: Simon Hausmann --- src/qml/compiler/qqmlirbuilder.cpp | 36 ++++++++++++++---------------------- src/qml/compiler/qv4compileddata_p.h | 4 ++++ 2 files changed, 18 insertions(+), 22 deletions(-) (limited to 'src/qml') diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 868f600a10..558399ad6c 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1558,15 +1558,12 @@ void QmlUnitGenerator::generate(Document &output, const QV4::CompiledData::Depen QQmlRefPointer compilationUnit = output.javaScriptCompilationUnit; - const QV4::CompiledData::Unit *jsUnit = nullptr; - std::function unitFinalizer - = [](QV4::CompiledData::QmlUnit *unit, uint) { - return unit; - }; + QV4::CompiledData::Unit *jsUnit = nullptr; + const bool finalize = !compilationUnit->data; // We may already have unit data if we're loading an ahead-of-time generated cache file. - if (compilationUnit->data) { - jsUnit = compilationUnit->data; + if (!finalize) { + jsUnit = const_cast(compilationUnit->data); #ifndef V4_BOOTSTRAP output.javaScriptCompilationUnit->dynamicStrings = output.jsGenerator.stringTable.allStrings(); #endif @@ -1599,20 +1596,6 @@ void QmlUnitGenerator::generate(Document &output, const QV4::CompiledData::Depen #endif createdUnit->sourceFileIndex = output.jsGenerator.stringTable.getStringId(output.jsModule.fileName); createdUnit->finalUrlIndex = output.jsGenerator.stringTable.getStringId(output.jsModule.finalUrl); - - // Combine the qml data into the general unit data. - unitFinalizer = [&jsUnit](QV4::CompiledData::QmlUnit *qmlUnit, uint qmlDataSize) { - void *ptr = const_cast(jsUnit); - QV4::CompiledData::Unit *newUnit = (QV4::CompiledData::Unit *)realloc(ptr, jsUnit->unitSize + qmlDataSize); - jsUnit = newUnit; - newUnit->offsetToQmlUnit = newUnit->unitSize; - newUnit->unitSize += qmlDataSize; - memcpy(const_cast(newUnit->qmlUnit()), qmlUnit, qmlDataSize); - free(const_cast(qmlUnit)); - qmlUnit = nullptr; - newUnit->generateChecksum(); - return const_cast(newUnit->qmlUnit()); - }; } // No more new strings after this point, we're calculating offsets. @@ -1779,7 +1762,16 @@ void QmlUnitGenerator::generate(Document &output, const QV4::CompiledData::Depen } } - qmlUnit = unitFinalizer(qmlUnit, totalSize); + if (finalize) { + // Combine the qml data into the general unit data. + jsUnit = static_cast(realloc(jsUnit, jsUnit->unitSize + totalSize)); + jsUnit->offsetToQmlUnit = jsUnit->unitSize; + jsUnit->unitSize += totalSize; + memcpy(jsUnit->qmlUnit(), qmlUnit, totalSize); + free(qmlUnit); + jsUnit->generateChecksum(); + qmlUnit = jsUnit->qmlUnit(); + } static const bool showStats = qEnvironmentVariableIsSet("QML_SHOW_UNIT_STATS"); if (showStats) { diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h index 3fd9fdf74b..76795f7aa3 100644 --- a/src/qml/compiler/qv4compileddata_p.h +++ b/src/qml/compiler/qv4compileddata_p.h @@ -891,6 +891,10 @@ struct Unit return reinterpret_cast(reinterpret_cast(this) + offsetToQmlUnit); } + QmlUnit *qmlUnit() { + return reinterpret_cast(reinterpret_cast(this) + offsetToQmlUnit); + } + bool isSingleton() const { return flags & Unit::IsSingleton; } -- cgit v1.2.3