diff options
Diffstat (limited to 'src/qml/debugger')
-rw-r--r-- | src/qml/debugger/qqmldebug.cpp | 18 | ||||
-rw-r--r-- | src/qml/debugger/qqmlmemoryprofiler.cpp | 37 | ||||
-rw-r--r-- | src/qml/debugger/qqmlmemoryprofiler_p.h | 48 |
3 files changed, 73 insertions, 30 deletions
diff --git a/src/qml/debugger/qqmldebug.cpp b/src/qml/debugger/qqmldebug.cpp index 386fb60b3a..b2c4b139ee 100644 --- a/src/qml/debugger/qqmldebug.cpp +++ b/src/qml/debugger/qqmldebug.cpp @@ -169,4 +169,22 @@ bool QQmlDebuggingEnabler::startDebugConnector(const QString &pluginName, return connector ? connector->open(configuration) : false; } +enum { HookCount = 3 }; + +// Only add to the end, and bump version if you do. +quintptr Q_QML_EXPORT qtDeclarativeHookData[] = { + // Version of this Array. Bump if you add to end. + 1, + + // Number of entries in this array. + HookCount, + + // TypeInformationVersion, an integral value, bumped whenever private + // object sizes or member offsets that are used in Qt Creator's + // data structure "pretty printing" change. + 2 +}; + +Q_STATIC_ASSERT(HookCount == sizeof(qtDeclarativeHookData) / sizeof(qtDeclarativeHookData[0])); + QT_END_NAMESPACE diff --git a/src/qml/debugger/qqmlmemoryprofiler.cpp b/src/qml/debugger/qqmlmemoryprofiler.cpp index 60f6d96eaf..53d4e7ab21 100644 --- a/src/qml/debugger/qqmlmemoryprofiler.cpp +++ b/src/qml/debugger/qqmlmemoryprofiler.cpp @@ -38,18 +38,11 @@ ****************************************************************************/ #include "qqmlmemoryprofiler_p.h" -#include <QUrl> QT_BEGIN_NAMESPACE -enum LibraryState -{ - Unloaded, - Failed, - Loaded -}; -static LibraryState state = Unloaded; +QQmlMemoryScope::LibraryState QQmlMemoryScope::state = QQmlMemoryScope::Unloaded; typedef void (qmlmemprofile_stats)(int *allocCount, int *bytesAllocated); typedef void (qmlmemprofile_clear)(); @@ -73,7 +66,7 @@ static qmlmemprofile_is_enabled *memprofile_is_enabled; extern QFunctionPointer qt_linux_find_symbol_sys(const char *symbol); #endif -static bool openLibrary() +bool QQmlMemoryScope::doOpenLibrary() { #if defined(Q_OS_LINUX) && !defined(QT_NO_LIBRARY) if (state == Unloaded) { @@ -97,28 +90,22 @@ static bool openLibrary() return state == Loaded; } -QQmlMemoryScope::QQmlMemoryScope(const QUrl &url) - : QQmlMemoryScope(url.path().toUtf8().constData()) -{ -} - -QQmlMemoryScope::QQmlMemoryScope(const char *string) : pushed(false) +void QQmlMemoryScope::init(const char *string) { - if (openLibrary() && memprofile_is_enabled()) { + if (memprofile_is_enabled()) { memprofile_push_location(string, 0); pushed = true; } } -QQmlMemoryScope::~QQmlMemoryScope() +void QQmlMemoryScope::done() { - if (pushed) - memprofile_pop_location(); + memprofile_pop_location(); } bool QQmlMemoryProfiler::isEnabled() { - if (openLibrary()) + if (QQmlMemoryScope::openLibrary()) return memprofile_is_enabled(); return false; @@ -126,31 +113,31 @@ bool QQmlMemoryProfiler::isEnabled() void QQmlMemoryProfiler::enable() { - if (openLibrary()) + if (QQmlMemoryScope::openLibrary()) memprofile_enable(); } void QQmlMemoryProfiler::disable() { - if (openLibrary()) + if (QQmlMemoryScope::openLibrary()) memprofile_disable(); } void QQmlMemoryProfiler::clear() { - if (openLibrary()) + if (QQmlMemoryScope::openLibrary()) memprofile_clear(); } void QQmlMemoryProfiler::stats(int *allocCount, int *bytesAllocated) { - if (openLibrary()) + if (QQmlMemoryScope::openLibrary()) memprofile_stats(allocCount, bytesAllocated); } void QQmlMemoryProfiler::save(const char *filename) { - if (openLibrary()) + if (QQmlMemoryScope::openLibrary()) memprofile_save(filename); } diff --git a/src/qml/debugger/qqmlmemoryprofiler_p.h b/src/qml/debugger/qqmlmemoryprofiler_p.h index 59f08704ca..fb71c999c3 100644 --- a/src/qml/debugger/qqmlmemoryprofiler_p.h +++ b/src/qml/debugger/qqmlmemoryprofiler_p.h @@ -52,6 +52,7 @@ // #include <private/qtqmlglobal_p.h> +#include <QUrl> QT_BEGIN_NAMESPACE @@ -62,16 +63,53 @@ QT_BEGIN_NAMESPACE #else -class QUrl; - class Q_QML_PRIVATE_EXPORT QQmlMemoryScope { public: - explicit QQmlMemoryScope(const QUrl &url); - explicit QQmlMemoryScope(const char *string); - ~QQmlMemoryScope(); + explicit QQmlMemoryScope(const QUrl &url) + : pushed(false) + { + if (Q_UNLIKELY(openLibrary())) + init(url.path().toUtf8().constData()); + } + + explicit QQmlMemoryScope(const char *string) + : pushed(false) + { + if (Q_UNLIKELY(openLibrary())) + init(string); + } + + ~QQmlMemoryScope() + { + if (Q_UNLIKELY(pushed)) + done(); + } + + enum LibraryState + { + Unloaded, + Failed, + Loaded + }; + + static bool openLibrary() + { + if (Q_LIKELY(state == Loaded)) + return true; + if (state == Failed) + return false; + + return doOpenLibrary(); + } private: + Q_NEVER_INLINE void init(const char *string); + Q_NEVER_INLINE void done(); + Q_NEVER_INLINE static bool doOpenLibrary(); + + static LibraryState state; + bool pushed; }; |