QmlProfilerTool: add tool to QDeclarative
[profile/ivi/qtdeclarative.git] / tools / qmlprofiler / profiledata.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef PROFILEDATA_H
43 #define PROFILEDATA_H
44
45 #include <QtDeclarative/private/qdeclarativeprofilerservice_p.h>
46
47 #include <QtCore/QObject>
48 #include <QtCore/QHash>
49
50 struct DeclarativeEvent;
51 struct V8Event;
52
53 typedef QHash<QString, DeclarativeEvent *> DeclarativeEventHash;
54 typedef QList<DeclarativeEvent *> DeclarativeEvents;
55 typedef QList<V8Event *> V8Events;
56
57 struct EventLocation
58 {
59     EventLocation() : line(-1),column(-1) {}
60     EventLocation(const QString &file, int lineNumber, int columnNumber)
61         : filename(file), line(lineNumber), column(columnNumber) {}
62     QString filename;
63     int line;
64     int column;
65 };
66
67 struct DeclarativeEventSub {
68     DeclarativeEventSub(DeclarativeEvent *from)
69         : reference(from), duration(0), calls(0), inLoopPath(false)
70     {}
71     DeclarativeEventSub(DeclarativeEventSub *from)
72         : reference(from->reference), duration(from->duration),
73           calls(from->calls), inLoopPath(from->inLoopPath)
74     {}
75     DeclarativeEvent *reference;
76     qint64 duration;
77     qint64 calls;
78     bool inLoopPath;
79 };
80
81 struct DeclarativeEvent
82 {
83     DeclarativeEvent();
84     ~DeclarativeEvent();
85
86     QString displayname;
87     QString eventHashStr;
88     QString details;
89     EventLocation location;
90     QDeclarativeProfilerService::RangeType eventType;
91     QHash <QString, DeclarativeEventSub *> parentHash;
92     QHash <QString, DeclarativeEventSub *> childrenHash;
93     qint64 duration;
94     qint64 calls;
95     qint64 minTime;
96     qint64 maxTime;
97     double timePerCall;
98     double percentOfTime;
99     qint64 medianTime;
100     int eventId;
101     bool isBindingLoop;
102
103     DeclarativeEvent &operator=(const DeclarativeEvent &ref);
104 };
105
106 struct V8EventSub {
107     V8EventSub(V8Event *from)
108         : reference(from), totalTime(0)
109     {}
110     V8EventSub(V8EventSub *from)
111         : reference(from->reference), totalTime(from->totalTime)
112     {}
113
114     V8Event *reference;
115     qint64 totalTime;
116 };
117
118 struct V8Event
119 {
120     V8Event();
121     ~V8Event();
122
123     QString displayName;
124     QString filename;
125     QString functionName;
126     int line;
127     double totalTime; // given in milliseconds
128     double totalPercent;
129     double selfTime;
130     double selfPercent;
131     QHash <QString, V8EventSub *> parentHash;
132     QHash <QString, V8EventSub *> childrenHash;
133     int eventId;
134
135     V8Event &operator=(const V8Event &ref);
136 };
137
138 class ProfileData : public QObject
139 {
140     Q_OBJECT
141
142 public:
143     explicit ProfileData(QObject *parent = 0);
144     ~ProfileData();
145
146     DeclarativeEvents getDeclarativeEvents() const;
147     DeclarativeEvent *declarativeEvent(int eventId) const;
148     const V8Events& getV8Events() const;
149     V8Event *v8Event(int eventId) const;
150
151     int findFirstIndex(qint64 startTime) const;
152     int findFirstIndexNoParents(qint64 startTime) const;
153     int findLastIndex(qint64 endTime) const;
154     Q_INVOKABLE qint64 firstTimeMark() const;
155     Q_INVOKABLE qint64 lastTimeMark() const;
156
157     Q_INVOKABLE int count() const;
158
159     // data access
160     Q_INVOKABLE qint64 getStartTime(int index) const;
161     Q_INVOKABLE qint64 getEndTime(int index) const;
162     Q_INVOKABLE qint64 getDuration(int index) const;
163     Q_INVOKABLE int getType(int index) const;
164     Q_INVOKABLE int getNestingLevel(int index) const;
165     Q_INVOKABLE int getNestingDepth(int index) const;
166     Q_INVOKABLE QString getFilename(int index) const;
167     Q_INVOKABLE int getLine(int index) const;
168     Q_INVOKABLE int getColumn(int index) const;
169     Q_INVOKABLE QString getDetails(int index) const;
170     Q_INVOKABLE int getEventId(int index) const;
171     Q_INVOKABLE int getFramerate(int index) const;
172     Q_INVOKABLE int getAnimationCount(int index) const;
173     Q_INVOKABLE int getMaximumAnimationCount() const;
174     Q_INVOKABLE int getMinimumAnimationCount() const;
175
176     // per-type data
177     Q_INVOKABLE int uniqueEventsOfType(int type) const;
178     Q_INVOKABLE int maxNestingForType(int type) const;
179     Q_INVOKABLE QString eventTextForType(int type, int index) const;
180     Q_INVOKABLE QString eventDisplayNameForType(int type, int index) const;
181     Q_INVOKABLE int eventIdForType(int type, int index) const;
182     Q_INVOKABLE int eventPosInType(int index) const;
183
184     Q_INVOKABLE qint64 traceStartTime() const;
185     Q_INVOKABLE qint64 traceEndTime() const;
186     Q_INVOKABLE qint64 traceDuration() const;
187     Q_INVOKABLE qint64 declarativeMeasuredTime() const;
188     Q_INVOKABLE qint64 v8MeasuredTime() const;
189
190     void showErrorDialog(const QString &st ) const;
191     void compileStatistics(qint64 startTime, qint64 endTime);
192
193 signals:
194     void dataReady();
195     void countChanged();
196     void error(const QString &error);
197     void dataClear();
198     void processingData();
199     void postProcessing();
200
201     void requestDetailsForLocation(int eventType, const EventLocation &location);
202     void detailsChanged(int eventId, const QString &newString);
203     void reloadDetailLabels();
204     void reloadDocumentsForDetails();
205
206 public slots:
207     void clear();
208     void addDeclarativeEvent(QDeclarativeProfilerService::RangeType type,
209                              qint64 startTime, qint64 length,
210                              const QStringList &data,
211                              const EventLocation &location);
212     void complete();
213
214     void addV8Event(int depth,const QString &function,const QString &filename,
215                     int lineNumber, double totalTime, double selfTime);
216     void addFrameEvent(qint64 time, int framerate, int animationcount);
217     bool save(const QString &filename);
218     void load(const QString &filename);
219     void setFilename(const QString &filename);
220     void load();
221
222     void setTraceEndTime( qint64 time );
223     void setTraceStartTime( qint64 time );
224
225     void rewriteDetailsString(QDeclarativeProfilerService::RangeType eventType,
226                               const EventLocation &location,
227                               const QString &newString);
228     void finishedRewritingDetails();
229
230 private:
231     void postProcess();
232     void sortEndTimes();
233     void findAnimationLimits();
234     void sortStartTimes();
235     void computeLevels();
236     void computeNestingLevels();
237     void computeNestingDepth();
238     void prepareForDisplay();
239     void linkEndsToStarts();
240     void reloadDetails();
241     void findBindingLoops(qint64 startTime, qint64 endTime);
242
243 private:
244     class ProfileDataPrivate *d;
245 };
246
247 #endif // PROFILEDATA_H