aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp
diff options
context:
space:
mode:
authorUlf Hermann <[email protected]>2018-03-23 10:29:02 +0100
committerUlf Hermann <[email protected]>2018-04-12 10:15:44 +0000
commit1155601da5b52a48e4c6b9bedaba904e6b703e8a (patch)
tree55b44a19c6d239de04ffc8a2817afcf3c95ca709 /src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp
parent085dfac5602412010239520ddfb4b7e42e31452e (diff)
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 <[email protected]>
Diffstat (limited to 'src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp')
-rw-r--r--src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp72
1 files changed, 67 insertions, 5 deletions
diff --git a/src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp b/src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp
index 804d68e5e2d..18c4905b8b4 100644
--- a/src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp
@@ -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)