Commit 472745fb authored by Ulf Hermann's avatar Ulf Hermann
Browse files

QmlProfiler: Make members of QmlEventLocation private



You should not change them independently as that is error-prone.

Change-Id: I07890a29b045492fe804b9537094dea763bc1b8d
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent a41593c3
......@@ -168,9 +168,9 @@ 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 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() ?
......
......@@ -169,7 +169,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type
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];
......
......@@ -30,12 +30,12 @@ namespace QmlProfiler {
QDataStream &operator>>(QDataStream &stream, QmlEventLocation &location)
{
return stream >> location.filename >> location.line >> location.column;
return stream >> location.m_filename >> location.m_line >> location.m_column;
}
QDataStream &operator<<(QDataStream &stream, const QmlEventLocation &location)
{
return stream << location.filename << location.line << location.column;
return stream << location.m_filename << location.m_line << location.m_column;
}
} // namespace QmlProfiler
......@@ -31,17 +31,50 @@
namespace QmlProfiler {
struct QMLPROFILER_EXPORT QmlEventLocation
class QMLPROFILER_EXPORT QmlEventLocation
{
QmlEventLocation() : line(-1),column(-1) {}
QmlEventLocation(const QString &file, int lineNumber, int columnNumber) : filename(file),
line(lineNumber), column(columnNumber)
public:
QmlEventLocation() : m_line(-1),m_column(-1) {}
QmlEventLocation(const QString &file, int lineNumber, int columnNumber) : m_filename(file),
m_line(lineNumber), m_column(columnNumber)
{}
QString filename;
int line;
int column;
void clear()
{
m_filename.clear();
m_line = m_column = -1;
}
bool isValid() const
{
return !m_filename.isEmpty();
}
QString filename() const { return m_filename; }
int line() const { return m_line; }
int column() const { return m_column; }
private:
friend QDataStream &operator>>(QDataStream &stream, QmlEventLocation &location);
friend QDataStream &operator<<(QDataStream &stream, const QmlEventLocation &location);
QString m_filename;
int m_line;
int m_column;
};
inline bool operator==(const QmlEventLocation &location1, const QmlEventLocation &location2)
{
// compare filename last as it's expensive.
return location1.line() == location2.line() && location1.column() == location2.column()
&& location1.filename() == location2.filename();
}
inline bool operator!=(const QmlEventLocation &location1, const QmlEventLocation &location2)
{
return !(location1 == location2);
}
QDataStream &operator>>(QDataStream &stream, QmlEventLocation &location);
QDataStream &operator<<(QDataStream &stream, const QmlEventLocation &location);
......
......@@ -57,12 +57,12 @@ 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());
}
}
......@@ -182,7 +182,7 @@ void QmlProfilerDataModel::QmlProfilerDataModelPrivate::rewriteType(int typeInde
return;
// There is no point in looking for invalid locations
if (type.location.filename.isEmpty() || type.location.line < 0 || type.location.column < 0)
if (!type.location.isValid())
return;
detailsRewriter->requestDetailsForLocation(typeIndex, type.location);
......
......@@ -121,11 +121,12 @@ void QmlProfilerDetailsRewriter::requestDetailsForLocation(int requestId,
const QmlEventLocation &location)
{
QString localFile;
if (!d->m_filesCache.contains(location.filename)) {
localFile = d->m_projectFinder->findFile(location.filename);
d->m_filesCache[location.filename] = localFile;
const QString locationFile = location.filename();
if (!d->m_filesCache.contains(locationFile)) {
localFile = d->m_projectFinder->findFile(locationFile);
d->m_filesCache[locationFile] = localFile;
} else {
localFile = d->m_filesCache[location.filename];
localFile = d->m_filesCache[locationFile];
}
QFileInfo fileInfo(localFile);
if (!fileInfo.exists() || !fileInfo.isReadable())
......@@ -166,7 +167,7 @@ void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(QTextStream &textDoc,
QmlJS::Document::Ptr doc, int requestId, const QmlEventLocation &location)
{
PropertyVisitor propertyVisitor;
QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line, location.column);
QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line(), location.column());
if (!node)
return;
......
......@@ -655,9 +655,9 @@ void QmlProfilerStatisticsMainView::parseModel()
// metadata
newRow.at(0)->setData(QVariant(typeIndex),TypeIdRole);
newRow.at(0)->setData(QVariant(event.location.filename),FilenameRole);
newRow.at(0)->setData(QVariant(event.location.line),LineRole);
newRow.at(0)->setData(QVariant(event.location.column),ColumnRole);
newRow.at(0)->setData(event.location.filename(), FilenameRole);
newRow.at(0)->setData(event.location.line(), LineRole);
newRow.at(0)->setData(event.location.column(), ColumnRole);
// append
parentItem->appendRow(newRow);
......@@ -882,9 +882,9 @@ void QmlProfilerStatisticsRelativesView::rebuildTree(
type.data);
newRow.at(0)->setData(QVariant(typeIndex), TypeIdRole);
newRow.at(0)->setData(QVariant(type.location.filename),FilenameRole);
newRow.at(0)->setData(QVariant(type.location.line),LineRole);
newRow.at(0)->setData(QVariant(type.location.column),ColumnRole);
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(QVariant(QmlProfilerStatisticsMainView::nameForType(type.rangeType)));
newRow.at(2)->setData(QVariant(event.duration));
newRow.at(3)->setData(QVariant(event.calls));
......
......@@ -131,9 +131,9 @@ QVariantMap QmlProfilerTimelineModel::locationFromTypeId(int index) const
const QmlEventLocation &location = types.at(id).location;
result.insert(QStringLiteral("file"), location.filename);
result.insert(QStringLiteral("line"), location.line);
result.insert(QStringLiteral("column"), location.column);
result.insert(QStringLiteral("file"), location.filename());
result.insert(QStringLiteral("line"), location.line());
result.insert(QStringLiteral("column"), location.column());
return result;
}
......
......@@ -36,22 +36,19 @@ 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
}
inline static bool operator==(const QmlEventType &type1,
const QmlEventType &type2)
{
return type1.message == type2.message && type1.rangeType == type2.rangeType &&
type1.detailType == type2.detailType && type1.location.line == type2.location.line &&
type1.location.column == type2.location.column &&
// compare filename last as it's expensive.
type1.location.filename == type2.location.filename;
type1.detailType == type2.detailType && type1.location == type2.location;
}
class QmlProfilerTraceClientPrivate {
......@@ -252,9 +249,7 @@ void QmlProfilerTraceClient::setRequestedFeatures(quint64 features)
d->currentEvent.event.setTimestamp(context.timestamp);
d->currentEvent.event.setTypeIndex(-1);
d->currentEvent.event.setString(text);
d->currentEvent.type.location.filename = context.file;
d->currentEvent.type.location.line = context.line;
d->currentEvent.type.location.column = 1;
d->currentEvent.type.location = QmlEventLocation(context.file, context.line, 1);
d->currentEvent.type.displayName.clear();
d->currentEvent.type.data.clear();
d->currentEvent.type.message = DebugMessage;
......
......@@ -300,6 +300,9 @@ void QmlProfilerFileReader::loadEventTypes(QXmlStreamReader &stream)
};
const QmlEventType defaultEvent = type;
QString filename;
int line = 0, column = 0;
while (!stream.atEnd() && !stream.hasError()) {
if (isCanceled())
return;
......@@ -342,17 +345,17 @@ void QmlProfilerFileReader::loadEventTypes(QXmlStreamReader &stream)
}
if (elementName == _("filename")) {
type.location.filename = readData;
filename = readData;
break;
}
if (elementName == _("line")) {
type.location.line = readData.toInt();
line = readData.toInt();
break;
}
if (elementName == _("column")) {
type.location.column = readData.toInt();
column = readData.toInt();
break;
}
......@@ -392,6 +395,9 @@ void QmlProfilerFileReader::loadEventTypes(QXmlStreamReader &stream)
if (typeIndex >= 0) {
if (typeIndex >= m_eventTypes.size())
m_eventTypes.resize(typeIndex + 1);
type.location = QmlEventLocation(filename, line, column);
filename.clear();
line = column = 0;
m_eventTypes[typeIndex] = type;
ProfileFeature feature = type.feature();
if (feature != MaximumProfileFeature)
......@@ -620,10 +626,10 @@ void QmlProfilerFileWriter::saveQtd(QIODevice *device)
stream.writeAttribute(_("index"), QString::number(typeIndex));
stream.writeTextElement(_("displayname"), type.displayName);
stream.writeTextElement(_("type"), qmlTypeAsString(type.message, type.rangeType));
if (!type.location.filename.isEmpty()) {
stream.writeTextElement(_("filename"), type.location.filename);
stream.writeTextElement(_("line"), QString::number(type.location.line));
stream.writeTextElement(_("column"), QString::number(type.location.column));
if (!type.location.filename().isEmpty()) {
stream.writeTextElement(_("filename"), type.location.filename());
stream.writeTextElement(_("line"), QString::number(type.location.line()));
stream.writeTextElement(_("column"), QString::number(type.location.column()));
}
if (!type.data.isEmpty())
......
......@@ -48,8 +48,7 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
event.event.setTypeIndex(-1);
event.type.displayName.clear();
event.type.data.clear();
event.type.location.filename.clear();
event.type.location.line = event.type.location.column = -1;
event.type.location.clear();
event.serverTypeId = 0;
switch (messageType) {
......@@ -122,7 +121,9 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
}
case PixmapCacheEvent: {
qint32 width = 0, height = 0, refcount = 0;
stream >> event.type.location.filename;
QString filename;
stream >> filename;
event.type.location = QmlEventLocation(filename, 0, 0);
if (subtype == PixmapReferenceCountChanged || subtype == PixmapCacheCountChanged) {
stream >> refcount;
} else if (subtype == PixmapSizeKnown) {
......@@ -132,7 +133,6 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
event.type.message = static_cast<Message>(messageType);
event.type.rangeType = MaximumRangeType;
event.type.location.line = event.type.location.column = 0;
event.type.detailType = subtype;
event.event.setNumbers<qint32>({width, height, refcount});
break;
......@@ -174,17 +174,18 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
break;
}
case RangeLocation: {
stream >> event.type.location.filename
>> static_cast<qint32 &>(event.type.location.line);
QString filename;
qint32 line = 0;
qint32 column = 0;
stream >> filename >> line;
if (!stream.atEnd()) {
stream >> static_cast<qint32 &>(event.type.location.column);
stream >> column;
if (!stream.atEnd())
stream >> event.serverTypeId;
} else {
event.type.location.column = -1;
}
event.type.location = QmlEventLocation(filename, line, column);
event.type.message = MaximumMessage;
event.type.rangeType = rangeType;
event.event.setRangeStage(RangeLocation);
......
......@@ -41,7 +41,6 @@ void DebugMessagesModelTest::initTestCase()
QmlEventType type;
event.setTypeIndex(-1);
type.location.filename = QLatin1String("somefile.js");
type.displayName.clear();
type.data.clear();
type.message = DebugMessage;
......@@ -50,8 +49,7 @@ void DebugMessagesModelTest::initTestCase()
for (int i = 0; i < 10; ++i) {
event.setTimestamp(i);
event.setString(QString::fromLatin1("message %1").arg(i));
type.location.line = i;
type.location.column = 10 - i;
type.location = QmlEventLocation("somefile.js", i, 10 - i);
type.detailType = i % (QtMsgType::QtInfoMsg + 1);
event.setTypeIndex(manager.qmlModel()->addEventType(type));
manager.qmlModel()->addEvent(event);
......
......@@ -48,7 +48,6 @@ void FlameGraphModelTest::generateData(QmlProfilerModelManager *manager)
QmlEventType type;
event.setTypeIndex(-1);
type.location.filename = QLatin1String("somefile.js");
type.displayName.clear();
type.data = QLatin1String("funcfunc");
type.rangeType = MaximumRangeType;
......@@ -61,8 +60,7 @@ void FlameGraphModelTest::generateData(QmlProfilerModelManager *manager)
while (i < 10) {
int typeIndex = -1;
if (i < 5) {
type.location.line = i;
type.location.column = 20 - i;
type.location = QmlEventLocation("somefile.js", i, 20 - i);
type.rangeType = static_cast<RangeType>(static_cast<int>(Javascript) - i);
typeIndex = manager->qmlModel()->addEventType(type);
} else {
......
......@@ -285,7 +285,7 @@ void PixmapCacheModelTest::testColor()
QCOMPARE(model.color(i), row1Color);
} else {
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;
if (!pixmapColor.isValid())
pixmapColor = model.color(i);
......
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