summaryrefslogtreecommitdiffstats
path: root/src/declarative/debugger
diff options
context:
space:
mode:
authorFrantisek Vacek <fvacek@rim.com>2012-10-11 13:15:47 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-12 02:19:36 +0200
commit379ecbe8a7353d8fc6e9f1608c9c62f0ed27c891 (patch)
tree0e9e478226270e9ebb494d25cbbe34b6d5614d76 /src/declarative/debugger
parentee447020dbecef821b73d7d2981d7c8859c9a28b (diff)
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/debugger')
-rw-r--r--src/declarative/debugger/qdeclarativedebugtrace.cpp60
-rw-r--r--src/declarative/debugger/qdeclarativedebugtrace_p.h19
2 files changed, 78 insertions, 1 deletions
diff --git a/src/declarative/debugger/qdeclarativedebugtrace.cpp b/src/declarative/debugger/qdeclarativedebugtrace.cpp
index 1c2d440c50..d4ede07b5c 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 5a077ac90b..ef5e618e68 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;