Commit cc4aae53 authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: Show multiple rows for animations from different threads

Task-number: QTCREATORBUG-11659
Change-Id: I40ed0ff755b5583947de08207993325dc1039d87
Reviewed-by: default avatarKai Koehne <kai.koehne@digia.com>
parent 14dc364c
...@@ -55,6 +55,13 @@ enum BindingType { ...@@ -55,6 +55,13 @@ enum BindingType {
MaximumBindingType MaximumBindingType
}; };
enum AnimationThread {
GuiThread,
RenderThread,
MaximumAnimationThread
};
namespace Constants { namespace Constants {
const int QML_MIN_LEVEL = 1; // Set to 0 to remove the empty line between models in the timeline const int QML_MIN_LEVEL = 1; // Set to 0 to remove the empty line between models in the timeline
} }
......
...@@ -169,9 +169,14 @@ void QmlProfilerTraceClient::messageReceived(const QByteArray &data) ...@@ -169,9 +169,14 @@ void QmlProfilerTraceClient::messageReceived(const QByteArray &data)
d->maximumTime = qMax(time, d->maximumTime); d->maximumTime = qMax(time, d->maximumTime);
} else if (event == AnimationFrame) { } else if (event == AnimationFrame) {
int frameRate, animationCount; int frameRate, animationCount;
int threadId;
stream >> frameRate >> animationCount; stream >> frameRate >> animationCount;
if (!stream.atEnd())
stream >> threadId;
else
threadId = 0;
emit rangedEvent(QmlDebug::Painting, QmlDebug::AnimationFrame, time, 0, emit rangedEvent(QmlDebug::Painting, QmlDebug::AnimationFrame, time, 0,
QStringList(), QmlDebug::QmlEventLocation(), frameRate, animationCount, 0,0,0); QStringList(), QmlDebug::QmlEventLocation(), frameRate, animationCount, threadId,0,0);
d->maximumTime = qMax(time, d->maximumTime); d->maximumTime = qMax(time, d->maximumTime);
} else if (event == StartTrace) { } else if (event == StartTrace) {
emit this->traceStarted(time); emit this->traceStarted(time);
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "qmlprofilerdatamodel.h" #include "qmlprofilerdatamodel.h"
#include "sortedtimelinemodel.h" #include "sortedtimelinemodel.h"
#include "singlecategorytimelinemodel_p.h" #include "singlecategorytimelinemodel_p.h"
#include <utils/qtcassert.h>
#include <QCoreApplication> #include <QCoreApplication>
#include <QVector> #include <QVector>
...@@ -50,10 +51,9 @@ class PaintEventsModelProxy::PaintEventsModelProxyPrivate : ...@@ -50,10 +51,9 @@ class PaintEventsModelProxy::PaintEventsModelProxyPrivate :
SingleCategoryTimelineModel::SingleCategoryTimelineModelPrivate> SingleCategoryTimelineModel::SingleCategoryTimelineModelPrivate>
{ {
public: public:
void computeAnimationCountLimit();
int minAnimationCount; int maxGuiThreadAnimations;
int maxAnimationCount; int maxRenderThreadAnimations;
bool seenForeignPaintEvent; bool seenForeignPaintEvent;
private: private:
...@@ -67,8 +67,7 @@ PaintEventsModelProxy::PaintEventsModelProxy(QObject *parent) ...@@ -67,8 +67,7 @@ PaintEventsModelProxy::PaintEventsModelProxy(QObject *parent)
{ {
Q_D(PaintEventsModelProxy); Q_D(PaintEventsModelProxy);
d->seenForeignPaintEvent = false; d->seenForeignPaintEvent = false;
d->minAnimationCount = 1; d->maxGuiThreadAnimations = d->maxRenderThreadAnimations = 0;
d->maxAnimationCount = 1;
} }
...@@ -76,8 +75,7 @@ void PaintEventsModelProxy::clear() ...@@ -76,8 +75,7 @@ void PaintEventsModelProxy::clear()
{ {
Q_D(PaintEventsModelProxy); Q_D(PaintEventsModelProxy);
d->SortedTimelineModel::clear(); d->SortedTimelineModel::clear();
d->minAnimationCount = 1; d->maxGuiThreadAnimations = d->maxRenderThreadAnimations = 0;
d->maxAnimationCount = 1;
d->expanded = false; d->expanded = false;
d->seenForeignPaintEvent = false; d->seenForeignPaintEvent = false;
d->modelManager->modelProxyCountUpdated(d->modelId, 0, 1); d->modelManager->modelProxyCountUpdated(d->modelId, 0, 1);
...@@ -101,7 +99,7 @@ void PaintEventsModelProxy::loadData() ...@@ -101,7 +99,7 @@ void PaintEventsModelProxy::loadData()
const QVector<QmlProfilerDataModel::QmlEventData> referenceList = simpleModel->getEvents(); const QVector<QmlProfilerDataModel::QmlEventData> referenceList = simpleModel->getEvents();
QmlPaintEventData lastEvent; QmlPaintEventData lastEvent;
qint64 minNextStartTime = 0; qint64 minNextStartTimes[] = {0, 0};
foreach (const QmlProfilerDataModel::QmlEventData &event, referenceList) { foreach (const QmlProfilerDataModel::QmlEventData &event, referenceList) {
if (!eventAccepted(event)) { if (!eventAccepted(event)) {
...@@ -110,6 +108,8 @@ void PaintEventsModelProxy::loadData() ...@@ -110,6 +108,8 @@ void PaintEventsModelProxy::loadData()
continue; continue;
} }
lastEvent.threadId = (QmlDebug::AnimationThread)event.numericData3;
// initial estimation of the event duration: 1/framerate // initial estimation of the event duration: 1/framerate
qint64 estimatedDuration = event.numericData1 > 0 ? 1e9/event.numericData1 : 1; qint64 estimatedDuration = event.numericData1 > 0 ? 1e9/event.numericData1 : 1;
...@@ -117,7 +117,7 @@ void PaintEventsModelProxy::loadData() ...@@ -117,7 +117,7 @@ void PaintEventsModelProxy::loadData()
qint64 realEndTime = event.startTime; qint64 realEndTime = event.startTime;
// ranges should not overlap. If they do, our estimate wasn't accurate enough // ranges should not overlap. If they do, our estimate wasn't accurate enough
qint64 realStartTime = qMax(event.startTime - estimatedDuration, minNextStartTime); qint64 realStartTime = qMax(event.startTime - estimatedDuration, minNextStartTimes[lastEvent.threadId]);
// Sometimes our estimate is far off or the server has miscalculated the frame rate // Sometimes our estimate is far off or the server has miscalculated the frame rate
if (realStartTime >= realEndTime) if (realStartTime >= realEndTime)
...@@ -127,14 +127,21 @@ void PaintEventsModelProxy::loadData() ...@@ -127,14 +127,21 @@ void PaintEventsModelProxy::loadData()
// The server should know better after all and if it doesn't we want to see that. // The server should know better after all and if it doesn't we want to see that.
lastEvent.framerate = (int)event.numericData1; lastEvent.framerate = (int)event.numericData1;
lastEvent.animationcount = (int)event.numericData2; lastEvent.animationcount = (int)event.numericData2;
QTC_ASSERT(lastEvent.animationcount > 0, continue);
d->insert(realStartTime, realEndTime - realStartTime, lastEvent); d->insert(realStartTime, realEndTime - realStartTime, lastEvent);
minNextStartTime = event.startTime + 1; if (lastEvent.threadId == QmlDebug::GuiThread)
d->maxGuiThreadAnimations = qMax(lastEvent.animationcount, d->maxGuiThreadAnimations);
else
d->maxRenderThreadAnimations =
qMax(lastEvent.animationcount, d->maxRenderThreadAnimations);
minNextStartTimes[lastEvent.threadId] = event.startTime + 1;
d->modelManager->modelProxyCountUpdated(d->modelId, d->count(), referenceList.count()); d->modelManager->modelProxyCountUpdated(d->modelId, d->count(), referenceList.count());
} }
d->computeAnimationCountLimit();
d->computeNesting(); d->computeNesting();
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1); d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
...@@ -144,25 +151,25 @@ void PaintEventsModelProxy::loadData() ...@@ -144,25 +151,25 @@ void PaintEventsModelProxy::loadData()
int PaintEventsModelProxy::categoryDepth(int categoryIndex) const int PaintEventsModelProxy::categoryDepth(int categoryIndex) const
{ {
Q_D(const PaintEventsModelProxy);
Q_UNUSED(categoryIndex); Q_UNUSED(categoryIndex);
Q_D(const PaintEventsModelProxy);
if (isEmpty()) if (isEmpty())
return d->seenForeignPaintEvent ? 0 : 1; return d->seenForeignPaintEvent ? 0 : 1;
else else
return 2; return (d->maxGuiThreadAnimations == 0 || d->maxRenderThreadAnimations == 0) ? 2 : 3;
} }
int PaintEventsModelProxy::getEventRow(int index) const int PaintEventsModelProxy::getEventRow(int index) const
{ {
Q_UNUSED(index); Q_D(const PaintEventsModelProxy);
return 1; QmlDebug::AnimationThread threadId = d->range(index).threadId;
return (threadId == QmlDebug::GuiThread || d->maxGuiThreadAnimations == 0) ? 1 : 2;
} }
int PaintEventsModelProxy::getEventId(int index) const int PaintEventsModelProxy::getEventId(int index) const
{ {
// there is only one event Id for all painting events Q_D(const PaintEventsModelProxy);
Q_UNUSED(index); return d->range(index).threadId;
return 0;
} }
QColor PaintEventsModelProxy::getColor(int index) const QColor PaintEventsModelProxy::getColor(int index) const
...@@ -179,44 +186,34 @@ QColor PaintEventsModelProxy::getColor(int index) const ...@@ -179,44 +186,34 @@ QColor PaintEventsModelProxy::getColor(int index) const
float PaintEventsModelProxy::getHeight(int index) const float PaintEventsModelProxy::getHeight(int index) const
{ {
Q_D(const PaintEventsModelProxy); Q_D(const PaintEventsModelProxy);
float scale = d->maxAnimationCount - d->minAnimationCount; const PaintEventsModelProxyPrivate::Range &range = d->range(index);
float fraction = 1.0f; return (float)range.animationcount / (float)(range.threadId == QmlDebug::GuiThread ?
if (scale > 1) d->maxGuiThreadAnimations : d->maxRenderThreadAnimations) * 0.85f + 0.15f;
fraction = (float)(d->range(index).animationcount -
d->minAnimationCount) / scale;
return fraction * 0.85f + 0.15f;
} }
const QVariantList PaintEventsModelProxy::getLabelsForCategory(int category) const const QVariantList PaintEventsModelProxy::getLabelsForCategory(int category) const
{ {
Q_UNUSED(category); Q_UNUSED(category);
Q_D(const PaintEventsModelProxy);
QVariantList result; QVariantList result;
if (!isEmpty()) { if (d->maxGuiThreadAnimations > 0) {
QVariantMap element; QVariantMap element;
element.insert(QLatin1String("displayName"), QVariant(QLatin1String("Animations"))); element.insert(QLatin1String("displayName"), QVariant(tr("Animations")));
element.insert(QLatin1String("description"), QVariant(QLatin1String("Animations"))); element.insert(QLatin1String("description"), QVariant(tr("GUI Thread")));
element.insert(QLatin1String("id"), QVariant(0)); element.insert(QLatin1String("id"), QVariant(QmlDebug::GuiThread));
result << element; result << element;
} }
return result; if (d->maxRenderThreadAnimations > 0) {
} QVariantMap element;
element.insert(QLatin1String("displayName"), QVariant(tr("Animations")));
void PaintEventsModelProxy::PaintEventsModelProxyPrivate::computeAnimationCountLimit() element.insert(QLatin1String("description"), QVariant(tr("Render Thread")));
{ element.insert(QLatin1String("id"), QVariant(QmlDebug::RenderThread));
minAnimationCount = 1; result << element;
maxAnimationCount = 1;
if (count() == 0)
return;
for (int i=0; i < count(); i++) {
if (range(i).animationcount < minAnimationCount)
minAnimationCount = range(i).animationcount;
else if (range(i).animationcount > maxAnimationCount)
maxAnimationCount = range(i).animationcount;
} }
return result;
} }
const QVariantList PaintEventsModelProxy::getEventDetails(int index) const const QVariantList PaintEventsModelProxy::getEventDetails(int index) const
...@@ -253,6 +250,15 @@ const QVariantList PaintEventsModelProxy::getEventDetails(int index) const ...@@ -253,6 +250,15 @@ const QVariantList PaintEventsModelProxy::getEventDetails(int index) const
result << valuePair; result << valuePair;
} }
{
QVariantMap valuePair;
valuePair.insert(QCoreApplication::translate(trContext, "Context:"),
QCoreApplication::translate(trContext,
d->range(index).threadId == QmlDebug::GuiThread ?
"GUI Thread" : "Render Thread"));
result << valuePair;
}
return result; return result;
} }
......
...@@ -56,6 +56,7 @@ public: ...@@ -56,6 +56,7 @@ public:
struct QmlPaintEventData { struct QmlPaintEventData {
int framerate; int framerate;
int animationcount; int animationcount;
QmlDebug::AnimationThread threadId;
}; };
PaintEventsModelProxy(QObject *parent = 0); PaintEventsModelProxy(QObject *parent = 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment