Commit e10bc709 authored by Ulf Hermann's avatar Ulf Hermann

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: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent 5718f12a
......@@ -76,10 +76,10 @@ QVariantMap DebugMessagesModel::details(int index) const
const QmlEventType &type = modelManager()->qmlModel()->eventTypes()[m_data[index].typeId];
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("Message"), m_data[index].text);
result.insert(tr("Location"), type.displayName);
result.insert(tr("Location"), type.displayName());
return result;
}
......@@ -96,9 +96,9 @@ int DebugMessagesModel::collapsedRow(int index) const
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()));
if (type.detailType > m_maximumMsgType)
if (type.detailType() > m_maximumMsgType)
m_maximumMsgType = event.typeIndex();
}
......
......@@ -168,14 +168,14 @@ QVariant FlameGraphModel::lookup(const FlameGraphData &stats, int role) const
const QmlEventType &type = typeList[stats.typeIndex];
switch (role) {
case FilenameRole: return type.location.filename();
case LineRole: return type.location.line();
case ColumnRole: return type.location.column();
case TypeRole: return nameForType(type.rangeType);
case RangeTypeRole: return type.rangeType;
case DetailsRole: return type.data.isEmpty() ?
FlameGraphModel::tr("Source code not available") : type.data;
case LocationRole: return type.displayName;
case FilenameRole: return type.location().filename();
case LineRole: return type.location().line();
case ColumnRole: return type.location().column();
case TypeRole: return nameForType(type.rangeType());
case RangeTypeRole: return type.rangeType();
case DetailsRole: return type.data().isEmpty() ?
FlameGraphModel::tr("Source code not available") : type.data();
case LocationRole: return type.displayName();
default: return QVariant();
}
} else {
......
......@@ -142,11 +142,11 @@ int InputEventsModel::collapsedRow(int index) const
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)),
event.number<qint32>(1), event.number<qint32>(2)));
if (type.detailType == Mouse) {
if (type.detailType() == Mouse) {
if (m_mouseTypeId == -1)
m_mouseTypeId = event.typeIndex();
} else if (m_keyTypeId == -1) {
......@@ -170,7 +170,7 @@ void InputEventsModel::clear()
bool InputEventsModel::accepted(const QmlEventType &type) const
{
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) :
......
......@@ -122,19 +122,19 @@ QVariantMap MemoryUsageModel::details(int index) const
result.insert(tr("Type"), memoryTypeName);
result.insert(tr("Location"),
modelManager()->qmlModel()->eventTypes().at(ev->typeId).displayName);
modelManager()->qmlModel()->eventTypes().at(ev->typeId).displayName());
return result;
}
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)
{
if (type.message != MemoryAllocation) {
if (type.rangeType != MaximumRangeType) {
if (type.message() != MemoryAllocation) {
if (type.rangeType() != MaximumRangeType) {
if (event.rangeStage() == RangeStart)
m_rangeStack.push(RangeStackFrame(event.typeIndex(), event.timestamp()));
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)) {
m_data[m_currentUsageIndex].update(event.number<qint64>(0));
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)
&& type.detailType == selectionId(m_currentJSHeapIndex)) {
&& type.detailType() == selectionId(m_currentJSHeapIndex)) {
m_data[m_currentJSHeapIndex].update(event.number<qint64>(0));
m_currentSize = m_data[m_currentJSHeapIndex].size;
} else {
......@@ -204,7 +204,7 @@ void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type
if (m_currentJSHeapIndex != -1)
insertEnd(m_currentJSHeapIndex,
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_continuation = m_continuation | ContinueAllocation;
}
......
......@@ -163,13 +163,13 @@ QVariantMap PixmapCacheModel::details(int index) const
void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{
PixmapCacheItem newEvent;
const PixmapEventType pixmapType = static_cast<PixmapEventType>(type.detailType);
const PixmapEventType pixmapType = static_cast<PixmapEventType>(type.detailType());
newEvent.pixmapEventType = pixmapType;
qint64 pixmapStartTime = event.timestamp();
newEvent.urlIndex = -1;
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();
break;
}
......@@ -178,7 +178,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type
newEvent.sizeIndex = -1;
if (newEvent.urlIndex == -1) {
newEvent.urlIndex = m_pixmaps.count();
m_pixmaps << Pixmap(type.location.filename());
m_pixmaps << Pixmap(type.location().filename());
}
Pixmap &pixmap = m_pixmaps[newEvent.urlIndex];
......
......@@ -32,18 +32,45 @@ QDataStream &operator>>(QDataStream &stream, QmlEventType &type)
{
quint8 message;
quint8 rangeType;
stream >> type.displayName >> type.data >> type.location >> message >> rangeType
>> type.detailType;
type.message = static_cast<Message>(message);
type.rangeType = static_cast<RangeType>(rangeType);
stream >> type.m_displayName >> type.m_data >> type.m_location >> message >> rangeType
>> type.m_detailType;
type.m_message = static_cast<Message>(message);
type.m_rangeType = static_cast<RangeType>(rangeType);
return stream;
}
QDataStream &operator<<(QDataStream &stream, const QmlEventType &type)
{
return stream << type.displayName << type.data << type.location
<< static_cast<quint8>(type.message) << static_cast<quint8>(type.rangeType)
<< type.detailType;
return stream << type.m_displayName << type.m_data << type.m_location
<< static_cast<quint8>(type.m_message) << static_cast<quint8>(type.m_rangeType)
<< 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);
}
}
......
......@@ -31,48 +31,37 @@
namespace QmlProfiler {
struct QmlEventType {
QmlEventType(const QString &displayName = QString(),
const QmlEventLocation &location = QmlEventLocation(),
Message message = MaximumMessage, RangeType rangeType = MaximumRangeType,
int detailType = -1, const QString &data = QString()) :
displayName(displayName), data(data), location(location), message(message),
rangeType(rangeType), detailType(detailType)
class QmlEventType {
public:
QmlEventType(Message message = MaximumMessage, RangeType rangeType = MaximumRangeType,
int detailType = -1, const QmlEventLocation &location = QmlEventLocation(),
const QString &data = QString(), const QString displayName = QString()) :
m_displayName(displayName), m_data(data), m_location(location), m_message(message),
m_rangeType(rangeType), m_detailType(detailType)
{}
QString displayName;
QString data;
QmlEventLocation location;
Message message;
RangeType rangeType;
int detailType; // can be EventType, BindingType, PixmapEventType or SceneGraphFrameType
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
void setData(const QString &data) { m_data = data; }
void setLocation(const QmlEventLocation &location) { m_location = location; }
ProfileFeature feature() const
{
switch (message) {
case Event: {
switch (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(rangeType);
}
}
ProfileFeature feature() const;
QString displayName() const { return m_displayName; }
QString data() const { return m_data; }
QmlEventLocation location() const { return m_location; }
Message message() const { return m_message; }
RangeType rangeType() const { return m_rangeType; }
int detailType() const { return m_detailType; }
private:
friend QDataStream &operator>>(QDataStream &stream, QmlEventType &type);
friend QDataStream &operator<<(QDataStream &stream, const QmlEventType &type);
QString m_displayName;
QString m_data;
QmlEventLocation m_location;
Message m_message;
RangeType m_rangeType;
int m_detailType; // can be EventType, BindingType, PixmapEventType or SceneGraphFrameType
};
QDataStream &operator>>(QDataStream &stream, QmlEventType &type);
......
......@@ -57,7 +57,7 @@ void QmlProfilerAnimationsModel::clear()
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)
......
......@@ -57,24 +57,23 @@ public:
QString getDisplayName(const QmlEventType &event)
{
if (event.location.filename().isEmpty()) {
if (event.location().filename().isEmpty()) {
return QmlProfilerDataModel::tr("<bytecode>");
} 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(':') +
QString::number(event.location.line());
QString::number(event.location().line());
}
}
QString getInitialDetails(const QmlEventType &event)
{
QString details;
QString details = event.data();
// generate details string
if (!event.data.isEmpty()) {
details = event.data;
if (!details.isEmpty()) {
details = details.replace(QLatin1Char('\n'),QLatin1Char(' ')).simplified();
if (details.isEmpty()) {
if (event.rangeType == Javascript)
if (event.rangeType() == Javascript)
details = QmlProfilerDataModel::tr("anonymous function");
} else {
QRegExp rewrite(QLatin1String("\\(function \\$(\\w+)\\(\\) \\{ (return |)(.+) \\}\\)"));
......@@ -85,7 +84,7 @@ QString getInitialDetails(const QmlEventType &event)
details.startsWith(QLatin1String("qrc:/")))
details = details.mid(details.lastIndexOf(QLatin1Char('/')) + 1);
}
} else if (event.rangeType == Painting) {
} else if (event.rangeType() == Painting) {
// QtQuick1 animations always run in GUI thread.
details = QmlProfilerDataModel::tr("GUI Thread");
}
......@@ -174,18 +173,18 @@ bool QmlProfilerDataModel::isEmpty() const
void QmlProfilerDataModel::QmlProfilerDataModelPrivate::rewriteType(int typeIndex)
{
QmlEventType &type = eventTypes[typeIndex];
type.displayName = getDisplayName(type);
type.data = getInitialDetails(type);
type.setDisplayName(getDisplayName(type));
type.setData(getInitialDetails(type));
// Only bindings and signal handlers need rewriting
if (type.rangeType != Binding && type.rangeType != HandlingSignal)
if (type.rangeType() != Binding && type.rangeType() != HandlingSignal)
return;
// There is no point in looking for invalid locations
if (!type.location.isValid())
if (!type.location().isValid())
return;
detailsRewriter->requestDetailsForLocation(typeIndex, type.location);
detailsRewriter->requestDetailsForLocation(typeIndex, type.location());
}
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()];
if (rangeStart != -1 && rangeEnd != -1) {
if (event.timestamp() < rangeStart) {
if (type.rangeType != MaximumRangeType) {
if (type.rangeType() != MaximumRangeType) {
if (event.rangeStage() == RangeStart)
stack.push(event);
else if (event.rangeStage() == RangeEnd)
......@@ -213,7 +212,7 @@ void QmlProfilerDataModel::replayEvents(qint64 rangeStart, qint64 rangeEnd,
}
continue;
} else if (event.timestamp() > rangeEnd) {
if (type.rangeType != MaximumRangeType) {
if (type.rangeType() != MaximumRangeType) {
if (event.rangeStage() == RangeEnd) {
if (stack.isEmpty()) {
QmlEvent endEvent(event);
......@@ -251,7 +250,7 @@ void QmlProfilerDataModel::detailsChanged(int requestId, const QString &newStrin
{
Q_D(QmlProfilerDataModel);
QTC_ASSERT(requestId < d->eventTypes.count(), return);
d->eventTypes[requestId].data = newString;
d->eventTypes[requestId].setData(newString);
}
} // namespace QmlProfiler
......@@ -193,8 +193,8 @@ QVariantList QmlProfilerRangeModel::labels() const
for (int i = 1; i < expandedRowCount(); i++) { // Ignore the -1 for the first row
QVariantMap element;
int typeId = m_expandedRowTypes[i];
element.insert(QLatin1String("displayName"), QVariant(types[typeId].displayName));
element.insert(QLatin1String("description"), QVariant(types[typeId].data));
element.insert(QLatin1String("displayName"), QVariant(types[typeId].displayName()));
element.insert(QLatin1String("description"), QVariant(types[typeId].data()));
element.insert(QLatin1String("id"), QVariant(typeId));
result << element;
}
......@@ -212,8 +212,8 @@ QVariantMap QmlProfilerRangeModel::details(int index) const
tr(QmlProfilerModelManager::featureName(mainFeature())));
result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index)));
result.insert(tr("Details"), types[id].data);
result.insert(tr("Location"), types[id].displayName);
result.insert(tr("Details"), types[id].data());
result.insert(tr("Location"), types[id].displayName());
return result;
}
......
......@@ -207,7 +207,7 @@ void QmlProfilerStatisticsModel::notesChanged(int typeIndex)
void QmlProfilerStatisticsModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{
if (!d->acceptedTypes.contains(type.rangeType))
if (!d->acceptedTypes.contains(type.rangeType()))
return;
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
for (int ii = 1; ii < d->callStack.size(); ++ii) {
if (d->callStack.at(ii).typeIndex() == event.typeIndex()
&& type.rangeType != Javascript) {
&& type.rangeType() != Javascript) {
d->eventsInBindingLoop.insert(event.typeIndex());
break;
}
......
......@@ -53,15 +53,11 @@ struct Colors {
};
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;
if (d->m_fieldShown[Name])
newRow << new StatisticsViewItem(event.displayName.isEmpty() ? tr("<bytecode>") :
event.displayName);
newRow << new StatisticsViewItem(event.displayName().isEmpty() ? tr("<bytecode>") :
event.displayName());
if (d->m_fieldShown[Type]) {
QString typeString = QmlProfilerStatisticsMainView::nameForType(event.rangeType);
QString typeString = QmlProfilerStatisticsMainView::nameForType(event.rangeType());
newRow << new StatisticsViewItem(typeString);
newRow.last()->setData(QVariant(typeString));
}
......@@ -628,9 +624,9 @@ void QmlProfilerStatisticsMainView::parseModel()
}
if (d->m_fieldShown[Details]) {
newRow << new StatisticsViewItem(event.data.isEmpty() ?
tr("Source code not available") : event.data);
newRow.last()->setData(QVariant(event.data));
newRow << new StatisticsViewItem(event.data().isEmpty() ?
tr("Source code not available") : event.data());
newRow.last()->setData(event.data());
}
......@@ -642,9 +638,10 @@ void QmlProfilerStatisticsMainView::parseModel()
// metadata
newRow.at(0)->setData(typeIndex, TypeIdRole);
newRow.at(0)->setData(event.location.filename(), FilenameRole);
newRow.at(0)->setData(event.location.line(), LineRole);
newRow.at(0)->setData(event.location.column(), ColumnRole);
const QmlEventLocation location(event.location());
newRow.at(0)->setData(location.filename(), FilenameRole);
newRow.at(0)->setData(location.line(), LineRole);
newRow.at(0)->setData(location.column(), ColumnRole);
// append
parentItem->appendRow(newRow);
......@@ -859,23 +856,24 @@ void QmlProfilerStatisticsRelativesView::rebuildTree(
// 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
// no indirections at this level of abstraction!
newRow << new StatisticsViewItem(type.displayName.isEmpty() ? tr("<bytecode>") :
type.displayName);
newRow << new StatisticsViewItem(type.displayName().isEmpty() ? tr("<bytecode>") :
type.displayName());
newRow << new StatisticsViewItem(QmlProfilerStatisticsMainView::nameForType(
type.rangeType));
type.rangeType()));
newRow << new StatisticsViewItem(QmlProfilerDataModel::formatTime(event.duration));
newRow << new StatisticsViewItem(QString::number(event.calls));
newRow << new StatisticsViewItem(type.data.isEmpty() ? tr("Source code not available") :
type.data);
newRow << new StatisticsViewItem(type.data().isEmpty() ? tr("Source code not available") :
type.data());
newRow.at(0)->setData(typeIndex, TypeIdRole);
newRow.at(0)->setData(type.location.filename(), FilenameRole);
newRow.at(0)->setData(type.location.line(), LineRole);
newRow.at(0)->setData(type.location.column(), ColumnRole);
newRow.at(1)->setData(QmlProfilerStatisticsMainView::nameForType(type.rangeType));
const QmlEventLocation location(type.location());
newRow.at(0)->setData(location.filename(), FilenameRole);
newRow.at(0)->setData(location.line(), LineRole);
newRow.at(0)->setData(location.column(), ColumnRole);
newRow.at(1)->setData(QmlProfilerStatisticsMainView::nameForType(type.rangeType()));
newRow.at(2)->setData(event.duration);
newRow.at(3)->setData(event.calls);
newRow.at(4)->setData(type.data);
newRow.at(4)->setData(type.data());
if (event.isBindingLoop) {
foreach (QStandardItem *item, newRow) {
......
......@@ -57,9 +57,9 @@ ProfileFeature QmlProfilerTimelineModel::mainFeature() const
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
......@@ -129,7 +129,7 @@ QVariantMap QmlProfilerTimelineModel::locationFromTypeId(int index) const
if (id >= types.length())
return result;
const QmlEventLocation &location = types.at(id).location;
QmlEventLocation location = types.at(id).location();
result.insert(QStringLiteral("file"), location.filename());
result.insert(QStringLiteral("line"), location.line());
......
......@@ -48,7 +48,7 @@ public:
Message message() const;
ProfileFeature mainFeature() const;
virtual bool accepted(const QmlEventType &event) const;
virtual bool accepted(const QmlEventType &type) const;
bool handlesTypeId(int typeId) const;
Q_INVOKABLE virtual int bindingLoopDest(int index) const;
QVariantMap locationFromTypeId(int index) const;
......
......@@ -36,19 +36,18 @@ namespace QmlProfiler {
inline static uint qHash(const QmlEventType &type)
{
return qHash(type.location.filename()) ^
((type.location.line() & 0xfff) | // 12 bits of line number
((type.message << 12) & 0xf000) | // 4 bits of message
((type.location.column() << 16) & 0xff0000) | // 8 bits of column
((type.rangeType << 24) & 0xf000000) | // 4 bits of rangeType
((type.detailType << 28) & 0xf0000000)); // 4 bits of detailType
return qHash(type.location().filename()) ^
((type.location().line() & 0xfff) | // 12 bits of line number
((type.message() << 12) & 0xf000) | // 4 bits of message
((type.location().column() << 16) & 0xff0000) | // 8 bits of column
((type.rangeType() << 24) & 0xf000000) | // 4 bits of rangeType
((type.detailType() << 28) & 0xf0000000)); // 4 bits of detailType
}