flamegraphmodel.h 3.31 KB
Newer Older
Ulf Hermann's avatar
Ulf Hermann committed
1 2
/****************************************************************************
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
Ulf Hermann's avatar
Ulf Hermann committed
5 6 7 8 9 10 11
**
** 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
12 13 14
** 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.
Ulf Hermann's avatar
Ulf Hermann committed
15
**
16 17 18 19 20 21 22
** 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.
Ulf Hermann's avatar
Ulf Hermann committed
23 24 25
**
****************************************************************************/

hjk's avatar
hjk committed
26
#pragma once
Ulf Hermann's avatar
Ulf Hermann committed
27

28 29 30 31
#include "qmlprofilerdatamodel.h"
#include "qmlprofilernotesmodel.h"
#include "qmlprofilereventtypes.h"
#include "qmlprofilereventlocation.h"
Ulf Hermann's avatar
Ulf Hermann committed
32 33 34 35 36

#include <QSet>
#include <QVector>
#include <QAbstractItemModel>

37
namespace QmlProfiler {
Ulf Hermann's avatar
Ulf Hermann committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
namespace Internal {

struct FlameGraphData {
    FlameGraphData(FlameGraphData *parent = 0, int typeIndex = -1, qint64 duration = 0);
    ~FlameGraphData();

    qint64 duration;
    qint64 calls;
    int typeIndex;

    FlameGraphData *parent;
    QVector<FlameGraphData *> children;
};

class FlameGraphModel : public QAbstractItemModel
{
    Q_OBJECT
    Q_ENUMS(Role)
public:
    enum Role {
58 59 60 61 62 63 64 65 66 67 68 69 70
        TypeIdRole = Qt::UserRole + 1, // Sort by data, not by displayed string
        TypeRole,
        DurationRole,
        CallCountRole,
        DetailsRole,
        FilenameRole,
        LineRole,
        ColumnRole,
        NoteRole,
        TimePerCallRole,
        TimeInPercentRole,
        RangeTypeRole,
        LocationRole,
Ulf Hermann's avatar
Ulf Hermann committed
71 72 73
        MaxRole
    };

74
    FlameGraphModel(QmlProfilerModelManager *modelManager, QObject *parent = 0);
Ulf Hermann's avatar
Ulf Hermann committed
75 76 77

    QModelIndex index(int row, int column, const QModelIndex &parent) const override;
    QModelIndex parent(const QModelIndex &child) const override;
78
    Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override;
Ulf Hermann's avatar
Ulf Hermann committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    int columnCount(const QModelIndex &parent) const override;
    QVariant data(const QModelIndex &index, int role) const override;
    QHash<int, QByteArray> roleNames() const override;

public slots:
    void loadData(qint64 rangeStart = -1, qint64 rangeEnd = -1);
    void loadNotes(int typeId, bool emitSignal);

private:
    friend class FlameGraphRelativesModel;
    friend class FlameGraphParentsModel;
    friend class FlameGraphChildrenModel;

    QVariant lookup(const FlameGraphData &data, int role) const;
    void clear();
94
    FlameGraphData *pushChild(FlameGraphData *parent, const QmlEvent *data);
Ulf Hermann's avatar
Ulf Hermann committed
95 96 97 98 99

    int m_selectedTypeIndex;
    FlameGraphData m_stackBottom;

    int m_modelId;
100
    QmlProfilerModelManager *m_modelManager;
Ulf Hermann's avatar
Ulf Hermann committed
101

102
    QList<RangeType> m_acceptedTypes;
Ulf Hermann's avatar
Ulf Hermann committed
103 104 105 106
    QSet<int> m_typeIdsWithNotes;
};

} // namespace Internal
107
} // namespace QmlProfiler