flamegraphmodel.h 3.55 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
#include "qmlprofilerdatamodel.h"
#include "qmlprofilernotesmodel.h"
#include "qmlprofilereventtypes.h"
31
#include "qmleventlocation.h"
Ulf Hermann's avatar
Ulf Hermann committed
32 33 34

#include <QSet>
#include <QVector>
35
#include <QStack>
Ulf Hermann's avatar
Ulf Hermann committed
36 37
#include <QAbstractItemModel>

38
namespace QmlProfiler {
Ulf Hermann's avatar
Ulf Hermann committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
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 {
59 60 61 62 63 64 65 66 67 68 69 70 71
        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
72 73 74
        MaxRole
    };

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

    QModelIndex index(int row, int column, const QModelIndex &parent) const override;
    QModelIndex parent(const QModelIndex &child) const override;
79
    Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override;
Ulf Hermann's avatar
Ulf Hermann committed
80 81 82 83 84
    int columnCount(const QModelIndex &parent) const override;
    QVariant data(const QModelIndex &index, int role) const override;
    QHash<int, QByteArray> roleNames() const override;

public slots:
85 86 87
    void loadEvent(const QmlEvent &event, const QmlEventType &type);
    void finalize();
    void onModelManagerStateChanged();
Ulf Hermann's avatar
Ulf Hermann committed
88 89
    void loadData(qint64 rangeStart = -1, qint64 rangeEnd = -1);
    void loadNotes(int typeId, bool emitSignal);
90
    void clear();
Ulf Hermann's avatar
Ulf Hermann committed
91 92 93 94 95 96 97

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

    QVariant lookup(const FlameGraphData &data, int role) const;
98
    FlameGraphData *pushChild(FlameGraphData *parent, const QmlEvent &data);
Ulf Hermann's avatar
Ulf Hermann committed
99 100

    int m_selectedTypeIndex;
101 102 103

    // used by binding loop detection
    QStack<QmlEvent> m_callStack;
Ulf Hermann's avatar
Ulf Hermann committed
104
    FlameGraphData m_stackBottom;
105
    FlameGraphData *m_stackTop;
Ulf Hermann's avatar
Ulf Hermann committed
106 107

    int m_modelId;
108
    QmlProfilerModelManager *m_modelManager;
Ulf Hermann's avatar
Ulf Hermann committed
109

110
    QList<RangeType> m_acceptedTypes;
Ulf Hermann's avatar
Ulf Hermann committed
111 112 113 114
    QSet<int> m_typeIdsWithNotes;
};

} // namespace Internal
115
} // namespace QmlProfiler