Commit a9555371 authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: Fix the naming scheme for events and event types

Move them out of the QmlProfilerDataModel class, drop the "Data"
suffix, and rename symbols that refer to them in order to call them by
their names.

Change-Id: I41151359921b325edb79111371083c4185bd148b
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@theqtcompany.com>
parent 08f807a1
......@@ -28,7 +28,7 @@
namespace QmlProfiler {
namespace Internal {
bool DebugMessagesModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
bool DebugMessagesModel::accepted(const QmlEventType &event) const
{
return event.message == DebugMessage;
}
......@@ -78,8 +78,7 @@ QVariantList DebugMessagesModel::labels() const
QVariantMap DebugMessagesModel::details(int index) const
{
const QmlProfilerDataModel::QmlEventTypeData &type =
modelManager()->qmlModel()->getEventTypes()[m_data[index].typeId];
const QmlEventType &type = modelManager()->qmlModel()->eventTypes()[m_data[index].typeId];
QVariantMap result;
result.insert(QLatin1String("displayName"), messageType(type.detailType));
......@@ -106,10 +105,10 @@ void DebugMessagesModel::loadData()
if (simpleModel->isEmpty())
return;
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types = simpleModel->getEventTypes();
const QVector<QmlEventType> &types = simpleModel->eventTypes();
foreach (const QmlProfilerDataModel::QmlEventData &event, simpleModel->getEvents()) {
const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex()];
foreach (const QmlEvent &event, simpleModel->events()) {
const QmlEventType &type = types[event.typeIndex()];
if (!accepted(type) || event.startTime() < 0)
continue;
......@@ -117,7 +116,7 @@ void DebugMessagesModel::loadData()
MessageData(event.stringData(), event.typeIndex()));
if (type.detailType > m_maximumMsgType)
m_maximumMsgType = event.typeIndex();
updateProgress(count(), simpleModel->getEvents().count());
updateProgress(count(), simpleModel->events().count());
}
setCollapsedRowCount(2);
setExpandedRowCount(m_maximumMsgType + 2);
......
......@@ -35,7 +35,7 @@ class DebugMessagesModel : public QmlProfilerTimelineModel
Q_OBJECT
protected:
bool accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const override;
bool accepted(const QmlEventType &event) const override;
public:
DebugMessagesModel(QmlProfilerModelManager *manager, QObject *parent = 0);
......
......@@ -102,20 +102,18 @@ void FlameGraphModel::loadData(qint64 rangeStart, qint64 rangeEnd)
beginResetModel();
clear();
const QVector<QmlProfilerDataModel::QmlEventData> &eventList
= m_modelManager->qmlModel()->getEvents();
const QVector<QmlProfilerDataModel::QmlEventTypeData> &typesList
= m_modelManager->qmlModel()->getEventTypes();
const QVector<QmlEvent> &eventList = m_modelManager->qmlModel()->events();
const QVector<QmlEventType> &typesList = m_modelManager->qmlModel()->eventTypes();
// used by binding loop detection
QStack<const QmlProfilerDataModel::QmlEventData *> callStack;
QStack<const QmlEvent *> callStack;
callStack.append(0);
FlameGraphData *stackTop = &m_stackBottom;
for (int i = 0; i < eventList.size(); ++i) {
const QmlProfilerDataModel::QmlEventData *event = &eventList[i];
const QmlEvent *event = &eventList[i];
int typeIndex = event->typeIndex();
const QmlProfilerDataModel::QmlEventTypeData *type = &typesList[typeIndex];
const QmlEventType *type = &typesList[typeIndex];
if (!m_acceptedTypes.contains(type->rangeType))
continue;
......@@ -126,7 +124,7 @@ void FlameGraphModel::loadData(qint64 rangeStart, qint64 rangeEnd)
continue;
}
const QmlProfilerDataModel::QmlEventData *potentialParent = callStack.top();
const QmlEvent *potentialParent = callStack.top();
while (potentialParent &&
potentialParent->startTime() + potentialParent->duration() <= event->startTime()) {
callStack.pop();
......@@ -187,9 +185,8 @@ QVariant FlameGraphModel::lookup(const FlameGraphData &stats, int role) const
}
if (stats.typeIndex != -1) {
const QVector<QmlProfilerDataModel::QmlEventTypeData> &typeList =
m_modelManager->qmlModel()->getEventTypes();
const QmlProfilerDataModel::QmlEventTypeData &type = typeList[stats.typeIndex];
const QVector<QmlEventType> &typeList = m_modelManager->qmlModel()->eventTypes();
const QmlEventType &type = typeList[stats.typeIndex];
switch (role) {
case FilenameRole: return type.location.filename;
......@@ -216,7 +213,7 @@ FlameGraphData::~FlameGraphData()
}
FlameGraphData *FlameGraphModel::pushChild(
FlameGraphData *parent, const QmlProfilerDataModel::QmlEventData *data)
FlameGraphData *parent, const QmlEvent *data)
{
foreach (FlameGraphData *child, parent->children) {
if (child->typeIndex == data->typeIndex()) {
......
......@@ -91,8 +91,7 @@ private:
QVariant lookup(const FlameGraphData &data, int role) const;
void clear();
FlameGraphData *pushChild(FlameGraphData *parent,
const QmlProfilerDataModel::QmlEventData *data);
FlameGraphData *pushChild(FlameGraphData *parent, const QmlEvent *data);
int m_selectedTypeIndex;
FlameGraphData m_stackBottom;
......
......@@ -146,9 +146,9 @@ void InputEventsModel::loadData()
if (simpleModel->isEmpty())
return;
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types = simpleModel->getEventTypes();
foreach (const QmlProfilerDataModel::QmlEventData &event, simpleModel->getEvents()) {
const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex()];
const QVector<QmlEventType> &types = simpleModel->eventTypes();
foreach (const QmlEvent &event, simpleModel->events()) {
const QmlEventType &type = types[event.typeIndex()];
if (!accepted(type))
continue;
......@@ -162,7 +162,7 @@ void InputEventsModel::loadData()
} else if (m_keyTypeId == -1) {
m_keyTypeId = event.typeIndex();
}
updateProgress(count(), simpleModel->getEvents().count());
updateProgress(count(), simpleModel->events().count());
}
setCollapsedRowCount(2);
setExpandedRowCount(3);
......@@ -176,7 +176,7 @@ void InputEventsModel::clear()
QmlProfilerTimelineModel::clear();
}
bool InputEventsModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
bool InputEventsModel::accepted(const QmlEventType &event) const
{
return QmlProfilerTimelineModel::accepted(event) &&
(event.detailType == Mouse || event.detailType == Key);
......
......@@ -35,7 +35,7 @@ class InputEventsModel : public QmlProfilerTimelineModel
Q_OBJECT
protected:
bool accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const;
bool accepted(const QmlEventType &event) const;
public:
struct InputEvent {
......
......@@ -82,7 +82,7 @@ QVariantMap MemoryUsageModel::location(int index) const
int originType = m_data[index].originTypeIndex;
if (originType > -1) {
const QmlEventLocation &location =
modelManager()->qmlModel()->getEventTypes().at(originType).location;
modelManager()->qmlModel()->eventTypes().at(originType).location;
result.insert(file, location.filename);
result.insert(line, location.line);
......@@ -132,7 +132,7 @@ QVariantMap MemoryUsageModel::details(int index) const
if (ev->originTypeIndex != -1) {
result.insert(tr("Location"),
modelManager()->qmlModel()->getEventTypes().at(ev->originTypeIndex).displayName);
modelManager()->qmlModel()->eventTypes().at(ev->originTypeIndex).displayName);
}
return result;
}
......@@ -159,9 +159,9 @@ void MemoryUsageModel::loadData()
QStack<RangeStackFrame> rangeStack;
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types = simpleModel->getEventTypes();
foreach (const QmlProfilerDataModel::QmlEventData &event, simpleModel->getEvents()) {
const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex()];
const QVector<QmlEventType> &types = simpleModel->eventTypes();
foreach (const QmlEvent &event, simpleModel->events()) {
const QmlEventType &type = types[event.typeIndex()];
while (!rangeStack.empty() && rangeStack.top().endTime < event.startTime())
rangeStack.pop();
if (!accepted(type)) {
......@@ -218,7 +218,7 @@ void MemoryUsageModel::loadData()
}
}
updateProgress(count(), simpleModel->getEvents().count());
updateProgress(count(), simpleModel->events().count());
}
if (currentJSHeapIndex != -1)
......
......@@ -174,9 +174,9 @@ void PixmapCacheModel::loadData()
int lastCacheSizeEvent = -1;
int cumulatedCount = 0;
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types = simpleModel->getEventTypes();
foreach (const QmlProfilerDataModel::QmlEventData &event, simpleModel->getEvents()) {
const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex()];
const QVector<QmlEventType> &types = simpleModel->eventTypes();
foreach (const QmlEvent &event, simpleModel->events()) {
const QmlEventType &type = types[event.typeIndex()];
if (!accepted(type))
continue;
......@@ -398,7 +398,7 @@ void PixmapCacheModel::loadData()
break;
}
updateProgress(count(), 2 * simpleModel->getEvents().count());
updateProgress(count(), 2 * simpleModel->events().count());
}
if (lastCacheSizeEvent != -1)
......
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QString>
namespace QmlProfiler {
struct QmlEvent {
QmlEvent(qint64 startTime = -1, qint64 duration = -1, int typeIndex = -1,
qint64 num0 = 0, qint64 num1 = 0, qint64 num2 = 0, qint64 num3 = 0,
qint64 num4 = 0) :
m_startTime(startTime), m_duration(duration), m_dataType(NumericData),
m_typeIndex(typeIndex)
{
m_numericData[0] = num0;
m_numericData[1] = num1;
m_numericData[2] = num2;
m_numericData[3] = num3;
m_numericData[4] = num4;
}
QmlEvent(qint64 startTime, qint64 duration, int typeIndex, const QString &data)
: m_startTime(startTime), m_duration(duration), m_typeIndex(typeIndex)
{
assignStringData(data);
}
QmlEvent(const QmlEvent &other) :
m_startTime(other.m_startTime), m_duration(other.m_duration),
m_dataType(other.m_dataType), m_typeIndex(other.m_typeIndex)
{
assignData(other);
}
QmlEvent &operator=(const QmlEvent &other)
{
if (this != &other) {
if (m_dataType == StringData)
delete m_stringData;
m_startTime = other.m_startTime;
m_duration = other.m_duration;
m_typeIndex = other.m_typeIndex;
m_dataType = other.m_dataType;
assignData(other);
}
return *this;
}
~QmlEvent()
{
if (m_dataType == StringData)
delete m_stringData;
}
qint64 startTime() const { return m_startTime; }
void setStartTime(qint64 startTime) { m_startTime = startTime; }
qint64 duration() const { return m_duration; }
void setDuration(qint64 duration) { m_duration = duration; }
int typeIndex() const { return m_typeIndex; }
void setTypeIndex(int typeIndex) { m_typeIndex = typeIndex; }
qint64 numericData(int i) const { return m_dataType == NumericData ? m_numericData[i] : 0; }
void setNumericData(int i, qint64 data)
{
if (m_dataType == StringData)
delete m_stringData;
m_dataType = NumericData;
m_numericData[i] = data;
}
QString stringData() const
{
switch (m_dataType) {
case NumericData: return QString();
case StringData: return *m_stringData;
default: return QString::fromUtf8(m_characterData, m_characterDataLength);
}
}
void setStringData(const QString &data)
{
if (m_dataType == StringData)
delete m_stringData;
assignStringData(data);
}
bool isValid() const
{
return m_startTime != -1;
}
private:
static const quint8 StringData = 254;
static const quint8 NumericData = 255;
qint64 m_startTime;
qint64 m_duration;
union {
qint64 m_numericData[5];
QString *m_stringData;
char m_characterData[5 * sizeof(qint64) + 3];
};
union {
quint8 m_dataType;
quint8 m_characterDataLength;
};
qint32 m_typeIndex;
void assignData(const QmlEvent &other)
{
switch (m_dataType) {
case StringData:
m_stringData = new QString(*other.m_stringData);
break;
case NumericData:
for (int i = 0; i < 5; ++i)
m_numericData[i] = other.m_numericData[i];
break;
default:
memcpy(m_characterData, other.m_characterData, m_characterDataLength);
break;
}
}
void assignStringData(const QString &data)
{
QByteArray cdata = data.toUtf8();
if (cdata.length() <= (int)sizeof(m_characterData)) {
m_characterDataLength = cdata.length();
memcpy(m_characterData, cdata.constData(), m_characterDataLength);
} else {
m_dataType = StringData;
m_stringData = new QString(data);
}
}
};
} // namespace QmlProfiler
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "qmlprofilereventlocation.h"
#include "qmlprofilereventtypes.h"
#include <QString>
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), location(location), message(message), rangeType(rangeType),
detailType(detailType), data(data)
{}
QString displayName;
QmlEventLocation location;
Message message;
RangeType rangeType;
int detailType; // can be EventType, BindingType, PixmapEventType or SceneGraphFrameType
QString data;
};
} // namespace QmlProfiler
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QString>
namespace QmlProfiler {
struct QmlNote {
QmlNote(int typeIndex = -1, qint64 startTime = -1, qint64 duration = -1,
const QString &text = QString()) :
typeIndex(typeIndex), startTime(startTime), duration(duration), text(text)
{}
int typeIndex;
qint64 startTime;
qint64 duration;
QString text;
};
} // namespace QmlProfiler
......@@ -50,6 +50,9 @@ HEADERS += \
localqmlprofilerrunner.h \
memoryusagemodel.h \
pixmapcachemodel.h \
qmlevent.h \
qmleventtype.h \
qmlnote.h \
qmlprofiler_global.h \
qmlprofileranimationsmodel.h \
qmlprofilerattachdialog.h \
......@@ -81,7 +84,7 @@ HEADERS += \
qmlprofilertracefile.h \
qmlprofilertraceview.h \
qmlprofilerviewmanager.h \
scenegraphtimelinemodel.h \
scenegraphtimelinemodel.h
RESOURCES += \
qml/qmlprofiler.qrc
......
......@@ -27,6 +27,7 @@ QtcPlugin {
"localqmlprofilerrunner.cpp", "localqmlprofilerrunner.h",
"memoryusagemodel.cpp", "memoryusagemodel.h",
"pixmapcachemodel.cpp", "pixmapcachemodel.h",
"qmlevent.h", "qmleventtype.h", "qmlnote.h",
"qmlprofiler_global.h",
"qmlprofileranimationsmodel.h", "qmlprofileranimationsmodel.cpp",
"qmlprofilerattachdialog.cpp", "qmlprofilerattachdialog.h",
......
......@@ -54,7 +54,7 @@ void QmlProfilerAnimationsModel::clear()
QmlProfilerTimelineModel::clear();
}
bool QmlProfilerAnimationsModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
bool QmlProfilerAnimationsModel::accepted(const QmlEventType &event) const
{
return QmlProfilerTimelineModel::accepted(event) && event.detailType == AnimationFrame;
}
......@@ -66,15 +66,15 @@ void QmlProfilerAnimationsModel::loadData()
return;
// collect events
const QVector<QmlProfilerDataModel::QmlEventData> &referenceList = simpleModel->getEvents();
const QVector<QmlProfilerDataModel::QmlEventTypeData> &typeList = simpleModel->getEventTypes();
const QVector<QmlEvent> &referenceList = simpleModel->events();
const QVector<QmlEventType> &typeList = simpleModel->eventTypes();
AnimationThread lastThread;
QmlPaintEventData lastEvent;
qint64 minNextStartTimes[] = {0, 0};
foreach (const QmlProfilerDataModel::QmlEventData &event, referenceList) {
const QmlProfilerDataModel::QmlEventTypeData &type = typeList[event.typeIndex()];
foreach (const QmlEvent &event, referenceList) {
const QmlEventType &type = typeList[event.typeIndex()];
if (!accepted(type))
continue;
......
......@@ -64,7 +64,7 @@ public:
QVariantList labels() const;
QVariantMap details(int index) const;
bool accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const;
bool accepted(const QmlEventType &event) const;
protected:
void loadData();
......
......@@ -39,17 +39,17 @@ namespace QmlProfiler {
class QmlProfilerDataModel::QmlProfilerDataModelPrivate
{
public:
QVector<QmlEventTypeData> eventTypes;
QVector<QmlEventData> eventList;
QVector<QmlEventNoteData> eventNotes;
QHash<QmlEventTypeData, int> eventTypeIds;
QVector<QmlEventType> eventTypes;
QVector<QmlEvent> eventList;
QVector<QmlNote> eventNotes;
QHash<QmlEventType, int> eventTypeIds;
QmlProfilerModelManager *modelManager;
int modelId;
Internal::QmlProfilerDetailsRewriter *detailsRewriter;
};
QString getDisplayName(const QmlProfilerDataModel::QmlEventTypeData &event)
QString getDisplayName(const QmlEventType &event)
{
if (event.location.filename.isEmpty()) {
return QmlProfilerDataModel::tr("<bytecode>");
......@@ -60,7 +60,7 @@ QString getDisplayName(const QmlProfilerDataModel::QmlEventTypeData &event)
}
}
QString getInitialDetails(const QmlProfilerDataModel::QmlEventTypeData &event)
QString getInitialDetails(const QmlEventType &event)
{
QString details;
// generate details string
......@@ -124,27 +124,27 @@ QmlProfilerDataModel::~QmlProfilerDataModel()
delete d;
}
const QVector<QmlProfilerDataModel::QmlEventData> &QmlProfilerDataModel::getEvents() const
const QVector<QmlEvent> &QmlProfilerDataModel::events() const
{
Q_D(const QmlProfilerDataModel);
return d->eventList;
}
const QVector<QmlProfilerDataModel::QmlEventTypeData> &QmlProfilerDataModel::getEventTypes() const
const QVector<QmlEventType> &QmlProfilerDataModel::eventTypes() const
{
Q_D(const QmlProfilerDataModel);
return d->eventTypes;
}
const QVector<QmlProfilerDataModel::QmlEventNoteData> &QmlProfilerDataModel::getEventNotes() const
const QVector<QmlNote> &QmlProfilerDataModel::notes() const
{
Q_D(const QmlProfilerDataModel);
return d->eventNotes;
}
void QmlProfilerDataModel::setData(qint64 traceStart, qint64 traceEnd,
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types,
const QVector<QmlProfilerDataModel::QmlEventData> &events)
const QVector<QmlEventType> &types,
const QVector<QmlEvent> &events)
{
Q_D(QmlProfilerDataModel);