From abb55de9b50e6989ff3216e0c85131a31d3199a5 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 12 Feb 2014 17:50:55 +0100 Subject: [PATCH] QmlProfiler: Make the progress bar somewhat nicer. Allow adding a weight to certain tasks so that the movement of the bar gets smoother and update the progress from more places. Change-Id: Ifb8331dc77116cc0464b3970cd6344fbbeacec41 Reviewed-by: Kai Koehne --- .../qmlprofilereventsmodelproxy.cpp | 6 ++++++ .../qmlprofiler/qmlprofilermodelmanager.cpp | 18 +++++++++++++++--- .../qmlprofiler/qmlprofilermodelmanager.h | 1 + .../qmlprofiler/qmlprofilerprocessedmodel.cpp | 9 ++++++++- .../qmlprofiler/qmlprofilerprocessedmodel.h | 1 + .../qmlprofiler/qmlprofilersimplemodel.cpp | 1 + 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.cpp b/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.cpp index 19cc03223c7..ca9b036f4b4 100644 --- a/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.cpp +++ b/src/plugins/qmlprofiler/qmlprofilereventsmodelproxy.cpp @@ -69,6 +69,9 @@ QmlProfilerEventsModelProxy::QmlProfilerEventsModelProxy(QmlProfilerModelManager connect(modelManager->simpleModel(), SIGNAL(changed()), this, SLOT(dataChanged())); d->modelId = modelManager->registerModelProxy(); + // We're iterating twice in loadData. + modelManager->setProxyCountWeight(d->modelId, 2); + d->acceptedTypes << QmlDebug::Compiling << QmlDebug::Creating << QmlDebug::Binding << QmlDebug::HandlingSignal << QmlDebug::Javascript; } @@ -211,6 +214,8 @@ void QmlProfilerEventsModelProxy::loadData(qint64 rangeStart, qint64 rangeEnd) } // post-process: calc mean time, median time, percentoftime + int i = d->data.size(); + int total = i * 2; foreach (const QString &hash, d->data.keys()) { QmlEventStats* stats = &d->data[hash]; if (stats->calls > 0) @@ -223,6 +228,7 @@ void QmlProfilerEventsModelProxy::loadData(qint64 rangeStart, qint64 rangeEnd) } stats->percentOfTime = stats->duration * 100.0 / qmlTime; + d->modelManager->modelProxyCountUpdated(d->modelId, i++, total); } // set binding loop flag diff --git a/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp b/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp index abedd2700f4..df5dfbc20db 100644 --- a/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp @@ -145,6 +145,8 @@ public: QmlProfilerTraceTime *traceTime; QVector partialCounts; + QVector partialCountWeights; + int totalWeight; double progress; qint64 estimatedTime; @@ -156,6 +158,7 @@ public: QmlProfilerModelManager::QmlProfilerModelManager(Utils::FileInProjectFinder *finder, QObject *parent) : QObject(parent), d(new QmlProfilerModelManagerPrivate(this)) { + d->totalWeight = 0; d->model = new QmlProfilerProcessedModel(finder, this); d->v8Model = new QV8ProfilerDataModel(this); // d->model = new QmlProfilerSimpleModel(this); @@ -201,20 +204,29 @@ double QmlProfilerModelManager::progress() const int QmlProfilerModelManager::registerModelProxy() { d->partialCounts << 0; + d->partialCountWeights << 1; + d->totalWeight++; return d->partialCounts.count()-1; } +void QmlProfilerModelManager::setProxyCountWeight(int proxyId, int weight) +{ + d->totalWeight += weight - d->partialCountWeights[proxyId]; + d->partialCountWeights[proxyId] = weight; +} + void QmlProfilerModelManager::modelProxyCountUpdated(int proxyId, qint64 count, qint64 max) { - d->progress -= d->partialCounts[proxyId] / d->partialCounts.count(); + d->progress -= d->partialCounts[proxyId] * d->partialCountWeights[proxyId] / + d->totalWeight; if (max <= 0) d->partialCounts[proxyId] = 1; else d->partialCounts[proxyId] = (double)count / (double) max; - d->progress += d->partialCounts[proxyId] / d->partialCounts.count(); - + d->progress += d->partialCounts[proxyId] * d->partialCountWeights[proxyId] / + d->totalWeight; emit progressChanged(); } diff --git a/src/plugins/qmlprofiler/qmlprofilermodelmanager.h b/src/plugins/qmlprofiler/qmlprofilermodelmanager.h index 92acb8fb8de..8920ec0adeb 100644 --- a/src/plugins/qmlprofiler/qmlprofilermodelmanager.h +++ b/src/plugins/qmlprofiler/qmlprofilermodelmanager.h @@ -117,6 +117,7 @@ public: double progress() const; int registerModelProxy(); + void setProxyCountWeight(int proxyId, int weight); void modelProxyCountUpdated(int proxyId, qint64 count, qint64 max); qint64 estimatedProfilingTime() const; diff --git a/src/plugins/qmlprofiler/qmlprofilerprocessedmodel.cpp b/src/plugins/qmlprofiler/qmlprofilerprocessedmodel.cpp index 240814a125b..1946a3ce1d8 100644 --- a/src/plugins/qmlprofiler/qmlprofilerprocessedmodel.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerprocessedmodel.cpp @@ -101,6 +101,10 @@ QmlProfilerProcessedModel::QmlProfilerProcessedModel(Utils::FileInProjectFinder : QmlProfilerSimpleModel(parent) , m_detailsRewriter(new QmlProfilerDetailsRewriter(this, fileFinder)) { + m_processedModelId = m_modelManager->registerModelProxy(); + // The document loading is very expensive. + m_modelManager->setProxyCountWeight(m_processedModelId, 3); + connect(m_detailsRewriter, SIGNAL(rewriteDetailsString(int,QString)), this, SLOT(detailsChanged(int,QString))); connect(m_detailsRewriter, SIGNAL(eventDetailsChanged()), @@ -114,13 +118,14 @@ QmlProfilerProcessedModel::~QmlProfilerProcessedModel() void QmlProfilerProcessedModel::clear() { m_detailsRewriter->clearRequests(); - + m_modelManager->modelProxyCountUpdated(m_processedModelId, 0, 1); // This call emits changed(). Don't emit it again here. QmlProfilerSimpleModel::clear(); } void QmlProfilerProcessedModel::complete() { + m_modelManager->modelProxyCountUpdated(m_processedModelId, 0, 1); // post-processing // sort events by start time @@ -150,6 +155,7 @@ void QmlProfilerProcessedModel::complete() continue; m_detailsRewriter->requestDetailsForLocation(i, event->location); + m_modelManager->modelProxyCountUpdated(m_processedModelId, i, n); } // Allow QmlProfilerBaseModel::complete() only after documents have been reloaded to avoid @@ -167,6 +173,7 @@ void QmlProfilerProcessedModel::detailsChanged(int requestId, const QString &new void QmlProfilerProcessedModel::detailsDone() { + m_modelManager->modelProxyCountUpdated(m_processedModelId, 1, 1); // The child models are supposed to synchronously update on changed(), triggered by // QmlProfilerBaseModel::complete(). QmlProfilerSimpleModel::complete(); diff --git a/src/plugins/qmlprofiler/qmlprofilerprocessedmodel.h b/src/plugins/qmlprofiler/qmlprofilerprocessedmodel.h index 3e3738824dd..ca24675151b 100644 --- a/src/plugins/qmlprofiler/qmlprofilerprocessedmodel.h +++ b/src/plugins/qmlprofiler/qmlprofilerprocessedmodel.h @@ -52,6 +52,7 @@ private slots: void detailsDone(); private: + int m_processedModelId; QmlProfilerDetailsRewriter *m_detailsRewriter; }; diff --git a/src/plugins/qmlprofiler/qmlprofilersimplemodel.cpp b/src/plugins/qmlprofiler/qmlprofilersimplemodel.cpp index 93759ec14b9..231c062fc77 100644 --- a/src/plugins/qmlprofiler/qmlprofilersimplemodel.cpp +++ b/src/plugins/qmlprofiler/qmlprofilersimplemodel.cpp @@ -42,6 +42,7 @@ namespace QmlProfiler { QmlProfilerSimpleModel::QmlProfilerSimpleModel(QmlProfilerModelManager *parent) : QmlProfilerBaseModel(parent) { + m_modelManager->setProxyCountWeight(m_modelId, 2); } QmlProfilerSimpleModel::~QmlProfilerSimpleModel()