1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
45 #include <QtQml/private/qqmlprofilerservice_p.h>
47 #include <QtCore/QObject>
48 #include <QtCore/QHash>
50 struct DeclarativeEvent;
53 typedef QHash<QString, DeclarativeEvent *> DeclarativeEventHash;
54 typedef QList<DeclarativeEvent *> DeclarativeEvents;
55 typedef QList<V8Event *> V8Events;
59 EventLocation() : line(-1),column(-1) {}
60 EventLocation(const QString &file, int lineNumber, int columnNumber)
61 : filename(file), line(lineNumber), column(columnNumber) {}
67 struct DeclarativeEventSub {
68 DeclarativeEventSub(DeclarativeEvent *from)
69 : reference(from), duration(0), calls(0), inLoopPath(false)
71 DeclarativeEventSub(DeclarativeEventSub *from)
72 : reference(from->reference), duration(from->duration),
73 calls(from->calls), inLoopPath(from->inLoopPath)
75 DeclarativeEvent *reference;
81 struct DeclarativeEvent
89 EventLocation location;
90 QQmlProfilerService::RangeType eventType;
91 QHash <QString, DeclarativeEventSub *> parentHash;
92 QHash <QString, DeclarativeEventSub *> childrenHash;
103 DeclarativeEvent &operator=(const DeclarativeEvent &ref);
107 V8EventSub(V8Event *from)
108 : reference(from), totalTime(0)
110 V8EventSub(V8EventSub *from)
111 : reference(from->reference), totalTime(from->totalTime)
125 QString functionName;
127 double totalTime; // given in milliseconds
131 QHash <QString, V8EventSub *> parentHash;
132 QHash <QString, V8EventSub *> childrenHash;
135 V8Event &operator=(const V8Event &ref);
138 class ProfileData : public QObject
143 explicit ProfileData(QObject *parent = 0);
146 DeclarativeEvents getDeclarativeEvents() const;
147 DeclarativeEvent *declarativeEvent(int eventId) const;
148 const V8Events& getV8Events() const;
149 V8Event *v8Event(int eventId) const;
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;
157 Q_INVOKABLE int count() const;
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;
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;
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;
190 void showErrorDialog(const QString &st ) const;
191 void compileStatistics(qint64 startTime, qint64 endTime);
196 void error(const QString &error);
198 void processingData();
199 void postProcessing();
201 void requestDetailsForLocation(int eventType, const EventLocation &location);
202 void detailsChanged(int eventId, const QString &newString);
203 void reloadDetailLabels();
204 void reloadDocumentsForDetails();
208 void addDeclarativeEvent(QQmlProfilerService::RangeType type,
209 qint64 startTime, qint64 length,
210 const QStringList &data,
211 const EventLocation &location);
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);
222 void setTraceEndTime( qint64 time );
223 void setTraceStartTime( qint64 time );
225 void rewriteDetailsString(QQmlProfilerService::RangeType eventType,
226 const EventLocation &location,
227 const QString &newString);
228 void finishedRewritingDetails();
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);
244 class ProfileDataPrivate *d;
247 #endif // PROFILEDATA_H