forked from qt-creator/qt-creator
QmlProfiler: Add text marks for QML/JS types into documents
The text marks are little labels next to the lines in the editor that tell you how much of total run time was spent in the respective QML/JS construct during the last profiling session. This is similar to what the valgrind profiler does. We add the text marks only when the documents are loaded into an editor. This keeps the number of text marks manageable. Multiple events on a single line are shown using a tooltip. Task-number: QTCREATORBUG-17757 Change-Id: Ie38b8ab880a718a1ef72ef343d84070ab34bc5bc Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -225,6 +225,53 @@ void QmlProfilerStatisticsView::clear()
|
||||
d->m_statsParents->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 = d->model->getData()[typeId].percentOfTime;
|
||||
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;
|
||||
}
|
||||
|
||||
QStringList QmlProfilerStatisticsView::details(int typeId) const
|
||||
{
|
||||
const QmlEventType &type = d->model->getTypes()[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(d->model->getData()[typeId].percentOfTime, 'f', 2) + QLatin1Char('%')
|
||||
});
|
||||
}
|
||||
|
||||
QModelIndex QmlProfilerStatisticsView::selectedModelIndex() const
|
||||
{
|
||||
return d->m_statsTree->selectedModelIndex();
|
||||
|
||||
Reference in New Issue
Block a user