1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVETRACE_P_H
43 #define QDECLARATIVETRACE_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include <QtCore/qglobal.h>
57 #include <private/qdeclarativepool_p.h>
59 // #define QML_ENABLE_TRACE
61 #if defined(QML_ENABLE_TRACE) && defined(Q_OS_MAC)
62 #include <mach/mach_time.h>
68 class QDeclarativeTrace
71 inline QDeclarativeTrace(const char *desc);
72 inline ~QDeclarativeTrace();
74 inline void addDetail(const char *);
75 inline void addDetail(const char *, int);
76 inline void addDetail(const char *, const QString &);
77 inline void addDetail(const char *, const QUrl &);
79 inline void event(const char *desc);
81 #ifdef QML_ENABLE_TRACE
84 typedef uint64_t TimeType;
86 typedef timespec TimeType;
89 struct Entry : public QDeclarativePool::POD {
90 enum Type { Null, RangeStart, RangeEnd, Detail, IntDetail, StringDetail, UrlDetail, Event };
96 struct RangeEnd : public Entry {
100 struct RangeStart : public Entry {
102 const char *description;
104 QDeclarativeTrace::RangeEnd *end;
106 struct Detail : public Entry {
108 inline Detail(Type t);
109 const char *description;
111 struct IntDetail : public Detail {
115 struct StringDetail : public Detail {
116 inline StringDetail();
119 struct UrlDetail : public Detail {
123 struct Event : public Entry {
125 const char *description;
127 QDeclarativeTrace::RangeStart *start;
130 struct Pool : public QDeclarativePool {
142 static TimeType gettime() {
144 return mach_absolute_time();
147 clock_gettime(CLOCK_MONOTONIC, &ts);
154 #ifdef QML_ENABLE_TRACE
155 QDeclarativeTrace::Entry::Entry()
156 : type(Null), next(0)
160 QDeclarativeTrace::Entry::Entry(Type type)
161 : type(type), next(0)
163 QDeclarativeTrace::last->next = this;
164 QDeclarativeTrace::last = this;
167 QDeclarativeTrace::RangeEnd::RangeEnd()
168 : QDeclarativeTrace::Entry(QDeclarativeTrace::Entry::RangeEnd),
173 QDeclarativeTrace::RangeStart::RangeStart()
174 : QDeclarativeTrace::Entry(QDeclarativeTrace::Entry::RangeStart),
175 description(0), time(gettime())
179 QDeclarativeTrace::Detail::Detail()
180 : QDeclarativeTrace::Entry(QDeclarativeTrace::Entry::Detail),
185 QDeclarativeTrace::Detail::Detail(Type type)
186 : QDeclarativeTrace::Entry(type), description(0)
190 QDeclarativeTrace::IntDetail::IntDetail()
191 : QDeclarativeTrace::Detail(QDeclarativeTrace::Entry::IntDetail),
196 QDeclarativeTrace::StringDetail::StringDetail()
197 : QDeclarativeTrace::Detail(QDeclarativeTrace::Entry::StringDetail),
202 QDeclarativeTrace::UrlDetail::UrlDetail()
203 : QDeclarativeTrace::Detail(QDeclarativeTrace::Entry::UrlDetail),
208 QDeclarativeTrace::Event::Event()
209 : QDeclarativeTrace::Entry(QDeclarativeTrace::Entry::Event),
210 description(0), time(gettime()), start(0)
215 QDeclarativeTrace::QDeclarativeTrace(const char *desc)
217 #ifdef QML_ENABLE_TRACE
218 RangeStart *e = logPool.New<RangeStart>();
219 e->description = desc;
227 QDeclarativeTrace::~QDeclarativeTrace()
229 #ifdef QML_ENABLE_TRACE
230 RangeEnd *e = logPool.New<RangeEnd>();
235 void QDeclarativeTrace::addDetail(const char *desc)
237 #ifdef QML_ENABLE_TRACE
238 Detail *e = logPool.New<Detail>();
239 e->description = desc;
245 void QDeclarativeTrace::addDetail(const char *desc, int v)
247 #ifdef QML_ENABLE_TRACE
248 IntDetail *e = logPool.New<IntDetail>();
249 e->description = desc;
257 void QDeclarativeTrace::addDetail(const char *desc, const QString &v)
259 #ifdef QML_ENABLE_TRACE
260 StringDetail *e = logPool.New<StringDetail>();
261 e->description = desc;
262 e->value = logPool.NewString(v);
269 void QDeclarativeTrace::addDetail(const char *desc, const QUrl &v)
271 #ifdef QML_ENABLE_TRACE
272 UrlDetail *e = logPool.New<UrlDetail>();
273 e->description = desc;
274 e->value = logPool.NewUrl(v);
281 void QDeclarativeTrace::event(const char *desc)
283 #ifdef QML_ENABLE_TRACE
284 Event *e = logPool.New<Event>();
286 e->description = desc;
294 #endif // QDECLARATIVETRACE_P_H