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
****************************************************************************/
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/qqmlpool_p.h>
59
// #define QML_ENABLE_TRACE
61
#if defined(QML_ENABLE_TRACE) && defined(Q_OS_MAC)
62
#include <mach/mach_time.h>
71
inline QQmlTrace(const char *desc);
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 QQmlPool::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
QQmlTrace::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
QQmlTrace::RangeStart *start;
130
struct Pool : public QQmlPool {
142
static TimeType gettime() {
144
return mach_absolute_time();
147
clock_gettime(CLOCK_MONOTONIC, &ts);
154
#ifdef QML_ENABLE_TRACE
155
QQmlTrace::Entry::Entry()
156
: type(Null), next(0)
160
QQmlTrace::Entry::Entry(Type type)
161
: type(type), next(0)
163
QQmlTrace::last->next = this;
164
QQmlTrace::last = this;
167
QQmlTrace::RangeEnd::RangeEnd()
168
: QQmlTrace::Entry(QQmlTrace::Entry::RangeEnd),
173
QQmlTrace::RangeStart::RangeStart()
174
: QQmlTrace::Entry(QQmlTrace::Entry::RangeStart),
175
description(0), time(gettime())
179
QQmlTrace::Detail::Detail()
180
: QQmlTrace::Entry(QQmlTrace::Entry::Detail),
185
QQmlTrace::Detail::Detail(Type type)
186
: QQmlTrace::Entry(type), description(0)
190
QQmlTrace::IntDetail::IntDetail()
191
: QQmlTrace::Detail(QQmlTrace::Entry::IntDetail),
196
QQmlTrace::StringDetail::StringDetail()
197
: QQmlTrace::Detail(QQmlTrace::Entry::StringDetail),
202
QQmlTrace::UrlDetail::UrlDetail()
203
: QQmlTrace::Detail(QQmlTrace::Entry::UrlDetail),
208
QQmlTrace::Event::Event()
209
: QQmlTrace::Entry(QQmlTrace::Entry::Event),
210
description(0), time(gettime()), start(0)
215
QQmlTrace::QQmlTrace(const char *desc)
217
#ifdef QML_ENABLE_TRACE
218
RangeStart *e = logPool.New<RangeStart>();
219
e->description = desc;
227
QQmlTrace::~QQmlTrace()
229
#ifdef QML_ENABLE_TRACE
230
RangeEnd *e = logPool.New<RangeEnd>();
235
void QQmlTrace::addDetail(const char *desc)
237
#ifdef QML_ENABLE_TRACE
238
Detail *e = logPool.New<Detail>();
239
e->description = desc;
245
void QQmlTrace::addDetail(const char *desc, int v)
247
#ifdef QML_ENABLE_TRACE
248
IntDetail *e = logPool.New<IntDetail>();
249
e->description = desc;
257
void QQmlTrace::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 QQmlTrace::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 QQmlTrace::event(const char *desc)
283
#ifdef QML_ENABLE_TRACE
284
Event *e = logPool.New<Event>();
286
e->description = desc;
294
#endif // QQMLTRACE_P_H