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

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

37
namespace QmlProfiler {
Ulf Hermann's avatar
Ulf Hermann committed
38 39 40 41 42 43 44 45
namespace Internal {

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

    qint64 duration;
    qint64 calls;
46 47 48
    qint64 memory;

    int allocations;
Ulf Hermann's avatar
Ulf Hermann committed
49 50 51 52 53 54 55 56 57 58 59 60
    int typeIndex;

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

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

79
    FlameGraphModel(QmlProfilerModelManager *modelManager, QObject *parent = 0);
Ulf Hermann's avatar
Ulf Hermann committed
80

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

public slots:
91 92 93
    void loadEvent(const QmlEvent &event, const QmlEventType &type);
    void finalize();
    void onModelManagerStateChanged();
94
    void restrictToFeatures(quint64 visibleFeatures);
Ulf Hermann's avatar
Ulf Hermann committed
95
    void loadNotes(int typeId, bool emitSignal);
96
    void clear();
Ulf Hermann's avatar
Ulf Hermann committed
97 98 99

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

102 103
    // used by binding loop detection
    QStack<QmlEvent> m_callStack;
104
    QStack<QmlEvent> m_compileStack;
Ulf Hermann's avatar
Ulf Hermann committed
105
    FlameGraphData m_stackBottom;
106 107
    FlameGraphData *m_callStackTop;
    FlameGraphData *m_compileStackTop;
Ulf Hermann's avatar
Ulf Hermann committed
108

109
    quint64 m_acceptedFeatures;
Ulf Hermann's avatar
Ulf Hermann committed
110
    int m_modelId;
111
    QmlProfilerModelManager *m_modelManager;
Ulf Hermann's avatar
Ulf Hermann committed
112 113 114 115 116

    QSet<int> m_typeIdsWithNotes;
};

} // namespace Internal
117
} // namespace QmlProfiler