diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2016-04-25 14:52:12 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-05-02 09:03:46 +0000 |
commit | 434750f1a6cd78b595933210f41e1bf3ab3bd51b (patch) | |
tree | d898623df2075f3376112e856e685472a7cbbf35 /src/qml/debugger/qqmlprofiler.cpp | |
parent | a2e64a20777867726b51a9c9196dc1b8dd68f512 (diff) |
QmlProfiler: Reduce memory usage for file names and URLs
As the various file names are actually not kept as QStrings in the
respective objects being profiled, our saving them as QStrings in each
and every profiling event is not implicitly shared and causes a huge
memory overhead. Avoid that by saving each location only once, indexed
by a disguised pointer to the object it refers to.
Normally, objects could disappear during the profiling session, and new
objects could be allocated in their place, which would mess up our
indexing system. We prevent that by referencing the objects when we
index them, thus preventing them from getting auto-destructed.
Mind that those are not JavaScript objects but rather functions,
bindings, components and the like. So, this will only cause a memory
leak if you're compiling and dropping QML components over and over.
Task-number: QTBUG-52937
Change-Id: Ia4dfb09a71a5c9a2d6ce25c3811bbe2a1036c1c1
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/debugger/qqmlprofiler.cpp')
-rw-r--r-- | src/qml/debugger/qqmlprofiler.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/qml/debugger/qqmlprofiler.cpp b/src/qml/debugger/qqmlprofiler.cpp index 8d60325a19..629d5cb7b8 100644 --- a/src/qml/debugger/qqmlprofiler.cpp +++ b/src/qml/debugger/qqmlprofiler.cpp @@ -45,7 +45,9 @@ QT_BEGIN_NAMESPACE QQmlProfiler::QQmlProfiler() : featuresEnabled(0) { static int metatype = qRegisterMetaType<QVector<QQmlProfilerData> >(); + static int metatype2 = qRegisterMetaType<QQmlProfiler::LocationHash> (); Q_UNUSED(metatype); + Q_UNUSED(metatype2); m_timer.start(); } @@ -62,8 +64,18 @@ void QQmlProfiler::stopProfiling() void QQmlProfiler::reportData() { - emit dataReady(m_data); - m_data.clear(); + LocationHash resolved; + resolved.reserve(m_locations.size()); + for (auto it = m_locations.constBegin(), end = m_locations.constEnd(); it != end; ++it) + resolved.insert(it.key(), it.value()); + + // This unrefs all the objects. We have to make sure we do this in the GUI thread. Also, it's + // a good idea to release the memory before creating the packets to be sent. + m_locations.clear(); + + QVector<QQmlProfilerData> data; + data.swap(m_data); + emit dataReady(data, resolved); } QT_END_NAMESPACE |