Introduce Q_TRACE_SCOPE to simplify tracing of a function entry/exit
Additionally, we also add a Q_TRACE_EXIT which runs a trace point when the scope is exited, leveraging qScopeGuard behind the scenes. Q_TRACE_SCOPE uses Q_TRACE_EXIT internally - the difference is that the _SCOPE version enforces the naming scheme of _entry / _exit for the tracepoints, whereas Q_TRACE_EXIT can be used generically. Change-Id: I4a2f5ea09f451fcf664d07fd493b679f7527ac06 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
5f62202e6c
commit
127518deda
|
|
@ -52,11 +52,18 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The Qt tracepoints API consists of only three macros:
|
* The Qt tracepoints API consists of only five macros:
|
||||||
*
|
*
|
||||||
* - Q_TRACE(tracepoint, args...)
|
* - Q_TRACE(tracepoint, args...)
|
||||||
* Fires 'tracepoint' if it is enabled.
|
* Fires 'tracepoint' if it is enabled.
|
||||||
*
|
*
|
||||||
|
* - Q_TRACE_EXIT(tracepoint, args...)
|
||||||
|
* Fires 'tracepoint' if it is enabled when the current scope exists.
|
||||||
|
*
|
||||||
|
* - Q_TRACE_SCOPE(tracepoint, args...)
|
||||||
|
* Wrapper around Q_TRACE/_EXIT to trace entry and exit. First it traces
|
||||||
|
* `${tracepoint}_entry` and then `${tracepoint}_exit` on scope exit.
|
||||||
|
*
|
||||||
* - Q_UNCONDITIONAL_TRACE(tracepoint, args...)
|
* - Q_UNCONDITIONAL_TRACE(tracepoint, args...)
|
||||||
* Fires 'tracepoint' unconditionally: no check is performed to query
|
* Fires 'tracepoint' unconditionally: no check is performed to query
|
||||||
* whether 'tracepoint' is enabled.
|
* whether 'tracepoint' is enabled.
|
||||||
|
|
@ -110,15 +117,23 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QtCore/qglobal.h>
|
#include <QtCore/qglobal.h>
|
||||||
|
#include <QtCore/qscopeguard.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
#if defined(Q_TRACEPOINT) && !defined(QT_BOOTSTRAPPED)
|
#if defined(Q_TRACEPOINT) && !defined(QT_BOOTSTRAPPED)
|
||||||
# define Q_TRACE(x, ...) QtPrivate::trace_ ## x(__VA_ARGS__)
|
# define Q_TRACE(x, ...) QtPrivate::trace_ ## x(__VA_ARGS__)
|
||||||
|
# define Q_TRACE_EXIT(x, ...) \
|
||||||
|
const auto qTraceExit_ ## x ## __COUNTER__ = qScopeGuard([&]() { Q_TRACE(x, __VA_ARGS__); });
|
||||||
|
# define Q_TRACE_SCOPE(x, ...) \
|
||||||
|
Q_TRACE(x ## _entry, __VA_ARGS__); \
|
||||||
|
Q_TRACE_EXIT(x ## _exit, __VA_ARGS__);
|
||||||
# define Q_UNCONDITIONAL_TRACE(x, ...) QtPrivate::do_trace_ ## x(__VA_ARGS__)
|
# define Q_UNCONDITIONAL_TRACE(x, ...) QtPrivate::do_trace_ ## x(__VA_ARGS__)
|
||||||
# define Q_TRACE_ENABLED(x) QtPrivate::trace_ ## x ## _enabled()
|
# define Q_TRACE_ENABLED(x) QtPrivate::trace_ ## x ## _enabled()
|
||||||
#else
|
#else
|
||||||
# define Q_TRACE(x, ...)
|
# define Q_TRACE(x, ...)
|
||||||
|
# define Q_TRACE_EXIT(x, ...)
|
||||||
|
# define Q_TRACE_SCOPE(x, ...)
|
||||||
# define Q_UNCONDITIONAL_TRACE(x, ...)
|
# define Q_UNCONDITIONAL_TRACE(x, ...)
|
||||||
# define Q_TRACE_ENABLED(x) false
|
# define Q_TRACE_ENABLED(x) false
|
||||||
#endif // defined(Q_TRACEPOINT) && !defined(QT_BOOTSTRAPPED)
|
#endif // defined(Q_TRACEPOINT) && !defined(QT_BOOTSTRAPPED)
|
||||||
|
|
|
||||||
|
|
@ -778,7 +778,7 @@ QCoreApplication::QCoreApplication(int &argc, char **argv
|
||||||
|
|
||||||
void QCoreApplicationPrivate::init()
|
void QCoreApplicationPrivate::init()
|
||||||
{
|
{
|
||||||
Q_TRACE(QCoreApplicationPrivate_init_entry);
|
Q_TRACE_SCOPE(QCoreApplicationPrivate_init);
|
||||||
|
|
||||||
#if defined(Q_OS_MACOS)
|
#if defined(Q_OS_MACOS)
|
||||||
QMacAutoReleasePool pool;
|
QMacAutoReleasePool pool;
|
||||||
|
|
@ -883,8 +883,6 @@ void QCoreApplicationPrivate::init()
|
||||||
#ifndef QT_NO_QOBJECT
|
#ifndef QT_NO_QOBJECT
|
||||||
is_app_running = true; // No longer starting up.
|
is_app_running = true; // No longer starting up.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Q_TRACE(QCoreApplicationPrivate_init_exit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -1421,7 +1421,7 @@ void QGuiApplicationPrivate::eventDispatcherReady()
|
||||||
|
|
||||||
void QGuiApplicationPrivate::init()
|
void QGuiApplicationPrivate::init()
|
||||||
{
|
{
|
||||||
Q_TRACE(QGuiApplicationPrivate_init_entry);
|
Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
|
||||||
|
|
||||||
#if defined(Q_OS_MACOS)
|
#if defined(Q_OS_MACOS)
|
||||||
QMacAutoReleasePool pool;
|
QMacAutoReleasePool pool;
|
||||||
|
|
@ -1585,8 +1585,6 @@ void QGuiApplicationPrivate::init()
|
||||||
if (!QGuiApplicationPrivate::displayName)
|
if (!QGuiApplicationPrivate::displayName)
|
||||||
QObject::connect(q, &QGuiApplication::applicationNameChanged,
|
QObject::connect(q, &QGuiApplication::applicationNameChanged,
|
||||||
q, &QGuiApplication::applicationDisplayNameChanged);
|
q, &QGuiApplication::applicationDisplayNameChanged);
|
||||||
|
|
||||||
Q_TRACE(QGuiApplicationPrivate_init_exit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void qt_cleanupFontDatabase();
|
extern void qt_cleanupFontDatabase();
|
||||||
|
|
@ -1830,7 +1828,7 @@ bool QGuiApplicationPrivate::processNativeEvent(QWindow *window, const QByteArra
|
||||||
|
|
||||||
void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
|
void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
|
||||||
{
|
{
|
||||||
Q_TRACE(QGuiApplicationPrivate_processWindowSystemEvent_entry, e->type);
|
Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
|
||||||
|
|
||||||
switch(e->type) {
|
switch(e->type) {
|
||||||
case QWindowSystemInterfacePrivate::Mouse:
|
case QWindowSystemInterfacePrivate::Mouse:
|
||||||
|
|
@ -1940,8 +1938,6 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv
|
||||||
qWarning() << "Unknown user input event type:" << e->type;
|
qWarning() << "Unknown user input event type:" << e->type;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_TRACE(QGuiApplicationPrivate_processWindowSystemEvent_exit, e->type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \internal
|
/*! \internal
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue