diff options
author | Frantisek Vacek <fvacek@rim.com> | 2012-10-11 11:15:47 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-12 00:19:36 (GMT) |
commit | 379ecbe8a7353d8fc6e9f1608c9c62f0ed27c891 (patch) | |
tree | 0e9e478226270e9ebb494d25cbbe34b6d5614d76 /src/declarative | |
parent | ee447020dbecef821b73d7d2981d7c8859c9a28b (diff) | |
download | Qt-379ecbe8a7353d8fc6e9f1608c9c62f0ed27c891.zip Qt-379ecbe8a7353d8fc6e9f1608c9c62f0ed27c891.tar.gz Qt-379ecbe8a7353d8fc6e9f1608c9c62f0ed27c891.tar.bz2 |
QDeclarativeTrace patch for a custom trace instance
Needed for the BB10 Cascades profiling. There are more reasons for
introducing this patch:
1) Cascades do not use QtGui library for QML rendering. It has its own
paint engine with client-server architecture. Profiler traces are sent
asynchronously from non Qt renderer thread to the Qt client.
The QPerformanceTimer has to be patched too, cause we need to know time
difference between tracing zero time and some time in past,
see: qint64 elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const
2) Since we need more sophisticated trace engine in cascades, this patch
allows explicitly assign custom class derived from QDeclaraqtiveDebugtrace
to the trace framework.
If no custom instance is assigned, the default QDeclarativeDebugTrace
instance is created implicitly on first trace request.
Using custom trace instance which is not part of Qt
(it is part of libbbcascades) allows us to implement all Cascades trace
special needs in libbbcascades and not to carry Qt with the platform
specific code.
3) The NO_CUSTOM_DECLARATIVE_DEBUG_TRACE_INSTANCE macro is introduced to
allow custom trace engine only on the bleckberry platform,
see declarative.pro.
If this macro is defined Qt compiles from its original code.
4) Possibility of custom QDeclaraqtiveDebugTrace instance might be usable
for other projects which needs to extends somehow default Qt trace
functionality.
5) Patch is not intended to be applied to Qt Quick 2, since declarative
debugging infrastructure is changed there.
(cherry picked from commit f13b52f25c1e0bc26dcf3ea304b3495f7d5cd370)
Change-Id: I199211c1de66e930e252e8c033503d7f4940565f
Reviewed-by: Christiaan Janssen <christiaan.janssen@digia.com>
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/debugger/qdeclarativedebugtrace.cpp | 60 | ||||
-rw-r--r-- | src/declarative/debugger/qdeclarativedebugtrace_p.h | 19 | ||||
-rw-r--r-- | src/declarative/declarative.pro | 3 | ||||
-rw-r--r-- | src/declarative/qml/qperformancetimer.cpp | 38 | ||||
-rw-r--r-- | src/declarative/qml/qperformancetimer_p.h | 4 |
5 files changed, 120 insertions, 4 deletions
diff --git a/src/declarative/debugger/qdeclarativedebugtrace.cpp b/src/declarative/debugger/qdeclarativedebugtrace.cpp index 1c2d440..d4ede07 100644 --- a/src/declarative/debugger/qdeclarativedebugtrace.cpp +++ b/src/declarative/debugger/qdeclarativedebugtrace.cpp @@ -44,8 +44,68 @@ #include <QtCore/qdatastream.h> #include <QtCore/qurl.h> #include <QtCore/qtimer.h> +#include <QDebug> + +#ifdef CUSTOM_DECLARATIVE_DEBUG_TRACE_INSTANCE + +namespace { + + class GlobalInstanceDeleter + { + private: + QBasicAtomicPointer<QDeclarativeDebugTrace> &m_pointer; + public: + GlobalInstanceDeleter(QBasicAtomicPointer<QDeclarativeDebugTrace> &p) + : m_pointer(p) + {} + ~GlobalInstanceDeleter() + { + delete m_pointer; + m_pointer = 0; + } + }; + + QBasicAtomicPointer<QDeclarativeDebugTrace> s_globalInstance = Q_BASIC_ATOMIC_INITIALIZER(0); +} + + +static QDeclarativeDebugTrace *traceInstance() +{ + return QDeclarativeDebugTrace::globalInstance(); +} + +QDeclarativeDebugTrace *QDeclarativeDebugTrace::globalInstance() +{ + if (!s_globalInstance) { + // create default QDeclarativeDebugTrace instance if it is not explicitly set by setGlobalInstance(QDeclarativeDebugTrace *instance) + // thread safe implementation + QDeclarativeDebugTrace *x = new QDeclarativeDebugTrace(); + if (!s_globalInstance.testAndSetOrdered(0, x)) + delete x; + else + static GlobalInstanceDeleter cleanup(s_globalInstance); + } + return s_globalInstance; +} + +/*! + * Set custom QDeclarativeDebugTrace instance \a custom_instance. + * Function fails if QDeclarativeDebugTrace::globalInstance() was called before. + * QDeclarativeDebugTrace framework takes ownership of the custom instance. + */ +void QDeclarativeDebugTrace::setGlobalInstance(QDeclarativeDebugTrace *custom_instance) +{ + if (!s_globalInstance.testAndSetOrdered(0, custom_instance)) { + qWarning() << "QDeclarativeDebugTrace::setGlobalInstance() - instance already set."; + delete custom_instance; + } else { + static GlobalInstanceDeleter cleanup(s_globalInstance); + } +} +#else // CUSTOM_DECLARATIVE_DEBUG_TRACE_INSTANCE Q_GLOBAL_STATIC(QDeclarativeDebugTrace, traceInstance); +#endif // convert to a QByteArray that can be sent to the debug client // use of QDataStream can skew results if m_deferredSend == false diff --git a/src/declarative/debugger/qdeclarativedebugtrace_p.h b/src/declarative/debugger/qdeclarativedebugtrace_p.h index 5a077ac..ef5e618 100644 --- a/src/declarative/debugger/qdeclarativedebugtrace_p.h +++ b/src/declarative/debugger/qdeclarativedebugtrace_p.h @@ -44,6 +44,7 @@ #include <private/qdeclarativedebugservice_p.h> #include <private/qperformancetimer_p.h> +#include <QtCore/qglobal.h> QT_BEGIN_HEADER @@ -63,7 +64,7 @@ struct QDeclarativeDebugData }; class QUrl; -class Q_AUTOTEST_EXPORT QDeclarativeDebugTrace : public QDeclarativeDebugService +class Q_DECLARATIVE_EXPORT QDeclarativeDebugTrace : public QDeclarativeDebugService { public: enum Message { @@ -105,6 +106,21 @@ public: static void endRange(RangeType); QDeclarativeDebugTrace(); +#ifdef CUSTOM_DECLARATIVE_DEBUG_TRACE_INSTANCE +public: + static QDeclarativeDebugTrace* globalInstance(); + static void setGlobalInstance(QDeclarativeDebugTrace *custom_instance); +protected: + virtual void messageReceived(const QByteArray &); +protected: + virtual void addEventImpl(EventType); + virtual void startRangeImpl(RangeType); + virtual void rangeDataImpl(RangeType, const QString &); + virtual void rangeDataImpl(RangeType, const QUrl &); + virtual void rangeLocationImpl(RangeType, const QString &, int); + virtual void rangeLocationImpl(RangeType, const QUrl &, int); + virtual void endRangeImpl(RangeType); +#else protected: virtual void messageReceived(const QByteArray &); private: @@ -115,6 +131,7 @@ private: void rangeLocationImpl(RangeType, const QString &, int); void rangeLocationImpl(RangeType, const QUrl &, int); void endRangeImpl(RangeType); +#endif void processMessage(const QDeclarativeDebugData &); void sendMessages(); QPerformanceTimer m_timer; diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index 055e4b9..5bf4e01 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -41,3 +41,6 @@ linux-g++-maemo:DEFINES += QDECLARATIVEVIEW_NOBACKGROUND DEFINES += QT_NO_OPENTYPE INCLUDEPATH += ../3rdparty/harfbuzz/src +blackberry: { + DEFINES += CUSTOM_DECLARATIVE_DEBUG_TRACE_INSTANCE +} diff --git a/src/declarative/qml/qperformancetimer.cpp b/src/declarative/qml/qperformancetimer.cpp index fd70472..bee61fa 100644 --- a/src/declarative/qml/qperformancetimer.cpp +++ b/src/declarative/qml/qperformancetimer.cpp @@ -81,10 +81,18 @@ void QPerformanceTimer::start() qint64 QPerformanceTimer::elapsed() const { - uint64_t cpu_time = mach_absolute_time(); + qint64 cpu_time = mach_absolute_time(); return absoluteToNSecs(cpu_time - t1); } +// return number of nsecs elapsed from timer start time till absoluteMonotonicTimeNs +// elapsedToAbsoluteTime(0) returns negative value of absolute time (ns) when the timer was started +qint64 QPerformanceTimer::elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const +{ + qint64 absolute_t1_ns = absoluteToNSecs(t1); + return absoluteMonotonicTimeNs - absolute_t1_ns; +} + ////////////////////////////// Symbian ////////////////////////////// #elif defined(Q_OS_SYMBIAN) @@ -108,6 +116,12 @@ qint64 QPerformanceTimer::elapsed() const } +qint64 QPerformanceTimer::elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const +{ + qint64 absolute_t1_ns = getTimeFromTick(t1); + return absoluteMonotonicTimeNs - absolute_t1_ns; +} + ////////////////////////////// Unix ////////////////////////////// #elif defined(Q_OS_UNIX) @@ -182,6 +196,16 @@ qint64 QPerformanceTimer::elapsed() const return sec * Q_INT64_C(1000000000) + frac; } +qint64 QPerformanceTimer::elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const +{ + qint64 sec = absoluteMonotonicTimeNs / Q_INT64_C(1000000000); + qint64 frac = absoluteMonotonicTimeNs % Q_INT64_C(1000000000); + sec = sec - t1; + frac = frac - t2; + + return sec * Q_INT64_C(1000000000) + frac; +} + ////////////////////////////// Windows ////////////////////////////// #elif defined(Q_OS_WIN) @@ -207,6 +231,12 @@ qint64 QPerformanceTimer::elapsed() const return getTimeFromTick(li.QuadPart - t1); } +qint64 QPerformanceTimer::elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const +{ + qint64 absolute_t1_ns = getTimeFromTick(t1); + return absoluteMonotonicTimeNs - absolute_t1_ns; +} + ////////////////////////////// Default ////////////////////////////// #else @@ -220,6 +250,12 @@ qint64 QPerformanceTimer::elapsed() const return 0; } +qint64 QPerformanceTimer::elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const +{ + Q_UNUSED(absoluteMonotonicTimeNs); + return 0; +} + #endif QT_END_NAMESPACE diff --git a/src/declarative/qml/qperformancetimer_p.h b/src/declarative/qml/qperformancetimer_p.h index cb39382..badba80 100644 --- a/src/declarative/qml/qperformancetimer_p.h +++ b/src/declarative/qml/qperformancetimer_p.h @@ -61,12 +61,12 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class Q_AUTOTEST_EXPORT QPerformanceTimer +class Q_DECLARATIVE_EXPORT QPerformanceTimer { public: void start(); qint64 elapsed() const; - + qint64 elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const; private: qint64 t1; qint64 t2; |