qmlprofilermodelmanager.h 4.81 KB
Newer Older
Christiaan Janssen's avatar
Christiaan Janssen committed
1
2
/****************************************************************************
**
3
4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
Christiaan Janssen's avatar
Christiaan Janssen 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.
Christiaan Janssen's avatar
Christiaan Janssen 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.
Christiaan Janssen's avatar
Christiaan Janssen committed
23
24
25
**
****************************************************************************/

hjk's avatar
hjk committed
26
#pragma once
Christiaan Janssen's avatar
Christiaan Janssen committed
27
28

#include "qmlprofiler_global.h"
29
#include "qmlprofilereventtypes.h"
30
#include "qmleventlocation.h"
31
32
#include "qmlevent.h"
#include "qmleventtype.h"
33
#include "qmlprofilertextmark.h"
34

Christiaan Janssen's avatar
Christiaan Janssen committed
35
36
#include <utils/fileinprojectfinder.h>

37
#include <QObject>
38
#include <functional>
39

40
41
namespace ProjectExplorer { class RunConfiguration; }

Christiaan Janssen's avatar
Christiaan Janssen committed
42
43
namespace QmlProfiler {
class QmlProfilerModelManager;
44
class QmlProfilerNotesModel;
Christiaan Janssen's avatar
Christiaan Janssen committed
45
46
47

namespace Internal {

48
class QMLPROFILER_EXPORT QmlProfilerTraceTime : public QObject
Christiaan Janssen's avatar
Christiaan Janssen committed
49
50
51
52
53
54
55
56
{
    Q_OBJECT
public:
    explicit QmlProfilerTraceTime(QObject *parent);

    qint64 startTime() const;
    qint64 endTime() const;
    qint64 duration() const;
57
    bool isRestrictedToRange() const;
Christiaan Janssen's avatar
Christiaan Janssen committed
58
59
60

public slots:
    void clear();
Ulf Hermann's avatar
Ulf Hermann committed
61

62
    void setTime(qint64 startTime, qint64 endTime);
Ulf Hermann's avatar
Ulf Hermann committed
63
64
    void decreaseStartTime(qint64 time);
    void increaseEndTime(qint64 time);
65
    void restrictToRange(qint64 startTime, qint64 endTime);
Christiaan Janssen's avatar
Christiaan Janssen committed
66
67
68
69

private:
    qint64 m_startTime;
    qint64 m_endTime;
70
71
72

    qint64 m_restrictedStartTime;
    qint64 m_restrictedEndTime;
Christiaan Janssen's avatar
Christiaan Janssen committed
73
74
75
76
77
78
79
80
81
82
83
};

} // End internal namespace

using namespace Internal;

// Interface between the Data Model and the Engine/Tool
class QMLPROFILER_EXPORT QmlProfilerModelManager : public QObject
{
    Q_OBJECT
public:
84
85
86
87
88
89
90
    enum State {
        Empty,
        AcquiringData,
        ProcessingData,
        ClearingData,
        Done
    };
Christiaan Janssen's avatar
Christiaan Janssen committed
91

92
93
94
    typedef std::function<void(const QmlEvent &, const QmlEventType &)> EventLoader;
    typedef std::function<void()> Finalizer;

95
    explicit QmlProfilerModelManager(QObject *parent = 0);
Christiaan Janssen's avatar
Christiaan Janssen committed
96
97
    ~QmlProfilerModelManager();

98
    State state() const;
Christiaan Janssen's avatar
Christiaan Janssen committed
99
    QmlProfilerTraceTime *traceTime() const;
100
    QmlProfilerNotesModel *notesModel() const;
101
    QmlProfilerTextMarkModel *textMarkModel() const;
Christiaan Janssen's avatar
Christiaan Janssen committed
102
103

    bool isEmpty() const;
104
    uint numLoadedEvents() const;
105
    uint numLoadedEventTypes() const;
Christiaan Janssen's avatar
Christiaan Janssen committed
106
107

    int registerModelProxy();
108
109
    void announceFeatures(quint64 features, EventLoader eventLoader, Finalizer finalizer);

110
111
112
    int numFinishedFinalizers() const;
    int numRegisteredFinalizers() const;

113
114
115
116
117
    void addEvents(const QVector<QmlEvent> &events);
    void addEvent(const QmlEvent &event);

    void addEventTypes(const QVector<QmlEventType> &types);
    void addEventType(const QmlEventType &type);
118
119
    const QVector<QmlEventType> &eventTypes() const;

120
    bool replayEvents(qint64 rangeStart, qint64 rangeEnd, EventLoader loader) const;
121

122
123
124
125
126
    quint64 availableFeatures() const;
    quint64 visibleFeatures() const;
    void setVisibleFeatures(quint64 features);
    quint64 recordedFeatures() const;
    void setRecordedFeatures(quint64 features);
127
128
    bool aggregateTraces() const;
    void setAggregateTraces(bool aggregateTraces);
129

130
131
132
    void acquiringDone();
    void processingDone();

133
134
135
    void populateFileFinder(const ProjectExplorer::RunConfiguration *runConfiguration = nullptr);
    QString findLocalFile(const QString &remoteFile);

136
    static const char *featureName(ProfileFeature feature);
Christiaan Janssen's avatar
Christiaan Janssen committed
137
138
139
140

signals:
    void error(const QString &error);
    void stateChanged();
141
    void loadFinished();
142
    void saveFinished();
Christiaan Janssen's avatar
Christiaan Janssen committed
143

144
    void availableFeaturesChanged(quint64 features);
145
146
    void visibleFeaturesChanged(quint64 features);
    void recordedFeaturesChanged(quint64 features);
Christiaan Janssen's avatar
Christiaan Janssen committed
147
148
149

public slots:
    void clear();
150
151
    void restrictToRange(qint64 startTime, qint64 endTime);
    bool isRestrictedToRange() const;
Christiaan Janssen's avatar
Christiaan Janssen committed
152

153
    void startAcquiring();
Christiaan Janssen's avatar
Christiaan Janssen committed
154
155
156
157
158

    void save(const QString &filename);
    void load(const QString &filename);

private:
159
    void setState(State state);
160
    void detailsChanged(int typeId, const QString &newString);
Christiaan Janssen's avatar
Christiaan Janssen committed
161
162
163
164
165
166

private:
    class QmlProfilerModelManagerPrivate;
    QmlProfilerModelManagerPrivate *d;
};

167
} // namespace QmlProfiler