QmlProfiler: Provide a sane ctor for QmlEventType and use it

... in turn, make its members private, so that we don't accidentally
change them.

Change-Id: Ibc65b406ee341d33f69647ed1b19e1e34f5cd535
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2016-06-06 19:51:55 +02:00
parent 5718f12af5
commit e10bc709bc
23 changed files with 267 additions and 318 deletions

View File

@@ -76,10 +76,10 @@ QVariantMap DebugMessagesModel::details(int index) const
const QmlEventType &type = modelManager()->qmlModel()->eventTypes()[m_data[index].typeId]; const QmlEventType &type = modelManager()->qmlModel()->eventTypes()[m_data[index].typeId];
QVariantMap result; QVariantMap result;
result.insert(QLatin1String("displayName"), messageType(type.detailType)); result.insert(QLatin1String("displayName"), messageType(type.detailType()));
result.insert(tr("Timestamp"), QmlProfilerDataModel::formatTime(startTime(index))); result.insert(tr("Timestamp"), QmlProfilerDataModel::formatTime(startTime(index)));
result.insert(tr("Message"), m_data[index].text); result.insert(tr("Message"), m_data[index].text);
result.insert(tr("Location"), type.displayName); result.insert(tr("Location"), type.displayName());
return result; return result;
} }
@@ -96,9 +96,9 @@ int DebugMessagesModel::collapsedRow(int index) const
void DebugMessagesModel::loadEvent(const QmlEvent &event, const QmlEventType &type) void DebugMessagesModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{ {
m_data.insert(insert(event.timestamp(), 0, type.detailType), m_data.insert(insert(event.timestamp(), 0, type.detailType()),
MessageData(event.string(), event.typeIndex())); MessageData(event.string(), event.typeIndex()));
if (type.detailType > m_maximumMsgType) if (type.detailType() > m_maximumMsgType)
m_maximumMsgType = event.typeIndex(); m_maximumMsgType = event.typeIndex();
} }

View File

@@ -168,14 +168,14 @@ QVariant FlameGraphModel::lookup(const FlameGraphData &stats, int role) const
const QmlEventType &type = typeList[stats.typeIndex]; const QmlEventType &type = typeList[stats.typeIndex];
switch (role) { switch (role) {
case FilenameRole: return type.location.filename(); case FilenameRole: return type.location().filename();
case LineRole: return type.location.line(); case LineRole: return type.location().line();
case ColumnRole: return type.location.column(); case ColumnRole: return type.location().column();
case TypeRole: return nameForType(type.rangeType); case TypeRole: return nameForType(type.rangeType());
case RangeTypeRole: return type.rangeType; case RangeTypeRole: return type.rangeType();
case DetailsRole: return type.data.isEmpty() ? case DetailsRole: return type.data().isEmpty() ?
FlameGraphModel::tr("Source code not available") : type.data; FlameGraphModel::tr("Source code not available") : type.data();
case LocationRole: return type.displayName; case LocationRole: return type.displayName();
default: return QVariant(); default: return QVariant();
} }
} else { } else {

View File

@@ -142,11 +142,11 @@ int InputEventsModel::collapsedRow(int index) const
void InputEventsModel::loadEvent(const QmlEvent &event, const QmlEventType &type) void InputEventsModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{ {
m_data.insert(insert(event.timestamp(), 0, type.detailType), m_data.insert(insert(event.timestamp(), 0, type.detailType()),
InputEvent(static_cast<InputEventType>(event.number<qint32>(0)), InputEvent(static_cast<InputEventType>(event.number<qint32>(0)),
event.number<qint32>(1), event.number<qint32>(2))); event.number<qint32>(1), event.number<qint32>(2)));
if (type.detailType == Mouse) { if (type.detailType() == Mouse) {
if (m_mouseTypeId == -1) if (m_mouseTypeId == -1)
m_mouseTypeId = event.typeIndex(); m_mouseTypeId = event.typeIndex();
} else if (m_keyTypeId == -1) { } else if (m_keyTypeId == -1) {
@@ -170,7 +170,7 @@ void InputEventsModel::clear()
bool InputEventsModel::accepted(const QmlEventType &type) const bool InputEventsModel::accepted(const QmlEventType &type) const
{ {
return QmlProfilerTimelineModel::accepted(type) && return QmlProfilerTimelineModel::accepted(type) &&
(type.detailType == Mouse || type.detailType == Key); (type.detailType() == Mouse || type.detailType() == Key);
} }
InputEventsModel::InputEvent::InputEvent(InputEventType type, int a, int b) : InputEventsModel::InputEvent::InputEvent(InputEventType type, int a, int b) :

View File

@@ -122,19 +122,19 @@ QVariantMap MemoryUsageModel::details(int index) const
result.insert(tr("Type"), memoryTypeName); result.insert(tr("Type"), memoryTypeName);
result.insert(tr("Location"), result.insert(tr("Location"),
modelManager()->qmlModel()->eventTypes().at(ev->typeId).displayName); modelManager()->qmlModel()->eventTypes().at(ev->typeId).displayName());
return result; return result;
} }
bool MemoryUsageModel::accepted(const QmlEventType &type) const bool MemoryUsageModel::accepted(const QmlEventType &type) const
{ {
return QmlProfilerTimelineModel::accepted(type) || type.rangeType != MaximumRangeType; return QmlProfilerTimelineModel::accepted(type) || type.rangeType() != MaximumRangeType;
} }
void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type) void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{ {
if (type.message != MemoryAllocation) { if (type.message() != MemoryAllocation) {
if (type.rangeType != MaximumRangeType) { if (type.rangeType() != MaximumRangeType) {
if (event.rangeStage() == RangeStart) if (event.rangeStage() == RangeStart)
m_rangeStack.push(RangeStackFrame(event.typeIndex(), event.timestamp())); m_rangeStack.push(RangeStackFrame(event.typeIndex(), event.timestamp()));
else if (event.rangeStage() == RangeEnd) else if (event.rangeStage() == RangeEnd)
@@ -164,7 +164,7 @@ void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type
} }
}; };
if (type.detailType == SmallItem || type.detailType == LargeItem) { if (type.detailType() == SmallItem || type.detailType() == LargeItem) {
if (canContinue(ContinueUsage)) { if (canContinue(ContinueUsage)) {
m_data[m_currentUsageIndex].update(event.number<qint64>(0)); m_data[m_currentUsageIndex].update(event.number<qint64>(0));
m_currentUsage = m_data[m_currentUsageIndex].size; m_currentUsage = m_data[m_currentUsageIndex].size;
@@ -186,9 +186,9 @@ void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type
} }
} }
if (type.detailType == HeapPage || type.detailType == LargeItem) { if (type.detailType() == HeapPage || type.detailType() == LargeItem) {
if (canContinue(ContinueAllocation) if (canContinue(ContinueAllocation)
&& type.detailType == selectionId(m_currentJSHeapIndex)) { && type.detailType() == selectionId(m_currentJSHeapIndex)) {
m_data[m_currentJSHeapIndex].update(event.number<qint64>(0)); m_data[m_currentJSHeapIndex].update(event.number<qint64>(0));
m_currentSize = m_data[m_currentJSHeapIndex].size; m_currentSize = m_data[m_currentJSHeapIndex].size;
} else { } else {
@@ -204,7 +204,7 @@ void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type
if (m_currentJSHeapIndex != -1) if (m_currentJSHeapIndex != -1)
insertEnd(m_currentJSHeapIndex, insertEnd(m_currentJSHeapIndex,
event.timestamp() - startTime(m_currentJSHeapIndex) - 1); event.timestamp() - startTime(m_currentJSHeapIndex) - 1);
m_currentJSHeapIndex = insertStart(event.timestamp(), type.detailType); m_currentJSHeapIndex = insertStart(event.timestamp(), type.detailType());
m_data.insert(m_currentJSHeapIndex, allocation); m_data.insert(m_currentJSHeapIndex, allocation);
m_continuation = m_continuation | ContinueAllocation; m_continuation = m_continuation | ContinueAllocation;
} }

View File

@@ -163,13 +163,13 @@ QVariantMap PixmapCacheModel::details(int index) const
void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type) void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{ {
PixmapCacheItem newEvent; PixmapCacheItem newEvent;
const PixmapEventType pixmapType = static_cast<PixmapEventType>(type.detailType); const PixmapEventType pixmapType = static_cast<PixmapEventType>(type.detailType());
newEvent.pixmapEventType = pixmapType; newEvent.pixmapEventType = pixmapType;
qint64 pixmapStartTime = event.timestamp(); qint64 pixmapStartTime = event.timestamp();
newEvent.urlIndex = -1; newEvent.urlIndex = -1;
for (auto i = m_pixmaps.cend(), begin = m_pixmaps.cbegin(); i != begin;) { for (auto i = m_pixmaps.cend(), begin = m_pixmaps.cbegin(); i != begin;) {
if ((--i)->url == type.location.filename()) { if ((--i)->url == type.location().filename()) {
newEvent.urlIndex = i - m_pixmaps.cbegin(); newEvent.urlIndex = i - m_pixmaps.cbegin();
break; break;
} }
@@ -178,7 +178,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type
newEvent.sizeIndex = -1; newEvent.sizeIndex = -1;
if (newEvent.urlIndex == -1) { if (newEvent.urlIndex == -1) {
newEvent.urlIndex = m_pixmaps.count(); newEvent.urlIndex = m_pixmaps.count();
m_pixmaps << Pixmap(type.location.filename()); m_pixmaps << Pixmap(type.location().filename());
} }
Pixmap &pixmap = m_pixmaps[newEvent.urlIndex]; Pixmap &pixmap = m_pixmaps[newEvent.urlIndex];

View File

@@ -32,18 +32,45 @@ QDataStream &operator>>(QDataStream &stream, QmlEventType &type)
{ {
quint8 message; quint8 message;
quint8 rangeType; quint8 rangeType;
stream >> type.displayName >> type.data >> type.location >> message >> rangeType stream >> type.m_displayName >> type.m_data >> type.m_location >> message >> rangeType
>> type.detailType; >> type.m_detailType;
type.message = static_cast<Message>(message); type.m_message = static_cast<Message>(message);
type.rangeType = static_cast<RangeType>(rangeType); type.m_rangeType = static_cast<RangeType>(rangeType);
return stream; return stream;
} }
QDataStream &operator<<(QDataStream &stream, const QmlEventType &type) QDataStream &operator<<(QDataStream &stream, const QmlEventType &type)
{ {
return stream << type.displayName << type.data << type.location return stream << type.m_displayName << type.m_data << type.m_location
<< static_cast<quint8>(type.message) << static_cast<quint8>(type.rangeType) << static_cast<quint8>(type.m_message) << static_cast<quint8>(type.m_rangeType)
<< type.detailType; << type.m_detailType;
}
ProfileFeature QmlEventType::feature() const
{
switch (m_message) {
case Event: {
switch (m_detailType) {
case Mouse:
case Key:
return ProfileInputEvents;
case AnimationFrame:
return ProfileAnimations;
default:
return MaximumProfileFeature;
}
}
case PixmapCacheEvent:
return ProfilePixmapCache;
case SceneGraphFrame:
return ProfileSceneGraph;
case MemoryAllocation:
return ProfileMemory;
case DebugMessage:
return ProfileDebugMessages;
default:
return featureFromRangeType(m_rangeType);
}
} }

View File

@@ -31,48 +31,37 @@
namespace QmlProfiler { namespace QmlProfiler {
struct QmlEventType { class QmlEventType {
QmlEventType(const QString &displayName = QString(), public:
const QmlEventLocation &location = QmlEventLocation(), QmlEventType(Message message = MaximumMessage, RangeType rangeType = MaximumRangeType,
Message message = MaximumMessage, RangeType rangeType = MaximumRangeType, int detailType = -1, const QmlEventLocation &location = QmlEventLocation(),
int detailType = -1, const QString &data = QString()) : const QString &data = QString(), const QString displayName = QString()) :
displayName(displayName), data(data), location(location), message(message), m_displayName(displayName), m_data(data), m_location(location), m_message(message),
rangeType(rangeType), detailType(detailType) m_rangeType(rangeType), m_detailType(detailType)
{} {}
QString displayName; void setDisplayName(const QString &displayName) { m_displayName = displayName; }
QString data; void setData(const QString &data) { m_data = data; }
QmlEventLocation location; void setLocation(const QmlEventLocation &location) { m_location = location; }
Message message;
RangeType rangeType;
int detailType; // can be EventType, BindingType, PixmapEventType or SceneGraphFrameType
ProfileFeature feature() const ProfileFeature feature() const;
{ QString displayName() const { return m_displayName; }
switch (message) { QString data() const { return m_data; }
case Event: { QmlEventLocation location() const { return m_location; }
switch (detailType) { Message message() const { return m_message; }
case Mouse: RangeType rangeType() const { return m_rangeType; }
case Key: int detailType() const { return m_detailType; }
return ProfileInputEvents;
case AnimationFrame: private:
return ProfileAnimations; friend QDataStream &operator>>(QDataStream &stream, QmlEventType &type);
default: friend QDataStream &operator<<(QDataStream &stream, const QmlEventType &type);
return MaximumProfileFeature;
} QString m_displayName;
} QString m_data;
case PixmapCacheEvent: QmlEventLocation m_location;
return ProfilePixmapCache; Message m_message;
case SceneGraphFrame: RangeType m_rangeType;
return ProfileSceneGraph; int m_detailType; // can be EventType, BindingType, PixmapEventType or SceneGraphFrameType
case MemoryAllocation:
return ProfileMemory;
case DebugMessage:
return ProfileDebugMessages;
default:
return featureFromRangeType(rangeType);
}
}
}; };
QDataStream &operator>>(QDataStream &stream, QmlEventType &type); QDataStream &operator>>(QDataStream &stream, QmlEventType &type);

View File

@@ -57,7 +57,7 @@ void QmlProfilerAnimationsModel::clear()
bool QmlProfilerAnimationsModel::accepted(const QmlEventType &event) const bool QmlProfilerAnimationsModel::accepted(const QmlEventType &event) const
{ {
return QmlProfilerTimelineModel::accepted(event) && event.detailType == AnimationFrame; return QmlProfilerTimelineModel::accepted(event) && event.detailType() == AnimationFrame;
} }
void QmlProfilerAnimationsModel::loadEvent(const QmlEvent &event, const QmlEventType &type) void QmlProfilerAnimationsModel::loadEvent(const QmlEvent &event, const QmlEventType &type)

View File

@@ -57,24 +57,23 @@ public:
QString getDisplayName(const QmlEventType &event) QString getDisplayName(const QmlEventType &event)
{ {
if (event.location.filename().isEmpty()) { if (event.location().filename().isEmpty()) {
return QmlProfilerDataModel::tr("<bytecode>"); return QmlProfilerDataModel::tr("<bytecode>");
} else { } else {
const QString filePath = QUrl(event.location.filename()).path(); const QString filePath = QUrl(event.location().filename()).path();
return filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1) + QLatin1Char(':') + return filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1) + QLatin1Char(':') +
QString::number(event.location.line()); QString::number(event.location().line());
} }
} }
QString getInitialDetails(const QmlEventType &event) QString getInitialDetails(const QmlEventType &event)
{ {
QString details; QString details = event.data();
// generate details string // generate details string
if (!event.data.isEmpty()) { if (!details.isEmpty()) {
details = event.data;
details = details.replace(QLatin1Char('\n'),QLatin1Char(' ')).simplified(); details = details.replace(QLatin1Char('\n'),QLatin1Char(' ')).simplified();
if (details.isEmpty()) { if (details.isEmpty()) {
if (event.rangeType == Javascript) if (event.rangeType() == Javascript)
details = QmlProfilerDataModel::tr("anonymous function"); details = QmlProfilerDataModel::tr("anonymous function");
} else { } else {
QRegExp rewrite(QLatin1String("\\(function \\$(\\w+)\\(\\) \\{ (return |)(.+) \\}\\)")); QRegExp rewrite(QLatin1String("\\(function \\$(\\w+)\\(\\) \\{ (return |)(.+) \\}\\)"));
@@ -85,7 +84,7 @@ QString getInitialDetails(const QmlEventType &event)
details.startsWith(QLatin1String("qrc:/"))) details.startsWith(QLatin1String("qrc:/")))
details = details.mid(details.lastIndexOf(QLatin1Char('/')) + 1); details = details.mid(details.lastIndexOf(QLatin1Char('/')) + 1);
} }
} else if (event.rangeType == Painting) { } else if (event.rangeType() == Painting) {
// QtQuick1 animations always run in GUI thread. // QtQuick1 animations always run in GUI thread.
details = QmlProfilerDataModel::tr("GUI Thread"); details = QmlProfilerDataModel::tr("GUI Thread");
} }
@@ -174,18 +173,18 @@ bool QmlProfilerDataModel::isEmpty() const
void QmlProfilerDataModel::QmlProfilerDataModelPrivate::rewriteType(int typeIndex) void QmlProfilerDataModel::QmlProfilerDataModelPrivate::rewriteType(int typeIndex)
{ {
QmlEventType &type = eventTypes[typeIndex]; QmlEventType &type = eventTypes[typeIndex];
type.displayName = getDisplayName(type); type.setDisplayName(getDisplayName(type));
type.data = getInitialDetails(type); type.setData(getInitialDetails(type));
// Only bindings and signal handlers need rewriting // Only bindings and signal handlers need rewriting
if (type.rangeType != Binding && type.rangeType != HandlingSignal) if (type.rangeType() != Binding && type.rangeType() != HandlingSignal)
return; return;
// There is no point in looking for invalid locations // There is no point in looking for invalid locations
if (!type.location.isValid()) if (!type.location().isValid())
return; return;
detailsRewriter->requestDetailsForLocation(typeIndex, type.location); detailsRewriter->requestDetailsForLocation(typeIndex, type.location());
} }
void QmlProfilerDataModel::replayEvents(qint64 rangeStart, qint64 rangeEnd, void QmlProfilerDataModel::replayEvents(qint64 rangeStart, qint64 rangeEnd,
@@ -205,7 +204,7 @@ void QmlProfilerDataModel::replayEvents(qint64 rangeStart, qint64 rangeEnd,
const QmlEventType &type = d->eventTypes[event.typeIndex()]; const QmlEventType &type = d->eventTypes[event.typeIndex()];
if (rangeStart != -1 && rangeEnd != -1) { if (rangeStart != -1 && rangeEnd != -1) {
if (event.timestamp() < rangeStart) { if (event.timestamp() < rangeStart) {
if (type.rangeType != MaximumRangeType) { if (type.rangeType() != MaximumRangeType) {
if (event.rangeStage() == RangeStart) if (event.rangeStage() == RangeStart)
stack.push(event); stack.push(event);
else if (event.rangeStage() == RangeEnd) else if (event.rangeStage() == RangeEnd)
@@ -213,7 +212,7 @@ void QmlProfilerDataModel::replayEvents(qint64 rangeStart, qint64 rangeEnd,
} }
continue; continue;
} else if (event.timestamp() > rangeEnd) { } else if (event.timestamp() > rangeEnd) {
if (type.rangeType != MaximumRangeType) { if (type.rangeType() != MaximumRangeType) {
if (event.rangeStage() == RangeEnd) { if (event.rangeStage() == RangeEnd) {
if (stack.isEmpty()) { if (stack.isEmpty()) {
QmlEvent endEvent(event); QmlEvent endEvent(event);
@@ -251,7 +250,7 @@ void QmlProfilerDataModel::detailsChanged(int requestId, const QString &newStrin
{ {
Q_D(QmlProfilerDataModel); Q_D(QmlProfilerDataModel);
QTC_ASSERT(requestId < d->eventTypes.count(), return); QTC_ASSERT(requestId < d->eventTypes.count(), return);
d->eventTypes[requestId].data = newString; d->eventTypes[requestId].setData(newString);
} }
} // namespace QmlProfiler } // namespace QmlProfiler

View File

@@ -193,8 +193,8 @@ QVariantList QmlProfilerRangeModel::labels() const
for (int i = 1; i < expandedRowCount(); i++) { // Ignore the -1 for the first row for (int i = 1; i < expandedRowCount(); i++) { // Ignore the -1 for the first row
QVariantMap element; QVariantMap element;
int typeId = m_expandedRowTypes[i]; int typeId = m_expandedRowTypes[i];
element.insert(QLatin1String("displayName"), QVariant(types[typeId].displayName)); element.insert(QLatin1String("displayName"), QVariant(types[typeId].displayName()));
element.insert(QLatin1String("description"), QVariant(types[typeId].data)); element.insert(QLatin1String("description"), QVariant(types[typeId].data()));
element.insert(QLatin1String("id"), QVariant(typeId)); element.insert(QLatin1String("id"), QVariant(typeId));
result << element; result << element;
} }
@@ -212,8 +212,8 @@ QVariantMap QmlProfilerRangeModel::details(int index) const
tr(QmlProfilerModelManager::featureName(mainFeature()))); tr(QmlProfilerModelManager::featureName(mainFeature())));
result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index))); result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index)));
result.insert(tr("Details"), types[id].data); result.insert(tr("Details"), types[id].data());
result.insert(tr("Location"), types[id].displayName); result.insert(tr("Location"), types[id].displayName());
return result; return result;
} }

View File

@@ -207,7 +207,7 @@ void QmlProfilerStatisticsModel::notesChanged(int typeIndex)
void QmlProfilerStatisticsModel::loadEvent(const QmlEvent &event, const QmlEventType &type) void QmlProfilerStatisticsModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{ {
if (!d->acceptedTypes.contains(type.rangeType)) if (!d->acceptedTypes.contains(type.rangeType()))
return; return;
switch (event.rangeStage()) { switch (event.rangeStage()) {
@@ -215,7 +215,7 @@ void QmlProfilerStatisticsModel::loadEvent(const QmlEvent &event, const QmlEvent
// binding loop detection: check whether event is already in stack // binding loop detection: check whether event is already in stack
for (int ii = 1; ii < d->callStack.size(); ++ii) { for (int ii = 1; ii < d->callStack.size(); ++ii) {
if (d->callStack.at(ii).typeIndex() == event.typeIndex() if (d->callStack.at(ii).typeIndex() == event.typeIndex()
&& type.rangeType != Javascript) { && type.rangeType() != Javascript) {
d->eventsInBindingLoop.insert(event.typeIndex()); d->eventsInBindingLoop.insert(event.typeIndex());
break; break;
} }

View File

@@ -53,15 +53,11 @@ struct Colors {
}; };
struct RootEventType : public QmlEventType { struct RootEventType : public QmlEventType {
RootEventType() RootEventType() : QmlEventType(MaximumMessage, MaximumRangeType, -1,
QmlEventLocation("<program>", 1, 1),
QmlProfilerStatisticsMainView::tr("Main Program"),
QmlProfilerStatisticsMainView::tr("<program>"))
{ {
QString rootEventName = QmlProfilerStatisticsMainView::tr("<program>");
displayName = rootEventName;
location = QmlEventLocation(rootEventName, 1, 1);
message = MaximumMessage;
rangeType = MaximumRangeType;
detailType = -1;
data = QmlProfilerStatisticsMainView::tr("Main Program");
} }
}; };
@@ -571,11 +567,11 @@ void QmlProfilerStatisticsMainView::parseModel()
QList<QStandardItem *> newRow; QList<QStandardItem *> newRow;
if (d->m_fieldShown[Name]) if (d->m_fieldShown[Name])
newRow << new StatisticsViewItem(event.displayName.isEmpty() ? tr("<bytecode>") : newRow << new StatisticsViewItem(event.displayName().isEmpty() ? tr("<bytecode>") :
event.displayName); event.displayName());
if (d->m_fieldShown[Type]) { if (d->m_fieldShown[Type]) {
QString typeString = QmlProfilerStatisticsMainView::nameForType(event.rangeType); QString typeString = QmlProfilerStatisticsMainView::nameForType(event.rangeType());
newRow << new StatisticsViewItem(typeString); newRow << new StatisticsViewItem(typeString);
newRow.last()->setData(QVariant(typeString)); newRow.last()->setData(QVariant(typeString));
} }
@@ -628,9 +624,9 @@ void QmlProfilerStatisticsMainView::parseModel()
} }
if (d->m_fieldShown[Details]) { if (d->m_fieldShown[Details]) {
newRow << new StatisticsViewItem(event.data.isEmpty() ? newRow << new StatisticsViewItem(event.data().isEmpty() ?
tr("Source code not available") : event.data); tr("Source code not available") : event.data());
newRow.last()->setData(QVariant(event.data)); newRow.last()->setData(event.data());
} }
@@ -642,9 +638,10 @@ void QmlProfilerStatisticsMainView::parseModel()
// metadata // metadata
newRow.at(0)->setData(typeIndex, TypeIdRole); newRow.at(0)->setData(typeIndex, TypeIdRole);
newRow.at(0)->setData(event.location.filename(), FilenameRole); const QmlEventLocation location(event.location());
newRow.at(0)->setData(event.location.line(), LineRole); newRow.at(0)->setData(location.filename(), FilenameRole);
newRow.at(0)->setData(event.location.column(), ColumnRole); newRow.at(0)->setData(location.line(), LineRole);
newRow.at(0)->setData(location.column(), ColumnRole);
// append // append
parentItem->appendRow(newRow); parentItem->appendRow(newRow);
@@ -859,23 +856,24 @@ void QmlProfilerStatisticsRelativesView::rebuildTree(
// ToDo: here we were going to search for the data in the other model // ToDo: here we were going to search for the data in the other model
// maybe we should store the data in this model and get it here // maybe we should store the data in this model and get it here
// no indirections at this level of abstraction! // no indirections at this level of abstraction!
newRow << new StatisticsViewItem(type.displayName.isEmpty() ? tr("<bytecode>") : newRow << new StatisticsViewItem(type.displayName().isEmpty() ? tr("<bytecode>") :
type.displayName); type.displayName());
newRow << new StatisticsViewItem(QmlProfilerStatisticsMainView::nameForType( newRow << new StatisticsViewItem(QmlProfilerStatisticsMainView::nameForType(
type.rangeType)); type.rangeType()));
newRow << new StatisticsViewItem(QmlProfilerDataModel::formatTime(event.duration)); newRow << new StatisticsViewItem(QmlProfilerDataModel::formatTime(event.duration));
newRow << new StatisticsViewItem(QString::number(event.calls)); newRow << new StatisticsViewItem(QString::number(event.calls));
newRow << new StatisticsViewItem(type.data.isEmpty() ? tr("Source code not available") : newRow << new StatisticsViewItem(type.data().isEmpty() ? tr("Source code not available") :
type.data); type.data());
newRow.at(0)->setData(typeIndex, TypeIdRole); newRow.at(0)->setData(typeIndex, TypeIdRole);
newRow.at(0)->setData(type.location.filename(), FilenameRole); const QmlEventLocation location(type.location());
newRow.at(0)->setData(type.location.line(), LineRole); newRow.at(0)->setData(location.filename(), FilenameRole);
newRow.at(0)->setData(type.location.column(), ColumnRole); newRow.at(0)->setData(location.line(), LineRole);
newRow.at(1)->setData(QmlProfilerStatisticsMainView::nameForType(type.rangeType)); newRow.at(0)->setData(location.column(), ColumnRole);
newRow.at(1)->setData(QmlProfilerStatisticsMainView::nameForType(type.rangeType()));
newRow.at(2)->setData(event.duration); newRow.at(2)->setData(event.duration);
newRow.at(3)->setData(event.calls); newRow.at(3)->setData(event.calls);
newRow.at(4)->setData(type.data); newRow.at(4)->setData(type.data());
if (event.isBindingLoop) { if (event.isBindingLoop) {
foreach (QStandardItem *item, newRow) { foreach (QStandardItem *item, newRow) {

View File

@@ -57,9 +57,9 @@ ProfileFeature QmlProfilerTimelineModel::mainFeature() const
return m_mainFeature; return m_mainFeature;
} }
bool QmlProfilerTimelineModel::accepted(const QmlEventType &event) const bool QmlProfilerTimelineModel::accepted(const QmlEventType &type) const
{ {
return (event.rangeType == m_rangeType && event.message == m_message); return (type.rangeType() == m_rangeType && type.message() == m_message);
} }
bool QmlProfilerTimelineModel::handlesTypeId(int typeIndex) const bool QmlProfilerTimelineModel::handlesTypeId(int typeIndex) const
@@ -129,7 +129,7 @@ QVariantMap QmlProfilerTimelineModel::locationFromTypeId(int index) const
if (id >= types.length()) if (id >= types.length())
return result; return result;
const QmlEventLocation &location = types.at(id).location; QmlEventLocation location = types.at(id).location();
result.insert(QStringLiteral("file"), location.filename()); result.insert(QStringLiteral("file"), location.filename());
result.insert(QStringLiteral("line"), location.line()); result.insert(QStringLiteral("line"), location.line());

View File

@@ -48,7 +48,7 @@ public:
Message message() const; Message message() const;
ProfileFeature mainFeature() const; ProfileFeature mainFeature() const;
virtual bool accepted(const QmlEventType &event) const; virtual bool accepted(const QmlEventType &type) const;
bool handlesTypeId(int typeId) const; bool handlesTypeId(int typeId) const;
Q_INVOKABLE virtual int bindingLoopDest(int index) const; Q_INVOKABLE virtual int bindingLoopDest(int index) const;
QVariantMap locationFromTypeId(int index) const; QVariantMap locationFromTypeId(int index) const;

View File

@@ -36,19 +36,18 @@ namespace QmlProfiler {
inline static uint qHash(const QmlEventType &type) inline static uint qHash(const QmlEventType &type)
{ {
return qHash(type.location.filename()) ^ return qHash(type.location().filename()) ^
((type.location.line() & 0xfff) | // 12 bits of line number ((type.location().line() & 0xfff) | // 12 bits of line number
((type.message << 12) & 0xf000) | // 4 bits of message ((type.message() << 12) & 0xf000) | // 4 bits of message
((type.location.column() << 16) & 0xff0000) | // 8 bits of column ((type.location().column() << 16) & 0xff0000) | // 8 bits of column
((type.rangeType << 24) & 0xf000000) | // 4 bits of rangeType ((type.rangeType() << 24) & 0xf000000) | // 4 bits of rangeType
((type.detailType << 28) & 0xf0000000)); // 4 bits of detailType ((type.detailType() << 28) & 0xf0000000)); // 4 bits of detailType
} }
inline static bool operator==(const QmlEventType &type1, inline static bool operator==(const QmlEventType &type1, const QmlEventType &type2)
const QmlEventType &type2)
{ {
return type1.message == type2.message && type1.rangeType == type2.rangeType && return type1.message() == type2.message() && type1.rangeType() == type2.rangeType() &&
type1.detailType == type2.detailType && type1.location == type2.location; type1.detailType() == type2.detailType() && type1.location() == type2.location();
} }
class QmlProfilerTraceClientPrivate { class QmlProfilerTraceClientPrivate {
@@ -136,8 +135,8 @@ void QmlProfilerTraceClientPrivate::processCurrentEvent()
// all ranges are perfectly nested. This is why we can defer the type resolution until either // all ranges are perfectly nested. This is why we can defer the type resolution until either
// the range ends or a child range starts. With only the information in RangeStart we wouldn't // the range ends or a child range starts. With only the information in RangeStart we wouldn't
// be able to uniquely identify the event type. // be able to uniquely identify the event type.
Message rangeStage = currentEvent.type.rangeType == MaximumRangeType ? Message rangeStage = currentEvent.type.rangeType() == MaximumRangeType ?
currentEvent.type.message : currentEvent.event.rangeStage(); currentEvent.type.message() : currentEvent.event.rangeStage();
switch (rangeStage) { switch (rangeStage) {
case RangeStart: case RangeStart:
resolveStackTop(); resolveStackTop();
@@ -152,10 +151,10 @@ void QmlProfilerTraceClientPrivate::processCurrentEvent()
break; break;
} }
case RangeData: case RangeData:
rangesInProgress.top().type.data = currentEvent.type.data; rangesInProgress.top().type.setData(currentEvent.type.data());
break; break;
case RangeLocation: case RangeLocation:
rangesInProgress.top().type.location = currentEvent.type.location; rangesInProgress.top().type.setLocation(currentEvent.type.location());
break; break;
default: { default: {
int typeIndex = resolveType(currentEvent); int typeIndex = resolveType(currentEvent);
@@ -249,12 +248,8 @@ void QmlProfilerTraceClient::setRequestedFeatures(quint64 features)
d->currentEvent.event.setTimestamp(context.timestamp); d->currentEvent.event.setTimestamp(context.timestamp);
d->currentEvent.event.setTypeIndex(-1); d->currentEvent.event.setTypeIndex(-1);
d->currentEvent.event.setString(text); d->currentEvent.event.setString(text);
d->currentEvent.type.location = QmlEventLocation(context.file, context.line, 1); d->currentEvent.type = QmlEventType(DebugMessage, MaximumRangeType, type,
d->currentEvent.type.displayName.clear(); QmlEventLocation(context.file, context.line, 1));
d->currentEvent.type.data.clear();
d->currentEvent.type.message = DebugMessage;
d->currentEvent.type.rangeType = MaximumRangeType;
d->currentEvent.type.detailType = type;
d->currentEvent.serverTypeId = 0; d->currentEvent.serverTypeId = 0;
d->processCurrentEvent(); d->processCurrentEvent();
}); });
@@ -301,17 +296,17 @@ void QmlProfilerTraceClient::messageReceived(const QByteArray &data)
stream >> d->currentEvent; stream >> d->currentEvent;
d->maximumTime = qMax(d->currentEvent.event.timestamp(), d->maximumTime); d->maximumTime = qMax(d->currentEvent.event.timestamp(), d->maximumTime);
if (d->currentEvent.type.message == Complete) { if (d->currentEvent.type.message() == Complete) {
emit complete(d->maximumTime); emit complete(d->maximumTime);
setRecordingFromServer(false); setRecordingFromServer(false);
} else if (d->currentEvent.type.message == Event } else if (d->currentEvent.type.message() == Event
&& d->currentEvent.type.detailType == StartTrace) { && d->currentEvent.type.detailType() == StartTrace) {
if (!d->recording) if (!d->recording)
setRecordingFromServer(true); setRecordingFromServer(true);
emit traceStarted(d->currentEvent.event.timestamp(), emit traceStarted(d->currentEvent.event.timestamp(),
d->currentEvent.event.numbers<QList<int>, qint32>()); d->currentEvent.event.numbers<QList<int>, qint32>());
} else if (d->currentEvent.type.message == Event } else if (d->currentEvent.type.message() == Event
&& d->currentEvent.type.detailType == EndTrace) { && d->currentEvent.type.detailType() == EndTrace) {
emit traceFinished(d->currentEvent.event.timestamp(), emit traceFinished(d->currentEvent.event.timestamp(),
d->currentEvent.event.numbers<QList<int>, qint32>()); d->currentEvent.event.numbers<QList<int>, qint32>());
} else if (d->updateFeatures(d->currentEvent.type.feature())) { } else if (d->updateFeatures(d->currentEvent.type.feature())) {

View File

@@ -290,19 +290,23 @@ void QmlProfilerFileReader::loadEventTypes(QXmlStreamReader &stream)
QTC_ASSERT(stream.name() == _("eventData"), return); QTC_ASSERT(stream.name() == _("eventData"), return);
int typeIndex = -1; int typeIndex = -1;
QmlEventType type = {
QString(), // displayname
QmlEventLocation(),
MaximumMessage,
Painting, // type
QmlBinding, // bindingType, set for backwards compatibility
QString(), // details
};
const QmlEventType defaultEvent = type;
QPair<Message, RangeType> messageAndRange(MaximumMessage, MaximumRangeType);
int detailType = -1;
QString displayName;
QString data;
QString filename; QString filename;
int line = 0, column = 0; int line = 0, column = 0;
auto clearType = [&](){
messageAndRange = QPair<Message, RangeType>(MaximumMessage, MaximumRangeType);
detailType = -1;
displayName.clear();
data.clear();
filename.clear();
line = column = 0;
};
while (!stream.atEnd() && !stream.hasError()) { while (!stream.atEnd() && !stream.hasError()) {
if (isCanceled()) if (isCanceled())
return; return;
@@ -314,7 +318,7 @@ void QmlProfilerFileReader::loadEventTypes(QXmlStreamReader &stream)
case QXmlStreamReader::StartElement: { case QXmlStreamReader::StartElement: {
if (elementName == _("event")) { if (elementName == _("event")) {
updateProgress(stream.device()); updateProgress(stream.device());
type = defaultEvent; clearType();
const QXmlStreamAttributes attributes = stream.attributes(); const QXmlStreamAttributes attributes = stream.attributes();
if (attributes.hasAttribute(_("index"))) { if (attributes.hasAttribute(_("index"))) {
@@ -333,14 +337,12 @@ void QmlProfilerFileReader::loadEventTypes(QXmlStreamReader &stream)
const QString readData = stream.text().toString(); const QString readData = stream.text().toString();
if (elementName == _("displayname")) { if (elementName == _("displayname")) {
type.displayName = readData; displayName = readData;
break; break;
} }
if (elementName == _("type")) { if (elementName == _("type")) {
QPair<Message, RangeType> enums = qmlTypeAsEnum(readData); messageAndRange = qmlTypeAsEnum(readData);
type.message = enums.first;
type.rangeType = enums.second;
break; break;
} }
@@ -360,20 +362,19 @@ void QmlProfilerFileReader::loadEventTypes(QXmlStreamReader &stream)
} }
if (elementName == _("details")) { if (elementName == _("details")) {
type.data = readData; data = readData;
break; break;
} }
if (elementName == _("animationFrame")) { if (elementName == _("animationFrame")) {
type.detailType = readData.toInt(); detailType = readData.toInt();
// new animation frames used to be saved as ranges of range type Painting with // new animation frames used to be saved as ranges of range type Painting with
// binding type 4 (which was called "AnimationFrame" to make everything even more // binding type 4 (which was called "AnimationFrame" to make everything even more
// confusing), even though they clearly aren't ranges. Convert that to something // confusing), even though they clearly aren't ranges. Convert that to something
// sane here. // sane here.
if (type.detailType == 4) { if (detailType == 4) {
type.message = Event; messageAndRange = QPair<Message, RangeType>(Event, MaximumRangeType);
type.rangeType = MaximumRangeType; detailType = AnimationFrame;
type.detailType = AnimationFrame;
} }
} }
@@ -384,7 +385,7 @@ void QmlProfilerFileReader::loadEventTypes(QXmlStreamReader &stream)
elementName == _("mouseEvent") || elementName == _("mouseEvent") ||
elementName == _("keyEvent") || elementName == _("keyEvent") ||
elementName == _("level")) { elementName == _("level")) {
type.detailType = readData.toInt(); detailType = readData.toInt();
break; break;
} }
@@ -395,9 +396,8 @@ void QmlProfilerFileReader::loadEventTypes(QXmlStreamReader &stream)
if (typeIndex >= 0) { if (typeIndex >= 0) {
if (typeIndex >= m_eventTypes.size()) if (typeIndex >= m_eventTypes.size())
m_eventTypes.resize(typeIndex + 1); m_eventTypes.resize(typeIndex + 1);
type.location = QmlEventLocation(filename, line, column); QmlEventType type(messageAndRange.first, messageAndRange.second, detailType,
filename.clear(); QmlEventLocation(filename, line, column), data, displayName);
line = column = 0;
m_eventTypes[typeIndex] = type; m_eventTypes[typeIndex] = type;
ProfileFeature feature = type.feature(); ProfileFeature feature = type.feature();
if (feature != MaximumProfileFeature) if (feature != MaximumProfileFeature)
@@ -624,41 +624,42 @@ void QmlProfilerFileWriter::saveQtd(QIODevice *device)
stream.writeStartElement(_("event")); stream.writeStartElement(_("event"));
stream.writeAttribute(_("index"), QString::number(typeIndex)); stream.writeAttribute(_("index"), QString::number(typeIndex));
stream.writeTextElement(_("displayname"), type.displayName); stream.writeTextElement(_("displayname"), type.displayName());
stream.writeTextElement(_("type"), qmlTypeAsString(type.message, type.rangeType)); stream.writeTextElement(_("type"), qmlTypeAsString(type.message(), type.rangeType()));
if (!type.location.filename().isEmpty()) { const QmlEventLocation location(type.location());
stream.writeTextElement(_("filename"), type.location.filename()); if (!location.filename().isEmpty()) {
stream.writeTextElement(_("line"), QString::number(type.location.line())); stream.writeTextElement(_("filename"), location.filename());
stream.writeTextElement(_("column"), QString::number(type.location.column())); stream.writeTextElement(_("line"), QString::number(location.line()));
stream.writeTextElement(_("column"), QString::number(location.column()));
} }
if (!type.data.isEmpty()) if (!type.data().isEmpty())
stream.writeTextElement(_("details"), type.data); stream.writeTextElement(_("details"), type.data());
if (type.rangeType == Binding) { if (type.rangeType() == Binding) {
stream.writeTextElement(_("bindingType"), QString::number(type.detailType)); stream.writeTextElement(_("bindingType"), QString::number(type.detailType()));
} else if (type.message == Event) { } else if (type.message() == Event) {
switch (type.detailType) { switch (type.detailType()) {
case AnimationFrame: case AnimationFrame:
stream.writeTextElement(_("animationFrame"), QString::number(type.detailType)); stream.writeTextElement(_("animationFrame"), QString::number(type.detailType()));
break; break;
case Key: case Key:
stream.writeTextElement(_("keyEvent"), QString::number(type.detailType)); stream.writeTextElement(_("keyEvent"), QString::number(type.detailType()));
break; break;
case Mouse: case Mouse:
stream.writeTextElement(_("mouseEvent"), QString::number(type.detailType)); stream.writeTextElement(_("mouseEvent"), QString::number(type.detailType()));
break; break;
default: default:
break; break;
} }
} else if (type.message == PixmapCacheEvent) { } else if (type.message() == PixmapCacheEvent) {
stream.writeTextElement(_("cacheEventType"), QString::number(type.detailType)); stream.writeTextElement(_("cacheEventType"), QString::number(type.detailType()));
} else if (type.message == SceneGraphFrame) { } else if (type.message() == SceneGraphFrame) {
stream.writeTextElement(_("sgEventType"), QString::number(type.detailType)); stream.writeTextElement(_("sgEventType"), QString::number(type.detailType()));
} else if (type.message == MemoryAllocation) { } else if (type.message() == MemoryAllocation) {
stream.writeTextElement(_("memoryEventType"), QString::number(type.detailType)); stream.writeTextElement(_("memoryEventType"), QString::number(type.detailType()));
} else if (type.message == DebugMessage) { } else if (type.message() == DebugMessage) {
stream.writeTextElement(_("level"), QString::number(type.detailType)); stream.writeTextElement(_("level"), QString::number(type.detailType()));
} }
stream.writeEndElement(); stream.writeEndElement();
incrementProgress(); incrementProgress();
@@ -673,13 +674,13 @@ void QmlProfilerFileWriter::saveQtd(QIODevice *device)
if (isCanceled()) if (isCanceled())
return; return;
if (type.rangeType != MaximumRangeType && event.rangeStage() == RangeStart) { if (type.rangeType() != MaximumRangeType && event.rangeStage() == RangeStart) {
stack.push(event); stack.push(event);
return; return;
} }
stream.writeStartElement(_("range")); stream.writeStartElement(_("range"));
if (type.rangeType != MaximumRangeType && event.rangeStage() == RangeEnd) { if (type.rangeType() != MaximumRangeType && event.rangeStage() == RangeEnd) {
QmlEvent start = stack.pop(); QmlEvent start = stack.pop();
stream.writeAttribute(_("startTime"), QString::number(start.timestamp())); stream.writeAttribute(_("startTime"), QString::number(start.timestamp()));
stream.writeAttribute(_("duration"), stream.writeAttribute(_("duration"),
@@ -690,14 +691,14 @@ void QmlProfilerFileWriter::saveQtd(QIODevice *device)
stream.writeAttribute(_("eventIndex"), QString::number(event.typeIndex())); stream.writeAttribute(_("eventIndex"), QString::number(event.typeIndex()));
if (type.message == Event) { if (type.message() == Event) {
if (type.detailType == AnimationFrame) { if (type.detailType() == AnimationFrame) {
// special: animation event // special: animation event
stream.writeAttribute(_("framerate"), QString::number(event.number<qint32>(0))); stream.writeAttribute(_("framerate"), QString::number(event.number<qint32>(0)));
stream.writeAttribute(_("animationcount"), stream.writeAttribute(_("animationcount"),
QString::number(event.number<qint32>(1))); QString::number(event.number<qint32>(1)));
stream.writeAttribute(_("thread"), QString::number(event.number<qint32>(2))); stream.writeAttribute(_("thread"), QString::number(event.number<qint32>(2)));
} else if (type.detailType == Key || type.detailType == Mouse) { } else if (type.detailType() == Key || type.detailType() == Mouse) {
// special: input event // special: input event
stream.writeAttribute(_("type"), QString::number(event.number<qint32>(0))); stream.writeAttribute(_("type"), QString::number(event.number<qint32>(0)));
stream.writeAttribute(_("data1"), QString::number(event.number<qint32>(1))); stream.writeAttribute(_("data1"), QString::number(event.number<qint32>(1)));
@@ -706,18 +707,18 @@ void QmlProfilerFileWriter::saveQtd(QIODevice *device)
} }
// special: pixmap cache event // special: pixmap cache event
if (type.message == PixmapCacheEvent) { if (type.message() == PixmapCacheEvent) {
if (type.detailType == PixmapSizeKnown) { if (type.detailType() == PixmapSizeKnown) {
stream.writeAttribute(_("width"), QString::number(event.number<qint32>(0))); stream.writeAttribute(_("width"), QString::number(event.number<qint32>(0)));
stream.writeAttribute(_("height"), QString::number(event.number<qint32>(1))); stream.writeAttribute(_("height"), QString::number(event.number<qint32>(1)));
} }
if (type.detailType == PixmapReferenceCountChanged || if (type.detailType() == PixmapReferenceCountChanged
type.detailType == PixmapCacheCountChanged) || type.detailType() == PixmapCacheCountChanged)
stream.writeAttribute(_("refCount"), QString::number(event.number<qint32>(2))); stream.writeAttribute(_("refCount"), QString::number(event.number<qint32>(2)));
} }
if (type.message == SceneGraphFrame) { if (type.message() == SceneGraphFrame) {
// special: scenegraph frame events // special: scenegraph frame events
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
qint64 number = event.number<qint64>(i); qint64 number = event.number<qint64>(i);
@@ -729,10 +730,10 @@ void QmlProfilerFileWriter::saveQtd(QIODevice *device)
} }
// special: memory allocation event // special: memory allocation event
if (type.message == MemoryAllocation) if (type.message() == MemoryAllocation)
stream.writeAttribute(_("amount"), QString::number(event.number<qint64>(0))); stream.writeAttribute(_("amount"), QString::number(event.number<qint64>(0)));
if (type.message == DebugMessage) if (type.message() == DebugMessage)
stream.writeAttribute(_("text"), event.string()); stream.writeAttribute(_("text"), event.string());
stream.writeEndElement(); stream.writeEndElement();

View File

@@ -46,16 +46,11 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
event.event.setTimestamp(time); event.event.setTimestamp(time);
event.event.setTypeIndex(-1); event.event.setTypeIndex(-1);
event.type.displayName.clear();
event.type.data.clear();
event.type.location.clear();
event.serverTypeId = 0; event.serverTypeId = 0;
switch (messageType) { switch (messageType) {
case Event: { case Event: {
event.type.detailType = subtype; event.type = QmlEventType(static_cast<Message>(messageType), MaximumRangeType, subtype);
event.type.rangeType = MaximumRangeType;
event.type.message = static_cast<Message>(messageType);
switch (subtype) { switch (subtype) {
case StartTrace: case StartTrace:
case EndTrace: { case EndTrace: {
@@ -99,9 +94,7 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
break; break;
} }
case Complete: { case Complete: {
event.type.message = static_cast<Message>(messageType); event.type = QmlEventType(static_cast<Message>(messageType), MaximumRangeType, subtype);
event.type.rangeType = MaximumRangeType;
event.type.detailType = subtype;
break; break;
} }
case SceneGraphFrame: { case SceneGraphFrame: {
@@ -113,9 +106,7 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
params.push_back(param); params.push_back(param);
} }
event.type.message = static_cast<Message>(messageType); event.type = QmlEventType(static_cast<Message>(messageType), MaximumRangeType, subtype);
event.type.rangeType = MaximumRangeType;
event.type.detailType = subtype;
event.event.setNumbers<QVarLengthArray<qint64>, qint64>(params); event.event.setNumbers<QVarLengthArray<qint64>, qint64>(params);
break; break;
} }
@@ -123,7 +114,6 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
qint32 width = 0, height = 0, refcount = 0; qint32 width = 0, height = 0, refcount = 0;
QString filename; QString filename;
stream >> filename; stream >> filename;
event.type.location = QmlEventLocation(filename, 0, 0);
if (subtype == PixmapReferenceCountChanged || subtype == PixmapCacheCountChanged) { if (subtype == PixmapReferenceCountChanged || subtype == PixmapCacheCountChanged) {
stream >> refcount; stream >> refcount;
} else if (subtype == PixmapSizeKnown) { } else if (subtype == PixmapSizeKnown) {
@@ -131,9 +121,8 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
refcount = 1; refcount = 1;
} }
event.type.message = static_cast<Message>(messageType); event.type = QmlEventType(static_cast<Message>(messageType), MaximumRangeType, subtype,
event.type.rangeType = MaximumRangeType; QmlEventLocation(filename, 0, 0));
event.type.detailType = subtype;
event.event.setNumbers<qint32>({width, height, refcount}); event.event.setNumbers<qint32>({width, height, refcount});
break; break;
} }
@@ -141,9 +130,7 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
qint64 delta; qint64 delta;
stream >> delta; stream >> delta;
event.type.message = static_cast<Message>(messageType); event.type = QmlEventType(static_cast<Message>(messageType), MaximumRangeType, subtype);
event.type.rangeType = MaximumRangeType;
event.type.detailType = subtype;
event.event.setNumbers<qint64>({delta}); event.event.setNumbers<qint64>({delta});
break; break;
} }
@@ -156,19 +143,16 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
// otherwise it's the old binding type of 4 bytes // otherwise it's the old binding type of 4 bytes
} }
event.type.message = MaximumMessage; event.type = QmlEventType(MaximumMessage, rangeType, -1);
event.type.rangeType = rangeType;
event.event.setRangeStage(RangeStart); event.event.setRangeStage(RangeStart);
event.type.detailType = -1;
break; break;
} }
case RangeData: { case RangeData: {
stream >> event.type.data; QString data;
stream >> data;
event.type.message = MaximumMessage; event.type = QmlEventType(MaximumMessage, rangeType, -1, QmlEventLocation(), data);
event.type.rangeType = rangeType;
event.event.setRangeStage(RangeData); event.event.setRangeStage(RangeData);
event.type.detailType = -1;
if (!stream.atEnd()) if (!stream.atEnd())
stream >> event.serverTypeId; stream >> event.serverTypeId;
break; break;
@@ -185,24 +169,18 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
stream >> event.serverTypeId; stream >> event.serverTypeId;
} }
event.type.location = QmlEventLocation(filename, line, column); event.type = QmlEventType(MaximumMessage, rangeType, -1,
event.type.message = MaximumMessage; QmlEventLocation(filename, line, column));
event.type.rangeType = rangeType;
event.event.setRangeStage(RangeLocation); event.event.setRangeStage(RangeLocation);
event.type.detailType = -1;
break; break;
} }
case RangeEnd: { case RangeEnd: {
event.type.message = MaximumMessage; event.type = QmlEventType(MaximumMessage, rangeType, -1);
event.type.rangeType = rangeType;
event.event.setRangeStage(RangeEnd); event.event.setRangeStage(RangeEnd);
event.type.detailType = -1;
break; break;
} }
default: default:
event.type.message = static_cast<Message>(messageType); event.type = QmlEventType(static_cast<Message>(messageType), MaximumRangeType, subtype);
event.type.rangeType = MaximumRangeType;
event.type.detailType = subtype;
break; break;
} }

View File

@@ -134,7 +134,7 @@ QVariantMap SceneGraphTimelineModel::details(int index) const
void SceneGraphTimelineModel::loadEvent(const QmlEvent &event, const QmlEventType &type) void SceneGraphTimelineModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{ {
// combine the data of several eventtypes into two rows // combine the data of several eventtypes into two rows
switch ((SceneGraphFrameType)type.detailType) { switch ((SceneGraphFrameType)type.detailType()) {
case SceneGraphRendererFrame: { case SceneGraphRendererFrame: {
// Breakdown of render times. We repeat "render" here as "net" render time. It would // Breakdown of render times. We repeat "render" here as "net" render time. It would
// look incomplete if that was left out as the printf profiler lists it, too, and people // look incomplete if that was left out as the printf profiler lists it, too, and people

View File

@@ -38,19 +38,13 @@ void DebugMessagesModelTest::initTestCase()
{ {
manager.startAcquiring(); manager.startAcquiring();
QmlEvent event; QmlEvent event;
QmlEventType type;
event.setTypeIndex(-1); event.setTypeIndex(-1);
type.displayName.clear();
type.data.clear();
type.message = DebugMessage;
type.rangeType = MaximumRangeType;
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
event.setTimestamp(i); event.setTimestamp(i);
event.setString(QString::fromLatin1("message %1").arg(i)); event.setString(QString::fromLatin1("message %1").arg(i));
type.location = QmlEventLocation("somefile.js", i, 10 - i); QmlEventType type(DebugMessage, MaximumRangeType, i % (QtMsgType::QtInfoMsg + 1),
type.detailType = i % (QtMsgType::QtInfoMsg + 1); QmlEventLocation("somefile.js", i, 10 - i));
event.setTypeIndex(manager.qmlModel()->addEventType(type)); event.setTypeIndex(manager.qmlModel()->addEventType(type));
manager.qmlModel()->addEvent(event); manager.qmlModel()->addEvent(event);
} }

View File

@@ -45,23 +45,17 @@ void FlameGraphModelTest::generateData(QmlProfilerModelManager *manager)
manager->startAcquiring(); manager->startAcquiring();
QmlEvent event; QmlEvent event;
QmlEventType type;
event.setTypeIndex(-1); event.setTypeIndex(-1);
type.displayName.clear();
type.data = QLatin1String("funcfunc");
type.rangeType = MaximumRangeType;
type.detailType = -1;
type.message = MaximumMessage;
QStack<int> typeIndices; QStack<int> typeIndices;
int i = 0; int i = 0;
while (i < 10) { while (i < 10) {
int typeIndex = -1; int typeIndex = -1;
if (i < 5) { if (i < 5) {
type.location = QmlEventLocation("somefile.js", i, 20 - i); QmlEventType type(MaximumMessage,
type.rangeType = static_cast<RangeType>(static_cast<int>(Javascript) - i); static_cast<RangeType>(static_cast<int>(Javascript) - i),
-1, QmlEventLocation("somefile.js", i, 20 - i), QString("funcfunc"));
typeIndex = manager->qmlModel()->addEventType(type); typeIndex = manager->qmlModel()->addEventType(type);
} else { } else {
typeIndex = typeIndices[i - 5]; typeIndex = typeIndices[i - 5];

View File

@@ -33,14 +33,8 @@ namespace Internal {
InputEventsModelTest::InputEventsModelTest(QObject *parent) : InputEventsModelTest::InputEventsModelTest(QObject *parent) :
QObject(parent), manager(nullptr), model(&manager) QObject(parent), manager(nullptr), model(&manager)
{ {
QmlEventType type; keyTypeId = manager.qmlModel()->addEventType(QmlEventType(Event, MaximumRangeType, Key));
type.message = Event; mouseTypeId = manager.qmlModel()->addEventType(QmlEventType(Event, MaximumRangeType, Mouse));
type.rangeType = MaximumRangeType;
type.detailType = Key;
keyTypeId = manager.qmlModel()->addEventType(type);
type.detailType = Mouse;
mouseTypeId = manager.qmlModel()->addEventType(type);
} }
void InputEventsModelTest::initTestCase() void InputEventsModelTest::initTestCase()
@@ -63,16 +57,11 @@ void InputEventsModelTest::initTestCase()
void InputEventsModelTest::testAccepted() void InputEventsModelTest::testAccepted()
{ {
QmlEventType type; QVERIFY(!model.accepted(QmlEventType()));
QVERIFY(!model.accepted(type)); QVERIFY(!model.accepted(QmlEventType(Event)));
type.message = Event; QVERIFY(!model.accepted(QmlEventType(Event, MaximumRangeType)));
QVERIFY(!model.accepted(type)); QVERIFY(model.accepted(QmlEventType(Event, MaximumRangeType, Key)));
type.rangeType = MaximumRangeType; QVERIFY(model.accepted(QmlEventType(Event, MaximumRangeType, Mouse)));
QVERIFY(!model.accepted(type));
type.detailType = Key;
QVERIFY(model.accepted(type));
type.detailType = Mouse;
QVERIFY(model.accepted(type));
} }
void InputEventsModelTest::testTypeId() void InputEventsModelTest::testTypeId()

View File

@@ -39,16 +39,13 @@ void MemoryUsageModelTest::initTestCase()
manager.startAcquiring(); manager.startAcquiring();
qint64 timestamp = 0; qint64 timestamp = 0;
QmlEventType type;
type.message = MemoryAllocation;
type.rangeType = MaximumRangeType;
type.detailType = HeapPage; heapPageTypeId = manager.qmlModel()->addEventType(
heapPageTypeId = manager.qmlModel()->addEventType(type); QmlEventType(MemoryAllocation, MaximumRangeType, HeapPage));
type.detailType = SmallItem; smallItemTypeId = manager.qmlModel()->addEventType(
smallItemTypeId = manager.qmlModel()->addEventType(type); QmlEventType(MemoryAllocation, MaximumRangeType, SmallItem));
type.detailType = LargeItem; largeItemTypeId = manager.qmlModel()->addEventType(
largeItemTypeId = manager.qmlModel()->addEventType(type); QmlEventType(MemoryAllocation, MaximumRangeType, LargeItem));
auto addMemoryEvents = [&]() { auto addMemoryEvents = [&]() {
QmlEvent event; QmlEvent event;
@@ -75,12 +72,10 @@ void MemoryUsageModelTest::initTestCase()
}; };
addMemoryEvents(); addMemoryEvents();
QmlEventType rangeType; rangeTypeId = manager.qmlModel()->addEventType(
rangeType.message = MaximumMessage; QmlEventType(MaximumMessage, Javascript, -1,
rangeType.rangeType = Javascript; QmlEventLocation(QString("somefile.js"), 10, 20),
rangeType.data = QString("funcfunc"); QString("funcfunc")));
rangeType.location = QmlEventLocation(QString("somefile.js"), 10, 20);
rangeTypeId = manager.qmlModel()->addEventType(rangeType);
QmlEvent event; QmlEvent event;
event.setRangeStage(RangeStart); event.setRangeStage(RangeStart);
@@ -229,16 +224,10 @@ void MemoryUsageModelTest::testRelativeHeight()
void MemoryUsageModelTest::testAccepted() void MemoryUsageModelTest::testAccepted()
{ {
QmlEventType type; QVERIFY(!model.accepted(QmlEventType()));
QVERIFY(!model.accepted(type)); QVERIFY(!model.accepted(QmlEventType(MaximumMessage, MaximumRangeType, HeapPage)));
type.detailType = HeapPage; QVERIFY(model.accepted(QmlEventType(MemoryAllocation, MaximumRangeType, HeapPage)));
QVERIFY(!model.accepted(type)); QVERIFY(model.accepted(QmlEventType(MaximumMessage, Javascript)));
type.message = MemoryAllocation;
QVERIFY(model.accepted(type));
type.message = MaximumMessage;
type.rangeType = Javascript;
QVERIFY(model.accepted(type));
} }
void MemoryUsageModelTest::cleanupTestCase() void MemoryUsageModelTest::cleanupTestCase()

View File

@@ -39,14 +39,10 @@ void PixmapCacheModelTest::initTestCase()
manager.startAcquiring(); manager.startAcquiring();
manager.traceTime()->setTime(1, 300); manager.traceTime()->setTime(1, 300);
QmlEventType type;
type.message = PixmapCacheEvent;
type.rangeType = MaximumRangeType;
type.location = QmlEventLocation("dings.png", -1, -1);
for (int i = 0; i < MaximumPixmapEventType; ++i) { for (int i = 0; i < MaximumPixmapEventType; ++i) {
type.detailType = i; eventTypeIndices[i] = manager.qmlModel()->addEventType(
eventTypeIndices[i] = manager.qmlModel()->addEventType(type); QmlEventType(PixmapCacheEvent, MaximumRangeType, i,
QmlEventLocation("dings.png", 0, 0)));
} }
// random data, should still result in consistent model. // random data, should still result in consistent model.
@@ -58,10 +54,10 @@ void PixmapCacheModelTest::initTestCase()
manager.qmlModel()->addEvent(event); manager.qmlModel()->addEvent(event);
} }
type.location = QmlEventLocation("blah.png", -1, -1);
for (int i = 0; i < MaximumPixmapEventType; ++i) { for (int i = 0; i < MaximumPixmapEventType; ++i) {
type.detailType = i; eventTypeIndices[i + MaximumPixmapEventType] = manager.qmlModel()->addEventType(
eventTypeIndices[i + MaximumPixmapEventType] = manager.qmlModel()->addEventType(type); QmlEventType(PixmapCacheEvent, MaximumRangeType, i,
QmlEventLocation("blah.png", 0, 0)));
} }
@@ -285,7 +281,7 @@ void PixmapCacheModelTest::testColor()
QCOMPARE(model.color(i), row1Color); QCOMPARE(model.color(i), row1Color);
} else { } else {
const QmlEventType &type = manager.qmlModel()->eventTypes()[model.typeId(i)]; const QmlEventType &type = manager.qmlModel()->eventTypes()[model.typeId(i)];
QColor &pixmapColor = (type.location.filename() == QString("blah.png")) ? QColor &pixmapColor = (type.location().filename() == QString("blah.png")) ?
blahColor : dingsColor; blahColor : dingsColor;
if (!pixmapColor.isValid()) if (!pixmapColor.isValid())
pixmapColor = model.color(i); pixmapColor = model.color(i);