forked from qt-creator/qt-creator
QmlProfiler: Use annotions instead of custom icons on marks
To display the relative cost in the editor a custom text mark icon was painted with a custom width factor for qml profiler marks. Move this textual information into a line annotation and be a bit more verbose what kind of information was collected in that line. Change-Id: I863c2afa52f2acdf19ffcab3dfc95af566ac0efe Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -156,26 +156,32 @@ QString QmlProfilerStatisticsModel::summary(const QVector<int> &typeIds) const
|
|||||||
double maximum = 0;
|
double maximum = 0;
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
|
|
||||||
|
QSet<RangeType> types;
|
||||||
|
|
||||||
for (int typeId : typeIds) {
|
for (int typeId : typeIds) {
|
||||||
|
types << m_modelManager->eventType(typeId).rangeType();
|
||||||
const double percentage = durationPercent(typeId);
|
const double percentage = durationPercent(typeId);
|
||||||
if (percentage > maximum)
|
if (percentage > maximum)
|
||||||
maximum = percentage;
|
maximum = percentage;
|
||||||
sum += percentage;
|
sum += percentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QStringList typeNames = Utils::transform<QList>(types, &nameForType);
|
||||||
|
const QString typeSummary = QString(" (%1)").arg(typeNames.join(", "));
|
||||||
|
|
||||||
const QLatin1Char percent('%');
|
const QLatin1Char percent('%');
|
||||||
|
|
||||||
if (sum < cutoff)
|
if (sum < cutoff)
|
||||||
return QLatin1Char('<') + QString::number(cutoff, 'f', 1) + percent;
|
return QLatin1Char('<') + QString::number(cutoff, 'f', 1) + percent + typeSummary;
|
||||||
|
|
||||||
if (typeIds.length() == 1)
|
if (typeIds.length() == 1)
|
||||||
return QLatin1Char('~') + QString::number(maximum, 'f', 1) + percent;
|
return QLatin1Char('~') + QString::number(maximum, 'f', 1) + percent + typeSummary;
|
||||||
|
|
||||||
// add/subtract 0.05 to avoid problematic rounding
|
// add/subtract 0.05 to avoid problematic rounding
|
||||||
if (maximum < cutoff)
|
if (maximum < cutoff)
|
||||||
return QChar(0x2264) + QString::number(sum + round, 'f', 1) + percent;
|
return QChar(0x2264) + QString::number(sum + round, 'f', 1) + percent + typeSummary;
|
||||||
|
|
||||||
return QChar(0x2265) + QString::number(qMax(maximum - round, cutoff), 'f', 1) + percent;
|
return QChar(0x2265) + QString::number(qMax(maximum - round, cutoff), 'f', 1) + percent + typeSummary;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProfilerStatisticsModel::clear()
|
void QmlProfilerStatisticsModel::clear()
|
||||||
|
@@ -39,29 +39,21 @@ namespace QmlProfiler {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
QmlProfilerTextMark::QmlProfilerTextMark(QmlProfilerViewManager *viewManager, int typeId,
|
QmlProfilerTextMark::QmlProfilerTextMark(QmlProfilerViewManager *viewManager, int typeId,
|
||||||
const FilePath &fileName, int lineNumber) :
|
const FilePath &fileName, int lineNumber)
|
||||||
TextMark(fileName, lineNumber, Constants::TEXT_MARK_CATEGORY, 3.5), m_viewManager(viewManager),
|
: TextMark(fileName, lineNumber, Constants::TEXT_MARK_CATEGORY)
|
||||||
m_typeIds(1, typeId)
|
, m_viewManager(viewManager)
|
||||||
{
|
{
|
||||||
|
addTypeId(typeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProfilerTextMark::addTypeId(int typeId)
|
void QmlProfilerTextMark::addTypeId(int typeId)
|
||||||
{
|
{
|
||||||
m_typeIds.append(typeId);
|
m_typeIds.append(typeId);
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProfilerTextMark::paintIcon(QPainter *painter, const QRect &paintRect) const
|
|
||||||
{
|
|
||||||
const QmlProfilerStatisticsView *statisticsView = m_viewManager->statisticsView();
|
const QmlProfilerStatisticsView *statisticsView = m_viewManager->statisticsView();
|
||||||
QTC_ASSERT(statisticsView, return);
|
QTC_ASSERT(statisticsView, return);
|
||||||
|
|
||||||
painter->save();
|
setLineAnnotation(statisticsView->summary(m_typeIds));
|
||||||
painter->setPen(Qt::black);
|
|
||||||
painter->fillRect(paintRect, Qt::white);
|
|
||||||
painter->drawRect(paintRect);
|
|
||||||
painter->drawText(paintRect, statisticsView->summary(m_typeIds),
|
|
||||||
Qt::AlignRight | Qt::AlignVCenter);
|
|
||||||
painter->restore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProfilerTextMark::clicked()
|
void QmlProfilerTextMark::clicked()
|
||||||
@@ -142,12 +134,27 @@ bool QmlProfilerTextMark::addToolTipContent(QLayout *target) const
|
|||||||
auto layout = new QGridLayout;
|
auto layout = new QGridLayout;
|
||||||
layout->setHorizontalSpacing(10);
|
layout->setHorizontalSpacing(10);
|
||||||
for (int row = 0, rowEnd = m_typeIds.length(); row != rowEnd; ++row) {
|
for (int row = 0, rowEnd = m_typeIds.length(); row != rowEnd; ++row) {
|
||||||
|
int typeId = m_typeIds[row];
|
||||||
const QStringList typeDetails = statisticsView->details(m_typeIds[row]);
|
const QStringList typeDetails = statisticsView->details(m_typeIds[row]);
|
||||||
for (int column = 0, columnEnd = typeDetails.length(); column != columnEnd; ++column) {
|
for (int column = 0, columnEnd = typeDetails.length(); column != columnEnd; ++column) {
|
||||||
QLabel *label = new QLabel;
|
QLabel *label = new QLabel;
|
||||||
label->setAlignment(column == columnEnd - 1 ? Qt::AlignRight : Qt::AlignLeft);
|
label->setAlignment(column == columnEnd - 1 ? Qt::AlignRight : Qt::AlignLeft);
|
||||||
label->setTextFormat(Qt::PlainText);
|
if (column == 0) {
|
||||||
label->setText(typeDetails[column]);
|
label->setTextFormat(Qt::RichText);
|
||||||
|
label->setTextInteractionFlags(Qt::LinksAccessibleByMouse
|
||||||
|
| Qt::LinksAccessibleByKeyboard);
|
||||||
|
label->setText(QString("<a href='selectType' style='text-decoration:none'>%1</a>")
|
||||||
|
.arg(typeDetails[column]));
|
||||||
|
QObject::connect(label,
|
||||||
|
&QLabel::linkActivated,
|
||||||
|
m_viewManager,
|
||||||
|
[this, typeId]() {
|
||||||
|
emit m_viewManager->typeSelected(typeId);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
label->setTextFormat(Qt::PlainText);
|
||||||
|
label->setText(typeDetails[column]);
|
||||||
|
}
|
||||||
layout->addWidget(label, row, column);
|
layout->addWidget(label, row, column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,6 @@ public:
|
|||||||
const Utils::FilePath &fileName, int lineNumber);
|
const Utils::FilePath &fileName, int lineNumber);
|
||||||
void addTypeId(int typeId);
|
void addTypeId(int typeId);
|
||||||
|
|
||||||
void paintIcon(QPainter *painter, const QRect &rect) const override;
|
|
||||||
void clicked() override;
|
void clicked() override;
|
||||||
bool isClickable() const override { return true; }
|
bool isClickable() const override { return true; }
|
||||||
bool addToolTipContent(QLayout *target) const override;
|
bool addToolTipContent(QLayout *target) const override;
|
||||||
|
Reference in New Issue
Block a user