[new compiler] Fix profiler support
authorSimon Hausmann <simon.hausmann@digia.com>
Mon, 3 Mar 2014 07:36:32 +0000 (08:36 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 4 Mar 2014 14:22:58 +0000 (15:22 +0100)
Add profiler tracing calls during objection creation and make sure to set the
function token / source location correctly for the synthesized function
declarations of signal handlers.

Change-Id: Ie4f8accce3a5c5d1d57bb0646cda588b89b76718
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/compiler/qqmltypecompiler.cpp
src/qml/debugger/qqmlprofiler_p.h
src/qml/qml/qqmlobjectcreator.cpp
src/qml/qml/qqmlobjectcreator_p.h

index 6dcf15f..780b3da 100644 (file)
@@ -1043,6 +1043,7 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio
         QQmlJS::AST::FunctionBody *body = new (pool) QQmlJS::AST::FunctionBody(elements);
 
         QQmlJS::AST::FunctionDeclaration *functionDeclaration = new (pool) QQmlJS::AST::FunctionDeclaration(compiler->newStringRef(stringAt(binding->propertyNameIndex)), paramList, body);
+        functionDeclaration->functionToken = foe->node->firstSourceLocation();
 
         foe->node = functionDeclaration;
         binding->propertyNameIndex = compiler->registerString(propertyName);
index ca464e8..27d4b58 100644 (file)
@@ -258,7 +258,7 @@ struct QQmlCompilingProfiler : public QQmlProfilerHelper {
     }
 };
 
-#define Q_QML_VME_PROFILE(profiler, Method) Q_QML_PROFILE_IF_ENABLED(profiler.profiler, profiler.Method)
+#define Q_QML_VME_PROFILE(profilerMember, Method) Q_QML_PROFILE_IF_ENABLED(profilerMember.profiler, profilerMember.Method)
 
 struct QQmlVmeProfiler : public QQmlProfilerDefinitions {
 public:
index 8a28fa1..6ec8c2b 100644 (file)
@@ -98,6 +98,7 @@ QQmlObjectCreator::QQmlObjectCreator(QQmlContextData *parentContext, QQmlCompile
     sharedState->allCreatedObjects.allocate(compiledData->totalObjectCount);
     sharedState->creationContext = creationContext;
     sharedState->rootContext = 0;
+    sharedState->profiler.profiler = QQmlEnginePrivate::get(engine)->profiler;
 }
 
 QQmlObjectCreator::QQmlObjectCreator(QQmlContextData *parentContext, QQmlCompiledData *compiledData, QQmlObjectCreatorSharedState *inheritedSharedState)
@@ -224,6 +225,8 @@ QObject *QQmlObjectCreator::create(int subComponentIndex, QObject *parent, QQmlI
         context->contextObject = instance;
     }
 
+    Q_QML_VME_PROFILE(sharedState->profiler, stop());
+
     phase = CreatingObjectsPhase2;
 
     if (interrupt && interrupt->shouldInterrupt())
@@ -993,6 +996,7 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent)
         installPropertyCache = !typeRef->isFullyDynamicType;
         QQmlType *type = typeRef->type;
         if (type) {
+            Q_QML_VME_PROFILE(sharedState->profiler, start(type->qmlTypeName(), context->url, obj->location.line, obj->location.column));
             instance = type->create();
             if (!instance) {
                 recordError(obj->location, tr("Unable to create object of type %1").arg(stringAt(obj->inheritedTypeNameIndex)));
@@ -1019,8 +1023,10 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent)
                 recordError(obj->location, tr("Composite Singleton Type %1 is not creatable").arg(stringAt(obj->inheritedTypeNameIndex)));
                 return 0;
             }
+            Q_QML_VME_PROFILE(sharedState->profiler, startBackground(typeRef->component->name));
             QQmlObjectCreator subCreator(context, typeRef->component, sharedState.data());
             instance = subCreator.create();
+            Q_QML_VME_PROFILE(sharedState->profiler, foreground(context->url, obj->location.line, obj->location.column));
             if (!instance) {
                 errors += subCreator.errors;
                 return 0;
@@ -1129,6 +1135,7 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru
     if (true /* ### componentCompleteEnabled()*/) { // the qml designer does the component complete later
         QQmlTrace trace("VME Component Complete");
         while (!sharedState->allParserStatusCallbacks.isEmpty()) {
+            Q_QML_VME_PROFILE(sharedState->profiler, pop());
             QQmlParserStatus *status = sharedState->allParserStatusCallbacks.pop();
 
             if (status && status->d) {
@@ -1139,6 +1146,7 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru
             if (watcher.hasRecursed() || interrupt.shouldInterrupt())
                 return 0;
         }
+        Q_QML_VME_PROFILE(sharedState->profiler, clear());
     }
 
     {
@@ -1187,12 +1195,20 @@ void QQmlObjectCreator::clear()
     while (!sharedState->allCreatedObjects.isEmpty())
         delete sharedState->allCreatedObjects.pop();
 
+    // If profiling is switched off during a VME run and then switched back on
+    // before or during the next run background ranges from the first run will
+    // be reported in the second run because we don't clear() here. We accept
+    // that as the collected data will be incomplete anyway and because not
+    // calling clear() here is benefitial for the non-profiling case.
+    Q_QML_VME_PROFILE(sharedState->profiler, clear(true));
+
     phase = Done;
 }
 
 bool QQmlObjectCreator::populateInstance(int index, QObject *instance, QQmlRefPointer<QQmlPropertyCache> cache, QObject *bindingTarget, QQmlPropertyData *valueTypeProperty, bool installPropertyCache, const QBitArray &bindingsToSkip)
 {
     const QV4::CompiledData::Object *obj = qmlUnit->objectAt(index);
+    Q_QML_VME_PROFILE(sharedState->profiler, push());
 
     QQmlData *declarativeData = QQmlData::get(instance, /*create*/true);
 
index cda17fe..b7d6790 100644 (file)
 #include <private/qqmltypecompiler_p.h>
 #include <private/qfinitestack_p.h>
 #include <private/qrecursionwatcher_p.h>
+#include <private/qqmlprofiler_p.h>
 
 QT_BEGIN_NAMESPACE
 
 class QQmlAbstractBinding;
 struct QQmlTypeCompiler;
 class QQmlInstantiationInterrupt;
+struct QQmlVmeProfiler;
 
 struct QQmlObjectCreatorSharedState
 {
@@ -64,6 +66,7 @@ struct QQmlObjectCreatorSharedState
     QFiniteStack<QObject*> allCreatedObjects;
     QQmlComponentAttached *componentAttached;
     QList<QQmlEnginePrivate::FinalizeCallback> finalizeCallbacks;
+    QQmlVmeProfiler profiler;
     QRecursionNode recursionNode;
 };