summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qmlcompiler.cpp31
-rw-r--r--src/declarative/qml/qmlcompiler_p.h18
2 files changed, 49 insertions, 0 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index 7a417bb..8f3d6a2 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -76,6 +76,7 @@
QT_BEGIN_NAMESPACE
DEFINE_BOOL_CONFIG_OPTION(compilerDump, QML_COMPILER_DUMP);
+DEFINE_BOOL_CONFIG_OPTION(compilerStatDump, QML_COMPILER_STATISTICS_DUMP);
using namespace QmlParser;
@@ -613,6 +614,8 @@ bool QmlCompiler::compile(QmlEngine *engine,
if (!isError()) {
if (compilerDump())
out->dumpInstructions();
+ if (compilerStatDump())
+ dumpStats();
} else {
reset(out);
}
@@ -664,6 +667,8 @@ void QmlCompiler::compileTree(Object *tree)
bool QmlCompiler::buildObject(Object *obj, const BindingContext &ctxt)
{
+ componentStat.objects++;
+
Q_ASSERT (obj->type != -1);
const QmlCompiledData::TypeReference &tr =
output->types.at(obj->type);
@@ -1148,15 +1153,21 @@ bool QmlCompiler::buildComponentFromRoot(QmlParser::Object *obj,
const BindingContext &ctxt)
{
ComponentCompileState oldComponentCompileState = compileState;
+ ComponentStat oldComponentStat = componentStat;
+
compileState = ComponentCompileState();
compileState.root = obj;
+ componentStat = ComponentStat();
+ componentStat.lineNumber = obj->location.start.line;
+
if (obj)
COMPILE_CHECK(buildObject(obj, ctxt));
COMPILE_CHECK(completeComponentBuild());
compileState = oldComponentCompileState;
+ componentStat = oldComponentStat;
return true;
}
@@ -1646,6 +1657,7 @@ void QmlCompiler::saveComponentState()
Q_ASSERT(!savedCompileStates.contains(compileState.root));
savedCompileStates.insert(compileState.root, compileState);
+ savedComponentStats.append(componentStat);
}
QmlCompiler::ComponentCompileState
@@ -2454,6 +2466,8 @@ int QmlCompiler::genContextCache()
bool QmlCompiler::completeComponentBuild()
{
+ componentStat.ids = compileState.ids.count();
+
for (int ii = 0; ii < compileState.aliasingObjects.count(); ++ii) {
Object *aliasObject = compileState.aliasingObjects.at(ii);
COMPILE_CHECK(buildDynamicMeta(aliasObject, ResolveAliases));
@@ -2478,6 +2492,8 @@ bool QmlCompiler::completeComponentBuild()
QByteArray(bs.compileData(), bs.compileDataSize());
type = QmlExpressionPrivate::BasicScriptEngineData;
binding.isBasicScript = true;
+
+ componentStat.optimizedBindings++;
} else {
type = QmlExpressionPrivate::PreTransformedQtScriptData;
@@ -2495,6 +2511,8 @@ bool QmlCompiler::completeComponentBuild()
QByteArray((const char *)expression.constData(),
expression.length() * sizeof(QChar));
binding.isBasicScript = false;
+
+ componentStat.scriptBindings++;
}
binding.compiledData.prepend(QByteArray((const char *)&type,
sizeof(quint32)));
@@ -2505,6 +2523,19 @@ bool QmlCompiler::completeComponentBuild()
return true;
}
+void QmlCompiler::dumpStats()
+{
+ qWarning().nospace() << "QML Document: " << output->url.toString();
+ for (int ii = 0; ii < savedComponentStats.count(); ++ii) {
+ const ComponentStat &stat = savedComponentStats.at(ii);
+ qWarning().nospace() << " Component Line " << stat.lineNumber;
+ qWarning().nospace() << " Total Objects: " << stat.objects;
+ qWarning().nospace() << " IDs Used: " << stat.ids;
+ qWarning().nospace() << " Optimized Bindings: " << stat.optimizedBindings;
+ qWarning().nospace() << " QScript Bindings: " << stat.scriptBindings;
+ }
+}
+
/*!
Returns true if from can be assigned to a (QObject) property of type
to.
diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h
index 8a9ca9c..6050c20 100644
--- a/src/declarative/qml/qmlcompiler_p.h
+++ b/src/declarative/qml/qmlcompiler_p.h
@@ -255,6 +255,8 @@ private:
void addId(const QString &, QmlParser::Object *);
+ void dumpStats();
+
struct BindingReference {
QmlParser::Variant expression;
QmlParser::Property *property;
@@ -280,9 +282,25 @@ private:
};
ComponentCompileState compileState;
+ struct ComponentStat
+ {
+ ComponentStat()
+ : ids(0), scriptBindings(0), optimizedBindings(0), objects(0) {}
+
+ int lineNumber;
+
+ int ids;
+ int scriptBindings;
+ int optimizedBindings;
+ int objects;
+ };
+ ComponentStat componentStat;
+
void saveComponentState();
+
ComponentCompileState componentState(QmlParser::Object *);
QHash<QmlParser::Object *, ComponentCompileState> savedCompileStates;
+ QList<ComponentStat> savedComponentStats;
QList<QmlError> exceptions;
QmlCompiledData *output;