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 <kai.koehne@digia.com>
This commit is contained in:
Ulf Hermann
2014-02-12 17:50:55 +01:00
parent 47ce17b1ba
commit abb55de9b5
6 changed files with 32 additions and 4 deletions

View File

@@ -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

View File

@@ -145,6 +145,8 @@ public:
QmlProfilerTraceTime *traceTime;
QVector <double> partialCounts;
QVector <int> 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();
}

View File

@@ -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;

View File

@@ -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();

View File

@@ -52,6 +52,7 @@ private slots:
void detailsDone();
private:
int m_processedModelId;
QmlProfilerDetailsRewriter *m_detailsRewriter;
};

View File

@@ -42,6 +42,7 @@ namespace QmlProfiler {
QmlProfilerSimpleModel::QmlProfilerSimpleModel(QmlProfilerModelManager *parent)
: QmlProfilerBaseModel(parent)
{
m_modelManager->setProxyCountWeight(m_modelId, 2);
}
QmlProfilerSimpleModel::~QmlProfilerSimpleModel()