2013-08-08 13:28:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-08-08 13:28:08 +02:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-08-08 13:28:08 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-08-08 13:28:08 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
#include "qmlprofilernotesmodel.h"
|
2016-05-02 12:18:57 +02:00
|
|
|
#include "qmlprofilereventtypes.h"
|
2016-05-04 18:54:59 +02:00
|
|
|
#include "qmleventlocation.h"
|
2016-04-28 16:02:54 +02:00
|
|
|
#include "qmlprofilerconstants.h"
|
2016-05-02 12:18:57 +02:00
|
|
|
|
2018-03-23 10:56:31 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
#include <QHash>
|
2016-09-08 18:26:55 +02:00
|
|
|
#include <QStack>
|
2013-08-08 13:28:08 +02:00
|
|
|
#include <QVector>
|
2018-03-23 09:28:57 +01:00
|
|
|
#include <QPointer>
|
2018-03-23 12:43:16 +01:00
|
|
|
#include <QAbstractTableModel>
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
namespace QmlProfiler {
|
|
|
|
|
class QmlProfilerModelManager;
|
2016-04-26 16:38:56 +02:00
|
|
|
class QmlProfilerStatisticsRelativesModel;
|
|
|
|
|
|
|
|
|
|
enum QmlProfilerStatisticsRelation {
|
2018-03-23 10:14:48 +01:00
|
|
|
QmlProfilerStatisticsCallees,
|
|
|
|
|
QmlProfilerStatisticsCallers
|
2016-04-26 16:38:56 +02:00
|
|
|
};
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2018-03-23 12:43:16 +01:00
|
|
|
enum ItemRole {
|
|
|
|
|
SortRole = Qt::UserRole + 1, // Sort by data, not by displayed string
|
|
|
|
|
FilterRole, // Filter out non-range types
|
|
|
|
|
TypeIdRole,
|
|
|
|
|
FilenameRole,
|
|
|
|
|
LineRole,
|
|
|
|
|
ColumnRole
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum MainField {
|
|
|
|
|
MainLocation,
|
|
|
|
|
MainType,
|
|
|
|
|
MainTimeInPercent,
|
|
|
|
|
MainTotalTime,
|
|
|
|
|
MainSelfTimeInPercent,
|
|
|
|
|
MainSelfTime,
|
|
|
|
|
MainCallCount,
|
|
|
|
|
MainTimePerCall,
|
|
|
|
|
MainMedianTime,
|
|
|
|
|
MainMaxTime,
|
|
|
|
|
MainMinTime,
|
|
|
|
|
MainDetails,
|
|
|
|
|
MaxMainField
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum RelativeField {
|
|
|
|
|
RelativeLocation,
|
|
|
|
|
RelativeType,
|
|
|
|
|
RelativeTotalTime,
|
|
|
|
|
RelativeCallCount,
|
|
|
|
|
RelativeDetails,
|
|
|
|
|
MaxRelativeField
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QmlProfilerStatisticsModel : public QAbstractTableModel
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2018-03-23 10:29:02 +01:00
|
|
|
static QString nameForType(RangeType typeNumber);
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
struct QmlEventStats {
|
2018-03-23 10:56:31 +01:00
|
|
|
std::vector<qint64> durations;
|
|
|
|
|
qint64 total = 0;
|
|
|
|
|
qint64 self = 0;
|
|
|
|
|
qint64 recursive = 0;
|
|
|
|
|
qint64 minimum = 0;
|
|
|
|
|
qint64 maximum = 0;
|
|
|
|
|
qint64 median = 0;
|
2018-03-23 09:28:57 +01:00
|
|
|
qint64 calls = 0;
|
2018-03-23 10:56:31 +01:00
|
|
|
|
|
|
|
|
void finalize()
|
|
|
|
|
{
|
|
|
|
|
static const qint64 qint64Max = std::numeric_limits<qint64>::max();
|
|
|
|
|
size_t size = durations.size();
|
|
|
|
|
QTC_ASSERT(size <= qint64Max, size = qint64Max);
|
|
|
|
|
calls = static_cast<qint64>(size);
|
|
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::sort(durations.begin(), durations.end());
|
|
|
|
|
const auto avg
|
|
|
|
|
= [](const qint64 a, const qint64 b) { return a / 2ll + b / 2ll + ((a & 1) + (b & 1)) / 2ll; };
|
|
|
|
|
|
|
|
|
|
const size_t half = size / 2;
|
|
|
|
|
median = (size & 1) == 0 ? avg(durations[half - 1], durations[half]) : durations[half];
|
|
|
|
|
minimum = durations.front();
|
|
|
|
|
maximum = durations.back();
|
|
|
|
|
|
|
|
|
|
durations.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 average() const
|
|
|
|
|
{
|
|
|
|
|
return calls == 0 ? 0 : total / calls;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 totalNonRecursive() const
|
|
|
|
|
{
|
|
|
|
|
return total - recursive;
|
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
};
|
|
|
|
|
|
2016-12-28 18:12:49 +01:00
|
|
|
double durationPercent(int typeId) const;
|
|
|
|
|
double durationSelfPercent(int typeId) const;
|
|
|
|
|
|
2018-03-23 09:28:57 +01:00
|
|
|
QmlProfilerStatisticsModel(QmlProfilerModelManager *modelManager);
|
|
|
|
|
~QmlProfilerStatisticsModel() override = default;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2018-03-23 09:51:44 +01:00
|
|
|
void restrictToFeatures(quint64 features);
|
2018-03-23 09:28:57 +01:00
|
|
|
bool isRestrictedToRange() const;
|
2014-03-06 16:12:02 +01:00
|
|
|
|
2018-03-23 10:29:02 +01:00
|
|
|
QStringList details(int typeIndex) const;
|
|
|
|
|
QString summary(const QVector<int> &typeIds) const;
|
2018-03-23 10:56:31 +01:00
|
|
|
const QVector<QmlEventStats> &getData() const;
|
2016-04-26 11:50:59 +02:00
|
|
|
const QVector<QmlEventType> &getTypes() const;
|
2014-09-26 18:25:39 +02:00
|
|
|
const QHash<int, QString> &getNotes() const;
|
2018-03-23 10:56:31 +01:00
|
|
|
qint64 rootDuration() const { return m_rootDuration; }
|
2014-09-26 18:25:39 +02:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int count() const;
|
|
|
|
|
void clear();
|
|
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
void setRelativesModel(QmlProfilerStatisticsRelativesModel *childModel,
|
|
|
|
|
QmlProfilerStatisticsRelation relation);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2018-03-23 12:43:16 +01:00
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
|
int columnCount(const QModelIndex &parent) const override;
|
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
signals:
|
|
|
|
|
void dataAvailable();
|
2014-09-26 18:25:39 +02:00
|
|
|
void notesAvailable(int typeIndex);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
private:
|
2016-04-26 16:38:56 +02:00
|
|
|
void loadEvent(const QmlEvent &event, const QmlEventType &type);
|
|
|
|
|
void finalize();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2018-03-23 12:31:51 +01:00
|
|
|
void modelManagerStateChanged();
|
2014-09-26 18:25:39 +02:00
|
|
|
void notesChanged(int typeIndex);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2018-03-23 12:43:16 +01:00
|
|
|
QVariant dataForMainEntry(const QModelIndex &index, int role) const;
|
|
|
|
|
|
2018-03-23 10:56:31 +01:00
|
|
|
QVector<QmlEventStats> m_data;
|
2018-03-23 09:28:57 +01:00
|
|
|
|
|
|
|
|
QPointer<QmlProfilerStatisticsRelativesModel> m_calleesModel;
|
|
|
|
|
QPointer<QmlProfilerStatisticsRelativesModel> m_callersModel;
|
|
|
|
|
QPointer<QmlProfilerModelManager> m_modelManager;
|
|
|
|
|
|
|
|
|
|
QList<RangeType> m_acceptedTypes;
|
|
|
|
|
QHash<int, QString> m_notes;
|
|
|
|
|
|
|
|
|
|
QStack<QmlEvent> m_callStack;
|
|
|
|
|
QStack<QmlEvent> m_compileStack;
|
2018-03-23 10:56:31 +01:00
|
|
|
|
|
|
|
|
qint64 m_rootDuration = 0;
|
2013-08-08 13:28:08 +02:00
|
|
|
};
|
|
|
|
|
|
2018-03-23 12:43:16 +01:00
|
|
|
class QmlProfilerStatisticsRelativesModel : public QAbstractTableModel
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2016-04-26 16:38:56 +02:00
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
struct QmlStatisticsRelativesData {
|
2018-03-23 10:56:31 +01:00
|
|
|
QmlStatisticsRelativesData(qint64 duration = 0, qint64 calls = 0, int typeIndex = -1,
|
|
|
|
|
bool isRecursive = false)
|
|
|
|
|
: duration(duration), calls(calls), typeIndex(typeIndex), isRecursive(isRecursive) {}
|
2018-04-12 12:08:48 +02:00
|
|
|
qint64 duration;
|
|
|
|
|
qint64 calls;
|
2018-03-23 10:56:31 +01:00
|
|
|
int typeIndex;
|
2018-04-12 12:08:48 +02:00
|
|
|
bool isRecursive;
|
2013-08-08 13:28:08 +02:00
|
|
|
};
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlProfilerStatisticsRelativesModel(QmlProfilerModelManager *modelManager,
|
|
|
|
|
QmlProfilerStatisticsModel *statisticsModel,
|
2018-03-23 09:28:57 +01:00
|
|
|
QmlProfilerStatisticsRelation relation);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
int count() const;
|
|
|
|
|
void clear();
|
|
|
|
|
|
2018-03-23 10:56:31 +01:00
|
|
|
const QVector<QmlStatisticsRelativesData> &getData(int typeId) const;
|
2016-04-26 11:50:59 +02:00
|
|
|
const QVector<QmlEventType> &getTypes() const;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-12-28 18:12:49 +01:00
|
|
|
void loadEvent(RangeType type, const QmlEvent &event, bool isRecursive);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-05-24 15:50:31 +02:00
|
|
|
QmlProfilerStatisticsRelation relation() const;
|
|
|
|
|
|
2018-03-23 12:43:16 +01:00
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
|
int columnCount(const QModelIndex &parent) const override;
|
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
2018-03-23 13:37:37 +01:00
|
|
|
|
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
signals:
|
|
|
|
|
void dataAvailable();
|
|
|
|
|
|
|
|
|
|
protected:
|
2018-03-23 12:43:16 +01:00
|
|
|
QVariant dataForMainEntry(qint64 totalDuration, int role, int column) const;
|
|
|
|
|
|
2018-03-23 10:56:31 +01:00
|
|
|
QHash<int, QVector<QmlStatisticsRelativesData>> m_data;
|
2018-03-23 09:28:57 +01:00
|
|
|
QPointer<QmlProfilerModelManager> m_modelManager;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2018-03-23 12:43:16 +01:00
|
|
|
int m_relativeTypeIndex = std::numeric_limits<int>::max();
|
|
|
|
|
|
2016-09-08 18:26:55 +02:00
|
|
|
struct Frame {
|
2018-04-12 12:08:48 +02:00
|
|
|
Frame(qint64 startTime = 0, int typeId = -1) : startTime(startTime), typeId(typeId) {}
|
|
|
|
|
qint64 startTime;
|
|
|
|
|
int typeId;
|
2016-09-08 18:26:55 +02:00
|
|
|
};
|
|
|
|
|
QStack<Frame> m_callStack;
|
|
|
|
|
QStack<Frame> m_compileStack;
|
2016-04-26 16:38:56 +02:00
|
|
|
const QmlProfilerStatisticsRelation m_relation;
|
2013-08-08 13:28:08 +02:00
|
|
|
};
|
|
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
} // namespace QmlProfiler
|