forked from qt-creator/qt-creator
QmlProfiler: Move some methods from statistics view into model
This allows us to tighten up the public interface of the model. Change-Id: Iaa0363993de7cd94c3468d2c939198e65746e829 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -37,6 +37,19 @@
|
||||
|
||||
namespace QmlProfiler {
|
||||
|
||||
QString QmlProfilerStatisticsModel::nameForType(RangeType typeNumber)
|
||||
{
|
||||
switch (typeNumber) {
|
||||
case Painting: return QmlProfilerStatisticsModel::tr("Painting");
|
||||
case Compiling: return QmlProfilerStatisticsModel::tr("Compiling");
|
||||
case Creating: return QmlProfilerStatisticsModel::tr("Creating");
|
||||
case Binding: return QmlProfilerStatisticsModel::tr("Binding");
|
||||
case HandlingSignal: return QmlProfilerStatisticsModel::tr("Handling Signal");
|
||||
case Javascript: return QmlProfilerStatisticsModel::tr("JavaScript");
|
||||
default: return QString();
|
||||
}
|
||||
}
|
||||
|
||||
double QmlProfilerStatisticsModel::durationPercent(int typeId) const
|
||||
{
|
||||
const QmlEventStats &global = m_data[-1];
|
||||
@@ -124,6 +137,60 @@ const QHash<int, QString> &QmlProfilerStatisticsModel::getNotes() const
|
||||
return m_notes;
|
||||
}
|
||||
|
||||
QStringList QmlProfilerStatisticsModel::details(int typeIndex) const
|
||||
{
|
||||
QString data;
|
||||
QString displayName;
|
||||
if (typeIndex < 0) {
|
||||
data = tr("Main Program");
|
||||
} else {
|
||||
const QmlEventType &type = m_modelManager->eventTypes().at(typeIndex);
|
||||
displayName = nameForType(type.rangeType());
|
||||
|
||||
const QChar ellipsisChar(0x2026);
|
||||
const int maxColumnWidth = 32;
|
||||
|
||||
data = type.data();
|
||||
if (data.length() > maxColumnWidth)
|
||||
data = data.left(maxColumnWidth - 1) + ellipsisChar;
|
||||
}
|
||||
|
||||
return QStringList({
|
||||
displayName,
|
||||
data,
|
||||
QString::number(durationPercent(typeIndex), 'f', 2) + QLatin1Char('%')
|
||||
});
|
||||
}
|
||||
|
||||
QString QmlProfilerStatisticsModel::summary(const QVector<int> &typeIds) const
|
||||
{
|
||||
const double cutoff = 0.1;
|
||||
const double round = 0.05;
|
||||
double maximum = 0;
|
||||
double sum = 0;
|
||||
|
||||
for (int typeId : typeIds) {
|
||||
const double percentage = durationPercent(typeId);
|
||||
if (percentage > maximum)
|
||||
maximum = percentage;
|
||||
sum += percentage;
|
||||
}
|
||||
|
||||
const QLatin1Char percent('%');
|
||||
|
||||
if (sum < cutoff)
|
||||
return QLatin1Char('<') + QString::number(cutoff, 'f', 1) + percent;
|
||||
|
||||
if (typeIds.length() == 1)
|
||||
return QLatin1Char('~') + QString::number(maximum, 'f', 1) + percent;
|
||||
|
||||
// add/subtract 0.05 to avoid problematic rounding
|
||||
if (maximum < cutoff)
|
||||
return QChar(0x2264) + QString::number(sum + round, 'f', 1) + percent;
|
||||
|
||||
return QChar(0x2265) + QString::number(qMax(maximum - round, cutoff), 'f', 1) + percent;
|
||||
}
|
||||
|
||||
void QmlProfilerStatisticsModel::clear()
|
||||
{
|
||||
m_data.clear();
|
||||
@@ -146,11 +213,6 @@ void QmlProfilerStatisticsModel::setRelativesModel(QmlProfilerStatisticsRelative
|
||||
m_calleesModel = relative;
|
||||
}
|
||||
|
||||
QmlProfilerModelManager *QmlProfilerStatisticsModel::modelManager() const
|
||||
{
|
||||
return m_modelManager;
|
||||
}
|
||||
|
||||
void QmlProfilerStatisticsModel::dataChanged()
|
||||
{
|
||||
if (m_modelManager->state() == QmlProfilerModelManager::ClearingData)
|
||||
|
||||
@@ -49,6 +49,8 @@ class QmlProfilerStatisticsModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static QString nameForType(RangeType typeNumber);
|
||||
|
||||
struct QmlEventStats {
|
||||
qint64 duration = 0;
|
||||
qint64 durationSelf = 0;
|
||||
@@ -68,6 +70,8 @@ public:
|
||||
void restrictToFeatures(quint64 features);
|
||||
bool isRestrictedToRange() const;
|
||||
|
||||
QStringList details(int typeIndex) const;
|
||||
QString summary(const QVector<int> &typeIds) const;
|
||||
const QHash<int, QmlEventStats> &getData() const;
|
||||
const QVector<QmlEventType> &getTypes() const;
|
||||
const QHash<int, QString> &getNotes() const;
|
||||
@@ -77,7 +81,6 @@ public:
|
||||
|
||||
void setRelativesModel(QmlProfilerStatisticsRelativesModel *childModel,
|
||||
QmlProfilerStatisticsRelation relation);
|
||||
QmlProfilerModelManager *modelManager() const;
|
||||
|
||||
signals:
|
||||
void dataAvailable();
|
||||
|
||||
@@ -243,49 +243,12 @@ void QmlProfilerStatisticsView::clear()
|
||||
|
||||
QString QmlProfilerStatisticsView::summary(const QVector<int> &typeIds) const
|
||||
{
|
||||
const double cutoff = 0.1;
|
||||
const double round = 0.05;
|
||||
double maximum = 0;
|
||||
double sum = 0;
|
||||
|
||||
for (int typeId : typeIds) {
|
||||
const double percentage = m_mainView->durationPercent(typeId);
|
||||
if (percentage > maximum)
|
||||
maximum = percentage;
|
||||
sum += percentage;
|
||||
}
|
||||
|
||||
const QLatin1Char percent('%');
|
||||
|
||||
if (sum < cutoff)
|
||||
return QLatin1Char('<') + QString::number(cutoff, 'f', 1) + percent;
|
||||
|
||||
if (typeIds.length() == 1)
|
||||
return QLatin1Char('~') + QString::number(maximum, 'f', 1) + percent;
|
||||
|
||||
// add/subtract 0.05 to avoid problematic rounding
|
||||
if (maximum < cutoff)
|
||||
return QChar(0x2264) + QString::number(sum + round, 'f', 1) + percent;
|
||||
|
||||
return QChar(0x2265) + QString::number(qMax(maximum - round, cutoff), 'f', 1) + percent;
|
||||
return m_mainView->summary(typeIds);
|
||||
}
|
||||
|
||||
QStringList QmlProfilerStatisticsView::details(int typeId) const
|
||||
{
|
||||
const QmlEventType &type = m_mainView->getType(typeId);
|
||||
|
||||
const QChar ellipsisChar(0x2026);
|
||||
const int maxColumnWidth = 32;
|
||||
|
||||
QString data = type.data();
|
||||
if (data.length() > maxColumnWidth)
|
||||
data = data.left(maxColumnWidth - 1) + ellipsisChar;
|
||||
|
||||
return QStringList({
|
||||
QmlProfilerStatisticsMainView::nameForType(type.rangeType()),
|
||||
data,
|
||||
QString::number(m_mainView->durationPercent(typeId), 'f', 2) + QLatin1Char('%')
|
||||
});
|
||||
return m_mainView->details(typeId);
|
||||
}
|
||||
|
||||
QModelIndex QmlProfilerStatisticsView::selectedModelIndex() const
|
||||
@@ -493,14 +456,14 @@ bool QmlProfilerStatisticsMainView::isRestrictedToRange() const
|
||||
return m_model->isRestrictedToRange();
|
||||
}
|
||||
|
||||
double QmlProfilerStatisticsMainView::durationPercent(int typeId) const
|
||||
QString QmlProfilerStatisticsMainView::summary(const QVector<int> &typeIds) const
|
||||
{
|
||||
return m_model->durationPercent(typeId);
|
||||
return m_model->summary(typeIds);
|
||||
}
|
||||
|
||||
const QmlEventType &QmlProfilerStatisticsMainView::getType(int typeId) const
|
||||
QStringList QmlProfilerStatisticsMainView::details(int typeId) const
|
||||
{
|
||||
return m_model->getTypes()[typeId];
|
||||
return m_model->details(typeId);
|
||||
}
|
||||
|
||||
void QmlProfilerStatisticsMainView::parseModel()
|
||||
@@ -520,7 +483,7 @@ void QmlProfilerStatisticsMainView::parseModel()
|
||||
type.displayName().isEmpty() ? tr("<bytecode>") : type.displayName(),
|
||||
type.displayName());
|
||||
|
||||
QString typeString = QmlProfilerStatisticsMainView::nameForType(type.rangeType());
|
||||
QString typeString = QmlProfilerStatisticsModel::nameForType(type.rangeType());
|
||||
newRow << new StatisticsViewItem(typeString, typeString);
|
||||
|
||||
const double percent = m_model->durationPercent(typeIndex);
|
||||
@@ -582,19 +545,6 @@ QStandardItem *QmlProfilerStatisticsMainView::itemFromIndex(const QModelIndex &i
|
||||
return m_standardItemModel->item(index.row());
|
||||
}
|
||||
|
||||
QString QmlProfilerStatisticsMainView::nameForType(RangeType typeNumber)
|
||||
{
|
||||
switch (typeNumber) {
|
||||
case Painting: return QmlProfilerStatisticsMainView::tr("Painting");
|
||||
case Compiling: return QmlProfilerStatisticsMainView::tr("Compiling");
|
||||
case Creating: return QmlProfilerStatisticsMainView::tr("Creating");
|
||||
case Binding: return QmlProfilerStatisticsMainView::tr("Binding");
|
||||
case HandlingSignal: return QmlProfilerStatisticsMainView::tr("Handling Signal");
|
||||
case Javascript: return QmlProfilerStatisticsMainView::tr("JavaScript");
|
||||
default: return QString();
|
||||
}
|
||||
}
|
||||
|
||||
int QmlProfilerStatisticsMainView::selectedTypeId() const
|
||||
{
|
||||
QModelIndex index = selectedModelIndex();
|
||||
@@ -753,7 +703,7 @@ void QmlProfilerStatisticsRelativesView::rebuildTree(
|
||||
newRow << new StatisticsViewItem(
|
||||
type.displayName().isEmpty() ? tr("<bytecode>") : type.displayName(),
|
||||
type.displayName());
|
||||
const QString typeName = QmlProfilerStatisticsMainView::nameForType(type.rangeType());
|
||||
const QString typeName = QmlProfilerStatisticsModel::nameForType(type.rangeType());
|
||||
newRow << new StatisticsViewItem(typeName, typeName);
|
||||
newRow << new StatisticsViewItem(Timeline::formatTime(stats.duration),
|
||||
stats.duration);
|
||||
|
||||
@@ -117,8 +117,6 @@ public:
|
||||
void copyTableToClipboard() const;
|
||||
void copyRowToClipboard() const;
|
||||
|
||||
static QString nameForType(RangeType typeNumber);
|
||||
|
||||
int selectedTypeId() const;
|
||||
|
||||
void setShowExtendedStatistics(bool);
|
||||
@@ -132,9 +130,9 @@ public:
|
||||
|
||||
void restrictToFeatures(quint64 features);
|
||||
bool isRestrictedToRange() const;
|
||||
double durationPercent(int typeId) const;
|
||||
|
||||
const QmlEventType &getType(int typeId) const;
|
||||
QString summary(const QVector<int> &typeIds) const;
|
||||
QStringList details(int typeId) const;
|
||||
|
||||
signals:
|
||||
void gotoSourceLocation(const QString &fileName, int lineNumber, int columnNumber);
|
||||
|
||||
Reference in New Issue
Block a user