1/****************************************************************************
2**
3** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Rafael Roquetto <rafael.roquetto@kdab.com>
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QTRACE_P_H
41#define QTRACE_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54/*
55 * The Qt tracepoints API consists of only three macros:
56 *
57 * - Q_TRACE(tracepoint, args...)
58 * Fires 'tracepoint' if it is enabled.
59 *
60 * - Q_UNCONDITIONAL_TRACE(tracepoint, args...)
61 * Fires 'tracepoint' unconditionally: no check is performed to query
62 * whether 'tracepoint' is enabled.
63 *
64 * - Q_TRACE_ENABLED(tracepoint)
65 * Returns 'true' if 'tracepoint' is enabled; false otherwise.
66 *
67 * When using LTTNG, Q_TRACE, Q_UNCONDITIONAL_TRACE and Q_TRACE_ENABLED map
68 * ultimately to tracepoint(), do_tracepoint() and tracepoint_enabled(),
69 * respectively, described on the lttng-ust manpage (man 3 lttng-ust).
70 *
71 * On ETW, Q_TRACE() and Q_UNCONDITIONAL_TRACE() are equivalent, ultimately
72 * amounting to a call to TraceLoggingWrite(), whereas Q_TRACE_ENABLED()
73 * wraps around TraceLoggingProviderEnabled().
74 *
75 * A tracepoint provider is defined in a separate file, that follows the
76 * following format:
77 *
78 * tracepoint_name(arg_type arg_name, ...)
79 *
80 * For instance:
81 *
82 * qcoreapplication_ctor(int argc, const char * const argv)
83 * qcoreapplication_foo(int argc, const char[10] argv)
84 * qcoreapplication_baz(const char[len] some_string, unsigned int len)
85 * qcoreapplication_qstring(const QString &foo)
86 * qcoreapplication_qrect(const QRect &rect)
87 *
88 * The provider file is then parsed by src/tools/tracegen, which can be
89 * switched to output either ETW or LTTNG tracepoint definitions. The provider
90 * name is deduced to be basename(provider_file).
91 *
92 * To use the above (inside qtcore), you need to include
93 * <providername_tracepoints_p.h>. After that, the following call becomes
94 * possible:
95 *
96 * Q_TRACE(qcoreapplication_qrect, myRect);
97 *
98 * Currently, all C++ primitive non-pointer types are supported for
99 * arguments. Additionally, char * is supported, and is assumed to
100 * be a NULL-terminated string. Finally, the following subset of Qt types also
101 * currently supported:
102 *
103 * - QString
104 * - QByteArray
105 * - QUrl
106 * - QRect
107 *
108 * Dynamic arrays are supported using the syntax illustrated by
109 * qcoreapplication_baz above.
110 */
111
112#include <QtCore/qglobal.h>
113
114QT_BEGIN_NAMESPACE
115
116#if defined(Q_TRACEPOINT) && !defined(QT_BOOTSTRAPPED)
117# define Q_HAS_TRACEPOINTS 1
118# define Q_TRACE(x, ...) QtPrivate::trace_ ## x(__VA_ARGS__)
119# define Q_UNCONDITIONAL_TRACE(x, ...) QtPrivate::do_trace_ ## x(__VA_ARGS__)
120# define Q_TRACE_ENABLED(x) QtPrivate::trace_ ## x ## _enabled()
121#else
122# define Q_HAS_TRACEPOINTS 0
123# define Q_TRACE(x, ...)
124# define Q_UNCONDITIONAL_TRACE(x, ...)
125# define Q_TRACE_ENABLED(x) false
126#endif // defined(Q_TRACEPOINT) && !defined(QT_BOOTSTRAPPED)
127
128QT_END_NAMESPACE
129
130#endif // QTRACE_P_H
131